引入了常量池优化,修改constvalue类并对IR生成修复,能够编译通过
This commit is contained in:
@@ -91,7 +91,7 @@ std::any LLVMIRGenerator::visitVarDecl(SysYParser::VarDeclContext* ctx) {
|
||||
|
||||
if (varDef->ASSIGN()) {
|
||||
value = std::any_cast<std::string>(varDef->initVal()->accept(this));
|
||||
if (irTmpTable.find(value) != irTmpTable.end() && isa<sysy::ConstantValue>(irTmpTable[value])) {
|
||||
if (irTmpTable.find(value) != irTmpTable.end() && sysy::isa<sysy::ConstantValue>(irTmpTable[value])) {
|
||||
initValue = irTmpTable[value];
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ std::any LLVMIRGenerator::visitConstDecl(SysYParser::ConstDeclContext* ctx) {
|
||||
|
||||
try {
|
||||
value = std::any_cast<std::string>(constDef->constInitVal()->accept(this));
|
||||
if (isa<sysy::ConstantValue>(irTmpTable[value])) {
|
||||
if (sysy::isa<sysy::ConstantValue>(irTmpTable[value])) {
|
||||
initValue = irTmpTable[value];
|
||||
}
|
||||
} catch (...) {
|
||||
@@ -310,7 +310,7 @@ std::any LLVMIRGenerator::visitFuncDef(SysYParser::FuncDefContext* ctx) {
|
||||
} else {
|
||||
irStream << " ret " << currentReturnType << " 0\n";
|
||||
sysy::IRBuilder builder(currentIRBlock);
|
||||
builder.createReturnInst(sysy::ConstantValue::get(0));
|
||||
builder.createReturnInst(sysy::ConstantValue::get(getIRType("int"),0));
|
||||
}
|
||||
}
|
||||
irStream << "}\n";
|
||||
@@ -524,10 +524,10 @@ std::any LLVMIRGenerator::visitNumber(SysYParser::NumberContext* ctx) {
|
||||
sysy::Value* irValue = nullptr;
|
||||
if (ctx->ILITERAL()) {
|
||||
value = ctx->ILITERAL()->getText();
|
||||
irValue = sysy::ConstantValue::get(std::stoi(value));
|
||||
irValue = sysy::ConstantValue::get(getIRType("int"), std::stoi(value));
|
||||
} else if (ctx->FLITERAL()) {
|
||||
value = ctx->FLITERAL()->getText();
|
||||
irValue = sysy::ConstantValue::get(std::stof(value));
|
||||
irValue = sysy::ConstantValue::get(getIRType("float"), std::stof(value));
|
||||
} else {
|
||||
value = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user