llvm.org GIT mirror llvm / 2bdf881
[OCaml] Build stub OCaml libraries for all configured targets This allows to only link in the needed targets, reducing binary size and more importantly link time. Note that this is an incomplete implementation: currently, LLVM does not have the plumbing which would allow to conditionally link in AsmPrinter, AsmParser and Disassembler for the targets which support them. This should be improved in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194670 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 7 years ago
6 changed file(s) with 195 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 name = "llvm_@TARGET@"
1 version = "@PACKAGE_VERSION@"
2 description = "@TARGET@ Backend for LLVM"
3 requires = "llvm"
4 archive(byte) = "llvm_@TARGET@.cma"
5 archive(native) = "llvm_@TARGET@.cmxa"
6 directory = "."
7 linkopts = "-ccopt -lstdc++"
0 ##===- bindings/ocaml/backends/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 master makefile for backend-specific bindings. It works by
10 # creating a stub makefile for each configured target, e.g. Makefile.ARM, and
11 # invoking it to compile the corresponding library, e.g. Llvm_ARM.
12 #
13 # This scheme allows to keep changes to Makefile.ocaml minimal.
14 #
15 ##===----------------------------------------------------------------------===##
16
17 LEVEL := ../../..
18 ExtraMakefiles = $(PROJ_OBJ_DIR)/Makefile.common
19
20 include $(LEVEL)/Makefile.config
21 include $(LEVEL)/Makefile.common
22
23 all-local:: all-backends
24 clean-local:: clean-backends
25 install-local:: install-backends
26 uninstall-local:: uninstall-backends
27
28 stubs:
29 $(Verb) for i in $(TARGETS_TO_BUILD); do \
30 $(ECHO) "TARGET := $$i" > Makefile.$$i; \
31 $(ECHO) "include Makefile.common" >> Makefile.$$i; \
32 done
33
34 all-backends: stubs
35 $(Verb) for i in $(TARGETS_TO_BUILD); do \
36 $(MAKE) -f Makefile.$$i all; \
37 done
38
39 clean-backends: stubs
40 $(Verb) for i in $(TARGETS_TO_BUILD); do \
41 $(MAKE) -f Makefile.$$i clean; \
42 $(RM) -f Makefile.$$i; \
43 done
44
45 install-backends: stubs
46 $(Verb) for i in $(TARGETS_TO_BUILD); do \
47 $(MAKE) -f Makefile.$$i install; \
48 done
49
50 uninstall-backends: stubs
51 $(Verb) for i in $(TARGETS_TO_BUILD); do \
52 $(MAKE) -f Makefile.$$i uninstall; \
53 done
54
55 .PHONY: all-backends clean-backends install-backends uninstall-backends
0 ##===- bindings/ocaml/backends/Makefile.common -------------*- 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 slave makefile for backend-specific bindings. This makefile should
10 # be included after defining TARGET. It will then substitute @TARGET@ for
11 # the value of TARGET in various *.in files and build an OCaml library in
12 # a regular way.
13 #
14 ##===----------------------------------------------------------------------===##
15
16 LEVEL := ../../..
17 LIBRARYNAME := llvm_$(TARGET)
18 UsedComponents := $(TARGET)
19 UsedOcamlInterfaces := llvm
20
21 include $(LEVEL)/Makefile.config
22
23 SOURCES := $(TARGET)_ocaml.c
24 OcamlHeaders1 := $(PROJ_SRC_DIR)/llvm_$(TARGET).mli
25 OcamlSources1 := $(PROJ_SRC_DIR)/llvm_$(TARGET).ml
26
27 include ../Makefile.ocaml
28
29 $(ObjDir)/llvm_$(TARGET).ml: $(PROJ_SRC_DIR)/llvm_backend.ml.in $(ObjDir)/.dir
30 $(Verb) $(SED) -e 's/@TARGET@/$(TARGET)/' $< > $@
31
32 $(ObjDir)/llvm_$(TARGET).mli: $(PROJ_SRC_DIR)/llvm_backend.mli.in $(ObjDir)/.dir
33 $(Verb) $(SED) -e 's/@TARGET@/$(TARGET)/' $< > $@
34
35 $(ObjDir)/$(TARGET)_ocaml.o: $(PROJ_SRC_DIR)/backend_ocaml.c $(ObjDir)/.dir
36 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
37 $(Verb) $(Compile.C) -DTARGET=$(TARGET) $< -o $@
38
39
40 ##===- OCamlFind Package --------------------------------------------------===##
41
42 all-local:: copy-meta
43 install-local:: install-meta
44 uninstall-local:: uninstall-meta
45
46 DestMETA := $(PROJ_libocamldir)/META.llvm_$(TARGET)
47
48 # Easy way of generating META in the objdir
49 copy-meta: $(OcamlDir)/META.llvm_$(TARGET)
50
51 $(OcamlDir)/META.llvm_$(TARGET): META.llvm_backend.in
52 $(Verb) $(SED) -e 's/@TARGET@/$(TARGET)/' \
53 -e 's/@PACKAGE_VERSION@/$(LLVMVersion)/' $< > $@
54
55 install-meta:: $(OcamlDir)/META.llvm_$(TARGET)
56 $(Echo) "Install $(BuildMode) $(DestMETA)"
57 $(Verb) $(MKDIR) $(PROJ_libocamldir)
58 $(Verb) $(DataInstall) $< "$(DestMETA)"
59
60 uninstall-meta::
61 $(Echo) "Uninstalling $(DestMETA)"
62 -$(Verb) $(RM) -f "$(DestMETA)"
63
64 .PHONY: copy-meta install-meta uninstall-meta
0 /*===-- backend_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/Target.h"
18 #include "caml/alloc.h"
19 #include "caml/memory.h"
20
21 #define INITIALIZER1(target) \
22 CAMLprim value llvm_initialize_ ## target(value Unit) { \
23 LLVMInitialize ## target ## TargetInfo(); \
24 LLVMInitialize ## target ## Target(); \
25 LLVMInitialize ## target ## TargetMC(); \
26 // TODO: Figure out how to call these only for targets \
27 // which support them. \
28 // LLVMInitialize ## target ## AsmPrinter(); \
29 // LLVMInitialize ## target ## AsmParser(); \
30 // LLVMInitialize ## target ## Disassembler(); \
31 return Val_unit; \
32 }
33
34 #define INITIALIZER(target) INITIALIZER1(target)
35
36 INITIALIZER(TARGET)
0 (*===-- llvm_backend.ml.in - 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 initialize : unit -> unit = "llvm_initialize_@TARGET@"
0 (*===-- llvm_backend.mli.in - 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 (** @TARGET@ Initialization.
10
11 This interface provides an OCaml API for initialization of
12 the @TARGET@ LLVM target. By referencing this module, you will cause
13 OCaml to load or link in the LLVM libraries corresponding to the target.
14 By calling [initialize], you will register components of this target
15 in the target registry, which is necessary in order to emit assembly,
16 object files, and so on. *)
17
18 external initialize : unit -> unit = "llvm_initialize_@TARGET@"