diff options
author | Stephen Hines <srhines@google.com> | 2014-12-01 14:51:49 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-12-02 16:08:10 -0800 |
commit | 37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch) | |
tree | 8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /test/Bindings/OCaml/target.ml | |
parent | d2327b22152ced7bc46dc629fc908959e8a52d03 (diff) | |
download | external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2 |
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'test/Bindings/OCaml/target.ml')
-rw-r--r-- | test/Bindings/OCaml/target.ml | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/test/Bindings/OCaml/target.ml b/test/Bindings/OCaml/target.ml new file mode 100644 index 0000000..41faefa --- /dev/null +++ b/test/Bindings/OCaml/target.ml @@ -0,0 +1,116 @@ +(* RUN: cp %s %T/target.ml + * RUN: %ocamlc -g -warn-error A -package llvm.target -package llvm.all_backends -linkpkg %T/target.ml -o %t + * RUN: %ocamlopt -g -warn-error A -package llvm.target -package llvm.all_backends -linkpkg %T/target.ml -o %t + * RUN: %t %t.bc + * 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_target + +let () = Llvm_all_backends.initialize () + +let context = global_context () +let i32_type = Llvm.i32_type context +let i64_type = Llvm.i64_type context + +(* Tiny unit test framework - really just to help find which line is busted *) +let print_checkpoints = false + +let _ = + Printexc.record_backtrace true + +let assert_equal a b = + if a <> b then failwith "assert_equal" + + +(*===-- Fixture -----------------------------------------------------------===*) + +let filename = Sys.argv.(1) +let m = create_module context filename + +let target = Target.by_triple (Target.default_triple ()) + +let machine = TargetMachine.create (Target.default_triple ()) target + +(*===-- Data Layout -------------------------------------------------------===*) + +let test_target_data () = + let module DL = DataLayout in + let layout = "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-n32-S32" in + let dl = DL.of_string layout in + let sty = struct_type context [| i32_type; i64_type |] in + + assert_equal (DL.as_string dl) layout; + assert_equal (DL.byte_order dl) Endian.Little; + assert_equal (DL.pointer_size dl) 4; + assert_equal (DL.intptr_type context dl) i32_type; + assert_equal (DL.qualified_pointer_size 0 dl) 4; + assert_equal (DL.qualified_intptr_type context 0 dl) i32_type; + assert_equal (DL.size_in_bits sty dl) (Int64.of_int 96); + assert_equal (DL.store_size sty dl) (Int64.of_int 12); + assert_equal (DL.abi_size sty dl) (Int64.of_int 12); + assert_equal (DL.stack_align sty dl) 4; + assert_equal (DL.preferred_align sty dl) 8; + assert_equal (DL.preferred_align_of_global (declare_global sty "g" m) dl) 8; + assert_equal (DL.element_at_offset sty (Int64.of_int 1) dl) 0; + assert_equal (DL.offset_of_element sty 1 dl) (Int64.of_int 4); + + let pm = PassManager.create () in + ignore (DL.add_to_pass_manager pm dl) + + +(*===-- Target ------------------------------------------------------------===*) + +let test_target () = + let module T = Target in + ignore (T.succ target); + ignore (T.name target); + ignore (T.description target); + ignore (T.has_jit target); + ignore (T.has_target_machine target); + ignore (T.has_asm_backend target) + + +(*===-- Target Machine ----------------------------------------------------===*) + +let test_target_machine () = + let module TM = TargetMachine in + assert_equal (TM.target machine) target; + assert_equal (TM.triple machine) (Target.default_triple ()); + assert_equal (TM.cpu machine) ""; + assert_equal (TM.features machine) ""; + ignore (TM.data_layout machine); + TM.set_verbose_asm true machine; + let pm = PassManager.create () in + TM.add_analysis_passes pm machine + + +(*===-- Code Emission -----------------------------------------------------===*) + +let test_code_emission () = + TargetMachine.emit_to_file m CodeGenFileType.ObjectFile filename machine; + try + TargetMachine.emit_to_file m CodeGenFileType.ObjectFile + "/nonexistent/file" machine; + failwith "must raise" + with Llvm_target.Error _ -> + (); + + let buf = TargetMachine.emit_to_memory_buffer m CodeGenFileType.ObjectFile + machine in + Llvm.MemoryBuffer.dispose buf + + +(*===-- Driver ------------------------------------------------------------===*) + +let _ = + test_target_data (); + test_target (); + test_target_machine (); + test_code_emission (); + dispose_module m |