llvm.org GIT mirror llvm / a353ffa
Adding bindings for target triple and data layout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45369 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 12 years ago
6 changed file(s) with 98 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
106106
107107 external create_module : string -> llmodule = "llvm_create_module"
108108 external dispose_module : llmodule -> unit = "llvm_dispose_module"
109 external target_triple: llmodule -> string
110 = "llvm_target_triple"
111 external set_target_triple: string -> llmodule -> unit
112 = "llvm_set_target_triple"
113 external data_layout: llmodule -> string
114 = "llvm_data_layout"
115 external set_data_layout: string -> llmodule -> unit
116 = "llvm_set_data_layout"
109117 external define_type_name : string -> lltype -> llmodule -> bool
110118 = "llvm_add_type_name"
111119 external delete_type_name : string -> llmodule -> unit
161161 [llvm::Module::~Module]. **)
162162 external dispose_module : llmodule -> unit = "llvm_dispose_module"
163163
164 (** [target_triple m] is the target specifier for the module [m], something like
165 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. **)
166 external target_triple: llmodule -> string
167 = "llvm_target_triple"
168
169 (** [target_triple triple m] changes the target specifier for the module [m] to
170 the string [triple]. See the method [llvm::Module::setTargetTriple]. **)
171 external set_target_triple: string -> llmodule -> unit
172 = "llvm_set_target_triple"
173
174 (** [data_layout m] is the data layout specifier for the module [m], something
175 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
176 method [llvm::Module::getDataLayout]. **)
177 external data_layout: llmodule -> string
178 = "llvm_data_layout"
179
180 (** [set_data_layout s m] changes the data layout specifier for the module [m]
181 to the string [s]. See the method [llvm::Module::setDataLayout]. **)
182 external set_data_layout: string -> llmodule -> unit
183 = "llvm_set_data_layout"
184
164185 (** [define_type_name name ty m] adds a named type to the module's symbol table.
165186 Returns [true] if successful. If such a name already exists, then no entry
166187 is added and [false] is returned. See the [llvm::Module::addTypeName]
5858 /* llmodule -> unit */
5959 CAMLprim value llvm_dispose_module(LLVMModuleRef M) {
6060 LLVMDisposeModule(M);
61 return Val_unit;
62 }
63
64 /* llmodule -> string */
65 CAMLprim value llvm_target_triple(LLVMModuleRef M) {
66 return copy_string(LLVMGetTarget(M));
67 }
68
69 /* string -> llmodule -> unit */
70 CAMLprim value llvm_set_target_triple(value Trip, LLVMModuleRef M) {
71 LLVMSetTarget(M, String_val(Trip));
72 return Val_unit;
73 }
74
75 /* llmodule -> string */
76 CAMLprim value llvm_data_layout(LLVMModuleRef M) {
77 return copy_string(LLVMGetDataLayout(M));
78 }
79
80 /* string -> llmodule -> unit */
81 CAMLprim value llvm_set_data_layout(value Layout, LLVMModuleRef M) {
82 LLVMSetDataLayout(M, String_val(Layout));
6183 return Val_unit;
6284 }
6385
147147 /* Create and destroy modules. */
148148 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
149149 void LLVMDisposeModule(LLVMModuleRef M);
150
151 /* Data layout */
152 const char *LLVMGetDataLayout(LLVMModuleRef M);
153 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
154
155 /* Target triple */
156 const char *LLVMGetTarget(LLVMModuleRef M);
157 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
150158
151159 /* Same as Module::addTypeName. */
152160 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
4242 delete unwrap(M);
4343 }
4444
45 /*--.. Data layout .........................................................--*/
46 const char * LLVMGetDataLayout(LLVMModuleRef M) {
47 return unwrap(M)->getDataLayout().c_str();
48 }
49
50 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
51 unwrap(M)->setDataLayout(Triple);
52 }
53
54 /*--.. Target triple .......................................................--*/
55 const char * LLVMGetTarget(LLVMModuleRef M) {
56 return unwrap(M)->getTargetTriple().c_str();
57 }
58
59 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
60 unwrap(M)->setTargetTriple(Triple);
61 }
62
63 /*--.. Type names ..........................................................--*/
4564 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
4665 return unwrap(M)->addTypeName(Name, unwrap(Ty));
4766 }
3434 let filename = Sys.argv.(1)
3535 let m = create_module filename
3636
37
38 (*===-- Target ------------------------------------------------------------===*)
39
40 let test_target () =
41 begin group "triple";
42 (* RUN: grep "i686-apple-darwin8" < %t.ll
43 *)
44 let trip = "i686-apple-darwin8" in
45 set_target_triple trip m;
46 insist (trip = target_triple m)
47 end;
48
49 begin group "layout";
50 (* RUN: grep "bogus" < %t.ll
51 *)
52 let layout = "bogus" in
53 set_data_layout layout m;
54 insist (layout = data_layout m)
55 end
3756
3857 (*===-- Types -------------------------------------------------------------===*)
3958
822841 (*===-- Driver ------------------------------------------------------------===*)
823842
824843 let _ =
844 suite "target" test_target;
825845 suite "types" test_types;
826846 suite "constants" test_constants;
827847 suite "global values" test_global_values;