Add support for inserting inline asm to ocaml.
[oota-llvm.git] / test / Bindings / Ocaml / vmcore.ml
index 10a20ea6f7c7957f5366fd863129a7b74c2940f1..40747f36111788d8b2d2287065fd2840c4bcc8f2 100644 (file)
@@ -185,6 +185,14 @@ let test_types () =
   let ty = opaque_type context in
   insist (define_type_name "delete_type" ty m);
   delete_type_name "delete_type" m;
+
+  (* RUN: grep {type_name.*opaque} < %t.ll
+   *)
+  group "type_name"; begin
+    let ty = opaque_type context in
+    insist (define_type_name "type_name" ty m);
+    insist ((type_by_name m "type_name") = Some ty)
+  end;
   
   (* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
    *)
@@ -292,7 +300,7 @@ let test_constants () =
   group "union";
   let t = union_type context [| i1_type; i16_type; i64_type; double_type |] in
   let c = const_union t one in
-  ignore (define_global "Const_union" c m);
+  ignore (define_global "const_union" c m);
   insist (t = (type_of c));
   
   (* RUN: grep {const_null.*zeroinit} < %t.ll
@@ -307,6 +315,13 @@ let test_constants () =
   group "all ones";
   let c = const_all_ones i64_type in
   ignore (define_global "const_all_ones" c m);
+
+  group "pointer null"; begin
+    (* RUN: grep {const_pointer_null = global i64\\* null} < %t.ll
+     *)
+    let c = const_pointer_null (pointer_type i64_type) in
+    ignore (define_global "const_pointer_null" c m);
+  end;
   
   (* RUN: grep {const_undef.*undef} < %t.ll
    *)
@@ -318,12 +333,25 @@ let test_constants () =
   
   group "constant arithmetic";
   (* RUN: grep {@const_neg = global i64 sub} < %t.ll
+   * RUN: grep {@const_nsw_neg = global i64 sub nsw } < %t.ll
+   * RUN: grep {@const_nuw_neg = global i64 sub nuw } < %t.ll
+   * RUN: grep {@const_fneg = global double fsub } < %t.ll
    * RUN: grep {@const_not = global i64 xor } < %t.ll
    * RUN: grep {@const_add = global i64 add } < %t.ll
+   * RUN: grep {@const_nsw_add = global i64 add nsw } < %t.ll
+   * RUN: grep {@const_nuw_add = global i64 add nuw } < %t.ll
+   * RUN: grep {@const_fadd = global double fadd } < %t.ll
    * RUN: grep {@const_sub = global i64 sub } < %t.ll
+   * RUN: grep {@const_nsw_sub = global i64 sub nsw } < %t.ll
+   * RUN: grep {@const_nuw_sub = global i64 sub nuw } < %t.ll
+   * RUN: grep {@const_fsub = global double fsub } < %t.ll
    * RUN: grep {@const_mul = global i64 mul } < %t.ll
+   * RUN: grep {@const_nsw_mul = global i64 mul nsw } < %t.ll
+   * RUN: grep {@const_nuw_mul = global i64 mul nuw } < %t.ll
+   * RUN: grep {@const_fmul = global double fmul } < %t.ll
    * RUN: grep {@const_udiv = global i64 udiv } < %t.ll
    * RUN: grep {@const_sdiv = global i64 sdiv } < %t.ll
+   * RUN: grep {@const_exact_sdiv = global i64 sdiv exact } < %t.ll
    * RUN: grep {@const_fdiv = global double fdiv } < %t.ll
    * RUN: grep {@const_urem = global i64 urem } < %t.ll
    * RUN: grep {@const_srem = global i64 srem } < %t.ll
@@ -341,12 +369,25 @@ let test_constants () =
   let foldbomb = const_ptrtoint foldbomb_gv i64_type in
   let ffoldbomb = const_uitofp foldbomb double_type in
   ignore (define_global "const_neg" (const_neg foldbomb) m);
+  ignore (define_global "const_nsw_neg" (const_nsw_neg foldbomb) m);
+  ignore (define_global "const_nuw_neg" (const_nuw_neg foldbomb) m);
+  ignore (define_global "const_fneg" (const_fneg ffoldbomb) m);
   ignore (define_global "const_not" (const_not foldbomb) m);
   ignore (define_global "const_add" (const_add foldbomb five) m);
+  ignore (define_global "const_nsw_add" (const_nsw_add foldbomb five) m);
+  ignore (define_global "const_nuw_add" (const_nuw_add foldbomb five) m);
+  ignore (define_global "const_fadd" (const_fadd ffoldbomb ffive) m);
   ignore (define_global "const_sub" (const_sub foldbomb five) m);
+  ignore (define_global "const_nsw_sub" (const_nsw_sub foldbomb five) m);
+  ignore (define_global "const_nuw_sub" (const_nuw_sub foldbomb five) m);
+  ignore (define_global "const_fsub" (const_fsub ffoldbomb ffive) m);
   ignore (define_global "const_mul" (const_mul foldbomb five) m);
+  ignore (define_global "const_nsw_mul" (const_nsw_mul foldbomb five) m);
+  ignore (define_global "const_nuw_mul" (const_nuw_mul foldbomb five) m);
+  ignore (define_global "const_fmul" (const_fmul ffoldbomb ffive) m);
   ignore (define_global "const_udiv" (const_udiv foldbomb five) m);
   ignore (define_global "const_sdiv" (const_sdiv foldbomb five) m);
+  ignore (define_global "const_exact_sdiv" (const_exact_sdiv foldbomb five) m);
   ignore (define_global "const_fdiv" (const_fdiv ffoldbomb ffive) m);
   ignore (define_global "const_urem" (const_urem foldbomb five) m);
   ignore (define_global "const_srem" (const_srem foldbomb five) m);
@@ -415,7 +456,17 @@ let test_constants () =
   ignore (define_global "const_shufflevector" (const_shufflevector
     (const_vector [| zero; one |])
     (const_vector [| one; zero |])
-    (const_bitcast foldbomb (vector_type i32_type 2))) m)
+    (const_bitcast foldbomb (vector_type i32_type 2))) m);
+
+  group "asm"; begin
+    let ft = function_type void_type [| i32_type; i32_type; i32_type |] in
+    ignore (const_inline_asm
+      ft
+      ""
+      "{cx},{ax},{di},~{dirflag},~{fpsr},~{flags},~{edi},~{ecx}"
+      true
+      false)
+  end
 
 
 (*===-- Global Values -----------------------------------------------------===*)
