Skip to content

Commit

Permalink
Expose Function::viewCFG and Function::viewCFGOnly to bindings.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48982 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Erick Tryzelaar committed Mar 31, 2008
1 parent 86550b0 commit d6d0185
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bindings/ocaml/analysis/analysis_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions bindings/ocaml/analysis/llvm_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 11 additions & 0 deletions bindings/ocaml/analysis/llvm_analysis.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions include/llvm-c/Analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions lib/Analysis/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ int LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
static_cast<VerifierFailureAction>(Action));
}

void LLVMViewFunctionCFG(LLVMValueRef Fn) {
Function *F = unwrap<Function>(Fn);
F->viewCFG();
}

void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
Function *F = unwrap<Function>(Fn);
F->viewCFGOnly();
}

0 comments on commit d6d0185

Please sign in to comment.