Add addAST function to the JIT
This commit is contained in:
parent
8c85dd4bbe
commit
c63425485c
|
@ -27,6 +27,7 @@
|
|||
#include "serene/errors.h"
|
||||
#include "serene/errors/error.h"
|
||||
#include "serene/export.h"
|
||||
#include "serene/namespace.h"
|
||||
#include "serene/utils.h"
|
||||
|
||||
#include <llvm/ADT/StringRef.h>
|
||||
|
@ -181,6 +182,8 @@ public:
|
|||
llvm::Optional<errors::ErrorTree> addNS(Namespace &ns,
|
||||
reader::LocationRange &loc);
|
||||
|
||||
llvm::Optional<errors::ErrorTree> addAST(exprs::Ast &ast);
|
||||
|
||||
Namespace &getActiveNS();
|
||||
};
|
||||
|
||||
|
|
|
@ -147,7 +147,6 @@ public:
|
|||
|
||||
SereneContext &getContext();
|
||||
|
||||
// TODO: Fix the return type and use a `llvm::Optional` instead
|
||||
/// Generate and return a MLIR ModuleOp tha contains the IR of the namespace
|
||||
/// with respect to the compilation phase
|
||||
MaybeModuleOp generate(unsigned offset = 0);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
set(LLVM_TARGET_DEFINITIONS dialect.td)
|
||||
mlir_tablegen(ops.h.inc -gen-op-decls)
|
||||
mlir_tablegen(ops.cpp.inc -gen-op-defs)
|
||||
mlir_tablegen(types.h.inc -gen-typedef-decls)
|
||||
mlir_tablegen(types.cpp.inc -gen-typedef-defs)
|
||||
mlir_tablegen(dialect.h.inc -gen-dialect-decls)
|
||||
mlir_tablegen(dialect.cpp.inc -gen-dialect-defs)
|
||||
add_public_tablegen_target(SereneDialectGen)
|
||||
|
|
|
@ -462,6 +462,26 @@ MaybeJIT Halley::make(SereneContext &serene_ctx,
|
|||
return MaybeJIT(std::move(jitEngine));
|
||||
};
|
||||
|
||||
llvm::Optional<errors::ErrorTree> Halley::addAST(exprs::Ast &ast) {
|
||||
auto offset = activeNS->getTree().size();
|
||||
auto errs = activeNS->addTree(ast);
|
||||
|
||||
if (errs) {
|
||||
return errs.getValue();
|
||||
}
|
||||
|
||||
auto maybeModule = activeNS->compileToLLVMFromOffset(offset);
|
||||
|
||||
auto tsm = std::move(maybeModule.getValue());
|
||||
tsm.withModuleDo([](llvm::Module &m) { packFunctionArguments(&m); });
|
||||
|
||||
auto *dylib = ctx.getLatestJITDylib(*activeNS);
|
||||
// TODO: Make sure that the data layout of the module is the same as the
|
||||
// engine
|
||||
cantFail(engine->addIRModule(*dylib, std::move(tsm)));
|
||||
return llvm::None;
|
||||
};
|
||||
|
||||
Namespace &Halley::getActiveNS() { return *activeNS; };
|
||||
|
||||
llvm::Expected<std::unique_ptr<Halley>> makeHalleyJIT(SereneContext &ctx) {
|
||||
|
|
|
@ -109,34 +109,37 @@ SERENE_EXPORT exprs::MaybeAst read(SereneContext &ctx, std::string &input) {
|
|||
|
||||
SERENE_EXPORT exprs::MaybeNode eval(SereneContext &ctx, exprs::Ast &input) {
|
||||
|
||||
// TODO: Fix the eval function
|
||||
UNUSED(input);
|
||||
|
||||
auto loc = reader::LocationRange::UnknownLocation("nsname");
|
||||
|
||||
auto ns = ctx.importNamespace("docs.examples.hello_world", loc);
|
||||
// auto ns = ctx.importNamespace("docs.examples.hello_world", loc);
|
||||
|
||||
if (!ns) {
|
||||
auto es = ns.getError();
|
||||
auto nsloadErr = errors::makeError(loc, errors::NSLoadError);
|
||||
es.push_back(nsloadErr);
|
||||
return exprs::MaybeNode::error(es);
|
||||
// if (!ns) {
|
||||
// auto es = ns.getError();
|
||||
// auto nsloadErr = errors::makeError(loc, errors::NSLoadError);
|
||||
// es.push_back(nsloadErr);
|
||||
// return exprs::MaybeNode::error(es);
|
||||
// }
|
||||
|
||||
auto errs = ctx.jit->addAST(input);
|
||||
if (errs) {
|
||||
return exprs::MaybeNode::error(errs.getValue());
|
||||
}
|
||||
|
||||
auto e = input[0];
|
||||
auto *sym = llvm::dyn_cast<exprs::Symbol>(e.get());
|
||||
// auto e = input[0];
|
||||
// auto *sym = llvm::dyn_cast<exprs::Symbol>(e.get());
|
||||
|
||||
if (sym == nullptr) {
|
||||
return exprs::makeErrorNode(e->location, errors::UnknownError, "only sym");
|
||||
}
|
||||
// if (sym == nullptr) {
|
||||
// return exprs::makeErrorNode(e->location, errors::UnknownError, "only
|
||||
// sym");
|
||||
// }
|
||||
|
||||
llvm::outs() << "Read: " << sym->toString() << "\n";
|
||||
// llvm::outs() << "Read: " << sym->toString() << "\n";
|
||||
|
||||
// Get the anonymous expression's JITSymbol.
|
||||
auto symptr = ctx.jit->lookup(*sym);
|
||||
if (!symptr) {
|
||||
return exprs::MaybeNode::error(symptr.getError());
|
||||
}
|
||||
// // Get the anonymous expression's JITSymbol.
|
||||
// auto symptr = ctx.jit->lookup(*sym);
|
||||
// if (!symptr) {
|
||||
// return exprs::MaybeNode::error(symptr.getError());
|
||||
// }
|
||||
|
||||
llvm::outs() << "eval here\n";
|
||||
|
||||
|
|
Loading…
Reference in New Issue