[PR-2610] Adding Ocaml bindings for Switch::addCase.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54571 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gordon Henriksen 2008-08-09 01:55:52 +00:00
parent b75de8d843
commit 21491edbf4
4 changed files with 30 additions and 3 deletions

View File

@ -619,6 +619,8 @@ external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
llvalue = "llvm_build_cond_br"
external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
= "llvm_build_switch"
external add_case : llvalue -> llvalue -> llbasicblock -> unit
= "llvm_add_case"
external build_invoke : llvalue -> llvalue array -> llbasicblock ->
llbasicblock -> string -> llbuilder -> llvalue
= "llvm_build_invoke_bc" "llvm_build_invoke_nat"

View File

@ -1212,13 +1212,20 @@ external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
llvalue = "llvm_build_cond_br"
(** [build_switch case elsebb b] creates an empty
(** [build_switch case elsebb count b] creates an empty
[switch %case, %elsebb]
instruction at the position specified by the instruction builder [b].
instruction at the position specified by the instruction builder [b] with
space reserved for [count] cases.
See the method [llvm::LLVMBuilder::CreateSwitch]. *)
external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
= "llvm_build_switch"
(** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
when its input matches the constant [onval].
See the method [llvm::SwitchInst::addCase]. **)
external add_case : llvalue -> llvalue -> llbasicblock -> unit
= "llvm_add_case"
(** [build_invoke fn args tobb unwindbb name b] creates an
[%name = invoke %fn(args) to %tobb unwind %unwindbb]
instruction at the position specified by the instruction builder [b].

View File

@ -848,6 +848,13 @@ CAMLprim LLVMValueRef llvm_build_switch(LLVMValueRef Of,
return LLVMBuildSwitch(Builder_val(B), Of, Else, Int_val(EstimatedCount));
}
CAMLprim value llvm_add_case(LLVMValueRef Switch,
LLVMValueRef OnVal,
LLVMBasicBlockRef Dest) {
LLVMAddCase(Switch, OnVal, Dest);
return Val_unit;
}
/* llvalue -> llvalue array -> llbasicblock -> llbasicblock -> string ->
llbuilder -> llvalue */
CAMLprim LLVMValueRef llvm_build_invoke_nat(LLVMValueRef Fn, value Args,

View File

@ -825,7 +825,18 @@ let test_builder () =
ignore (build_cond_br cond bb03 bb00 b)
end;
(* TODO: Switch *)
group "switch"; begin
(* RUN: grep {switch.*P1.*SwiBlock3} < %t.ll
* RUN: grep {2,.*SwiBlock2} < %t.ll
*)
let bb1 = append_block "SwiBlock1" fn in
let bb2 = append_block "SwiBlock2" fn in
ignore (build_unreachable (builder_at_end bb2));
let bb3 = append_block "SwiBlock3" fn in
ignore (build_unreachable (builder_at_end bb3));
let si = build_switch p1 bb3 1 (builder_at_end bb1) in
ignore (add_case si (const_int i32_type 2) bb2)
end;
group "invoke"; begin
(* RUN: grep {Inst02.*invoke.*P1.*P2} < %t.ll