[lab2]checkopint with "while, continue, break" not implemented

This commit is contained in:
ladev789
2025-03-31 20:46:04 +08:00
parent dfa396b06f
commit 9d619b11d7
4 changed files with 8 additions and 6 deletions

View File

@@ -264,7 +264,7 @@ std::any SysYIRGenerator::visitUnaryExp(SysYParser::UnaryExpContext* ctx) {
std::string argList = ""; std::string argList = "";
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
if (i > 0) argList += ", "; if (i > 0) argList += ", ";
argList += args[i]; argList +=tmpTable[args[i]] + " noundef " + args[i];
} }
irStream << " " << temp << " = call " << currentReturnType << " @" << funcName << "(" << argList << ")\n"; irStream << " " << temp << " = call " << currentReturnType << " @" << funcName << "(" << argList << ")\n";
tmpTable[temp] = currentReturnType; tmpTable[temp] = currentReturnType;

View File

@@ -23,9 +23,11 @@ private:
std::vector<std::string> breakStack; std::vector<std::string> breakStack;
std::vector<std::string> continueStack; std::vector<std::string> continueStack;
bool hasReturn = false; bool hasReturn = false;
std::stack<std::string> loopEndStack; struct LoopLabels {
std::stack<std::string> loopCondStack; std::string breakLabel;
std::string continueLabel;
};
std::stack<LoopLabels> loopStack; // 用于管理循环的break和continue标签
std::string getNextTemp(); std::string getNextTemp();
std::string getLLVMType(const std::string& type); std::string getLLVMType(const std::string& type);

View File

@@ -1,7 +1,7 @@
//test file for backend lab //test file for backend lab
int main() { int main() {
int a; int a = 1;
const int b = 2; const int b = 2;
int c; int c;

View File

@@ -7,7 +7,7 @@ int mul(int x, int y) {
int main(){ int main(){
int a, b; int a, b;
a = 10; a = 10;
b = 0; b = 3;
a = mul(a, b); a = mul(a, b);
return a + b; return a + b;
} }