1(* RUN: cp %s %T/irreader.ml 2 * RUN: %ocamlc -g -w +A -package llvm.irreader -linkpkg %T/irreader.ml -o %t 3 * RUN: %t 4 * RUN: %ocamlopt -g -w +A -package llvm.irreader -linkpkg %T/irreader.ml -o %t 5 * RUN: %t 6 * XFAIL: vg_leak 7 *) 8 9(* Note: It takes several seconds for ocamlopt to link an executable with 10 libLLVMCore.a, so it's better to write a big test than a bunch of 11 little ones. *) 12 13open Llvm 14open Llvm_irreader 15 16let context = global_context () 17 18(* Tiny unit test framework - really just to help find which line is busted *) 19let print_checkpoints = false 20 21let suite name f = 22 if print_checkpoints then 23 prerr_endline (name ^ ":"); 24 f () 25 26let _ = 27 Printexc.record_backtrace true 28 29let insist cond = 30 if not cond then failwith "insist" 31 32 33(*===-- IR Reader ---------------------------------------------------------===*) 34 35let test_irreader () = 36 begin 37 let buf = MemoryBuffer.of_string "@foo = global i32 42" in 38 let m = parse_ir context buf in 39 match lookup_global "foo" m with 40 | Some foo -> 41 insist ((global_initializer foo) = (const_int (i32_type context) 42)) 42 | None -> 43 failwith "global" 44 end; 45 46 begin 47 let buf = MemoryBuffer.of_string "@foo = global garble" in 48 try 49 ignore (parse_ir context buf); 50 failwith "parsed" 51 with Llvm_irreader.Error _ -> 52 () 53 end 54 55 56(*===-- Driver ------------------------------------------------------------===*) 57 58let _ = 59 suite "irreader" test_irreader 60