@@ -467,28 +518,46 @@ let test_global_variables () =
   let (++) x f = f x; x in
   let fourty_two32 = const_int i32_type 42 in
 
-  (* RUN: grep {GVar01.*external} < %t.ll
-   *)
-  group "declarations";
-  insist (None == lookup_global "GVar01" m);
-  let g = declare_global i32_type "GVar01" m in
-  insist (is_declaration g);
-  insist (pointer_type float_type ==
-            type_of (declare_global float_type "GVar01" m));
-  insist (g == declare_global i32_type "GVar01" m);
-  insist (match lookup_global "GVar01" m with Some x -> x = g
-                                            | None -> false);
+  group "declarations"; begin
+    (* RUN: grep {GVar01.*external} < %t.ll
+     *)
+    insist (None == lookup_global "GVar01" m);
+    let g = declare_global i32_type "GVar01" m in
+    insist (is_declaration g);
+    insist (pointer_type float_type ==
+              type_of (declare_global float_type "GVar01" m));
+    insist (g == declare_global i32_type "GVar01" m);
+    insist (match lookup_global "GVar01" m with Some x -> x = g
+                                              | None -> false);
+
+    insist (None == lookup_global "QGVar01" m);
+    let g = declare_qualified_global i32_type "QGVar01" 3 m in
+    insist (is_declaration g);
+    insist (qualified_pointer_type float_type 3 ==
+              type_of (declare_qualified_global float_type "QGVar01" 3 m));
+    insist (g == declare_qualified_global i32_type "QGVar01" 3 m);
+    insist (match lookup_global "QGVar01" m with Some x -> x = g
+                                              | None -> false);
+  end;
   
