1 //===- analysis.go - Bindings for analysis --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines bindings for the analysis component.
12 //===----------------------------------------------------------------------===//
17 #include "llvm-c/Analysis.h" // If you are getting an error here read bindings/go/README.txt
23 type VerifierFailureAction C.LLVMVerifierFailureAction
26 // verifier will print to stderr and abort()
27 AbortProcessAction VerifierFailureAction = C.LLVMAbortProcessAction
28 // verifier will print to stderr and return 1
29 PrintMessageAction VerifierFailureAction = C.LLVMPrintMessageAction
30 // verifier will just return 1
31 ReturnStatusAction VerifierFailureAction = C.LLVMReturnStatusAction
34 // Verifies that a module is valid, taking the specified action if not.
35 // Optionally returns a human-readable description of any invalid constructs.
36 func VerifyModule(m Module, a VerifierFailureAction) error {
38 broken := C.LLVMVerifyModule(m.C, C.LLVMVerifierFailureAction(a), &cmsg)
40 // C++'s verifyModule means isModuleBroken, so it returns false if
41 // there are no errors
43 err := errors.New(C.GoString(cmsg))
44 C.LLVMDisposeMessage(cmsg)
50 var verifyFunctionError = errors.New("Function is broken")
52 // Verifies that a single function is valid, taking the specified action.
53 // Useful for debugging.
54 func VerifyFunction(f Value, a VerifierFailureAction) error {
55 broken := C.LLVMVerifyFunction(f.C, C.LLVMVerifierFailureAction(a))
57 // C++'s verifyFunction means isFunctionBroken, so it returns false if
58 // there are no errors
60 return verifyFunctionError
65 // Open up a ghostview window that displays the CFG of the current function.
66 // Useful for debugging.
67 func ViewFunctionCFG(f Value) { C.LLVMViewFunctionCFG(f.C) }
68 func ViewFunctionCFGOnly(f Value) { C.LLVMViewFunctionCFGOnly(f.C) }