}
)";
+inline llvm::Error createSMDiagnosticError(llvm::SMDiagnostic &Diag) {
+ using namespace llvm;
+ std::string Msg;
+ {
+ raw_string_ostream OS(Msg);
+ Diag.print("", OS);
+ }
+ return make_error<StringError>(std::move(Msg), inconvertibleErrorCode());
+}
+
inline llvm::Expected<llvm::orc::ThreadSafeModule>
parseExampleModule(llvm::StringRef Source, llvm::StringRef Name) {
using namespace llvm;
- using namespace llvm::orc;
-
auto Ctx = std::make_unique<LLVMContext>();
SMDiagnostic Err;
- auto M = parseIR(MemoryBufferRef(Source, Name), Err, *Ctx);
-
- if (!M) {
- std::string ErrMsg;
- {
- raw_string_ostream ErrStream(ErrMsg);
- Err.print("", ErrStream);
- }
- return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
- }
+ if (auto M = parseIR(MemoryBufferRef(Source, Name), Err, *Ctx))
+ return orc::ThreadSafeModule(std::move(M), std::move(Ctx));
- return ThreadSafeModule(std::move(M), std::move(Ctx));
+ return createSMDiagnosticError(Err);
}
#endif // LLVM_EXAMPLES_ORCV2EXAMPLES_EXAMPLEMODULES_H