+ "Could not open input file: " + EC.message());
+ return nullptr;
+ }
+
+ return ParseIR(FileOrErr.get().get(), Err, Context);
+}
+
+//===----------------------------------------------------------------------===//
+// C API.
+//===----------------------------------------------------------------------===//
+
+LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
+ LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
+ char **OutMessage) {
+ SMDiagnostic Diag;
+
+ std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
+ *OutM = wrap(ParseIR(MB.get(), Diag, *unwrap(ContextRef)));
+
+ if(!*OutM) {
+ if (OutMessage) {
+ std::string buf;
+ raw_string_ostream os(buf);
+
+ Diag.print(nullptr, os, false);
+ os.flush();
+
+ *OutMessage = strdup(buf.c_str());
+ }
+ return 1;