fix % repeat in IR print
This commit is contained in:
0
src/Mem2Reg.cpp
Normal file
0
src/Mem2Reg.cpp
Normal file
@@ -73,10 +73,12 @@ std::any SysYIRGenerator::visitGlobalVarDecl(SysYParser::GlobalVarDeclContext *c
|
||||
}
|
||||
}
|
||||
|
||||
ArrayValueTree* root = std::any_cast<ArrayValueTree *>(varDef->initVal()->accept(this));
|
||||
ValueCounter values;
|
||||
Utils::tree2Array(type, root, dims, dims.size(), values, &builder);
|
||||
delete root;
|
||||
ValueCounter values = {};
|
||||
if (varDef->initVal() != nullptr) {
|
||||
ArrayValueTree* root = std::any_cast<ArrayValueTree *>(varDef->initVal()->accept(this));
|
||||
Utils::tree2Array(type, root, dims, dims.size(), values, &builder);
|
||||
delete root;
|
||||
}
|
||||
// 创建全局变量,并更新符号表
|
||||
module->createGlobalValue(name, Type::getPointerType(type), dims, values);
|
||||
}
|
||||
@@ -456,7 +458,7 @@ std::any SysYIRGenerator::visitReturnStmt(SysYParser::ReturnStmtContext *ctx) {
|
||||
returnValue = std::any_cast<Value *>(visitExp(ctx->exp()));
|
||||
}
|
||||
|
||||
Type* funcType = builder.getBasicBlock()->getParent()->getType();
|
||||
Type* funcType = builder.getBasicBlock()->getParent()->getReturnType();
|
||||
if (funcType!= returnValue->getType() && returnValue != nullptr) {
|
||||
ConstantValue * constValue = dynamic_cast<ConstantValue *>(returnValue);
|
||||
if (constValue != nullptr) {
|
||||
|
||||
@@ -11,9 +11,7 @@ void SysYPrinter::printIR() {
|
||||
|
||||
const auto &functions = pModule->getFunctions();
|
||||
|
||||
// Print target datalayout and triple (minimal required by LLVM)
|
||||
std::cout << "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128\"\n";
|
||||
std::cout << "target triple = \"i386-pc-linux-gnu\"\n\n";
|
||||
//TODO: Print target datalayout and triple (minimal required by LLVM)
|
||||
|
||||
printGlobalVariable();
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class IRBuilder {
|
||||
std::string newName;
|
||||
if (name.empty()) {
|
||||
std::stringstream ss;
|
||||
ss << "%" << tmpIndex;
|
||||
ss << tmpIndex;
|
||||
newName = ss.str();
|
||||
tmpIndex++;
|
||||
} else {
|
||||
@@ -136,7 +136,7 @@ class IRBuilder {
|
||||
std::string newName;
|
||||
if (name.empty()) {
|
||||
std::stringstream ss;
|
||||
ss << "%" << tmpIndex;
|
||||
ss << tmpIndex;
|
||||
newName = ss.str();
|
||||
tmpIndex++;
|
||||
} else {
|
||||
@@ -221,7 +221,7 @@ class IRBuilder {
|
||||
std::string newName;
|
||||
if (name.empty() && callee->getReturnType() != Type::getVoidType()) {
|
||||
std::stringstream ss;
|
||||
ss << "%" << tmpIndex;
|
||||
ss << tmpIndex;
|
||||
newName = ss.str();
|
||||
tmpIndex++;
|
||||
} else {
|
||||
@@ -268,7 +268,7 @@ class IRBuilder {
|
||||
std::string newName;
|
||||
if (name.empty()) {
|
||||
std::stringstream ss;
|
||||
ss << "%" << tmpIndex;
|
||||
ss << tmpIndex;
|
||||
newName = ss.str();
|
||||
tmpIndex++;
|
||||
} else {
|
||||
@@ -284,7 +284,7 @@ class IRBuilder {
|
||||
std::string newName;
|
||||
if (name.empty()) {
|
||||
std::stringstream ss;
|
||||
ss << "%" << tmpIndex;
|
||||
ss << tmpIndex;
|
||||
newName = ss.str();
|
||||
tmpIndex++;
|
||||
} else {
|
||||
|
||||
0
src/include/Mem2Reg.h
Normal file
0
src/include/Mem2Reg.h
Normal file
Reference in New Issue
Block a user