-  (* RUN: grep {GVar02.*42} < %t.ll
-   * RUN: grep {GVar03.*42} < %t.ll
-   *)
-  group "definitions";
-  let g = define_global "GVar02" fourty_two32 m in
-  let g2 = declare_global i32_type "GVar03" m ++
+  group "definitions"; begin
+    (* RUN: grep {GVar02.*42} < %t.ll
+     * RUN: grep {GVar03.*42} < %t.ll
+     *)
+    let g = define_global "GVar02" fourty_two32 m in
+    let g2 = declare_global i32_type "GVar03" m ++
            set_initializer fourty_two32 in
-  insist (not (is_declaration g));
-  insist (not (is_declaration g2));
-  insist ((global_initializer g) == (global_initializer g2));
+    insist (not (is_declaration g));
+    insist (not (is_declaration g2));
+    insist ((global_initializer g) == (global_initializer g2));
+
+    let g = define_qualified_global "QGVar02" fourty_two32 3 m in
+    let g2 = declare_qualified_global i32_type "QGVar03" 3 m ++
+           set_initializer fourty_two32 in
+    insist (not (is_declaration g));
+    insist (not (is_declaration g2));
+    insist ((global_initializer g) == (global_initializer g2));
+  end;
 
   (* RUN: grep {GVar04.*thread_local} < %t.ll
    *)
@@ -871,6 +940,23 @@ let test_builder () =
     let si = build_switch p1 bb3 1 (builder_at_end context bb1) in
     ignore (add_case si (const_int i32_type 2) bb2)
   end;
