brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 7d8e4a9 Raw
60 lines · plain
1(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/irreader.ml2 * RUN: %ocamlc -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable3 * RUN: %t/executable4 * RUN: %ocamlopt -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable5 * RUN: %t/executable6 * XFAIL: vg_leak7 *)8 9(* Note: It takes several seconds for ocamlopt to link an executable with10         libLLVMCore.a, so it's better to write a big test than a bunch of11         little ones. *)12 13open Llvm14open Llvm_irreader15 16let context = global_context ()17 18(* Tiny unit test framework - really just to help find which line is busted *)19let print_checkpoints = false20 21let suite name f =22  if print_checkpoints then23    prerr_endline (name ^ ":");24  f ()25 26let _ =27  Printexc.record_backtrace true28 29let insist cond =30  if not cond then failwith "insist"31 32 33(*===-- IR Reader ---------------------------------------------------------===*)34 35let test_irreader () =36  begin37    let buf = MemoryBuffer.of_string "@foo = global i32 42" in38    let m   = parse_ir context buf in39    match lookup_global "foo" m with40    | Some foo ->41        insist ((global_initializer foo) = (Some (const_int (i32_type context) 42)))42    | None ->43        failwith "global"44  end;45 46  begin47    let buf = MemoryBuffer.of_string "@foo = global garble" in48    try49      ignore (parse_ir context buf);50      failwith "parsed"51    with Llvm_irreader.Error _ ->52      ()53  end54 55 56(*===-- Driver ------------------------------------------------------------===*)57 58let _ =59  suite "irreader" test_irreader60