(* RUN: grep {Ty04.*i42} < %t.ll
*)
group "i42";
- let ty = make_integer_type 42 in
+ let ty = integer_type 42 in
insist (define_type_name "Ty04" ty m);
(* RUN: grep {Ty05.*float} < %t.ll
(* RUN: grep {Ty07.*i32.*i1, double} < %t.ll
*)
group "function";
- let ty = make_function_type i32_type [| i1_type; double_type |] false in
+ 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 (not (is_var_arg ty));
(* RUN: grep {Ty08.*\.\.\.} < %t.ll
*)
- group "vararg";
- let ty = make_function_type void_type [| i32_type |] true in
+ group "var arg function";
+ let ty = var_arg_function_type void_type [| i32_type |] in
insist (define_type_name "Ty08" ty m);
insist (is_var_arg ty);
(* RUN: grep {Ty09.*\\\[7 x i8\\\]} < %t.ll
*)
group "array";
- let ty = make_array_type i8_type 7 in
+ let ty = array_type i8_type 7 in
insist (define_type_name "Ty09" ty m);
insist (7 = array_length ty);
insist (i8_type == element_type ty);
(* RUN: grep {Ty10.*float\*} < %t.ll
*)
group "pointer";
- let ty = make_pointer_type float_type in
+ 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);
(* RUN: grep {Ty11.*\<4 x i16\>} < %t.ll
*)
group "vector";
- let ty = make_vector_type i16_type 4 in
+ let ty = vector_type i16_type 4 in
insist (define_type_name "Ty11" ty m);
insist (i16_type == element_type ty);
insist (4 = vector_size ty);
(* RUN: grep {Ty12.*opaque} < %t.ll
*)
group "opaque";
- let ty = make_opaque_type () in
+ let ty = opaque_type () in
insist (define_type_name "Ty12" ty m);
insist (ty == ty);
- insist (ty <> make_opaque_type ());
+ insist (ty <> opaque_type ());
(* RUN: grep -v {Ty13} < %t.ll
*)
group "delete";
- let ty = make_opaque_type () in
+ let ty = opaque_type () in
insist (define_type_name "Ty13" ty m);
- delete_type_name "Ty13" m
+ delete_type_name "Ty13" m;
+
+ (* RUN: grep -v {RecursiveTy.*RecursiveTy} < %t.ll
+ *)
+ group "recursive";
+ let ty = opaque_type () in
+ let th = handle_to_type ty in
+ refine_type ty (pointer_type ty);
+ let ty = type_of_handle th in
+ insist (define_type_name "RecursiveTy" ty m);
+ insist (ty == element_type ty)
(*===-- Constants ---------------------------------------------------------===*)
(* RUN: grep {Const01.*i32.*-1} < %t.ll
*)
group "int";
- let c = make_int_constant i32_type (-1) true in
+ let c = const_int i32_type (-1) in
ignore (define_global "Const01" c m);
insist (i32_type = type_of c);
insist (is_constant c);
(* RUN: grep {Const02.*i64.*-1} < %t.ll
*)
group "sext int";
- let c = make_int_constant i64_type (-1) true in
+ let c = const_int i64_type (-1) in
ignore (define_global "Const02" c m);
insist (i64_type = type_of c);
(* RUN: grep {Const03.*i64.*4294967295} < %t.ll
*)
group "zext int64";
- let c = make_int64_constant i64_type (Int64.of_string "4294967295") false in
+ let c = const_of_int64 i64_type (Int64.of_string "4294967295") false in
ignore (define_global "Const03" c m);
insist (i64_type = type_of c);
(* RUN: grep {Const04.*"cruel\\\\00world"} < %t.ll
*)
group "string";
- let c = make_string_constant "cruel\000world" false in
+ let c = const_string "cruel\000world" in
ignore (define_global "Const04" c m);
- insist ((make_array_type i8_type 11) = type_of c);
+ insist ((array_type i8_type 11) = type_of c);
(* RUN: grep {Const05.*"hi\\\\00again\\\\00"} < %t.ll
*)
- group "string w/ null";
- let c = make_string_constant "hi\000again" true in
+ group "stringz";
+ let c = const_stringz "hi\000again" in
ignore (define_global "Const05" c m);
- insist ((make_array_type i8_type 9) = type_of c);
+ insist ((array_type i8_type 9) = type_of c);
(* RUN: grep {Const06.*3.1459} < %t.ll
*)
group "real";
- let c = make_real_constant double_type 3.1459 in
+ let c = const_float double_type 3.1459 in
ignore (define_global "Const06" c m);
insist (double_type = type_of c);
- let one = make_int_constant i16_type 1 true in
- let two = make_int_constant i16_type 2 true in
- let three = make_int_constant i32_type 3 true in
- let four = make_int_constant i32_type 4 true in
+ let one = const_int i16_type 1 in
+ let two = const_int i16_type 2 in
+ let three = const_int i32_type 3 in
+ let four = const_int i32_type 4 in
(* RUN: grep {Const07.*\\\[ i32 3, i32 4 \\\]} < %t.ll
*)
group "array";
- let c = make_array_constant i32_type [| three; four |] in
+ let c = const_array i32_type [| three; four |] in
ignore (define_global "Const07" c m);
- insist ((make_array_type i32_type 2) = (type_of c));
+ insist ((array_type i32_type 2) = (type_of c));
(* RUN: grep {Const08.*< i16 1, i16 2.* >} < %t.ll
*)
group "vector";
- let c = make_vector_constant [| one; two; one; two;
- one; two; one; two |] in
+ let c = const_vector [| one; two; one; two;
+ one; two; one; two |] in
ignore (define_global "Const08" c m);
- insist ((make_vector_type i16_type 8) = (type_of c));
+ insist ((vector_type i16_type 8) = (type_of c));
(* RUN: grep {Const09.*\{ i16, i16, i32, i32 \} \{} < %t.ll
*)
group "structure";
- let c = make_struct_constant [| one; two; three; four |] false in
+ let c = const_struct [| one; two; three; four |] in
ignore (define_global "Const09" c m);
- insist ((make_struct_type [| i16_type; i16_type; i32_type; i32_type |] false)
+ insist ((struct_type [| i16_type; i16_type; i32_type; i32_type |])
= (type_of c));
(* RUN: grep {Const10.*zeroinit} < %t.ll
*)
group "null";
- let c = make_null (make_struct_type [| i1_type; i8_type;
- i64_type; double_type |] true) in
+ let c = const_null (packed_struct_type [| i1_type; i8_type;
+ i64_type; double_type |]) in
ignore (define_global "Const10" c m);
(* RUN: grep {Const11.*-1} < %t.ll
*)
group "all ones";
- let c = make_all_ones i64_type in
+ let c = const_all_ones i64_type in
ignore (define_global "Const11" c m);
(* RUN: grep {Const12.*undef} < %t.ll
*)
group "undef";
- let c = make_undef i1_type in
+ let c = undef i1_type in
ignore (define_global "Const12" c m);
insist (i1_type = type_of c);
- insist (is_undef c)
+ insist (is_undef c);
+
+ group "constant arithmetic";
+ (* RUN: grep {ConstNeg.*sub} < %t.ll
+ * RUN: grep {ConstNot.*xor} < %t.ll
+ * RUN: grep {ConstAdd.*add} < %t.ll
+ * RUN: grep {ConstSub.*sub} < %t.ll
+ * RUN: grep {ConstMul.*mul} < %t.ll
+ * RUN: grep {ConstUDiv.*udiv} < %t.ll
+ * RUN: grep {ConstSDiv.*sdiv} < %t.ll
+ * RUN: grep {ConstFDiv.*fdiv} < %t.ll
+ * RUN: grep {ConstURem.*urem} < %t.ll
+ * RUN: grep {ConstSRem.*srem} < %t.ll
+ * RUN: grep {ConstFRem.*frem} < %t.ll
+ * RUN: grep {ConstAnd.*and} < %t.ll
+ * RUN: grep {ConstOr.*or} < %t.ll
+ * RUN: grep {ConstXor.*xor} < %t.ll
+ * RUN: grep {ConstICmp.*icmp} < %t.ll
+ * RUN: grep {ConstFCmp.*fcmp} < %t.ll
+ *)
+ let void_ptr = pointer_type i8_type in
+ let five = const_int i64_type 5 in
+ let ffive = const_uitofp five double_type in
+ let foldbomb_gv = define_global "FoldBomb" (const_null i8_type) m in
+ let foldbomb = const_ptrtoint foldbomb_gv i64_type in
+ let ffoldbomb = const_uitofp foldbomb double_type in
+ ignore (define_global "ConstNeg" (const_neg foldbomb) m);
+ ignore (define_global "ConstNot" (const_not foldbomb) m);
+ ignore (define_global "ConstAdd" (const_add foldbomb five) m);
+ ignore (define_global "ConstSub" (const_sub foldbomb five) m);
+ ignore (define_global "ConstMul" (const_mul foldbomb five) m);
+ ignore (define_global "ConstUDiv" (const_udiv foldbomb five) m);
+ ignore (define_global "ConstSDiv" (const_sdiv foldbomb five) m);
+ ignore (define_global "ConstFDiv" (const_fdiv ffoldbomb ffive) m);
+ ignore (define_global "ConstURem" (const_urem foldbomb five) m);
+ ignore (define_global "ConstSRem" (const_srem foldbomb five) m);
+ ignore (define_global "ConstFRem" (const_frem ffoldbomb ffive) m);
+ 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);
+
+ group "constant casts";
+ (* RUN: grep {ConstTrunc.*trunc} < %t.ll
+ * RUN: grep {ConstSExt.*sext} < %t.ll
+ * RUN: grep {ConstZExt.*zext} < %t.ll
+ * RUN: grep {ConstFPTrunc.*fptrunc} < %t.ll
+ * RUN: grep {ConstFPExt.*fpext} < %t.ll
+ * RUN: grep {ConstUIToFP.*uitofp} < %t.ll
+ * RUN: grep {ConstSIToFP.*sitofp} < %t.ll
+ * RUN: grep {ConstFPToUI.*fptoui} < %t.ll
+ * RUN: grep {ConstFPToSI.*fptosi} < %t.ll
+ * RUN: grep {ConstPtrToInt.*ptrtoint} < %t.ll
+ * RUN: grep {ConstIntToPtr.*inttoptr} < %t.ll
+ * RUN: grep {ConstBitCast.*bitcast} < %t.ll
+ *)
+ let i128_type = integer_type 128 in
+ ignore (define_global "ConstTrunc" (const_trunc (const_add foldbomb five)
+ i8_type) m);
+ ignore (define_global "ConstSExt" (const_sext foldbomb i128_type) m);
+ ignore (define_global "ConstZExt" (const_zext foldbomb i128_type) m);
+ ignore (define_global "ConstFPTrunc" (const_fptrunc ffoldbomb float_type) m);
+ ignore (define_global "ConstFPExt" (const_fpext ffoldbomb fp128_type) m);
+ ignore (define_global "ConstUIToFP" (const_uitofp foldbomb double_type) m);
+ ignore (define_global "ConstSIToFP" (const_sitofp foldbomb double_type) m);
+ ignore (define_global "ConstFPToUI" (const_fptoui ffoldbomb i32_type) m);
+ ignore (define_global "ConstFPToSI" (const_fptosi ffoldbomb i32_type) m);
+ ignore (define_global "ConstPtrToInt" (const_ptrtoint
+ (const_gep (const_null (pointer_type i8_type))
+ [| const_int i32_type 1 |])
+ i32_type) m);
+ ignore (define_global "ConstIntToPtr" (const_inttoptr (const_add foldbomb five)
+ void_ptr) m);
+ ignore (define_global "ConstBitCast" (const_bitcast ffoldbomb i64_type) m);
+
+ group "misc constants";
+ (* RUN: grep {ConstSizeOf.*getelementptr.*null} < %t.ll
+ * RUN: grep {ConstGEP.*getelementptr} < %t.ll
+ * RUN: grep {ConstSelect.*select} < %t.ll
+ * RUN: grep {ConstExtractElement.*extractelement} < %t.ll
+ * RUN: grep {ConstInsertElement.*insertelement} < %t.ll
+ * RUN: grep {ConstShuffleVector.*shufflevector} < %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_int i8_type (-1))
+ (const_int i8_type 0)) m);
+ let zero = const_int i32_type 0 in
+ let one = const_int i32_type 1 in
+ ignore (define_global "ConstExtractElement" (const_extractelement
+ (const_vector [| zero; one; zero; one |])
+ (const_trunc foldbomb i32_type)) m);
+ ignore (define_global "ConstInsertElement" (const_insertelement
+ (const_vector [| zero; one; zero; one |])
+ zero (const_trunc foldbomb i32_type)) m);
+ ignore (define_global "ConstShuffleVector" (const_shufflevector
+ (const_vector [| zero; one |])
+ (const_vector [| one; zero |])
+ (const_bitcast foldbomb (vector_type i32_type 2))) m)
(*===-- Global Values -----------------------------------------------------===*)
let test_global_values () =
let (++) x f = f x; x in
- let zero32 = make_null i32_type in
+ let zero32 = const_null i32_type in
(* RUN: grep {GVal01} < %t.ll
*)
let test_global_variables () =
let (++) x f = f x; x in
- let fourty_two32 = make_int_constant i32_type 42 false in
+ let fourty_two32 = const_int i32_type 42 in
(* RUN: grep {GVar01.*external} < %t.ll
*)
*)
group "delete";
let g = define_global "GVar05" fourty_two32 m in
- delete_global g
+ delete_global g;
+
+ (* RUN: grep -v {ConstGlobalVar.*constant} < %t.ll
+ *)
+ group "constant";
+ let g = define_global "ConstGlobalVar" fourty_two32 m in
+ insist (not (is_global_constant g));
+ set_global_constant true g;
+ insist (is_global_constant g)
(*===-- Functions ---------------------------------------------------------===*)
let test_functions () =
- let ty = make_function_type i32_type [| i32_type; i64_type |] false in
- let pty = make_pointer_type ty in
+ let ty = function_type i32_type [| i32_type; i64_type |] in
+ let pty = pointer_type ty in
(* RUN: grep {declare i32 @Fn1\(i32, i64\)} < %t.ll
*)
(*===-- Basic Blocks ------------------------------------------------------===*)
let test_basic_blocks () =
- let ty = make_function_type void_type [| |] false in
+ let ty = function_type void_type [| |] in
(* RUN: grep {Bb1} < %t.ll
*)
let bb = entry_block fn in
insist (bb = block_of_value (value_of_block bb));
insist (value_is_block (value_of_block bb));
- insist (not (value_is_block (make_null i32_type)))
+ insist (not (value_is_block (const_null i32_type)))
(*===-- Builder -----------------------------------------------------------===*)
begin
(* RUN: grep {ret void} < %t.ll
*)
- let fty = make_function_type void_type [| |] false in
+ let fty = function_type void_type [| |] in
let fn = declare_function "X6" fty m in
let b = builder_at_end (append_block "Bb01" fn) in
ignore (build_ret_void b)
end;
(* The rest of the tests will use one big function. *)
- let fty = make_function_type i32_type [| i32_type; i32_type |] false in
+ let fty = function_type i32_type [| i32_type; i32_type |] in
let fn = define_function "X7" fty m in
let atentry = builder_at_end (entry_block fn) in
let p1 = param fn 0 ++ set_value_name "P1" in
end;
group "casts"; begin
- let void_ptr = make_pointer_type i8_type in
+ let void_ptr = pointer_type i8_type in
(* RUN: grep {Inst28.*trunc.*P1.*i8} < %t.ll
* RUN: grep {Inst29.*zext.*Inst28.*i32} < %t.ll
let inst46 = build_icmp Icmp_eq p1 p2 "Inst46" atentry in
ignore (build_select inst46 p1 p2 "Inst47" atentry);
ignore (build_va_arg
- (make_null (make_pointer_type (make_pointer_type i8_type)))
+ (const_null (pointer_type (pointer_type i8_type)))
i32_type "Inst48" atentry);
(* Set up some vector vregs. *)
- let one = make_int_constant i32_type (-1) true in
- let zero = make_int_constant i32_type 1 true in
- let t1 = make_vector_constant [| one; zero; one; zero |] in
- let t2 = make_vector_constant [| zero; one; zero; one |] in
- let t3 = make_vector_constant [| one; one; zero; zero |] in
+ let one = const_int i32_type (-1) in
+ let zero = const_int i32_type 1 in
+ let t1 = const_vector [| one; zero; one; zero |] in
+ let t2 = const_vector [| zero; one; zero; one |] in
+ 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