diff --git a/include/codegen/CodeGen.hpp b/include/codegen/CodeGen.hpp index 8f74f80416ee5c9fdda3d058fdaa549774c40147..8680a7cecff17cec6861c66658640b63141d4f62 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 e4815ae4a1e6912bfae4f901d89601c6289ffefb..1ac3cc678cec9c6cefb126c28f5b8be9372d7551 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; }