From 4711fb603be2279295f1a79a39e45df4052d0dbd Mon Sep 17 00:00:00 2001 From: lixuanwang Date: Sun, 22 Jun 2025 14:39:38 +0800 Subject: [PATCH] fixed bugs brought out by merging --- src/CMakeLists.txt | 2 +- src/RISCv32Backend.cpp | 12 ++++++------ src/sysyc.cpp | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8249b81..d68d41a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,7 @@ add_executable(sysyc sysyc.cpp IR.cpp SysYIRGenerator.cpp - Backend.cpp + # Backend.cpp RISCv32Backend.cpp ) target_include_directories(sysyc PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/src/RISCv32Backend.cpp b/src/RISCv32Backend.cpp index 3b9652c..41df201 100644 --- a/src/RISCv32Backend.cpp +++ b/src/RISCv32Backend.cpp @@ -35,16 +35,16 @@ std::string RISCv32CodeGen::code_gen() { std::string RISCv32CodeGen::module_gen() { std::stringstream ss; // 生成全局变量(数据段) - for (const auto& global : *module->getGlobalValues()) { + for (const auto& global : module->getGlobals()) { ss << ".data\n"; - ss << ".globl " << global.second->getName() << "\n"; - ss << global.second->getName() << ":\n"; + ss << ".globl " << global->getName() << "\n"; + ss << global->getName() << ":\n"; ss << " .word 0\n"; // 假设初始化为0 } - // 生成函数 + // 生成函数(文本段) ss << ".text\n"; - for (const auto& func : *module->getFunctions()) { - ss << function_gen(func.second); + for (const auto& func : module->getFunctions()) { + ss << function_gen(func.second.get()); } return ss.str(); } diff --git a/src/sysyc.cpp b/src/sysyc.cpp index 085960e..ac13a68 100644 --- a/src/sysyc.cpp +++ b/src/sysyc.cpp @@ -74,8 +74,8 @@ int main(int argc, char **argv) { SysYIRGenerator generator; generator.visitCompUnit(moduleAST); if (argStopAfter == "ir") { - auto module = generator.get(); - module->print(cout); + // auto module = generator.get(); + // module->print(cout); return EXIT_SUCCESS; } @@ -83,7 +83,6 @@ int main(int argc, char **argv) { auto module = generator.get(); sysy::RISCv32CodeGen codegen(module); string asmCode = codegen.code_gen(); - cout << asmCode << endl; if (argStopAfter == "asm") { cout << asmCode << endl; return EXIT_SUCCESS;