+
+  group "indirectbr"; begin
+    (* RUN: grep {indirectbr i8\\* blockaddress(@X7, %IBRBlock2), \\\[label %IBRBlock2, label %IBRBlock3\\\]} < %t.ll
+     *)
+    let bb1 = append_block context "IBRBlock1" fn in
+
+    let bb2 = append_block context "IBRBlock2" fn in
+    ignore (build_unreachable (builder_at_end context bb2));
+
+    let bb3 = append_block context "IBRBlock3" fn in
+    ignore (build_unreachable (builder_at_end context bb3));
+
+    let addr = block_address fn bb2 in
+    let ibr = build_indirect_br addr 2 (builder_at_end context bb1) in
+    ignore (add_destination ibr bb2);
+    ignore (add_destination ibr bb3)
+  end;
   
   group "invoke"; begin
     (* RUN: grep {build_invoke.*invoke.*P1.*P2} < %t.ll
@@ -902,10 +988,20 @@ let test_builder () =
     let b = builder_at_end context bb07 in
     
     (* RUN: grep {%build_add = add i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nsw_add = add nsw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nuw_add = add nuw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_fadd = fadd float %F1, %F2} < %t.ll
      * RUN: grep {%build_sub = sub i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nsw_sub = sub nsw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nuw_sub = sub nuw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_fsub = fsub float %F1, %F2} < %t.ll
      * RUN: grep {%build_mul = mul i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nsw_mul = mul nsw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_nuw_mul = mul nuw i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_fmul = fmul float %F1, %F2} < %t.ll
      * RUN: grep {%build_udiv = udiv i32 %P1, %P2} < %t.ll
      * RUN: grep {%build_sdiv = sdiv i32 %P1, %P2} < %t.ll
+     * RUN: grep {%build_exact_sdiv = sdiv exact i32 %P1, %P2} < %t.ll
      * RUN: grep {%build_fdiv = fdiv float %F1, %F2} < %t.ll
      * RUN: grep {%build_urem = urem i32 %P1, %P2} < %t.ll
      * RUN: grep {%build_srem = srem i32 %P1, %P2} < %t.ll
@@ -917,13 +1013,26 @@ let test_builder () =
      * RUN: grep {%build_or = or i32 %P1, %P2} < %t.ll
      * RUN: grep {%build_xor = xor i32 %P1, %P2} < %t.ll
      * RUN: grep {%build_neg = sub i32 0, %P1} < %t.ll
+     * RUN: grep {%build_nsw_neg = sub nsw i32 0, %P1} < %t.ll
+     * RUN: grep {%build_nuw_neg = sub nuw i32 0, %P1} < %t.ll
+     * RUN: grep {%build_fneg = fsub float .*0.*, %F1} < %t.ll
      * RUN: grep {%build_not = xor i32 %P1, -1} < %t.ll
      *)
     ignore (build_add p1 p2 "build_add" b);
+    ignore (build_nsw_add p1 p2 "build_nsw_add" b);
+    ignore (build_nuw_add p1 p2 "build_nuw_add" b);
+    ignore (build_fadd f1 f2 "build_fadd" b);
     ignore (build_sub p1 p2 "build_sub" b);
+    ignore (build_nsw_sub p1 p2 "build_nsw_sub" b);
+    ignore (build_nuw_sub p1 p2 "build_nuw_sub" b);
+    ignore (build_fsub f1 f2 "build_fsub" b);
     ignore (build_mul p1 p2 "build_mul" b);
+    ignore (build_nsw_mul p1 p2 "build_nsw_mul" b);
+    ignore (build_nuw_mul p1 p2 "build_nuw_mul" b);
+    ignore (build_fmul f1 f2 "build_fmul" b);
     ignore (build_udiv p1 p2 "build_udiv" b);
     ignore (build_sdiv p1 p2 "build_sdiv" b);
+    ignore (build_exact_sdiv p1 p2 "build_exact_sdiv" b);
     ignore (build_fdiv f1 f2 "build_fdiv" b);
     ignore (build_urem p1 p2 "build_urem" b);
     ignore (build_srem p1 p2 "build_srem" b);
@@ -935,6 +1044,9 @@ let test_builder () =
     ignore (build_or p1 p2 "build_or" b);
     ignore (build_xor p1 p2 "build_xor" b);
     ignore (build_neg p1 "build_neg" b);
+    ignore (build_nsw_neg p1 "build_nsw_neg" b);
+    ignore (build_nuw_neg p1 "build_nuw_neg" b);
+    ignore (build_fneg f1 "build_fneg" b);
     ignore (build_not p1 "build_not" b);
     ignore (build_unreachable b)
   end;
@@ -1037,6 +1149,46 @@ let test_builder () =
     ignore (build_insertelement vec1 p1 p2 "build_insertelement" atentry);
     ignore (build_shufflevector vec1 vec2 t3 "build_shufflevector" atentry);
   end;
+
+  group "metadata"; begin
+    (* RUN: grep {%metadata = add i32 %P1, %P2, !test !0} < %t.ll
+     * RUN: grep {!0 = metadata !\{i32 1, metadata !"metadata test"\}} < %t.ll
+     *)
+    let i = build_add p1 p2 "metadata" atentry in
+    insist ((has_metadata i) = false);
+
+    let m1 = const_int i32_type 1 in
+    let m2 = mdstring context "metadata test" in
+    let md = mdnode context [| m1; m2 |] in
+
+    let kind = mdkind_id context "test" in
+    set_metadata i kind md;
+
+    insist ((has_metadata i) = true);
+    insist ((metadata i kind) = Some md);
+
+    clear_metadata i kind;
+
+    insist ((has_metadata i) = false);
+    insist ((metadata i kind) = None);
+
+    set_metadata i kind md
+  end;
+
+  group "dbg"; begin
+    (* RUN: grep {%dbg = add i32 %P1, %P2, !dbg !1} < %t.ll
+     * RUN: grep {!1 = metadata !\{i32 2, metadata !"dbg test"\}} < %t.ll
+     *)
+    let m1 = const_int i32_type 2 in
+    let m2 = mdstring context "dbg test" in
+    let md = mdnode context [| m1; m2 |] in
+    set_current_debug_location atentry md;
+
+    let i = build_add p1 p2 "dbg" atentry in
+    insist ((has_metadata i) = true);
+
+    clear_current_debug_location atentry
+  end;
   
   group "phi"; begin
     (* RUN: grep {PhiNode.*P1.*PhiBlock1.*P2.*PhiBlock2} < %t.ll