diff options
author | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-12-19 22:30:40 +0000 |
---|---|---|
committer | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-12-19 22:30:40 +0000 |
commit | 91ab68bbf0e71ea233d92871f637fc48b6c4db8d (patch) | |
tree | 6bfc10578fca9bc86214295b290bec5b0821be8f /lib/Bitcode/Reader | |
parent | 15e8f535219301e37eceba56d3ae047db8e10f4f (diff) | |
download | external_llvm-91ab68bbf0e71ea233d92871f637fc48b6c4db8d.zip external_llvm-91ab68bbf0e71ea233d92871f637fc48b6c4db8d.tar.gz external_llvm-91ab68bbf0e71ea233d92871f637fc48b6c4db8d.tar.bz2 |
Adding bindings for memory buffers and module providers. Switching
to exceptions rather than variants for error handling in Ocaml.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45226 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader')
-rw-r--r-- | lib/Bitcode/Reader/BitReader.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp index c660088..c7c3869 100644 --- a/lib/Bitcode/Reader/BitReader.cpp +++ b/lib/Bitcode/Reader/BitReader.cpp @@ -14,20 +14,33 @@ using namespace llvm; - -int LLVMReadBitcodeFromFile(const char *Path, LLVMModuleRef *OutModule, - char **OutMessage) { +/* Builds a module from the bitcode in the specified memory buffer, returning a + reference to the module via the OutModule parameter. Returns 0 on success. + Optionally returns a human-readable error message via OutMessage. */ +int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, + LLVMModuleRef *OutModule, char **OutMessage) { std::string Message; - MemoryBuffer *buf = MemoryBuffer::getFile(Path, strlen(Path), &Message); - if (!buf) { - if (!OutMessage) + *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message)); + if (!*OutModule) { + if (OutMessage) *OutMessage = strdup(Message.c_str()); return 1; } - *OutModule = wrap(ParseBitcodeFile(buf, &Message)); - if (!*OutModule) { + return 0; +} + +/* Reads a module from the specified path, returning via the OutModule parameter + a module provider which performs lazy deserialization. Returns 0 on success. + Optionally returns a human-readable error message via OutMessage. */ +int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, + LLVMModuleProviderRef *OutMP, + char **OutMessage) { + std::string Message; + + *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message)); + if (!*OutMP) { if (OutMessage) *OutMessage = strdup(Message.c_str()); return 1; @@ -35,8 +48,3 @@ int LLVMReadBitcodeFromFile(const char *Path, LLVMModuleRef *OutModule, return 0; } - -void LLVMDisposeBitcodeReaderMessage(char *Message) { - if (Message) - free(Message); -} |