-(* RUN: %ocamlc llvm.cma llvm_analysis.cma llvm_bitwriter.cma %s -o %t
+(* RUN: %ocamlc -warn-error A llvm.cma llvm_analysis.cma llvm_bitwriter.cma %s -o %t
* RUN: ./%t %t.bc
* RUN: llvm-dis < %t.bc > %t.ll
*)
let insist cond =
incr case_num;
- let msg = if cond then " pass " else begin
- exit_status := 10;
- " FAIL "
- end in
- prerr_endline (msg ^ (string_of_int !case_num))
+ if not cond then exit_status := 10;
+ prerr_endline (" " ^ (string_of_int !case_num) ^ if cond then ""
+ else " FAIL")
let suite name f =
prerr_endline (name ^ ":");
let m = create_module filename
+(*===-- Target ------------------------------------------------------------===*)
+
+let test_target () =
+ begin group "triple";
+ (* RUN: grep "i686-apple-darwin8" < %t.ll
+ *)
+ let trip = "i686-apple-darwin8" in
+ set_target_triple trip m;
+ insist (trip = target_triple m)
+ end;
+
+ begin group "layout";
+ (* RUN: grep "bogus" < %t.ll
+ *)
+ let layout = "bogus" in
+ set_data_layout layout m;
+ insist (layout = data_layout m)
+ end
+
(*===-- Types -------------------------------------------------------------===*)
let test_types () =
*)
group "void";
insist (define_type_name "Ty01" void_type m);
- insist (Void_type == classify_type void_type);
+ insist (TypeKind.Void == classify_type void_type);
(* RUN: grep {Ty02.*i1} < %t.ll
*)
group "i1";
insist (define_type_name "Ty02" i1_type m);
- insist (Integer_type == classify_type i1_type);
+ insist (TypeKind.Integer == classify_type i1_type);
(* RUN: grep {Ty03.*i32} < %t.ll
*)
*)
group "float";
insist (define_type_name "Ty05" float_type m);
- insist (Float_type == classify_type float_type);
+ insist (TypeKind.Float == classify_type float_type);
(* RUN: grep {Ty06.*double} < %t.ll
*)
group "double";
insist (define_type_name "Ty06" double_type m);
- insist (Double_type == classify_type double_type);
+ insist (TypeKind.Double == classify_type double_type);
(* RUN: grep {Ty07.*i32.*i1, double} < %t.ll
*)
group "function";
let ty = function_type i32_type [| i1_type; double_type |] in
insist (define_type_name "Ty07" ty m);
- insist (Function_type = classify_type ty);
+ insist (TypeKind.Function = classify_type ty);
insist (not (is_var_arg ty));
insist (i32_type == return_type ty);
insist (double_type == (param_types ty).(1));
insist (define_type_name "Ty09" ty m);
insist (7 = array_length ty);
insist (i8_type == element_type ty);
- insist (Array_type == classify_type ty);
+ insist (TypeKind.Array == classify_type ty);
- (* RUN: grep {Ty10.*float\*} < %t.ll
- *)
- group "pointer";
- let ty = pointer_type float_type in
- insist (define_type_name "Ty10" ty m);
- insist (float_type == element_type ty);
- insist (Pointer_type == classify_type ty);
+ begin group "pointer";
+ (* RUN: grep {UnqualPtrTy.*float\*} < %t.ll
+ *)
+ let ty = pointer_type float_type in
+ insist (define_type_name "UnqualPtrTy" ty m);
+ insist (float_type == element_type ty);
+ insist (0 == address_space ty);
+ insist (TypeKind.Pointer == classify_type ty)
+ end;
+
+ begin group "qualified_pointer";
+ (* RUN: grep {QualPtrTy.*i8.*3.*\*} < %t.ll
+ *)
+ let ty = qualified_pointer_type i8_type 3 in
+ insist (define_type_name "QualPtrTy" ty m);
+ insist (i8_type == element_type ty);
+ insist (3 == address_space ty)
+ end;
(* RUN: grep {Ty11.*\<4 x i16\>} < %t.ll
*)
ignore (define_global "ConstAnd" (const_and foldbomb five) m);
ignore (define_global "ConstOr" (const_or foldbomb five) m);
ignore (define_global "ConstXor" (const_xor foldbomb five) m);
- ignore (define_global "ConstICmp" (const_icmp Icmp_sle foldbomb five) m);
- ignore (define_global "ConstFCmp" (const_fcmp Fcmp_ole ffoldbomb ffive) m);
+ ignore (define_global "ConstICmp" (const_icmp Icmp.Sle foldbomb five) m);
+ ignore (define_global "ConstFCmp" (const_fcmp Fcmp.Ole ffoldbomb ffive) m);
group "constant casts";
(* RUN: grep {ConstTrunc.*trunc} < %t.ll
ignore (define_global "ConstSizeOf" (size_of (pointer_type i8_type)) m);
ignore (define_global "ConstGEP" (const_gep foldbomb_gv [| five |]) m);
ignore (define_global "ConstSelect" (const_select
- (const_icmp Icmp_sle foldbomb five)
+ (const_icmp Icmp.Sle foldbomb five)
(const_int i8_type (-1))
(const_int i8_type 0)) m);
let zero = const_int i32_type 0 in
*)
group "linkage";
let g = define_global "GVal02" zero32 m ++
- set_linkage Link_once_linkage in
- insist (Link_once_linkage = linkage g);
+ set_linkage Linkage.Link_once in
+ insist (Linkage.Link_once = linkage g);
(* RUN: grep {GVal03.*Hanalei} < %t.ll
*)
*)
group "visibility";
let g = define_global "GVal04" zero32 m ++
- set_visibility Hidden_visibility in
- insist (Hidden_visibility = visibility g);
+ set_visibility Visibility.Hidden in
+ insist (Visibility.Hidden = visibility g);
(* RUN: grep {GVal05.*align 128} < %t.ll
*)
*)
group "callconv";
let fn = define_function "Fn5" ty m in
- insist (ccc = function_call_conv fn);
- set_function_call_conv fastcc fn;
- insist (fastcc = function_call_conv fn);
- ignore (build_unreachable (builder_at_end (entry_block fn)))
+ insist (CallConv.c = function_call_conv fn);
+ set_function_call_conv CallConv.fast fn;
+ insist (CallConv.fast = function_call_conv fn);
+ ignore (build_unreachable (builder_at_end (entry_block fn)));
+
+ begin group "collector";
+ (* RUN: grep {Fn6.*gc.*shadowstack} < %t.ll
+ *)
+ let fn = define_function "Fn6" ty m in
+ insist (None = collector fn);
+ set_collector (Some "ocaml") fn;
+ insist (Some "ocaml" = collector fn);
+ set_collector None fn;
+ insist (None = collector fn);
+ set_collector (Some "shadowstack") fn;
+ ignore (build_unreachable (builder_at_end (entry_block fn)));
+ end
(*===-- Basic Blocks ------------------------------------------------------===*)
* RUN: grep {Inst42.*fcmp.*false.*F1.*F2} < %t.ll
* RUN: grep {Inst43.*fcmp.*true.*F2.*F1} < %t.ll
*)
- ignore (build_icmp Icmp_ne p1 p2 "Inst40" atentry);
- ignore (build_icmp Icmp_sle p2 p1 "Inst41" atentry);
- ignore (build_fcmp Fcmp_false f1 f2 "Inst42" atentry);
- ignore (build_fcmp Fcmp_true f2 f1 "Inst43" atentry)
+ ignore (build_icmp Icmp.Ne p1 p2 "Inst40" atentry);
+ ignore (build_icmp Icmp.Sle p2 p1 "Inst41" atentry);
+ ignore (build_fcmp Fcmp.False f1 f2 "Inst42" atentry);
+ ignore (build_fcmp Fcmp.True f2 f1 "Inst43" atentry)
end;
group "miscellaneous"; begin
- (* RUN: grep {Inst45.*call.*P2.*P1} < %t.ll
+ (* RUN: grep {CallInst.*call.*P2.*P1} < %t.ll
+ * RUN: grep {CallInst.*cc63} < %t.ll
* RUN: grep {Inst47.*select.*Inst46.*P1.*P2} < %t.ll
* RUN: grep {Inst48.*va_arg.*null.*i32} < %t.ll
* RUN: grep {Inst49.*extractelement.*Vec1.*P2} < %t.ll
* RUN: grep {Inst50.*insertelement.*Vec1.*P1.*P2} < %t.ll
* RUN: grep {Inst51.*shufflevector.*Vec1.*Vec2.*1.*1.*0.*0} < %t.ll
*)
- ignore (build_call fn [| p2; p1 |] "Inst45" atentry);
- let inst46 = build_icmp Icmp_eq p1 p2 "Inst46" atentry in
+ let ci = build_call fn [| p2; p1 |] "CallInst" atentry in
+ insist (CallConv.c = instruction_call_conv ci);
+ set_instruction_call_conv 63 ci;
+ insist (63 = instruction_call_conv ci);
+
+ let inst46 = build_icmp Icmp.Eq p1 p2 "Inst46" atentry in
ignore (build_select inst46 p1 p2 "Inst47" atentry);
ignore (build_va_arg
(const_null (pointer_type (pointer_type i8_type)))
let t3 = const_vector [| one; one; zero; zero |] in
let vec1 = build_insertelement t1 p1 p2 "Vec1" atentry in
let vec2 = build_insertelement t2 p1 p2 "Vec2" atentry in
- let vec3 = build_insertelement t3 p1 p2 "Vec3" atentry in
ignore (build_extractelement vec1 p2 "Inst49" atentry);
ignore (build_insertelement vec1 p1 p2 "Inst50" atentry);
end
+(*===-- Module Provider ---------------------------------------------------===*)
+
+let test_module_provider () =
+ let m = create_module "test" in
+ let mp = ModuleProvider.create m in
+ ModuleProvider.dispose mp
+
+
(*===-- Writer ------------------------------------------------------------===*)
let test_writer () =
(*===-- Driver ------------------------------------------------------------===*)
let _ =
+ suite "target" test_target;
suite "types" test_types;
suite "constants" test_constants;
suite "global values" test_global_values;
suite "functions" test_functions;
suite "basic blocks" test_basic_blocks;
suite "builder" test_builder;
+ suite "module provider" test_module_provider;
suite "writer" test_writer;
exit !exit_status