diff --git a/code_writer.hpp b/code_writer.hpp index 3492ed2..dd28c4d 100644 --- a/code_writer.hpp +++ b/code_writer.hpp @@ -1,21 +1,46 @@ #include "parser.hpp" #include +#include + +typedef std::vector lots_of_files; + +const std::unordered_map operation_map({{"add", "M+D"}, + {"sub", "M-D"}, + {"neg", "-M"}, + {"and", "D&M"}, + {"or", "D|M"}, + {"not", "!M"}, + {"eq", "JEQ"}, + {"lt", "JLT"}, + {"gt", "LGT"}}); + class code_writer { private: - std::string file_name; + lots_of_files files; std::vector commands; std::ofstream outfile; + std::string current_file = ""; + std::string current_function = ""; int ins_no = -1; - bool dbg = false; + bool dbg = true; + bool is_dir = false; public: - code_writer(std::string name); + code_writer(lots_of_files name); void write_assembly(); void write_push(std::string segment, int index, bool debug); + void write_push(std::string segment, bool debug); void write_pop(std::string segment, int index, bool debug); + void write_pop(std::string segment, bool debug); + void write_arithmetic(std::string comm, int index, bool debug); + void write_add_sub_and_or(std::string op, bool debug); + void write_neg_not(std::string op, bool debug); + void write_eq_lt_gt(std::string op, bool debug); + + /* void write_add(bool debug); void write_sub(bool debug); void write_neg(bool debug); @@ -25,4 +50,15 @@ public: void write_eq(bool debug); void write_lt(bool debug); void write_gt(bool debug); +*/ + void write_init(bool debug); + + void write_label(std::string label, int index, bool debug); + void write_goto(std::string label, int index, bool debug); + void write_if(std::string label, int index, bool debug); + + void write_call(std::string fun_name, int args, bool debug); + void write_return(bool debug); + void write_function(std::string fun_name, int locals, bool debug); + void write_frame_restore(std::string segment, int minus, bool debug); };