forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Gordon Henriksen
committed
Sep 18, 2007
1 parent
54c7e12
commit 8ef426b
Showing
16 changed files
with
1,213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
##===- bindings/Makefile -----------------------------------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file was developed by Gordon Henriksen and is distributed under the | ||
# University of Illinois Open Source License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL := .. | ||
|
||
include $(LEVEL)/Makefile.config | ||
|
||
ifdef OCAMLC | ||
PARALLEL_DIRS += ocaml | ||
endif | ||
|
||
include $(LEVEL)/Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This directory contains bindings for the LLVM compiler infrastructure to allow | ||
programs written in languages other than C or C++ to take advantage of the LLVM | ||
infrastructure--for instance, a self-hosted compiler front-end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
##===- bindings/ocaml/Makefile -----------------------------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file was developed by Gordon Henriksen and is distributed under the | ||
# University of Illinois Open Source License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL := ../.. | ||
DIRS = llvm bitwriter | ||
|
||
include $(LEVEL)/Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
##===- bindings/ocaml/llvm/Makefile ------------------------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file was developed by the LLVM research group and is distributed under | ||
# the University of Illinois Open Source License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
# | ||
# This is the makefile for the llvm-ml interface. Reference materials on | ||
# installing ocaml libraries: | ||
# | ||
# https://fedoraproject.org/wiki/Packaging/OCaml | ||
# http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL := ../../.. | ||
LIBRARYNAME := llvm_bitwriter | ||
DONT_BUILD_RELINKED := 1 | ||
UsedComponents := bitwriter | ||
|
||
include ../Makefile.ocaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*===-- bitwriter_ocaml.c - LLVM Ocaml Glue ---------------------*- C++ -*-===*\ | ||
|* *| | ||
|* The LLVM Compiler Infrastructure *| | ||
|* *| | ||
|* This file was developed by Gordon Henriksen and is distributed under the *| | ||
|* University of Illinois Open Source License. See LICENSE.TXT for details. *| | ||
|* *| | ||
|*===----------------------------------------------------------------------===*| | ||
|* *| | ||
|* This file glues LLVM's ocaml interface to its C interface. These functions *| | ||
|* are by and large transparent wrappers to the corresponding C functions. *| | ||
|* *| | ||
|* Note that these functions intentionally take liberties with the CAMLparamX *| | ||
|* macros, since most of the parameters are not GC heap objects. *| | ||
|* *| | ||
\*===----------------------------------------------------------------------===*/ | ||
|
||
#include "llvm-c/BitWriter.h" | ||
#include "llvm-c/Core.h" | ||
#include "caml/alloc.h" | ||
#include "caml/mlvalues.h" | ||
#include "caml/memory.h" | ||
|
||
/*===-- Modules -----------------------------------------------------------===*/ | ||
|
||
/* Llvm.llmodule -> string -> bool */ | ||
CAMLprim value llvm_write_bitcode_file(value M, value Path) { | ||
CAMLparam1(Path); | ||
int res = LLVMWriteBitcodeToFile((LLVMModuleRef) M, String_val(Path)); | ||
CAMLreturn(Val_bool(res == 0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(*===-- llvm_bitwriter.ml - LLVM Ocaml Interface ----------------*- C++ -*-===* | ||
* | ||
* The LLVM Compiler Infrastructure | ||
* | ||
* This file was developed by Gordon Henriksen and is distributed under the | ||
* University of Illinois Open Source License. See LICENSE.TXT for details. | ||
* | ||
*===----------------------------------------------------------------------=== | ||
* | ||
* This interface provides an ocaml API for the LLVM intermediate | ||
* representation, the classes in the VMCore library. | ||
* | ||
*===----------------------------------------------------------------------===*) | ||
|
||
|
||
(* Writes the bitcode for module the given path. Returns true if successful. *) | ||
external write_bitcode_file : Llvm.llmodule -> string -> bool | ||
= "llvm_write_bitcode_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(*===-- llvm_bitwriter.mli - LLVM Ocaml Interface ---------------*- C++ -*-===* | ||
* | ||
* The LLVM Compiler Infrastructure | ||
* | ||
* This file was developed by Gordon Henriksen and is distributed under the | ||
* University of Illinois Open Source License. See LICENSE.TXT for details. | ||
* | ||
*===----------------------------------------------------------------------=== | ||
* | ||
* This interface provides an ocaml API for the LLVM bitcode writer, the | ||
* classes in the classes in the Bitwriter library. | ||
* | ||
*===----------------------------------------------------------------------===*) | ||
|
||
|
||
(* Writes the bitcode for module the given path. Returns true if successful. *) | ||
external write_bitcode_file : Llvm.llmodule -> string -> bool | ||
= "llvm_write_bitcode_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
##===- bindings/ocaml/bitwriter/Makefile -------------------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file was developed by the LLVM research group and is distributed under | ||
# the University of Illinois Open Source License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
# | ||
# This is the makefile for the llvm-ml interface. Reference materials on | ||
# installing ocaml libraries: | ||
# | ||
# https://fedoraproject.org/wiki/Packaging/OCaml | ||
# http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL := ../../.. | ||
LIBRARYNAME := llvm | ||
DONT_BUILD_RELINKED := 1 | ||
UsedComponents := core | ||
UsedOcamLibs := llvm | ||
|
||
include ../Makefile.ocaml |
Oops, something went wrong.