fix heap overflow

This commit is contained in:
ridethepig 2023-06-13 21:28:43 +08:00
parent 8b0f0f63a1
commit 988534f446
2 changed files with 8 additions and 3 deletions

View File

@ -88,7 +88,7 @@ int main(int argc, const char **argv) {
ANTLRInputStream input(ifs_source_file); ANTLRInputStream input(ifs_source_file);
SysyLexer lexer(&input); SysyLexer lexer(&input);
CommonTokenStream tokens(&lexer); CommonTokenStream tokens(&lexer);
ifs_source_file.close();
// tokens.fill(); // tokens.fill();
// for (auto token : tokens.getTokens()) { // for (auto token : tokens.getTokens()) {
// std::cout << token->toString() << std::endl; // std::cout << token->toString() << std::endl;
@ -96,10 +96,12 @@ int main(int argc, const char **argv) {
SysyParser parser(&tokens); SysyParser parser(&tokens);
parser.removeErrorListeners(); parser.removeErrorListeners();
parser.addErrorListener(new AbortErrorListener()); auto _abort_listener = new AbortErrorListener();
parser.addErrorListener(_abort_listener);
auto tree = parser.program(); auto tree = parser.program();
Visitor visitor(lexer); Visitor visitor(lexer);
visitor.visitProgram(tree); visitor.visitProgram(tree);
delete _abort_listener;
std::vector<std::shared_ptr<Pass>> passes = { std::vector<std::shared_ptr<Pass>> passes = {
std::make_shared<PassBuildCFG>(), std::make_shared<PassBuildCFG>(),
@ -127,6 +129,7 @@ int main(int argc, const char **argv) {
return 1; return 1;
} }
visitor.llir_gen(ofs_llir_file); visitor.llir_gen(ofs_llir_file);
ofs_llir_file.close();
} }
// std::cout << tree->toStringTree(&parser) << std::endl << std::endl; // std::cout << tree->toStringTree(&parser) << std::endl << std::endl;
@ -141,6 +144,7 @@ int main(int argc, const char **argv) {
mc_module.debug1 = true; mc_module.debug1 = true;
mc_module.MC2ASM(ofs_virt_asm_file); mc_module.MC2ASM(ofs_virt_asm_file);
mc_module.debug1 = false; mc_module.debug1 = false;
ofs_virt_asm_file.close();
std::vector<sptr(MCPass)> mc_passes = {std::make_shared<PassRegAlloc>()}; std::vector<sptr(MCPass)> mc_passes = {std::make_shared<PassRegAlloc>()};
for (auto pass : mc_passes) { for (auto pass : mc_passes) {
@ -152,6 +156,7 @@ int main(int argc, const char **argv) {
return 1; return 1;
} }
mc_module.MC2ASM(ofs_asm_file); mc_module.MC2ASM(ofs_asm_file);
ofs_asm_file.close();
} }
return 0; return 0;
} }

View File

@ -82,7 +82,7 @@ static void live_in_blocks(
} }
else if (Value::is<InstLoad>(itr)) { else if (Value::is<InstLoad>(itr)) {
// a load before store, it live in this block // a load before store, it live in this block
if (Value::as<InstLoad>(itr)->operand_list[1] == ai) break; if (Value::as<InstLoad>(itr)->operand_list[0] == ai) break;
} }
} }
} }