Fix the unchecked Expected<T> in the context class

This commit is contained in:
Sameer Rahmani 2022-02-19 14:54:03 +00:00
parent bf0e24d75e
commit 8dde04d6ce
4 changed files with 13 additions and 8 deletions

View File

@ -127,8 +127,7 @@ public:
/// Execute the given function \p f by setting the `currentNS` /// Execute the given function \p f by setting the `currentNS`
/// to the given \p nsName. It will restore the value of `currentNS` /// to the given \p nsName. It will restore the value of `currentNS`
/// after \p f returned. It also passes the old value of `currentNS` /// after \p f returned.
/// to \p f.
template <typename T> template <typename T>
T withCurrentNS(llvm::StringRef nsName, CurrentNSFn<T> f) { T withCurrentNS(llvm::StringRef nsName, CurrentNSFn<T> f) {
assert(!currentNS.empty() && "The currentNS is not initialized!"); assert(!currentNS.empty() && "The currentNS is not initialized!");
@ -215,8 +214,8 @@ public:
auto maybeJIT = serene::jit::makeHalleyJIT(*ctx); auto maybeJIT = serene::jit::makeHalleyJIT(*ctx);
if (!maybeJIT) { if (!maybeJIT) {
// TODO: Raise an error here auto err = maybeJIT.takeError();
return nullptr; panic(*ctx, err);
} }
ctx->jit.swap(*maybeJIT); ctx->jit.swap(*maybeJIT);
@ -278,7 +277,10 @@ private:
}; };
/// Creates a new context object. Contexts are used through out the compilation /// Creates a new context object. Contexts are used through out the compilation
/// process to store the state /// process to store the state.
///
/// \p opts is an instance of \c Options that can be used to set options of
/// of the compiler.
SERENE_EXPORT std::unique_ptr<SereneContext> SERENE_EXPORT std::unique_ptr<SereneContext>
makeSereneContext(Options opts = Options()); makeSereneContext(Options opts = Options());

View File

@ -43,7 +43,6 @@ Namespace *SereneContext::getNS(llvm::StringRef nsName) {
}; };
Namespace &SereneContext::getCurrentNS() { Namespace &SereneContext::getCurrentNS() {
llvm::outs() << this->currentNS << "\n";
if (this->currentNS.empty() || (namespaces.count(this->currentNS) == 0)) { if (this->currentNS.empty() || (namespaces.count(this->currentNS) == 0)) {
panic(*this, llvm::formatv("getCurrentNS: Namespace '{0}' does not exist", panic(*this, llvm::formatv("getCurrentNS: Namespace '{0}' does not exist",
this->currentNS) this->currentNS)

View File

@ -185,7 +185,7 @@ std::unique_ptr<DiagnosticEngine> makeDiagnosticEngine(SereneContext &ctx) {
void DiagnosticEngine::emit(const llvm::Error &err) { void DiagnosticEngine::emit(const llvm::Error &err) {
UNUSED(ctx); UNUSED(ctx);
// TODO: create a diag and print it // TODO: create a diag and print it
llvm::errs() << err << "\n"; llvm::errs() << "[Error]: " << err << "\n";
}; };
// void DiagnosticEngine::emit(const llvm::Error &errs) { // void DiagnosticEngine::emit(const llvm::Error &errs) {

View File

@ -482,8 +482,12 @@ Namespace &Halley::getActiveNS() { return *activeNS; };
llvm::Expected<std::unique_ptr<Halley>> makeHalleyJIT(SereneContext &ctx) { llvm::Expected<std::unique_ptr<Halley>> makeHalleyJIT(SereneContext &ctx) {
llvm::orc::JITTargetMachineBuilder jtmb(ctx.getTargetTriple()); llvm::orc::JITTargetMachineBuilder jtmb(ctx.getTargetTriple());
auto maybeJIT = Halley::make(ctx, std::move(jtmb));
if (!maybeJIT) {
return maybeJIT.takeError();
}
return Halley::make(ctx, std::move(jtmb)); return maybeJIT;
}; };
} // namespace jit } // namespace jit
} // namespace serene } // namespace serene