Commit ea90d4dc authored by Yang's avatar Yang

recover ASMInst change

parent 78b2f265
...@@ -8,16 +8,13 @@ ...@@ -8,16 +8,13 @@
class CodeGen { class CodeGen {
public: public:
explicit CodeGen(Module *module) : m(module) {} explicit CodeGen(Module *module) : m(module) {}
~CodeGen(){
for(auto i : output) delete i;
}
std::string print() const; std::string print() const;
void run(); void run();
template <class... Args> void append_inst(Args... arg) { template <class... Args> void append_inst(Args... arg) {
output.emplace_back(new ASMInstruction(arg...)); output.emplace_back(arg...);
} }
void void
...@@ -29,7 +26,7 @@ class CodeGen { ...@@ -29,7 +26,7 @@ class CodeGen {
} }
content.pop_back(); content.pop_back();
content.pop_back(); content.pop_back();
output.emplace_back(new ASMInstruction(content, ty)); output.emplace_back(content, ty);
} }
private: private:
...@@ -101,5 +98,5 @@ class CodeGen { ...@@ -101,5 +98,5 @@ class CodeGen {
} context; } context;
Module *m; Module *m;
std::list<ASMInstruction*> output; std::list<ASMInstruction> output;
}; };
...@@ -405,7 +405,7 @@ void CodeGen::run() { ...@@ -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()) { for (auto func : m->get_functions()) {
if (not func->is_declaration()) { if (not func->is_declaration()) {
// 更新 context // 更新 context
...@@ -511,8 +511,8 @@ void CodeGen::run() { ...@@ -511,8 +511,8 @@ void CodeGen::run() {
std::string CodeGen::print() const { std::string CodeGen::print() const {
std::string result; std::string result;
for (const auto inst : output) { for (const auto& inst : output) {
result += inst->format(); result += inst.format();
} }
return result; return result;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment