Add support for global aliases to ocaml.
[oota-llvm.git] / test / Bindings / Ocaml / vmcore.ml
index 9a2f54753196d058e05d53b81854145d26d7820d..1b7200b19f47cb741e06436c3d9cc583a412cab1 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
    *)
@@ -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
    *)
@@ -441,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 -----------------------------------------------------===*)
@@ -493,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
    *)
@@ -563,6 +606,14 @@ let test_global_variables () =
     dispose_module m
   end
 
+(*===-- Aliases -----------------------------------------------------------===*)
+
+let test_aliases () =
+  (* RUN: grep {@alias = alias i32\\* @aliasee} < %t.ll
+   *)
+  let v = declare_global i32_type "aliasee" m in
+  ignore (add_alias m (pointer_type i32_type) v "alias")
+
 
 (*===-- Functions ---------------------------------------------------------===*)
 
@@ -1222,6 +1273,7 @@ let _ =
   suite "constants"        test_constants;
   suite "global values"    test_global_values;
   suite "global variables" test_global_variables;
+  suite "aliases"          test_aliases;
   suite "functions"        test_functions;
   suite "params"           test_params;
   suite "basic blocks"     test_basic_blocks;