From d6d018589cf3de22bc5d0b2b229e37cdb6afca61 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 31 Mar 2008 16:22:09 +0000 Subject: [PATCH] Expose Function::viewCFG and Function::viewCFGOnly to bindings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48982 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/ocaml/analysis/analysis_ocaml.c | 12 ++++++++++++ bindings/ocaml/analysis/llvm_analysis.ml | 3 +++ bindings/ocaml/analysis/llvm_analysis.mli | 11 +++++++++++ include/llvm-c/Analysis.h | 4 ++++ lib/Analysis/Analysis.cpp | 9 +++++++++ 5 files changed, 39 insertions(+) diff --git a/bindings/ocaml/analysis/analysis_ocaml.c b/bindings/ocaml/analysis/analysis_ocaml.c index e57c5a56d73..97167055f70 100644 --- a/bindings/ocaml/analysis/analysis_ocaml.c +++ b/bindings/ocaml/analysis/analysis_ocaml.c @@ -58,3 +58,15 @@ CAMLprim value llvm_assert_valid_function(LLVMValueRef Fn) { LLVMVerifyFunction(Fn, LLVMAbortProcessAction); return Val_unit; } + +/* Llvm.llvalue -> unit */ +CAMLprim value llvm_view_function_cfg(LLVMValueRef Fn) { + LLVMViewFunctionCFG(Fn); + return Val_unit; +} + +/* Llvm.llvalue -> unit */ +CAMLprim value llvm_view_function_cfg_only(LLVMValueRef Fn) { + LLVMViewFunctionCFGOnly(Fn); + return Val_unit; +} diff --git a/bindings/ocaml/analysis/llvm_analysis.ml b/bindings/ocaml/analysis/llvm_analysis.ml index f4379f8f17e..fc4d2037074 100644 --- a/bindings/ocaml/analysis/llvm_analysis.ml +++ b/bindings/ocaml/analysis/llvm_analysis.ml @@ -17,3 +17,6 @@ external assert_valid_module : Llvm.llmodule -> unit external assert_valid_function : Llvm.llvalue -> unit = "llvm_assert_valid_function" +external view_function_cfg : Llvm.llvalue -> unit = "llvm_view_function_cfg" +external view_function_cfg_only : Llvm.llvalue -> unit + = "llvm_view_function_cfg_only" diff --git a/bindings/ocaml/analysis/llvm_analysis.mli b/bindings/ocaml/analysis/llvm_analysis.mli index a97bd7e9e26..793f482e3c6 100644 --- a/bindings/ocaml/analysis/llvm_analysis.mli +++ b/bindings/ocaml/analysis/llvm_analysis.mli @@ -33,3 +33,14 @@ external assert_valid_module : Llvm.llmodule -> unit [llvm::verifyFunction]. *) external assert_valid_function : Llvm.llvalue -> unit = "llvm_assert_valid_function" + +(** [view_function_cfg f] opens up a ghostscript window displaying the CFG of + the current function with the code for each basic block inside. + See [llvm::Function::viewCFG]. *) +external view_function_cfg : Llvm.llvalue -> unit = "llvm_view_function_cfg" + +(** [view_function_cfg_only f] works just like [view_function_cfg], but does not + include the contents of basic blocks into the nodes. + See [llvm::Function::viewCFGOnly]. *) +external view_function_cfg_only : Llvm.llvalue -> unit + = "llvm_view_function_cfg_only" diff --git a/include/llvm-c/Analysis.h b/include/llvm-c/Analysis.h index e8f27871cc1..68d8e65db49 100644 --- a/include/llvm-c/Analysis.h +++ b/include/llvm-c/Analysis.h @@ -43,6 +43,10 @@ int LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, for debugging. */ int LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action); +/* Open up a ghostview window that displays the CFG of the current function. + Useful for debugging. */ +void LLVMViewFunctionCFG(LLVMValueRef Fn); +void LLVMViewFunctionCFGOnly(LLVMValueRef Fn); #ifdef __cplusplus } diff --git a/lib/Analysis/Analysis.cpp b/lib/Analysis/Analysis.cpp index 6b741bc5bdf..493c6e88b3f 100644 --- a/lib/Analysis/Analysis.cpp +++ b/lib/Analysis/Analysis.cpp @@ -33,3 +33,12 @@ int LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) { static_cast(Action)); } +void LLVMViewFunctionCFG(LLVMValueRef Fn) { + Function *F = unwrap(Fn); + F->viewCFG(); +} + +void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) { + Function *F = unwrap(Fn); + F->viewCFGOnly(); +} -- 2.34.1