1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00

Set JIT flag on LLVMVisitor

This commit is contained in:
A. R. Shajii 2021-11-04 13:04:35 -04:00
parent 7f355f912e
commit 2f3c7cc3d4
2 changed files with 21 additions and 8 deletions

View File

@ -25,6 +25,7 @@ JIT::JIT(const std::string &argv0)
engine = {};
seqassert(false, "JIT engine creation error");
}
compiler->getLLVMVisitor()->setJIT(true);
}
llvm::Error JIT::init() {
@ -34,17 +35,11 @@ llvm::Error JIT::init() {
auto transformed = ast::SimplifyVisitor::apply(
cache, std::make_shared<ast::SuiteStmt>(), JIT_FILENAME, {});
auto p = transformSimplified(transformed);
auto typechecked = ast::TypecheckVisitor::apply(cache, std::move(transformed));
ast::TranslateVisitor::apply(cache, std::move(typechecked));
cache->isJit = true; // we still need main(), so set isJit after it has been set
module->setSrcInfo({JIT_FILENAME, 0, 0, 0});
for (auto var : p.second)
llvisitor->registerGlobal(var);
for (auto var : p.second) {
if (auto *func = ir::cast<ir::Func>(var))
func->accept(*llvisitor);
}
module->accept(*llvisitor);
auto pair = llvisitor->takeModule();

View File

@ -229,6 +229,24 @@ public:
explicit LLVMVisitor(bool debug = false, bool jit = false,
const std::string &flags = "");
/// @return true if in debug mode, false otherwise
bool getDebug() const { return db.debug; }
/// Sets debug status.
/// @param d true if debug mode
void setDebug(bool d = true) { db.debug = d; }
/// @return true if in JIT mode, false otherwise
bool getJIT() const { return db.jit; }
/// Sets JIT status.
/// @param j true if JIT mode
void setJIT(bool j = true) { db.jit = j; }
/// @return program flags
std::string getFlags() const { return db.flags; }
/// Sets program flags.
/// @param f flags
void setFlags(const std::string &f) { db.flags = f; }
llvm::LLVMContext &getContext() { return *context; }
llvm::IRBuilder<> &getBuilder() { return *B; }
llvm::Module *getModule() { return M.get(); }