From ec7270c966b4a49840b1801bfbb11977d76cb333 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Wed, 6 Nov 2013 09:21:25 +0000 Subject: [OCaml] Impement Llvm_irreader, bindings to LLVM assembly parser git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194138 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Bindings/Ocaml/irreader.ml | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/Bindings/Ocaml/irreader.ml (limited to 'test/Bindings') diff --git a/test/Bindings/Ocaml/irreader.ml b/test/Bindings/Ocaml/irreader.ml new file mode 100644 index 0000000..3511c2b --- /dev/null +++ b/test/Bindings/Ocaml/irreader.ml @@ -0,0 +1,59 @@ +(* RUN: rm -rf %t.builddir + * RUN: mkdir -p %t.builddir + * RUN: cp %s %t.builddir + * RUN: %ocamlopt -g -warn-error A llvm.cmxa llvm_irreader.cmxa %t.builddir/irreader.ml -o %t + * RUN: %t + * XFAIL: vg_leak + *) + +(* Note: It takes several seconds for ocamlopt to link an executable with + libLLVMCore.a, so it's better to write a big test than a bunch of + little ones. *) + +open Llvm +open Llvm_irreader + +let context = global_context () + +(* Tiny unit test framework - really just to help find which line is busted *) +let print_checkpoints = false + +let suite name f = + if print_checkpoints then + prerr_endline (name ^ ":"); + f () + +let _ = + Printexc.record_backtrace true + +let insist cond = + if not cond then failwith "insist" + + +(*===-- IR Reader ---------------------------------------------------------===*) + +let test_irreader () = + begin + let buf = MemoryBuffer.of_string "@foo = global i32 42" in + let m = parse_ir context buf in + match lookup_global "foo" m with + | Some foo -> + insist ((global_initializer foo) = (const_int (i32_type context) 42)) + | None -> + failwith "global" + end; + + begin + let buf = MemoryBuffer.of_string "@foo = global garble" in + try + ignore (parse_ir context buf); + failwith "parsed" + with Llvm_irreader.Error _ -> + () + end + + +(*===-- Driver ------------------------------------------------------------===*) + +let _ = + suite "irreader" test_irreader -- cgit v1.1