From 9d619b11d7c4aacaebc654d33488d0eb08c36b97 Mon Sep 17 00:00:00 2001 From: ladev789 Date: Mon, 31 Mar 2025 20:46:04 +0800 Subject: [PATCH] [lab2]checkopint with "while, continue, break" not implemented --- src/SysYIRGenerator.cpp | 2 +- src/SysYIRGenerator.h | 8 +++++--- test/10_test.sy | 2 +- test/11_add2.sy | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/SysYIRGenerator.cpp b/src/SysYIRGenerator.cpp index 9077eee..9974771 100644 --- a/src/SysYIRGenerator.cpp +++ b/src/SysYIRGenerator.cpp @@ -264,7 +264,7 @@ std::any SysYIRGenerator::visitUnaryExp(SysYParser::UnaryExpContext* ctx) { std::string argList = ""; for (size_t i = 0; i < args.size(); ++i) { if (i > 0) argList += ", "; - argList += args[i]; + argList +=tmpTable[args[i]] + " noundef " + args[i]; } irStream << " " << temp << " = call " << currentReturnType << " @" << funcName << "(" << argList << ")\n"; tmpTable[temp] = currentReturnType; diff --git a/src/SysYIRGenerator.h b/src/SysYIRGenerator.h index 3e07914..8608cc2 100644 --- a/src/SysYIRGenerator.h +++ b/src/SysYIRGenerator.h @@ -23,9 +23,11 @@ private: std::vector breakStack; std::vector continueStack; bool hasReturn = false; - std::stack loopEndStack; - std::stack loopCondStack; - + struct LoopLabels { + std::string breakLabel; + std::string continueLabel; + }; + std::stack loopStack; // 用于管理循环的break和continue标签 std::string getNextTemp(); std::string getLLVMType(const std::string& type); diff --git a/test/10_test.sy b/test/10_test.sy index bf84af2..cadb6da 100644 --- a/test/10_test.sy +++ b/test/10_test.sy @@ -1,7 +1,7 @@ //test file for backend lab int main() { - int a; + int a = 1; const int b = 2; int c; diff --git a/test/11_add2.sy b/test/11_add2.sy index c783a32..7d3ff7f 100644 --- a/test/11_add2.sy +++ b/test/11_add2.sy @@ -7,7 +7,7 @@ int mul(int x, int y) { int main(){ int a, b; a = 10; - b = 0; + b = 3; a = mul(a, b); return a + b; }