Add support for global aliases to ocaml.
authorErick Tryzelaar <idadesub@users.sourceforge.net>
Sun, 28 Feb 2010 20:44:58 +0000 (20:44 +0000)
committerErick Tryzelaar <idadesub@users.sourceforge.net>
Sun, 28 Feb 2010 20:44:58 +0000 (20:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97413 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c
test/Bindings/Ocaml/vmcore.ml

index 92bfef51d0318d6b15aa7a426aef81ab4a0cf98e..48f649a3cfcbe2410b567b6caa5c083bec6e2b1e 100644 (file)
@@ -444,6 +444,10 @@ let rec fold_right_global_range f i e init =
 let fold_right_globals f m init =
   fold_right_global_range f (global_end m) (At_start m) init
 
 let fold_right_globals f m init =
   fold_right_global_range f (global_end m) (At_start m) init
 
+(*--... Operations on aliases ..............................................--*)
+external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
+                   = "llvm_add_alias"
+
 (*--... Operations on functions ............................................--*)
 external declare_function : string -> lltype -> llmodule -> llvalue
                           = "llvm_declare_function"
 (*--... Operations on functions ............................................--*)
 external declare_function : string -> lltype -> llmodule -> llvalue
                           = "llvm_declare_function"
index c8c48f3c5376dfc42d984babc6eaf938b527ff7d..3413a646609f2b9c66e2ec77146b7d8cd7ed1f5d 100644 (file)
@@ -1140,6 +1140,15 @@ external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
 
 
 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
 
 
+(** {7 Operations on aliases} *)
+
+(** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
+    the aliasee [a] with the name [n].
+    See the constructor for [llvm::GlobalAlias]. *)
+external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
+                   = "llvm_add_alias"
+
+
 (** {7 Operations on functions} *)
 
 (** [declare_function name ty m] returns a new function of type [ty] and
 (** {7 Operations on functions} *)
 
 (** [declare_function name ty m] returns a new function of type [ty] and
index 000db05449485295e6aa7a63d7fecdba19e6d815..78cf6e436851377cd05e02f8e573e9477a4f1bd5 100644 (file)
@@ -807,6 +807,13 @@ CAMLprim value llvm_set_global_constant(value Flag, LLVMValueRef GlobalVar) {
   return Val_unit;
 }
 
   return Val_unit;
 }
 
+/*--... Operations on aliases ..............................................--*/
+
+CAMLprim LLVMValueRef llvm_add_alias(LLVMModuleRef M, LLVMTypeRef Ty,
+                                     LLVMValueRef Aliasee, value Name) {
+  return LLVMAddAlias(M, Ty, Aliasee, String_val(Name));
+}
+
 /*--... Operations on functions ............................................--*/
 
 DEFINE_ITERATORS(function, Function, LLVMModuleRef, LLVMValueRef,
 /*--... Operations on functions ............................................--*/
 
 DEFINE_ITERATORS(function, Function, LLVMModuleRef, LLVMValueRef,
index 40747f36111788d8b2d2287065fd2840c4bcc8f2..1b7200b19f47cb741e06436c3d9cc583a412cab1 100644 (file)
@@ -606,6 +606,14 @@ let test_global_variables () =
     dispose_module m
   end
 
     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 ---------------------------------------------------------===*)
 
 
 (*===-- Functions ---------------------------------------------------------===*)
 
@@ -1265,6 +1273,7 @@ let _ =
   suite "constants"        test_constants;
   suite "global values"    test_global_values;
   suite "global variables" test_global_variables;
   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;
   suite "functions"        test_functions;
   suite "params"           test_params;
   suite "basic blocks"     test_basic_blocks;