aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/Reader/BitReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bitcode/Reader/BitReader.cpp')
-rw-r--r--lib/Bitcode/Reader/BitReader.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp
index 52851cd142da..e5b8f7c7685a 100644
--- a/lib/Bitcode/Reader/BitReader.cpp
+++ b/lib/Bitcode/Reader/BitReader.cpp
@@ -9,6 +9,7 @@
#include "llvm-c/BitReader.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/MemoryBuffer.h"
#include <string>
#include <cstring>
@@ -22,7 +23,24 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule, char **OutMessage) {
std::string Message;
- *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message));
+ *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), getGlobalContext(),
+ &Message));
+ if (!*OutModule) {
+ if (OutMessage)
+ *OutMessage = strdup(Message.c_str());
+ return 1;
+ }
+
+ return 0;
+}
+
+int LLVMParseBitcodeInContext(LLVMMemoryBufferRef MemBuf,
+ LLVMContextRef ContextRef,
+ LLVMModuleRef *OutModule, char **OutMessage) {
+ std::string Message;
+
+ *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef),
+ &Message));
if (!*OutModule) {
if (OutMessage)
*OutMessage = strdup(Message.c_str());
@@ -37,10 +55,29 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
Optionally returns a human-readable error message via OutMessage. */
int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP,
- char **OutMessage) {
+ char **OutMessage) {
+ std::string Message;
+
+ *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), getGlobalContext(),
+ &Message));
+
+ if (!*OutMP) {
+ if (OutMessage)
+ *OutMessage = strdup(Message.c_str());
+ return 1;
+ }
+
+ return 0;
+}
+
+int LLVMGetBitcodeModuleProviderInContext(LLVMMemoryBufferRef MemBuf,
+ LLVMContextRef ContextRef,
+ LLVMModuleProviderRef *OutMP,
+ char **OutMessage) {
std::string Message;
- *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message));
+ *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), *unwrap(ContextRef),
+ &Message));
if (!*OutMP) {
if (OutMessage)
*OutMessage = strdup(Message.c_str());