llvm.org GIT mirror llvm / 8ef426b
Adding ocaml language bindings for the vmcore and bitwriter libraries. These are built atop the C language bindings, and user programs can link with them as such: # Bytecode ocamlc -cc g++ llvm.cma llvmbitwriter.cma -o example example.ml # Native ocamlopt -cc g++ llvm.cmxa llvmbitwriter.cmxa -o example.opt example.ml The vmcore.ml test exercises most/all of the APIs thus far bound. Unfortunately, they're not yet numerous enough to write hello world. But: $ cat example.ml (* example.ml *) open Llvm open Llvm_bitwriter let _ = let filename = Sys.argv.(1) in let m = create_module filename in let v = make_int_constant i32_type 42 false in let g = define_global "hello_world" v m in if not (write_bitcode_file m filename) then exit 1; dispose_module m; $ ocamlc -cc g++ llvm.cma llvm_bitwriter.cma -o example example.ml File "example.ml", line 11, characters 6-7: Warning Y: unused variable g. $ ./example example.bc $ llvm-dis < example.bc ; ModuleID = '<stdin>' @hello_world = global i32 42 ; <i32*> [#uses=0] The ocaml test cases provide effective tests for the C interfaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42093 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 12 years ago
16 changed file(s) with 1213 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1919 DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-config \
2020 tools runtime docs
2121
22 OPTIONAL_DIRS := examples projects
22 OPTIONAL_DIRS := examples projects bindings
2323 EXTRA_DIST := test llvm.spec include win32 Xcode
2424
2525 include $(LEVEL)/Makefile.config
4545 # build LLVM.
4646 ifeq ($(MAKECMDGOALS),install)
4747 DIRS := $(filter-out utils, $(DIRS))
48 OPTIONAL_DIRS :=
48 OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
4949 endif
5050
5151 # Include the main makefile machinery.
0 ##===- bindings/Makefile -----------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file was developed by Gordon Henriksen and is distributed under the
5 # University of Illinois Open Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL := ..
10
11 include $(LEVEL)/Makefile.config
12
13 ifdef OCAMLC
14 PARALLEL_DIRS += ocaml
15 endif
16
17 include $(LEVEL)/Makefile.common
0 This directory contains bindings for the LLVM compiler infrastructure to allow
1 programs written in languages other than C or C++ to take advantage of the LLVM
2 infrastructure--for instance, a self-hosted compiler front-end.
0 ##===- bindings/ocaml/Makefile -----------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file was developed by Gordon Henriksen and is distributed under the
5 # University of Illinois Open Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL := ../..
10 DIRS = llvm bitwriter
11
12 include $(LEVEL)/Makefile.common
0 ##===- bindings/ocaml/llvm/Makefile ------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file was developed by the LLVM research group and is distributed under
5 # the University of Illinois Open Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This is the makefile for the llvm-ml interface. Reference materials on
10 # installing ocaml libraries:
11 #
12 # https://fedoraproject.org/wiki/Packaging/OCaml
13 # http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt
14 #
15 ##===----------------------------------------------------------------------===##
16
17 LEVEL := ../../..
18 LIBRARYNAME := llvm_bitwriter
19 DONT_BUILD_RELINKED := 1
20 UsedComponents := bitwriter
21
22 include ../Makefile.ocaml
0 /*===-- bitwriter_ocaml.c - LLVM Ocaml Glue ---------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file was developed by Gordon Henriksen and is distributed under the *|
5 |* University of Illinois Open Source License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
10 |* are by and large transparent wrappers to the corresponding C functions. *|
11 |* *|
12 |* Note that these functions intentionally take liberties with the CAMLparamX *|
13 |* macros, since most of the parameters are not GC heap objects. *|
14 |* *|
15 \*===----------------------------------------------------------------------===*/
16
17 #include "llvm-c/BitWriter.h"
18 #include "llvm-c/Core.h"
19 #include "caml/alloc.h"
20 #include "caml/mlvalues.h"
21 #include "caml/memory.h"
22
23 /*===-- Modules -----------------------------------------------------------===*/
24
25 /* Llvm.llmodule -> string -> bool */
26 CAMLprim value llvm_write_bitcode_file(value M, value Path) {
27 CAMLparam1(Path);
28 int res = LLVMWriteBitcodeToFile((LLVMModuleRef) M, String_val(Path));
29 CAMLreturn(Val_bool(res == 0));
30 }
0 (*===-- llvm_bitwriter.ml - LLVM Ocaml Interface ----------------*- C++ -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by Gordon Henriksen and is distributed under the
5 * University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===
8 *
9 * This interface provides an ocaml API for the LLVM intermediate
10 * representation, the classes in the VMCore library.
11 *
12 *===----------------------------------------------------------------------===*)
13
14
15 (* Writes the bitcode for module the given path. Returns true if successful. *)
16 external write_bitcode_file : Llvm.llmodule -> string -> bool
17 = "llvm_write_bitcode_file"
0 (*===-- llvm_bitwriter.mli - LLVM Ocaml Interface ---------------*- C++ -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by Gordon Henriksen and is distributed under the
5 * University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===
8 *
9 * This interface provides an ocaml API for the LLVM bitcode writer, the
10 * classes in the classes in the Bitwriter library.
11 *
12 *===----------------------------------------------------------------------===*)
13
14
15 (* Writes the bitcode for module the given path. Returns true if successful. *)
16 external write_bitcode_file : Llvm.llmodule -> string -> bool
17 = "llvm_write_bitcode_file"
0 ##===- bindings/ocaml/bitwriter/Makefile -------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file was developed by the LLVM research group and is distributed under
5 # the University of Illinois Open Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This is the makefile for the llvm-ml interface. Reference materials on
10 # installing ocaml libraries:
11 #
12 # https://fedoraproject.org/wiki/Packaging/OCaml
13 # http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt
14 #
15 ##===----------------------------------------------------------------------===##
16
17 LEVEL := ../../..
18 LIBRARYNAME := llvm
19 DONT_BUILD_RELINKED := 1
20 UsedComponents := core
21 UsedOcamLibs := llvm
22
23 include ../Makefile.ocaml
0 (*===-- tools/ml/llvm.ml - LLVM Ocaml Interface ---------------------------===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by Gordon Henriksen and is distributed under the
5 * University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===
8 *
9 * This interface provides an ocaml API for the LLVM intermediate
10 * representation, the classes in the VMCore library.
11 *
12 *===----------------------------------------------------------------------===*)
13
14
15 (* These abstract types correlate directly to the LLVM VMCore classes. *)
16 type llmodule
17 type lltype
18 type llvalue
19
20 type type_kind =
21 Void_type
22 | Float_type
23 | Double_type
24 | X86fp80_type
25 | Fp128_type
26 | Ppc_fp128_type
27 | Label_type
28 | Integer_type
29 | Function_type
30 | Struct_type
31 | Array_type
32 | Pointer_type
33 | Opaque_type
34 | Vector_type
35
36 type linkage =
37 External_linkage
38 | Link_once_linkage
39 | Weak_linkage
40 | Appending_linkage
41 | Internal_linkage
42 | Dllimport_linkage
43 | Dllexport_linkage
44 | External_weak_linkage
45 | Ghost_linkage
46
47 type visibility =
48 Default_visibility
49 | Hidden_visibility
50 | Protected_visibility
51
52
53 (*===-- Modules -----------------------------------------------------------===*)
54
55 (* Creates a module with the supplied module ID. Modules are not garbage
56 collected; it is mandatory to call dispose_module to free memory. *)
57 external create_module : string -> llmodule = "llvm_create_module"
58
59 (* Disposes a module. All references to subordinate objects are invalidated;
60 referencing them will invoke undefined behavior. *)
61 external dispose_module : llmodule -> unit = "llvm_dispose_module"
62
63 (* Adds a named type to the module's symbol table. Returns true if successful.
64 If such a name already exists, then no entry is added and returns false. *)
65 external add_type_name : string -> lltype -> llmodule -> bool
66 = "llvm_add_type_name"
67
68
69 (*===-- Types -------------------------------------------------------------===*)
70
71 external classify_type : lltype -> type_kind = "llvm_classify_type"
72 external refine_abstract_type : lltype -> lltype -> unit
73 = "llvm_refine_abstract_type"
74
75 (*--... Operations on integer types ........................................--*)
76 external _i1_type : unit -> lltype = "llvm_i1_type"
77 external _i8_type : unit -> lltype = "llvm_i8_type"
78 external _i16_type : unit -> lltype = "llvm_i16_type"
79 external _i32_type : unit -> lltype = "llvm_i32_type"
80 external _i64_type : unit -> lltype = "llvm_i64_type"
81
82 let i1_type = _i1_type ()
83 let i8_type = _i8_type ()
84 let i16_type = _i16_type ()
85 let i32_type = _i32_type ()
86 let i64_type = _i64_type ()
87
88 external make_integer_type : int -> lltype = "llvm_make_integer_type"
89 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
90
91 (*--... Operations on real types ...........................................--*)
92 external _float_type : unit -> lltype = "llvm_float_type"
93 external _double_type : unit -> lltype = "llvm_double_type"
94 external _x86fp80_type : unit -> lltype = "llvm_x86fp80_type"
95 external _fp128_type : unit -> lltype = "llvm_fp128_type"
96 external _ppc_fp128_type : unit -> lltype = "llvm_ppc_fp128_type"
97
98 let float_type = _float_type ()
99 let double_type = _double_type ()
100 let x86fp80_type = _x86fp80_type ()
101 let fp128_type = _fp128_type ()
102 let ppc_fp128_type = _ppc_fp128_type ()
103
104 (*--... Operations on function types .......................................--*)
105 (* FIXME: handle parameter attributes *)
106 external make_function_type : lltype -> lltype array -> bool -> lltype
107 = "llvm_make_function_type"
108 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
109 external return_type : lltype -> lltype = "llvm_return_type"
110 external param_types : lltype -> lltype array = "llvm_param_types"
111
112 (*--... Operations on struct types .........................................--*)
113 external make_struct_type : lltype array -> bool -> lltype
114 = "llvm_make_struct_type"
115 external element_types : lltype -> lltype array = "llvm_element_types"
116 external is_packed : lltype -> bool = "llvm_is_packed"
117
118 (*--... Operations on pointer, vector, and array types .....................--*)
119 external make_array_type : lltype -> int -> lltype = "llvm_make_array_type"
120 external make_pointer_type : lltype -> lltype = "llvm_make_pointer_type"
121 external make_vector_type : lltype -> int -> lltype = "llvm_make_vector_type"
122
123 external element_type : lltype -> lltype = "llvm_element_type"
124 external array_length : lltype -> int = "llvm_array_length"
125 external vector_size : lltype -> int = "llvm_vector_size"
126
127 (*--... Operations on other types ..........................................--*)
128 external make_opaque_type : unit -> lltype = "llvm_make_opaque_type"
129 external _void_type : unit -> lltype = "llvm_void_type"
130 external _label_type : unit -> lltype = "llvm_label_type"
131
132 let void_type = _void_type ()
133 let label_type = _label_type ()
134
135
136 (*===-- Values ------------------------------------------------------------===*)
137
138 external type_of : llvalue -> lltype = "llvm_type_of"
139 external value_name : llvalue -> string = "llvm_value_name"
140 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
141
142 (*--... Operations on constants of (mostly) any type .......................--*)
143 external make_null : lltype -> llvalue = "llvm_make_null"
144 external make_all_ones : lltype -> llvalue = "llvm_make_all_ones"
145 external make_undef : lltype -> llvalue = "llvm_make_undef"
146 external is_null : llvalue -> bool = "llvm_is_null"
147
148 (*--... Operations on scalar constants .....................................--*)
149 external make_int_constant : lltype -> int -> bool -> llvalue
150 = "llvm_make_int_constant"
151 external make_real_constant : lltype -> float -> llvalue
152 = "llvm_make_real_constant"
153
154 (*--... Operations on composite constants ..................................--*)
155 external make_string_constant : string -> bool -> llvalue
156 = "llvm_make_string_constant"
157 external make_array_constant : lltype -> llvalue array -> llvalue
158 = "llvm_make_array_constant"
159 external make_struct_constant : llvalue array -> bool -> llvalue
160 = "llvm_make_struct_constant"
161 external make_vector_constant : llvalue array -> llvalue
162 = "llvm_make_vector_constant"
163
164 (*--... Operations on global variables, functions, and aliases (globals) ...--*)
165 external is_declaration : llvalue -> bool = "llvm_is_declaration"
166 external linkage : llvalue -> linkage = "llvm_linkage"
167 external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
168 external section : llvalue -> string = "llvm_section"
169 external set_section : string -> llvalue -> unit = "llvm_set_section"
170 external visibility : llvalue -> visibility = "llvm_visibility"
171 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
172 external alignment : llvalue -> int = "llvm_alignment"
173 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
174
175 (*--... Operations on global variables .....................................--*)
176 external declare_global : lltype -> string -> llmodule -> llvalue
177 = "llvm_declare_global"
178 external define_global : string -> llvalue -> llmodule -> llvalue
179 = "llvm_define_global"
180 external delete_global : llvalue -> unit = "llvm_delete_global"
181 external global_initializer : llvalue -> llvalue = "llvm_global_initializer"
182 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
183 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
184 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
185 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
186
187
188 (*===-- Non-Externs -------------------------------------------------------===*)
189 (* These functions are built using the externals, so must be declared late. *)
190
191 let concat2 sep arr =
192 let s = ref "" in
193 if 0 < Array.length arr then begin
194 s := !s ^ arr.(0);
195 for i = 1 to (Array.length arr) - 1 do
196 s := !s ^ sep ^ arr.(i)
197 done
198 end;
199 !s
200
201 let rec string_of_lltype ty =
202 match classify_type ty with
203 Integer_type -> "i" ^ string_of_int (integer_bitwidth ty)
204 | Pointer_type -> (string_of_lltype (element_type ty)) ^ "*"
205 | Struct_type ->
206 let s = "{ " ^ (concat2 ", " (
207 Array.map string_of_lltype (element_types ty)
208 )) ^ " }" in
209 if is_packed ty
210 then "<" ^ s ^ ">"
211 else s
212 | Array_type -> "[" ^ (string_of_int (array_length ty)) ^
213 " x " ^ (string_of_lltype (element_type ty)) ^ "]"
214 | Vector_type -> "<" ^ (string_of_int (vector_size ty)) ^
215 " x " ^ (string_of_lltype (element_type ty)) ^ ">"
216 | Opaque_type -> "opaque"
217 | Function_type -> string_of_lltype (return_type ty) ^
218 " (" ^ (concat2 ", " (
219 Array.map string_of_lltype (param_types ty)
220 )) ^ ")"
221 | Label_type -> "label"
222 | Ppc_fp128_type -> "ppc_fp128"
223 | Fp128_type -> "fp128"
224 | X86fp80_type -> "x86_fp80"
225 | Double_type -> "double"
226 | Float_type -> "float"
227 | Void_type -> "void"
0 (*===-- tools/ml/llvm.ml - LLVM Ocaml Interface ---------------------------===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by Gordon Henriksen and is distributed under the
5 * University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===
8 *
9 * This interface provides an ocaml API for the LLVM intermediate
10 * representation, the classes in the VMCore library.
11 *
12 *===----------------------------------------------------------------------===*)
13
14
15 (* These abstract types correlate directly to the LLVM VMCore classes. *)
16 type llmodule
17 type lltype
18 type llvalue
19
20 type type_kind =
21 Void_type
22 | Float_type
23 | Double_type
24 | X86fp80_type
25 | Fp128_type
26 | Ppc_fp128_type
27 | Label_type
28 | Integer_type
29 | Function_type
30 | Struct_type
31 | Array_type
32 | Pointer_type
33 | Opaque_type
34 | Vector_type
35
36 type linkage =
37 External_linkage
38 | Link_once_linkage
39 | Weak_linkage
40 | Appending_linkage
41 | Internal_linkage
42 | Dllimport_linkage
43 | Dllexport_linkage
44 | External_weak_linkage
45 | Ghost_linkage
46
47 type visibility =
48 Default_visibility
49 | Hidden_visibility
50 | Protected_visibility
51
52
53 (*===-- Modules -----------------------------------------------------------===*)
54
55 (* Creates a module with the supplied module ID. Modules are not garbage
56 collected; it is mandatory to call dispose_module to free memory. *)
57 external create_module : string -> llmodule = "llvm_create_module"
58
59 (* Disposes a module. All references to subordinate objects are invalidated;
60 referencing them will invoke undefined behavior. *)
61 external dispose_module : llmodule -> unit = "llvm_dispose_module"
62
63 (* Adds a named type to the module's symbol table. Returns true if successful.
64 If such a name already exists, then no entry is added and returns false. *)
65 external add_type_name : string -> lltype -> llmodule -> bool
66 = "llvm_add_type_name"
67
68
69 (*===-- Types -------------------------------------------------------------===*)
70 external classify_type : lltype -> type_kind = "llvm_classify_type"
71 external refine_abstract_type : lltype -> lltype -> unit
72 = "llvm_refine_abstract_type"
73 val string_of_lltype : lltype -> string
74
75 (*--... Operations on integer types ........................................--*)
76 val i1_type : lltype
77 val i8_type : lltype
78 val i16_type : lltype
79 val i32_type : lltype
80 val i64_type : lltype
81 external make_integer_type : int -> lltype = "llvm_make_integer_type"
82 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
83
84 (*--... Operations on real types ...........................................--*)
85 val float_type : lltype
86 val double_type : lltype
87 val x86fp80_type : lltype
88 val fp128_type : lltype
89 val ppc_fp128_type : lltype
90
91 (*--... Operations on function types .......................................--*)
92 (* FIXME: handle parameter attributes *)
93 external make_function_type : lltype -> lltype array -> bool -> lltype
94 = "llvm_make_function_type"
95 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
96 external return_type : lltype -> lltype = "llvm_return_type"
97 external param_types : lltype -> lltype array = "llvm_param_types"
98
99 (*--... Operations on struct types .........................................--*)
100 external make_struct_type : lltype array -> bool -> lltype
101 = "llvm_make_struct_type"
102 external element_types : lltype -> lltype array = "llvm_element_types"
103 external is_packed : lltype -> bool = "llvm_is_packed"
104
105 (*--... Operations on pointer, vector, and array types .....................--*)
106 external make_array_type : lltype -> int -> lltype = "llvm_make_array_type"
107 external make_pointer_type : lltype -> lltype = "llvm_make_pointer_type"
108 external make_vector_type : lltype -> int -> lltype = "llvm_make_vector_type"
109
110 external element_type : lltype -> lltype = "llvm_element_type"
111 external array_length : lltype -> int = "llvm_array_length"
112 external vector_size : lltype -> int = "llvm_vector_size"
113
114 (*--... Operations on other types ..........................................--*)
115 external make_opaque_type : unit -> lltype = "llvm_make_opaque_type"
116 val void_type : lltype
117 val label_type : lltype
118
119
120 (*===-- Values ------------------------------------------------------------===*)
121 external type_of : llvalue -> lltype = "llvm_type_of"
122 external value_name : llvalue -> string = "llvm_value_name"
123 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
124
125 (*--... Operations on constants of (mostly) any type .......................--*)
126 external make_null : lltype -> llvalue = "llvm_make_null"
127 external make_all_ones : lltype -> llvalue = "llvm_make_all_ones"
128 external make_undef : lltype -> llvalue = "llvm_make_undef"
129 external is_null : llvalue -> bool = "llvm_is_null"
130
131 (*--... Operations on scalar constants .....................................--*)
132 external make_int_constant : lltype -> int -> bool -> llvalue
133 = "llvm_make_int_constant"
134 external make_real_constant : lltype -> float -> llvalue
135 = "llvm_make_real_constant"
136
137 (*--... Operations on composite constants ..................................--*)
138 external make_string_constant : string -> bool -> llvalue
139 = "llvm_make_string_constant"
140 external make_array_constant : lltype -> llvalue array -> llvalue
141 = "llvm_make_array_constant"
142 external make_struct_constant : llvalue array -> bool -> llvalue
143 = "llvm_make_struct_constant"
144 external make_vector_constant : llvalue array -> llvalue
145 = "llvm_make_vector_constant"
146
147 (*--... Operations on global variables, functions, and aliases (globals) ...--*)
148 external is_declaration : llvalue -> bool = "llvm_is_declaration"
149 external linkage : llvalue -> linkage = "llvm_linkage"
150 external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
151 external section : llvalue -> string = "llvm_section"
152 external set_section : string -> llvalue -> unit = "llvm_set_section"
153 external visibility : llvalue -> visibility = "llvm_visibility"
154 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
155 external alignment : llvalue -> int = "llvm_alignment"
156 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
157
158 (*--... Operations on global variables .....................................--*)
159 external declare_global : lltype -> string -> llmodule -> llvalue
160 = "llvm_declare_global"
161 external define_global : string -> llvalue -> llmodule -> llvalue
162 = "llvm_define_global"
163 external delete_global : llvalue -> unit = "llvm_delete_global"
164 external global_initializer : llvalue -> llvalue = "llvm_global_initializer"
165 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
166 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
167 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
168 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
169
0 /*===-- llvm_ocaml.h - LLVM Ocaml Glue --------------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file was developed by Gordon Henriksen and is distributed under the *|
5 |* University of Illinois Open Source License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
10 |* are by and large transparent wrappers to the corresponding C functions. *|
11 |* *|
12 |* Note that these functions intentionally take liberties with the CAMLparamX *|
13 |* macros, since most of the parameters are not GC heap objects. *|
14 |* *|
15 \*===----------------------------------------------------------------------===*/
16
17 #include "llvm-c/Core.h"
18 #include "caml/alloc.h"
19 #include "caml/mlvalues.h"
20 #include "caml/memory.h"
21 #include "stdio.h"
22
23
24 /*===-- Modules -----------------------------------------------------------===*/
25
26 /* string -> llmodule */
27 CAMLprim value llvm_create_module(value ModuleID) {
28 return (value) LLVMModuleCreateWithName(String_val(ModuleID));
29 }
30
31 /* llmodule -> unit */
32 CAMLprim value llvm_dispose_module(value M) {
33 LLVMDisposeModule((LLVMModuleRef) M);
34 return Val_unit;
35 }
36
37 /* string -> lltype -> llmodule -> bool */
38 CAMLprim value llvm_add_type_name(value Name, value Ty, value M) {
39 int res = LLVMAddTypeName((LLVMModuleRef) M,
40 String_val(Name), (LLVMTypeRef) Ty);
41 return Val_bool(res == 0);
42 }
43
44
45 /*===-- Types -------------------------------------------------------------===*/
46
47 /* lltype -> type_kind */
48 CAMLprim value llvm_classify_type(value Ty) {
49 return Val_int(LLVMGetTypeKind((LLVMTypeRef) Ty));
50 }
51
52 /* lltype -> lltype -> unit */
53 CAMLprim value llvm_refine_abstract_type(value ConcreteTy, value AbstractTy) {
54 LLVMRefineAbstractType((LLVMTypeRef) AbstractTy, (LLVMTypeRef) ConcreteTy);
55 return (value) Val_unit;
56 }
57
58 /*--... Operations on integer types ........................................--*/
59
60 /* unit -> lltype */
61 CAMLprim value llvm_i1_type (value Unit) { return (value) LLVMInt1Type(); }
62 CAMLprim value llvm_i8_type (value Unit) { return (value) LLVMInt8Type(); }
63 CAMLprim value llvm_i16_type(value Unit) { return (value) LLVMInt16Type(); }
64 CAMLprim value llvm_i32_type(value Unit) { return (value) LLVMInt32Type(); }
65 CAMLprim value llvm_i64_type(value Unit) { return (value) LLVMInt64Type(); }
66
67 /* int -> lltype */
68 CAMLprim value llvm_make_integer_type(value Width) {
69 return (value) LLVMCreateIntegerType(Int_val(Width));
70 }
71
72 /* lltype -> int */
73 CAMLprim value llvm_integer_bitwidth(value IntegerTy) {
74 return Val_int(LLVMGetIntegerTypeWidth((LLVMTypeRef) IntegerTy));
75 }
76
77 /*--... Operations on real types ...........................................--*/
78
79 /* unit -> lltype */
80 CAMLprim value llvm_float_type(value Unit) {
81 return (value) LLVMFloatType();
82 }
83
84 /* unit -> lltype */
85 CAMLprim value llvm_double_type(value Unit) {
86 return (value) LLVMDoubleType();
87 }
88
89 /* unit -> lltype */
90 CAMLprim value llvm_x86fp80_type(value Unit) {
91 return (value) LLVMX86FP80Type();
92 }
93
94 /* unit -> lltype */
95 CAMLprim value llvm_fp128_type(value Unit) {
96 return (value) LLVMFP128Type();
97 }
98
99 /* unit -> lltype */
100 CAMLprim value llvm_ppc_fp128_type(value Unit) {
101 return (value) LLVMPPCFP128Type();
102 }
103
104 /*--... Operations on function types .......................................--*/
105
106 /* lltype -> lltype array -> bool -> lltype */
107 CAMLprim value llvm_make_function_type(value RetTy, value ParamTys,
108 value IsVarArg) {
109 return (value) LLVMCreateFunctionType((LLVMTypeRef) RetTy,
110 (LLVMTypeRef *) ParamTys,
111 Wosize_val(ParamTys),
112 Bool_val(IsVarArg));
113 }
114
115 /* lltype -> bool */
116 CAMLprim value llvm_is_var_arg(value FunTy) {
117 return Val_bool(LLVMIsFunctionVarArg((LLVMTypeRef) FunTy));
118 }
119
120 /* lltype -> lltype */
121 CAMLprim value llvm_return_type(value FunTy) {
122 return (value) LLVMGetFunctionReturnType((LLVMTypeRef) FunTy);
123 }
124
125 /* lltype -> lltype array */
126 CAMLprim value llvm_param_types(value FunTy) {
127 unsigned Count = LLVMGetFunctionParamCount((LLVMTypeRef) FunTy);
128 LLVMTypeRef *FunTys = alloca(Count * sizeof(LLVMTypeRef));
129
130 /* copy into an ocaml array */
131 unsigned i;
132 value ParamTys = caml_alloc(Count, 0);
133
134 LLVMGetFunctionParamTypes((LLVMTypeRef) FunTy, FunTys);
135 for (i = 0; i != Count; ++i)
136 Store_field(ParamTys, i, (value) FunTys[i]);
137
138 return ParamTys;
139 }
140
141 /*--... Operations on struct types .........................................--*/
142
143 /* lltype array -> bool -> lltype */
144 CAMLprim value llvm_make_struct_type(value ElementTypes, value Packed) {
145 return (value) LLVMCreateStructType((LLVMTypeRef *) ElementTypes,
146 Wosize_val(ElementTypes),
147 Bool_val(Packed));
148 }
149
150 /* lltype -> lltype array */
151 CAMLprim value llvm_element_types(value StructTy) {
152 unsigned Count = LLVMGetStructElementCount((LLVMTypeRef) StructTy);
153 LLVMTypeRef *Tys = alloca(Count * sizeof(LLVMTypeRef));
154
155 /* copy into an ocaml array */
156 unsigned i;
157 value ElementTys = caml_alloc(Count, 0);
158
159 LLVMGetStructElementTypes((LLVMTypeRef) StructTy, Tys);
160 for (i = 0; i != Count; ++i)
161 Store_field(ElementTys, i, (value) Tys[i]);
162
163 return ElementTys;
164 }
165
166 CAMLprim value llvm_is_packed(value StructTy) {
167 return Val_bool(LLVMIsPackedStruct((LLVMTypeRef) StructTy));
168 }
169
170 /*--... Operations on array, pointer, and vector types .....................--*/
171
172 /* lltype -> int -> lltype */
173 CAMLprim value llvm_make_array_type(value ElementTy, value Count) {
174 return (value) LLVMCreateArrayType((LLVMTypeRef) ElementTy, Int_val(Count));
175 }
176
177 /* lltype -> lltype */
178 CAMLprim value llvm_make_pointer_type(value ElementTy) {
179 return (value) LLVMCreatePointerType((LLVMTypeRef) ElementTy);
180 }
181
182 /* lltype -> int -> lltype */
183 CAMLprim value llvm_make_vector_type(value ElementTy, value Count) {
184 return (value) LLVMCreateVectorType((LLVMTypeRef) ElementTy, Int_val(Count));
185 }
186
187 /* lltype -> lltype */
188 CAMLprim value llvm_element_type(value Ty) {
189 return (value) LLVMGetElementType((LLVMTypeRef) Ty);
190 }
191
192 /* lltype -> int */
193 CAMLprim value llvm_array_length(value ArrayTy) {
194 return Val_int(LLVMGetArrayLength((LLVMTypeRef) ArrayTy));
195 }
196
197 /* lltype -> int */
198 CAMLprim value llvm_vector_size(value VectorTy) {
199 return Val_int(LLVMGetVectorSize((LLVMTypeRef) VectorTy));
200 }
201
202 /*--... Operations on other types ..........................................--*/
203
204 /* unit -> lltype */
205 CAMLprim value llvm_void_type (value Unit) { return (value) LLVMVoidType(); }
206 CAMLprim value llvm_label_type(value Unit) { return (value) LLVMLabelType(); }
207
208 /* unit -> lltype */
209 CAMLprim value llvm_make_opaque_type(value Unit) {
210 return (value) LLVMCreateOpaqueType();
211 }
212
213
214 /*===-- VALUES ------------------------------------------------------------===*/
215
216 /* llvalue -> lltype */
217 CAMLprim value llvm_type_of(value Val) {
218 return (value) LLVMGetTypeOfValue((LLVMValueRef) Val);
219 }
220
221 /* llvalue -> string */
222 CAMLprim value llvm_value_name(value Val) {
223 return caml_copy_string(LLVMGetValueName((LLVMValueRef) Val));
224 }
225
226 /* string -> llvalue -> unit */
227 CAMLprim value llvm_set_value_name(value Name, value Val) {
228 LLVMSetValueName((LLVMValueRef) Val, String_val(Name));
229 return Val_unit;
230 }
231
232 /*--... Operations on constants of (mostly) any type .......................--*/
233
234 /* lltype -> llvalue */
235 CAMLprim value llvm_make_null(value Ty) {
236 return (value) LLVMGetNull((LLVMTypeRef) Ty);
237 }
238
239 /* lltype -> llvalue */
240 CAMLprim value llvm_make_all_ones(value Ty) {
241 return (value) LLVMGetAllOnes((LLVMTypeRef) Ty);
242 }
243
244 /* lltype -> llvalue */
245 CAMLprim value llvm_make_undef(value Ty) {
246 return (value) LLVMGetUndef((LLVMTypeRef) Ty);
247 }
248
249 /* llvalue -> bool */
250 CAMLprim value llvm_is_null(value Val) {
251 return Val_bool(LLVMIsNull((LLVMValueRef) Val));
252 }
253
254 /*--... Operations on scalar constants .....................................--*/
255
256 /* lltype -> int -> bool -> llvalue */
257 CAMLprim value llvm_make_int_constant(value IntTy, value N, value SExt) {
258 /* GCC warns if we use the ternary operator. */
259 unsigned long long N2;
260 if (Bool_val(SExt))
261 N2 = (intnat) Int_val(N);
262 else
263 N2 = (uintnat) Int_val(N);
264
265 return (value) LLVMGetIntConstant((LLVMTypeRef) IntTy, N2, Bool_val(SExt));
266 }
267
268 /* lltype -> float -> llvalue */
269 CAMLprim value llvm_make_real_constant(value RealTy, value N) {
270 return (value) LLVMGetRealConstant((LLVMTypeRef) RealTy, Double_val(N));
271 }
272
273 /*--... Operations on composite constants ..................................--*/
274
275 /* string -> bool -> llvalue */
276 CAMLprim value llvm_make_string_constant(value Str, value NullTerminate) {
277 return (value) LLVMGetStringConstant(String_val(Str),
278 Wosize_val(Str),
279 Bool_val(NullTerminate) == 0);
280 }
281
282 /* lltype -> llvalue array -> llvalue */
283 CAMLprim value llvm_make_array_constant(value ElementTy, value ElementVals) {
284 return (value) LLVMGetArrayConstant((LLVMTypeRef) ElementTy,
285 (LLVMValueRef*) Op_val(ElementVals),
286 Wosize_val(ElementVals));
287 }
288
289 /* llvalue array -> bool -> llvalue */
290 CAMLprim value llvm_make_struct_constant(value ElementVals, value Packed) {
291 return (value) LLVMGetStructConstant((LLVMValueRef*) Op_val(ElementVals),
292 Wosize_val(ElementVals),
293 Bool_val(Packed));
294 }
295
296 /* llvalue array -> llvalue */
297 CAMLprim value llvm_make_vector_constant(value ElementVals) {
298 return (value) LLVMGetVectorConstant((LLVMValueRef*) Op_val(ElementVals),
299 Wosize_val(ElementVals));
300 }
301
302 /*--... Operations on global variables, functions, and aliases (globals) ...--*/
303
304 /* llvalue -> bool */
305 CAMLprim value llvm_is_declaration(value Global) {
306 return Val_bool(LLVMIsDeclaration((LLVMValueRef) Global));
307 }
308
309 /* llvalue -> linkage */
310 CAMLprim value llvm_linkage(value Global) {
311 return Val_int(LLVMGetLinkage((LLVMValueRef) Global));
312 }
313
314 /* linkage -> llvalue -> unit */
315 CAMLprim value llvm_set_linkage(value Linkage, value Global) {
316 LLVMSetLinkage((LLVMValueRef) Global, Int_val(Linkage));
317 return Val_unit;
318 }
319
320 /* llvalue -> string */
321 CAMLprim value llvm_section(value Global) {
322 return caml_copy_string(LLVMGetSection((LLVMValueRef) Global));
323 }
324
325 /* string -> llvalue -> unit */
326 CAMLprim value llvm_set_section(value Section, value Global) {
327 LLVMSetSection((LLVMValueRef) Global, String_val(Section));
328 return Val_unit;
329 }
330
331 /* llvalue -> visibility */
332 CAMLprim value llvm_visibility(value Global) {
333 return Val_int(LLVMGetVisibility((LLVMValueRef) Global));
334 }
335
336 /* visibility -> llvalue -> unit */
337 CAMLprim value llvm_set_visibility(value Viz, value Global) {
338 LLVMSetVisibility((LLVMValueRef) Global, Int_val(Viz));
339 return Val_unit;
340 }
341
342 /* llvalue -> int */
343 CAMLprim value llvm_alignment(value Global) {
344 return Val_int(LLVMGetAlignment((LLVMValueRef) Global));
345 }
346
347 /* int -> llvalue -> unit */
348 CAMLprim value llvm_set_alignment(value Bytes, value Global) {
349 LLVMSetAlignment((LLVMValueRef) Global, Int_val(Bytes));
350 return Val_unit;
351 }
352
353 /*--... Operations on global variables .....................................--*/
354
355 /* lltype -> string -> llmodule -> llvalue */
356 CAMLprim value llvm_add_global(value Ty, value Name, value M) {
357 return (value) LLVMAddGlobal((LLVMModuleRef) M,
358 (LLVMTypeRef) Ty, String_val(Name));
359 }
360
361 /* lltype -> string -> llmodule -> llvalue */
362 CAMLprim value llvm_declare_global(value Ty, value Name, value M) {
363 return (value) LLVMAddGlobal((LLVMModuleRef) M,
364 (LLVMTypeRef) Ty, String_val(Name));
365 }
366
367 /* string -> llvalue -> llmodule -> llvalue */
368 CAMLprim value llvm_define_global(value Name, value ConstantVal, value M) {
369 LLVMValueRef Initializer = (LLVMValueRef) ConstantVal;
370 LLVMValueRef GlobalVar = LLVMAddGlobal((LLVMModuleRef) M,
371 LLVMGetTypeOfValue(Initializer),
372 String_val(Name));
373 LLVMSetInitializer(GlobalVar, Initializer);
374 return (value) GlobalVar;
375 }
376
377 /* llvalue -> unit */
378 CAMLprim value llvm_delete_global(value GlobalVar) {
379 LLVMDeleteGlobal((LLVMValueRef) GlobalVar);
380 return Val_unit;
381 }
382
383 /* llvalue -> llvalue */
384 CAMLprim value llvm_global_initializer(value GlobalVar) {
385 return (value) LLVMGetInitializer((LLVMValueRef) GlobalVar);
386 }
387
388 /* llvalue -> llvalue -> unit */
389 CAMLprim value llvm_set_initializer(value ConstantVal, value GlobalVar) {
390 LLVMSetInitializer((LLVMValueRef) GlobalVar, (LLVMValueRef) ConstantVal);
391 return Val_unit;
392 }
393
394 /* llvalue -> unit */
395 CAMLprim value llvm_remove_initializer(value GlobalVar) {
396 LLVMSetInitializer((LLVMValueRef) GlobalVar, NULL);
397 return Val_unit;
398 }
399
400 /* llvalue -> bool */
401 CAMLprim value llvm_is_thread_local(value GlobalVar) {
402 return Val_bool(LLVMIsThreadLocal((LLVMValueRef) GlobalVar));
403 }
404
405 /* bool -> llvalue -> unit */
406 CAMLprim value llvm_set_thread_local(value IsThreadLocal, value GlobalVar) {
407 LLVMSetThreadLocal((LLVMValueRef) GlobalVar, Bool_val(IsThreadLocal));
408 return Val_unit;
409 }
0 (* RUN: %ocamlc llvm.cma llvm_bitwriter.cma %s -o %t
1 * RUN: ./%t %t.bc
2 * RUN: llvm-dis < %t.bc | grep caml_int_ty
3 *)
4
5 (* Note that this takes a moment to link, so it's best to keep the number of
6 individual tests low. *)
7
8 let test x = if not x then exit 1 else ()
9
10 let _ =
11 let m = Llvm.create_module "ocaml_test_module" in
12
13 ignore (Llvm.add_type_name "caml_int_ty" Llvm.i32_type m);
14
15 test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1))
0 load_lib llvm.exp
1
2 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr,ml}]]
0 (* RUN: %ocamlc llvm.cma llvm_bitwriter.cma %s -o %t
1 * RUN: ./%t %t.bc
2 * RUN: llvm-dis < %t.bc > %t.ll
3 *)
4
5 (* Note: It takes several seconds for ocamlc to link an executable with
6 libLLVMCore.a, so it's better to write a big test than a bunch of
7 little ones. *)
8
9 open Llvm
10 open Llvm_bitwriter
11
12
13 (* Tiny unit test framework *)
14 let exit_status = ref 0
15 let case_num = ref 0
16
17 let all_done () =
18 prerr_endline "";
19 exit !exit_status
20
21 let group name =
22 prerr_endline "";
23 case_num := 0;
24 prerr_string (" " ^ name ^ "... ")
25
26 let insist cond =
27 incr case_num;
28 prerr_char ' ';
29 if not cond then begin
30 exit_status := 10;
31 prerr_char '!'
32 end;
33 prerr_int !case_num
34
35 let suite name f =
36 prerr_endline (name ^ ":");
37 f ()
38
39
40 (*===-- Fixture -----------------------------------------------------------===*)
41
42 let filename = Sys.argv.(1)
43 let m = create_module filename
44
45
46 (*===-- Types -------------------------------------------------------------===*)
47
48 let test_types () =
49 (* RUN: grep {Ty01.*void} < %t.ll
50 *)
51 group "void";
52 insist (add_type_name "Ty01" void_type m);
53 insist (Void_type == classify_type void_type);
54
55 (* RUN: grep {Ty02.*i1} < %t.ll
56 *)
57 group "i1";
58 insist (add_type_name "Ty02" i1_type m);
59 insist (Integer_type == classify_type i1_type);
60
61 (* RUN: grep {Ty03.*i32} < %t.ll
62 *)
63 group "i32";
64 insist (add_type_name "Ty03" i32_type m);
65
66 (* RUN: grep {Ty04.*i42} < %t.ll
67 *)
68 group "i42";
69 let ty = make_integer_type 42 in
70 insist (add_type_name "Ty04" ty m);
71
72 (* RUN: grep {Ty05.*float} < %t.ll
73 *)
74 group "float";
75 insist (add_type_name "Ty05" float_type m);
76 insist (Float_type == classify_type float_type);
77
78 (* RUN: grep {Ty06.*double} < %t.ll
79 *)
80 group "double";
81 insist (add_type_name "Ty06" double_type m);
82 insist (Double_type == classify_type double_type);
83
84 (* RUN: grep {Ty07.*i32.*i1, double} < %t.ll
85 *)
86 group "function";
87 let ty = make_function_type i32_type [| i1_type; double_type |] false in
88 insist (add_type_name "Ty07" ty m);
89 insist (Function_type = classify_type ty);
90 insist (not (is_var_arg ty));
91 insist (i32_type == return_type ty);
92 insist (double_type == (param_types ty).(1));
93
94 (* RUN: grep {Ty08.*\.\.\.} < %t.ll
95 *)
96 group "vararg";
97 let ty = make_function_type void_type [| i32_type |] true in
98 insist (add_type_name "Ty08" ty m);
99 insist (is_var_arg ty);
100
101 (* RUN: grep {Ty09.*\\\[7 x i8\\\]} < %t.ll
102 *)
103 group "array";
104 let ty = make_array_type i8_type 7 in
105 insist (add_type_name "Ty09" ty m);
106 insist (7 = array_length ty);
107 insist (i8_type == element_type ty);
108 insist (Array_type == classify_type ty);
109
110 (* RUN: grep {Ty10.*float\*} < %t.ll
111 *)
112 group "pointer";
113 let ty = make_pointer_type float_type in
114 insist (add_type_name "Ty10" ty m);
115 insist (float_type == element_type ty);
116 insist (Pointer_type == classify_type ty);
117
118 (* RUN: grep {Ty11.*\<4 x i16\>} < %t.ll
119 *)
120 group "vector";
121 let ty = make_vector_type i16_type 4 in
122 insist (add_type_name "Ty11" ty m);
123 insist (i16_type == element_type ty);
124 insist (4 = vector_size ty);
125
126 (* RUN: grep {Ty12.*opaque} < %t.ll
127 *)
128 group "opaque";
129 let ty = make_opaque_type () in
130 insist (add_type_name "Ty12" ty m);
131 insist (ty == ty);
132 insist (ty <> make_opaque_type ())
133
134
135 (*===-- Global Values -----------------------------------------------------===*)
136
137 let test_global_values () =
138 let (++) x f = f x; x in
139 let zero32 = make_null i32_type in
140
141 (* RUN: grep {GVal01} < %t.ll
142 *)
143 group "naming";
144 let g = define_global "TEMPORARY" zero32 m in
145 prerr_endline "";
146 prerr_endline (value_name g);
147 insist ("TEMPORARY" = value_name g);
148 set_value_name "GVal01" g;
149 insist ("GVal01" = value_name g);
150
151 (* RUN: grep {GVal02.*linkonce} < %t.ll
152 *)
153 group "linkage";
154 let g = define_global "GVal02" zero32 m ++
155 set_linkage Link_once_linkage in
156 insist (Link_once_linkage = linkage g);
157
158 (* RUN: grep {GVal03.*Hanalei} < %t.ll
159 *)
160 group "section";
161 let g = define_global "GVal03" zero32 m ++
162 set_section "Hanalei" in
163 insist ("Hanalei" = section g);
164
165 (* RUN: grep {GVal04.*hidden} < %t.ll
166 *)
167 group "visibility";
168 let g = define_global "GVal04" zero32 m ++
169 set_visibility Hidden_visibility in
170 insist (Hidden_visibility = visibility g);
171
172 (* RUN: grep {GVal05.*align 128} < %t.ll
173 *)
174 group "alignment";
175 let g = define_global "GVal05" zero32 m ++
176 set_alignment 128 in
177 insist (128 = alignment g)
178
179
180 (*===-- Global Variables --------------------------------------------------===*)
181
182 let test_global_variables () =
183 let (++) x f = f x; x in
184 let fourty_two32 = make_int_constant i32_type 42 false in
185
186 (* RUN: grep {GVar01.*external} < %t.ll
187 *)
188 group "declarations";
189 let g = declare_global i32_type "GVar01" m in
190 insist (is_declaration g);
191
192 (* RUN: grep {GVar02.*42} < %t.ll
193 * RUN: grep {GVar03.*42} < %t.ll
194 *)
195 group "definitions";
196 let g = define_global "GVar02" fourty_two32 m in
197 let g2 = declare_global i32_type "GVar03" m ++
198 set_initializer fourty_two32 in
199 insist (not (is_declaration g));
200 insist (not (is_declaration g2));
201 insist ((global_initializer g) == (global_initializer g2));
202
203 (* RUN: grep {GVar04.*thread_local} < %t.ll
204 *)
205 group "threadlocal";
206 let g = define_global "GVar04" fourty_two32 m ++
207 set_thread_local true in
208 insist (is_thread_local g);
209
210 (* RUN: grep -v {GVar05} < %t.ll
211 *)
212 let g = define_global "GVar05" fourty_two32 m in
213 delete_global g
214
215
216 (*===-- Writer ------------------------------------------------------------===*)
217
218 let test_writer () =
219 group "writer";
220 insist (write_bitcode_file m filename);
221
222 dispose_module m
223
224
225 (*===-- Driver ------------------------------------------------------------===*)
226
227 let _ =
228 suite "types" test_types;
229 suite "global values" test_global_values;
230 suite "global variables" test_global_variables;
231 suite "writer" test_writer;
232 all_done ()
4242 # cases.
4343 proc substitute { line test tmpFile } {
4444 global srcroot objroot srcdir objdir subdir target_triplet prcontext
45 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers
45 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
4646 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
4747 set path [file join $srcdir $subdir]
4848
6363 regsub -all {%link} $new_line "$link" new_line
6464 #replace %shlibext with shared library extension
6565 regsub -all {%shlibext} $new_line "$shlibext" new_line
66 #replace %ocamlc with ocaml compiler command
67 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
6668 #replace %llvmlibsdir with configure library directory
6769 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
6870 #replace %p with path to source,