[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

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