2013-11-01 08:26:01 +08:00
|
|
|
/*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
|
2007-12-11 08:20:48 +08:00
|
|
|
|* *|
|
|
|
|
|* The LLVM Compiler Infrastructure *|
|
|
|
|
|* *|
|
2007-12-30 06:59:10 +08:00
|
|
|
|* This file is distributed under the University of Illinois Open Source *|
|
|
|
|
|* License. See LICENSE.TXT for details. *|
|
2007-12-11 08:20:48 +08:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
2013-11-01 08:26:01 +08:00
|
|
|
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
2007-12-11 08:20:48 +08:00
|
|
|
|* are by and large transparent wrappers to the corresponding C functions. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include "llvm-c/BitReader.h"
|
2016-04-01 15:56:17 +08:00
|
|
|
#include "llvm-c/Core.h"
|
2007-12-11 08:20:48 +08:00
|
|
|
#include "caml/alloc.h"
|
2007-12-24 00:59:28 +08:00
|
|
|
#include "caml/fail.h"
|
2007-12-11 08:20:48 +08:00
|
|
|
#include "caml/memory.h"
|
2014-10-29 16:15:54 +08:00
|
|
|
#include "caml/callback.h"
|
2007-12-20 06:30:40 +08:00
|
|
|
|
2014-10-30 16:29:29 +08:00
|
|
|
void llvm_raise(value Prototype, char *Message);
|
2007-12-11 08:20:48 +08:00
|
|
|
|
2009-08-19 14:40:29 +08:00
|
|
|
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
2014-10-29 16:15:54 +08:00
|
|
|
CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
|
|
|
LLVMModuleRef M;
|
2014-10-28 14:15:18 +08:00
|
|
|
|
2015-12-19 07:46:42 +08:00
|
|
|
if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
|
2016-04-01 15:56:17 +08:00
|
|
|
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
2014-10-28 14:15:18 +08:00
|
|
|
|
2014-10-29 16:15:54 +08:00
|
|
|
return M;
|
2007-12-20 06:30:40 +08:00
|
|
|
}
|
2007-12-11 08:20:48 +08:00
|
|
|
|
2009-08-19 14:40:29 +08:00
|
|
|
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
2014-10-29 16:15:54 +08:00
|
|
|
CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
2007-12-11 08:20:48 +08:00
|
|
|
LLVMModuleRef M;
|
2014-10-28 14:15:18 +08:00
|
|
|
|
2015-12-19 07:46:42 +08:00
|
|
|
if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
|
2016-04-01 15:56:17 +08:00
|
|
|
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
2014-10-28 14:15:18 +08:00
|
|
|
|
2014-10-29 16:15:54 +08:00
|
|
|
return M;
|
2007-12-11 08:20:48 +08:00
|
|
|
}
|