llvm.org GIT mirror llvm / 21491ed
[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 Gordon Henriksen 12 years ago
4 changed file(s) with 30 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
618618 llvalue = "llvm_build_cond_br"
619619 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
620620 = "llvm_build_switch"
621 external add_case : llvalue -> llvalue -> llbasicblock -> unit
622 = "llvm_add_case"
621623 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
622624 llbasicblock -> string -> llbuilder -> llvalue
623625 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
12111211 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
12121212 llvalue = "llvm_build_cond_br"
12131213
1214 (** [build_switch case elsebb b] creates an empty
1214 (** [build_switch case elsebb count b] creates an empty
12151215 [switch %case, %elsebb]
1216 instruction at the position specified by the instruction builder [b].
1216 instruction at the position specified by the instruction builder [b] with
1217 space reserved for [count] cases.
12171218 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
12181219 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
12191220 = "llvm_build_switch"
1221
1222 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1223 when its input matches the constant [onval].
1224 See the method [llvm::SwitchInst::addCase]. **)
1225 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1226 = "llvm_add_case"
12201227
12211228 (** [build_invoke fn args tobb unwindbb name b] creates an
12221229 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
847847 return LLVMBuildSwitch(Builder_val(B), Of, Else, Int_val(EstimatedCount));
848848 }
849849
850 CAMLprim value llvm_add_case(LLVMValueRef Switch,
851 LLVMValueRef OnVal,
852 LLVMBasicBlockRef Dest) {
853 LLVMAddCase(Switch, OnVal, Dest);
854 return Val_unit;
855 }
856
850857 /* llvalue -> llvalue array -> llbasicblock -> llbasicblock -> string ->
851858 llbuilder -> llvalue */
852859 CAMLprim LLVMValueRef llvm_build_invoke_nat(LLVMValueRef Fn, value Args,
824824 ignore (build_cond_br cond bb03 bb00 b)
825825 end;
826826
827 (* TODO: Switch *)
827 group "switch"; begin
828 (* RUN: grep {switch.*P1.*SwiBlock3} < %t.ll
829 * RUN: grep {2,.*SwiBlock2} < %t.ll
830 *)
831 let bb1 = append_block "SwiBlock1" fn in
832 let bb2 = append_block "SwiBlock2" fn in
833 ignore (build_unreachable (builder_at_end bb2));
834 let bb3 = append_block "SwiBlock3" fn in
835 ignore (build_unreachable (builder_at_end bb3));
836 let si = build_switch p1 bb3 1 (builder_at_end bb1) in
837 ignore (add_case si (const_int i32_type 2) bb2)
838 end;
828839
829840 group "invoke"; begin
830841 (* RUN: grep {Inst02.*invoke.*P1.*P2} < %t.ll