Expose Function::viewCFG and Function::viewCFGOnly to bindings.
[oota-llvm.git] / lib / Analysis / Analysis.cpp
1 //===-- Analysis.cpp ------------------------------------------------------===//
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 #include "llvm-c/Analysis.h"
11 #include "llvm/Analysis/Verifier.h"
12 #include <fstream>
13 #include <cstring>
14
15 using namespace llvm;
16
17 int LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
18                      char **OutMessages) {
19   std::string Messages;
20   
21   int Result = verifyModule(*unwrap(M),
22                             static_cast<VerifierFailureAction>(Action),
23                             OutMessages? &Messages : 0);
24   
25   if (OutMessages)
26     *OutMessages = strdup(Messages.c_str());
27   
28   return Result;
29 }
30
31 int LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
32   return verifyFunction(*unwrap<Function>(Fn),
33                         static_cast<VerifierFailureAction>(Action));
34 }
35
36 void LLVMViewFunctionCFG(LLVMValueRef Fn) {
37   Function *F = unwrap<Function>(Fn);
38   F->viewCFG();
39 }
40
41 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
42   Function *F = unwrap<Function>(Fn);
43   F->viewCFGOnly();
44 }