fixed bugs brought out by merging
This commit is contained in:
@@ -15,7 +15,7 @@ add_executable(sysyc
|
|||||||
sysyc.cpp
|
sysyc.cpp
|
||||||
IR.cpp
|
IR.cpp
|
||||||
SysYIRGenerator.cpp
|
SysYIRGenerator.cpp
|
||||||
Backend.cpp
|
# Backend.cpp
|
||||||
RISCv32Backend.cpp
|
RISCv32Backend.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(sysyc PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(sysyc PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|||||||
@@ -35,16 +35,16 @@ std::string RISCv32CodeGen::code_gen() {
|
|||||||
std::string RISCv32CodeGen::module_gen() {
|
std::string RISCv32CodeGen::module_gen() {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
// 生成全局变量(数据段)
|
// 生成全局变量(数据段)
|
||||||
for (const auto& global : *module->getGlobalValues()) {
|
for (const auto& global : module->getGlobals()) {
|
||||||
ss << ".data\n";
|
ss << ".data\n";
|
||||||
ss << ".globl " << global.second->getName() << "\n";
|
ss << ".globl " << global->getName() << "\n";
|
||||||
ss << global.second->getName() << ":\n";
|
ss << global->getName() << ":\n";
|
||||||
ss << " .word 0\n"; // 假设初始化为0
|
ss << " .word 0\n"; // 假设初始化为0
|
||||||
}
|
}
|
||||||
// 生成函数
|
// 生成函数(文本段)
|
||||||
ss << ".text\n";
|
ss << ".text\n";
|
||||||
for (const auto& func : *module->getFunctions()) {
|
for (const auto& func : module->getFunctions()) {
|
||||||
ss << function_gen(func.second);
|
ss << function_gen(func.second.get());
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ int main(int argc, char **argv) {
|
|||||||
SysYIRGenerator generator;
|
SysYIRGenerator generator;
|
||||||
generator.visitCompUnit(moduleAST);
|
generator.visitCompUnit(moduleAST);
|
||||||
if (argStopAfter == "ir") {
|
if (argStopAfter == "ir") {
|
||||||
auto module = generator.get();
|
// auto module = generator.get();
|
||||||
module->print(cout);
|
// module->print(cout);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,6 @@ int main(int argc, char **argv) {
|
|||||||
auto module = generator.get();
|
auto module = generator.get();
|
||||||
sysy::RISCv32CodeGen codegen(module);
|
sysy::RISCv32CodeGen codegen(module);
|
||||||
string asmCode = codegen.code_gen();
|
string asmCode = codegen.code_gen();
|
||||||
cout << asmCode << endl;
|
|
||||||
if (argStopAfter == "asm") {
|
if (argStopAfter == "asm") {
|
||||||
cout << asmCode << endl;
|
cout << asmCode << endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user