[lab2]checkopint with "while, continue, break" not implemented
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user