[lab2]now 01_add.ll generated by sysy can be compiled to executable by clang

This commit is contained in:
ladev789
2025-03-31 03:54:39 +08:00
parent 8a743a0036
commit dfa396b06f

View File

@@ -137,6 +137,7 @@ std::any SysYIRGenerator::visitFuncDef(SysYParser::FuncDefContext* ctx) {
irStream << " store " << llvmType << " " << symbolTable[varName].first << ", " << llvmType irStream << " store " << llvmType << " " << symbolTable[varName].first << ", " << llvmType
<< "* " << allocaName << ", align 4\n"; << "* " << allocaName << ", align 4\n";
symbolTable[varName] = {allocaName, llvmType};
} }
} }
ctx->blockStmt()->accept(this); ctx->blockStmt()->accept(this);
@@ -175,7 +176,7 @@ std::any SysYIRGenerator::visitStmt(SysYParser::StmtContext* ctx) {
throw std::runtime_error("Invalid float literal: " + rhs); throw std::runtime_error("Invalid float literal: " + rhs);
} }
} }
irStream << " store1 " << lhsType << " " << rhs << ", " << lhsType irStream << " store " << lhsType << " " << rhs << ", " << lhsType
<< "* " << lhsAlloca << ", align 4\n"; << "* " << lhsAlloca << ", align 4\n";
} else if (ctx->RETURN()) { } else if (ctx->RETURN()) {
hasReturn = true; hasReturn = true;