1 /*===-- bitwriter_ocaml.c - LLVM Ocaml Glue ---------------------*- C++ -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file was developed by Gordon Henriksen and is distributed under the *|
6 |* University of Illinois Open Source License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
11 |* are by and large transparent wrappers to the corresponding C functions. *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c/BitReader.h"
16 #include "caml/alloc.h"
17 #include "caml/mlvalues.h"
18 #include "caml/memory.h"
20 /*===-- Modules -----------------------------------------------------------===*/
22 /* string -> bitreader_result
24 type bitreader_result =
25 | Bitreader_success of Llvm.llmodule
26 | Bitreader_failure of string
28 CAMLprim value llvm_read_bitcode_file(value Path) {
32 CAMLlocal2(Variant, MessageVal);
34 if (LLVMReadBitcodeFromFile(String_val(Path), &M, &Message)) {
35 MessageVal = copy_string(Message);
36 LLVMDisposeBitcodeReaderMessage(Message);
38 Variant = alloc(1, 1);
39 Field(Variant, 0) = MessageVal;
41 Variant = alloc(1, 0);
42 Field(Variant, 0) = Val_op(M);