From ea90d4dc179b6007b410440a18e9759850d51464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=BE=99=E6=88=90?= Date: Wed, 26 Nov 2025 22:59:28 +0800 Subject: [PATCH] recover ASMInst change --- include/codegen/CodeGen.hpp | 9 +++------ src/codegen/CodeGen.cpp | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/codegen/CodeGen.hpp b/include/codegen/CodeGen.hpp index 8f74f80..8680a7c 100755 --- a/include/codegen/CodeGen.hpp +++ b/include/codegen/CodeGen.hpp @@ -8,16 +8,13 @@ class CodeGen { public: explicit CodeGen(Module *module) : m(module) {} - ~CodeGen(){ - for(auto i : output) delete i; - } std::string print() const; void run(); template void append_inst(Args... arg) { - output.emplace_back(new ASMInstruction(arg...)); + output.emplace_back(arg...); } void @@ -29,7 +26,7 @@ class CodeGen { } content.pop_back(); content.pop_back(); - output.emplace_back(new ASMInstruction(content, ty)); + output.emplace_back(content, ty); } private: @@ -101,5 +98,5 @@ class CodeGen { } context; Module *m; - std::list output; + std::list output; }; diff --git a/src/codegen/CodeGen.cpp b/src/codegen/CodeGen.cpp index e4815ae..1ac3cc6 100755 --- a/src/codegen/CodeGen.cpp +++ b/src/codegen/CodeGen.cpp @@ -405,7 +405,7 @@ void CodeGen::run() { } // 函数代码段 - output.emplace_back(new ASMInstruction(".text", ASMInstruction::Attribute)); + output.emplace_back(".text", ASMInstruction::Attribute); for (auto func : m->get_functions()) { if (not func->is_declaration()) { // 更新 context @@ -511,8 +511,8 @@ void CodeGen::run() { std::string CodeGen::print() const { std::string result; - for (const auto inst : output) { - result += inst->format(); + for (const auto& inst : output) { + result += inst.format(); } return result; } -- GitLab