diff options
author | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-09-18 12:49:39 +0000 |
---|---|---|
committer | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-09-18 12:49:39 +0000 |
commit | c6606c6835781836dcb68343531ed178b9b4bd70 (patch) | |
tree | 45ef09f427e18bbf1afd9fd552a3d9fbf0f9e398 /test/Bindings/Ocaml/bitwriter.ml | |
parent | 4ac9209070703a7840d87e480a5f8156f772a7b3 (diff) | |
download | external_llvm-c6606c6835781836dcb68343531ed178b9b4bd70.zip external_llvm-c6606c6835781836dcb68343531ed178b9b4bd70.tar.gz external_llvm-c6606c6835781836dcb68343531ed178b9b4bd70.tar.bz2 |
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
Diffstat (limited to 'test/Bindings/Ocaml/bitwriter.ml')
-rw-r--r-- | test/Bindings/Ocaml/bitwriter.ml | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/Bindings/Ocaml/bitwriter.ml b/test/Bindings/Ocaml/bitwriter.ml new file mode 100644 index 0000000..5421e09 --- /dev/null +++ b/test/Bindings/Ocaml/bitwriter.ml @@ -0,0 +1,16 @@ +(* RUN: %ocamlc llvm.cma llvm_bitwriter.cma %s -o %t + * RUN: ./%t %t.bc + * RUN: llvm-dis < %t.bc | grep caml_int_ty + *) + +(* Note that this takes a moment to link, so it's best to keep the number of + individual tests low. *) + +let test x = if not x then exit 1 else () + +let _ = + let m = Llvm.create_module "ocaml_test_module" in + + ignore (Llvm.add_type_name "caml_int_ty" Llvm.i32_type m); + + test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1)) |