@@ -19,22 +19,22 @@ class Context : public std::enable_shared_from_this<Context>
1919 SymbolTable symbol_table_;
2020 static int label_counter_ ;
2121 std::string function_call_name_;
22- std::string exit_label_;
22+ static std::string exit_label_;
2323 static FunctionTable function_table_;
24- // reg stack not used
25- RegStack reg_stack_;
24+
25+
2626 static LiteralTable literal_table_;
2727
2828
2929 // Private constructor to enforce shared_ptr management
30- explicit Context (std::shared_ptr<Context> parent_context = nullptr , int offset = -20 , RegStack reg_stack = RegStack() )
31- : parent_context_(std::move(parent_context)), symbol_table_(SymbolTable(offset)), reg_stack_(reg_stack) {}
30+ explicit Context (std::shared_ptr<Context> parent_context = nullptr , int offset = -20 )
31+ : parent_context_(std::move(parent_context)), symbol_table_(SymbolTable(offset)) {}
3232
3333public:
3434 // Factory function to ensure Context is always created as a shared_ptr
35- static std::shared_ptr<Context> Create (std::shared_ptr<Context> parent_context = nullptr , int offset = -20 , RegStack reg_stack = RegStack() )
35+ static std::shared_ptr<Context> Create (std::shared_ptr<Context> parent_context = nullptr , int offset = -20 )
3636 {
37- return std::shared_ptr<Context>(new Context (std::move (parent_context), offset, reg_stack ));
37+ return std::shared_ptr<Context>(new Context (std::move (parent_context), offset));
3838 }
3939
4040 // Adds a symbol to the current context.
@@ -50,8 +50,8 @@ class Context : public std::enable_shared_from_this<Context>
5050 std::shared_ptr<Context> CreateChildContext ()
5151 {
5252 int offset = symbol_table_.GetOffset ();
53- RegStack reg_stack = reg_stack_ ;
54- return Create ( shared_from_this (), offset, reg_stack);
53+ return Create ( shared_from_this (), offset) ;
54+
5555 }
5656
5757 // Searches for a symbol in the current context and then in parent contexts.
@@ -80,24 +80,24 @@ class Context : public std::enable_shared_from_this<Context>
8080 return exit_label_;
8181 }
8282
83- void PushReg (std::ostream& stream , std::string reg, int offset ) {
84- reg_stack_ .PushReg (reg, offset );
85- stream << " addi sp, sp, -4 " << std::endl;
86- stream << " sw " << reg << " , 0(sp) " << std::endl;
83+ void PushReg (std::string reg , std::ostream& stream ) {
84+ function_table_ .PushReg (reg, stream );
85+
86+
8787 }
8888
89- Reg PopReg (std::ostream& stream) {
90- stream << " lw " << reg_stack_. TopReg (). reg << " , 0(sp) " << std::endl ;
91- stream << " addi sp, sp, 4 " << std::endl;
92- return reg_stack_. PopReg ();
89+ void PopReg (std::ostream& stream) {
90+ function_table_. PopReg (stream) ;
91+
92+
9393 }
9494
9595 void ExitRegStack (std::ostream& stream) {
96- while (!reg_stack_. Empty ()) {
97- stream << " lw " << reg_stack_. TopReg (). reg << " , 0(sp) " << std::endl;
98- stream << " addi sp, sp, 4 " << std::endl;
99- reg_stack_. PopReg ();
100- }
96+ function_table_. ExitRegStack (stream);
97+
98+
99+
100+
101101 }
102102
103103 void AddFunction (const std::string& name, const TypeSpecifier& return_type, const std::vector<TypeSpecifier>& parameters, int is_pointer)
0 commit comments