CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
80 lines
2.2 KiB
OCaml
80 lines
2.2 KiB
OCaml
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/irreader.ml
|
|
* RUN: %ocamlc -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
|
|
* RUN: %t/executable
|
|
* RUN: %ocamlopt -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
|
|
* RUN: %t/executable
|
|
* 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 = create_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"
|
|
|
|
(* TODO: Replace with Fun.protect when the minimum OCaml version supports it. *)
|
|
let protect ~finally f =
|
|
try
|
|
let r = f () in
|
|
finally ();
|
|
r
|
|
with x ->
|
|
finally ();
|
|
raise x
|
|
|
|
|
|
(*===-- IR Reader ---------------------------------------------------------===*)
|
|
|
|
let test_irreader () =
|
|
begin
|
|
let buf = MemoryBuffer.of_string "@foo = global i32 42" in
|
|
let m = protect ~finally:(fun () -> MemoryBuffer.dispose buf)
|
|
(fun () -> parse_ir_bitcode_or_assembly context buf) in
|
|
protect ~finally:(fun () -> dispose_module m) (fun () ->
|
|
match lookup_global "foo" m with
|
|
| Some foo ->
|
|
insist (global_initializer foo =
|
|
Some (const_int (i32_type context) 42))
|
|
| None ->
|
|
failwith "global")
|
|
end;
|
|
|
|
begin
|
|
let buf = MemoryBuffer.of_string "@foo = global garble" in
|
|
let parsed = protect ~finally:(fun () -> MemoryBuffer.dispose buf)
|
|
(fun () ->
|
|
try
|
|
let m = parse_ir_bitcode_or_assembly context buf in
|
|
dispose_module m;
|
|
true
|
|
with Llvm_irreader.Error _ ->
|
|
false)
|
|
in
|
|
if parsed then
|
|
failwith "parsed"
|
|
end
|
|
|
|
|
|
(*===-- Driver ------------------------------------------------------------===*)
|
|
|
|
let _ =
|
|
suite "irreader" test_irreader;
|
|
dispose_context context
|