[llvm-commits] [llvm] r45369 - in /llvm/trunk: bindings/ocaml/llvm/llvm.ml bindings/ocaml/llvm/llvm.mli bindings/ocaml/llvm/llvm_ocaml.c include/llvm-c/Core.h lib/VMCore/Core.cpp test/Bindings/Ocaml/vmcore.ml

Gordon Henriksen gordonhenriksen at mac.com
Thu Dec 27 12:13:48 PST 2007


Author: gordon
Date: Thu Dec 27 14:13:47 2007
New Revision: 45369

URL: http://llvm.org/viewvc/llvm-project?rev=45369&view=rev
Log:
Adding bindings for target triple and data layout.

Modified:
    llvm/trunk/bindings/ocaml/llvm/llvm.ml
    llvm/trunk/bindings/ocaml/llvm/llvm.mli
    llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
    llvm/trunk/include/llvm-c/Core.h
    llvm/trunk/lib/VMCore/Core.cpp
    llvm/trunk/test/Bindings/Ocaml/vmcore.ml

Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Thu Dec 27 14:13:47 2007
@@ -107,6 +107,14 @@
 
 external create_module : string -> llmodule = "llvm_create_module"
 external dispose_module : llmodule -> unit = "llvm_dispose_module"
+external target_triple: llmodule -> string
+                      = "llvm_target_triple"
+external set_target_triple: string -> llmodule -> unit
+                          = "llvm_set_target_triple"
+external data_layout: llmodule -> string
+                    = "llvm_data_layout"
+external set_data_layout: string -> llmodule -> unit
+                        = "llvm_set_data_layout"
 external define_type_name : string -> lltype -> llmodule -> bool
                           = "llvm_add_type_name"
 external delete_type_name : string -> llmodule -> unit

Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Thu Dec 27 14:13:47 2007
@@ -162,6 +162,27 @@
     [llvm::Module::~Module]. **)
 external dispose_module : llmodule -> unit = "llvm_dispose_module"
 
+(** [target_triple m] is the target specifier for the module [m], something like
+    [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. **)
+external target_triple: llmodule -> string
+                      = "llvm_target_triple"
+
+(** [target_triple triple m] changes the target specifier for the module [m] to
+    the string [triple]. See the method [llvm::Module::setTargetTriple]. **)
+external set_target_triple: string -> llmodule -> unit
+                          = "llvm_set_target_triple"
+
+(** [data_layout m] is the data layout specifier for the module [m], something
+    like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
+    method [llvm::Module::getDataLayout]. **)
+external data_layout: llmodule -> string
+                    = "llvm_data_layout"
+
+(** [set_data_layout s m] changes the data layout specifier for the module [m]
+    to the string [s]. See the method [llvm::Module::setDataLayout]. **)
+external set_data_layout: string -> llmodule -> unit
+                        = "llvm_set_data_layout"
+
 (** [define_type_name name ty m] adds a named type to the module's symbol table.
     Returns [true] if successful. If such a name already exists, then no entry
     is added and [false] is returned. See the [llvm::Module::addTypeName]

Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Thu Dec 27 14:13:47 2007
@@ -62,6 +62,28 @@
   return Val_unit;
 }
 
+/* llmodule -> string */
+CAMLprim value llvm_target_triple(LLVMModuleRef M) {
+  return copy_string(LLVMGetTarget(M));
+}
+
+/* string -> llmodule -> unit */
+CAMLprim value llvm_set_target_triple(value Trip, LLVMModuleRef M) {
+  LLVMSetTarget(M, String_val(Trip));
+  return Val_unit;
+}
+
+/* llmodule -> string */
+CAMLprim value llvm_data_layout(LLVMModuleRef M) {
+  return copy_string(LLVMGetDataLayout(M));
+}
+
+/* string -> llmodule -> unit */
+CAMLprim value llvm_set_data_layout(value Layout, LLVMModuleRef M) {
+  LLVMSetDataLayout(M, String_val(Layout));
+  return Val_unit;
+}
+
 /* string -> lltype -> llmodule -> bool */
 CAMLprim value llvm_add_type_name(value Name, LLVMTypeRef Ty, LLVMModuleRef M) {
   int res = LLVMAddTypeName(M, String_val(Name), Ty);

Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Thu Dec 27 14:13:47 2007
@@ -149,6 +149,14 @@
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
 void LLVMDisposeModule(LLVMModuleRef M);
 
+/* Data layout */
+const char *LLVMGetDataLayout(LLVMModuleRef M);
+void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
+
+/* Target triple */
+const char *LLVMGetTarget(LLVMModuleRef M);
+void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
+
 /* Same as Module::addTypeName. */
 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Thu Dec 27 14:13:47 2007
@@ -43,6 +43,25 @@
   delete unwrap(M);
 }
 
+/*--.. Data layout .........................................................--*/
+const char * LLVMGetDataLayout(LLVMModuleRef M) {
+  return unwrap(M)->getDataLayout().c_str();
+}
+
+void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
+  unwrap(M)->setDataLayout(Triple);
+}
+
+/*--.. Target triple .......................................................--*/
+const char * LLVMGetTarget(LLVMModuleRef M) {
+  return unwrap(M)->getTargetTriple().c_str();
+}
+
+void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
+  unwrap(M)->setTargetTriple(Triple);
+}
+
+/*--.. Type names ..........................................................--*/
 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
   return unwrap(M)->addTypeName(Name, unwrap(Ty));
 }

Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=45369&r1=45368&r2=45369&view=diff

==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Thu Dec 27 14:13:47 2007
@@ -36,6 +36,25 @@
 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 () =
@@ -823,6 +842,7 @@
 (*===-- Driver ------------------------------------------------------------===*)
 
 let _ =
+  suite "target"           test_target;
   suite "types"            test_types;
   suite "constants"        test_constants;
   suite "global values"    test_global_values;





More information about the llvm-commits mailing list