2013-11-01 00:26:01 +00:00
|
|
|
/*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
|
2007-12-11 00:20:48 +00:00
|
|
|
|* *|
|
2019-01-19 08:50:56 +00:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2007-12-11 00:20:48 +00:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
2013-11-01 00:26:01 +00:00
|
|
|
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
2007-12-11 00:20:48 +00:00
|
|
|
|* are by and large transparent wrappers to the corresponding C functions. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include "llvm-c/BitReader.h"
|
2016-04-01 07:56:17 +00:00
|
|
|
#include "llvm-c/Core.h"
|
2007-12-11 00:20:48 +00:00
|
|
|
#include "caml/alloc.h"
|
2007-12-23 16:59:28 +00:00
|
|
|
#include "caml/fail.h"
|
2007-12-11 00:20:48 +00:00
|
|
|
#include "caml/memory.h"
|
2014-10-29 08:15:54 +00:00
|
|
|
#include "caml/callback.h"
|
2007-12-19 22:30:40 +00:00
|
|
|
|
2014-10-30 08:29:29 +00:00
|
|
|
void llvm_raise(value Prototype, char *Message);
|
2007-12-11 00:20:48 +00:00
|
|
|
|
2009-08-19 06:40:29 +00:00
|
|
|
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
2014-10-29 08:15:54 +00:00
|
|
|
CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
|
|
|
LLVMModuleRef M;
|
2014-10-28 06:15:18 +00:00
|
|
|
|
2015-12-18 23:46:42 +00:00
|
|
|
if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
|
2016-04-01 07:56:17 +00:00
|
|
|
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
2014-10-28 06:15:18 +00:00
|
|
|
|
2014-10-29 08:15:54 +00:00
|
|
|
return M;
|
2007-12-19 22:30:40 +00:00
|
|
|
}
|
2007-12-11 00:20:48 +00:00
|
|
|
|
2009-08-19 06:40:29 +00:00
|
|
|
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
2014-10-29 08:15:54 +00:00
|
|
|
CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
2007-12-11 00:20:48 +00:00
|
|
|
LLVMModuleRef M;
|
2014-10-28 06:15:18 +00:00
|
|
|
|
2015-12-18 23:46:42 +00:00
|
|
|
if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
|
2016-04-01 07:56:17 +00:00
|
|
|
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
2014-10-28 06:15:18 +00:00
|
|
|
|
2014-10-29 08:15:54 +00:00
|
|
|
return M;
|
2007-12-11 00:20:48 +00:00
|
|
|
}
|