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 = {};
|
||||||
ValueCounter values;
|
if (varDef->initVal() != nullptr) {
|
||||||
Utils::tree2Array(type, root, dims, dims.size(), values, &builder);
|
ArrayValueTree* root = std::any_cast<ArrayValueTree *>(varDef->initVal()->accept(this));
|
||||||
delete root;
|
Utils::tree2Array(type, root, dims, dims.size(), values, &builder);
|
||||||
|
delete root;
|
||||||
|
}
|
||||||
// 创建全局变量,并更新符号表
|
// 创建全局变量,并更新符号表
|
||||||
module->createGlobalValue(name, Type::getPointerType(type), dims, values);
|
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()));
|
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) {
|
if (funcType!= returnValue->getType() && returnValue != nullptr) {
|
||||||
ConstantValue * constValue = dynamic_cast<ConstantValue *>(returnValue);
|
ConstantValue * constValue = dynamic_cast<ConstantValue *>(returnValue);
|
||||||
if (constValue != nullptr) {
|
if (constValue != nullptr) {
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ void SysYPrinter::printIR() {
|
|||||||
|
|
||||||
const auto &functions = pModule->getFunctions();
|
const auto &functions = pModule->getFunctions();
|
||||||
|
|
||||||
// Print target datalayout and triple (minimal required by LLVM)
|
//TODO: 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";
|
|
||||||
|
|
||||||
printGlobalVariable();
|
printGlobalVariable();
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class IRBuilder {
|
|||||||
std::string newName;
|
std::string newName;
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "%" << tmpIndex;
|
ss << tmpIndex;
|
||||||
newName = ss.str();
|
newName = ss.str();
|
||||||
tmpIndex++;
|
tmpIndex++;
|
||||||
} else {
|
} else {
|
||||||
@@ -136,7 +136,7 @@ class IRBuilder {
|
|||||||
std::string newName;
|
std::string newName;
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "%" << tmpIndex;
|
ss << tmpIndex;
|
||||||
newName = ss.str();
|
newName = ss.str();
|
||||||
tmpIndex++;
|
tmpIndex++;
|
||||||
} else {
|
} else {
|
||||||
@@ -221,7 +221,7 @@ class IRBuilder {
|
|||||||
std::string newName;
|
std::string newName;
|
||||||
if (name.empty() && callee->getReturnType() != Type::getVoidType()) {
|
if (name.empty() && callee->getReturnType() != Type::getVoidType()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "%" << tmpIndex;
|
ss << tmpIndex;
|
||||||
newName = ss.str();
|
newName = ss.str();
|
||||||
tmpIndex++;
|
tmpIndex++;
|
||||||
} else {
|
} else {
|
||||||
@@ -268,7 +268,7 @@ class IRBuilder {
|
|||||||
std::string newName;
|
std::string newName;
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "%" << tmpIndex;
|
ss << tmpIndex;
|
||||||
newName = ss.str();
|
newName = ss.str();
|
||||||
tmpIndex++;
|
tmpIndex++;
|
||||||
} else {
|
} else {
|
||||||
@@ -284,7 +284,7 @@ class IRBuilder {
|
|||||||
std::string newName;
|
std::string newName;
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "%" << tmpIndex;
|
ss << tmpIndex;
|
||||||
newName = ss.str();
|
newName = ss.str();
|
||||||
tmpIndex++;
|
tmpIndex++;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
0
src/include/Mem2Reg.h
Normal file
0
src/include/Mem2Reg.h
Normal file
Reference in New Issue
Block a user