Fix globals in JIT

pull/78/head
Ibrahim Numanagić 2022-09-29 20:40:00 -07:00
parent 7655e09e83
commit d5741a27e0
2 changed files with 8 additions and 7 deletions

View File

@ -144,19 +144,19 @@ StmtPtr SimplifyVisitor::transformAssignment(ExprPtr lhs, ExprPtr rhs, ExprPtr t
// Generate new canonical variable name for this assignment and add it to the context
auto canonical = ctx->generateCanonicalName(e->value);
auto assign = N<AssignStmt>(N<IdExpr>(canonical), rhs, type);
val = nullptr;
if (rhs && rhs->isType()) {
ctx->addType(e->value, canonical, lhs->getSrcInfo());
val = ctx->addType(e->value, canonical, lhs->getSrcInfo());
} else {
auto val = ctx->addVar(e->value, canonical, lhs->getSrcInfo());
val = ctx->addVar(e->value, canonical, lhs->getSrcInfo());
if (auto st = getStaticGeneric(type.get()))
val->staticType = st;
}
// Register all toplevel variables as global in JIT mode
bool isGlobal =
(ctx->cache->isJit && ctx->isGlobal() && getStaticGeneric(type.get()) == 0) ||
(canonical == VAR_ARGV);
if (isGlobal && !getStaticGeneric(type.get()))
bool isGlobal = (ctx->cache->isJit && val->isGlobal() && !val->isGeneric() == 0) ||
(canonical == VAR_ARGV);
if (isGlobal && !val->isGeneric())
ctx->cache->addGlobal(canonical);
return assign;

View File

@ -56,8 +56,9 @@ void SimplifyVisitor::visit(WhileStmt *stmt) {
transformConditionalScope(stmt->suite);
ctx->leaveConditionalBlock();
// Dominate loop variables
for (auto &var : ctx->getBase()->getLoop()->seenVars)
for (auto &var : ctx->getBase()->getLoop()->seenVars) {
ctx->findDominatingBinding(var);
}
ctx->getBase()->loops.pop_back();
// Complete while-else clause