llvm.org GIT mirror llvm / 787a419
[OCaml] Move Llvm.clone_module to its own Llvm_transform_utils module. This way most code won't link this (substantially large) library, if compiled statically with LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223072 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 4 years ago
15 changed file(s) with 117 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 add_ocaml_library(llvm
11 OCAML llvm
22 C llvm_ocaml
3 LLVM core transformutils support)
3 LLVM core support)
44
55 configure_file(
66 "${CMAKE_CURRENT_SOURCE_DIR}/META.llvm.in"
6060 archive(native) = "llvm_scalar_opts.cmxa"
6161 )
6262
63 package "transform_utils" (
64 requires = "llvm"
65 version = "@PACKAGE_VERSION@"
66 description = "Transform utilities for LLVM"
67 archive(byte) = "llvm_transform_utils.cma"
68 archive(native) = "llvm_transform_utils.cmxa"
69 )
70
6371 package "vectorize" (
6472 requires = "llvm"
6573 version = "@PACKAGE_VERSION@"
1212
1313 LEVEL := ../../..
1414 LIBRARYNAME := llvm
15 UsedComponents := core transformutils
15 UsedComponents := core
1616 UsedOcamlLibs := llvm
1717 ExtraLibs := -lstdc++
1818
312312 (*===-- Modules -----------------------------------------------------------===*)
313313 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
314314 external dispose_module : llmodule -> unit = "llvm_dispose_module"
315 external clone_module : llmodule -> llmodule = "LLVMCloneModule"
316315 external target_triple: llmodule -> string
317316 = "llvm_target_triple"
318317 external set_target_triple: string -> llmodule -> unit
430430 [llvm::Module::~Module]. *)
431431 val dispose_module : llmodule -> unit
432432
433 (** [clone_module m] returns an exact copy of module [m]. *)
434 val clone_module : llmodule -> llmodule
435
436433 (** [target_triple m] is the target specifier for the module [m], something like
437434 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
438435 val target_triple: llmodule -> string
0 add_subdirectory(ipo)
11 add_subdirectory(passmgr_builder)
22 add_subdirectory(scalar_opts)
3 add_subdirectory(utils)
34 add_subdirectory(vectorize)
77 ##===----------------------------------------------------------------------===##
88
99 LEVEL := ../../..
10 DIRS = scalar_opts ipo vectorize passmgr_builder
10 DIRS = ipo passmgr_builder scalar_opts utils vectorize
1111
1212 ocamldoc:
1313 $(Verb) for i in $(DIRS) ; do \
0 add_ocaml_library(llvm_transform_utils
1 OCAML llvm_transform_utils
2 OCAMLDEP llvm
3 C transform_utils_ocaml
4 LLVM transformutils)
0 ##===- bindings/ocaml/transforms/utils/Makefile ------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This is the makefile for the Objective Caml Llvm_vectorize interface.
10 #
11 ##===----------------------------------------------------------------------===##
12
13 LEVEL := ../../../..
14 LIBRARYNAME := llvm_transform_utils
15 UsedComponents := transformutils
16 UsedOcamlInterfaces := llvm
17
18 include ../../Makefile.ocaml
0 (*===-- llvm_transform_utils.ml - LLVM OCaml Interface --------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 external clone_module : Llvm.llmodule -> Llvm.llmodule = "llvm_clone_module"
0 (*===-- llvm_transform_utils.mli - LLVM OCaml Interface -------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 (** Transform Utilities.
10
11 This interface provides an OCaml API for LLVM transform utilities, the
12 classes in the [LLVMTransformUtils] library. *)
13
14 (** [clone_module m] returns an exact copy of module [m].
15 See the [llvm::CloneModule] function. *)
16 external clone_module : Llvm.llmodule -> Llvm.llmodule = "llvm_clone_module"
0 /*===-- vectorize_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* 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/mlvalues.h"
19 #include "caml/misc.h"
20
21 /*
22 * Do not move directly into external. This function is here to pull in
23 * -lLLVMTransformUtils, which would otherwise be not linked on static builds,
24 * as ld can't see the reference from OCaml code.
25 */
26
27 /* llmodule -> llmodule */
28 CAMLprim LLVMModuleRef llvm_clone_module(LLVMModuleRef M) {
29 return LLVMCloneModule(M);
30 }
119119 ocaml_llvm_ipo
120120 ocaml_llvm_passmgr_builder
121121 ocaml_llvm_scalar_opts
122 ocaml_llvm_transform_utils
122123 ocaml_llvm_vectorize
123124 )
124125
0 (* RUN: cp %s %T/transform_utils.ml
1 * RUN: %ocamlc -g -warn-error A -package llvm.transform_utils -linkpkg %T/transform_utils.ml -o %t
2 * RUN: %t
3 * RUN: %ocamlopt -g -warn-error A -package llvm.transform_utils -linkpkg %T/transform_utils.ml -o %t
4 * RUN: %t
5 * XFAIL: vg_leak
6 *)
7
8 open Llvm
9 open Llvm_transform_utils
10
11 let context = global_context ()
12
13 let test_clone_module () =
14 let m = create_module context "mod" in
15 let m' = clone_module m in
16 if m == m' then failwith "m == m'";
17 if string_of_llmodule m <> string_of_llmodule m' then failwith "string_of m <> m'"
18
19 let () =
20 test_clone_module ()
8181 ocaml_llvm_ipo
8282 ocaml_llvm_passmgr_builder
8383 ocaml_llvm_scalar_opts
84 ocaml_llvm_transform_utils
8485 ocaml_llvm_vectorize
8586 )
8687 endif()