83
|
1 //===- analysis.go - Bindings for analysis --------------------------------===//
|
|
2 //
|
|
3 // The LLVM Compiler Infrastructure
|
|
4 //
|
|
5 // This file is distributed under the University of Illinois Open Source
|
|
6 // License. See LICENSE.TXT for details.
|
|
7 //
|
|
8 //===----------------------------------------------------------------------===//
|
|
9 //
|
|
10 // This file defines bindings for the analysis component.
|
|
11 //
|
|
12 //===----------------------------------------------------------------------===//
|
|
13
|
|
14 package llvm
|
|
15
|
|
16 /*
|
|
17 #include "llvm-c/Analysis.h" // If you are getting an error here read bindings/go/README.txt
|
100
|
18 #include "llvm-c/Core.h"
|
83
|
19 #include <stdlib.h>
|
|
20 */
|
|
21 import "C"
|
|
22 import "errors"
|
|
23
|
|
24 type VerifierFailureAction C.LLVMVerifierFailureAction
|
|
25
|
|
26 const (
|
|
27 // verifier will print to stderr and abort()
|
|
28 AbortProcessAction VerifierFailureAction = C.LLVMAbortProcessAction
|
|
29 // verifier will print to stderr and return 1
|
|
30 PrintMessageAction VerifierFailureAction = C.LLVMPrintMessageAction
|
|
31 // verifier will just return 1
|
|
32 ReturnStatusAction VerifierFailureAction = C.LLVMReturnStatusAction
|
|
33 )
|
|
34
|
|
35 // Verifies that a module is valid, taking the specified action if not.
|
|
36 // Optionally returns a human-readable description of any invalid constructs.
|
|
37 func VerifyModule(m Module, a VerifierFailureAction) error {
|
|
38 var cmsg *C.char
|
|
39 broken := C.LLVMVerifyModule(m.C, C.LLVMVerifierFailureAction(a), &cmsg)
|
|
40
|
|
41 // C++'s verifyModule means isModuleBroken, so it returns false if
|
|
42 // there are no errors
|
|
43 if broken != 0 {
|
|
44 err := errors.New(C.GoString(cmsg))
|
|
45 C.LLVMDisposeMessage(cmsg)
|
|
46 return err
|
|
47 }
|
|
48 return nil
|
|
49 }
|
|
50
|
|
51 var verifyFunctionError = errors.New("Function is broken")
|
|
52
|
|
53 // Verifies that a single function is valid, taking the specified action.
|
|
54 // Useful for debugging.
|
|
55 func VerifyFunction(f Value, a VerifierFailureAction) error {
|
|
56 broken := C.LLVMVerifyFunction(f.C, C.LLVMVerifierFailureAction(a))
|
|
57
|
|
58 // C++'s verifyFunction means isFunctionBroken, so it returns false if
|
|
59 // there are no errors
|
|
60 if broken != 0 {
|
|
61 return verifyFunctionError
|
|
62 }
|
|
63 return nil
|
|
64 }
|
|
65
|
|
66 // Open up a ghostview window that displays the CFG of the current function.
|
|
67 // Useful for debugging.
|
|
68 func ViewFunctionCFG(f Value) { C.LLVMViewFunctionCFG(f.C) }
|
|
69 func ViewFunctionCFGOnly(f Value) { C.LLVMViewFunctionCFGOnly(f.C) }
|