cleaned code

This commit is contained in:
avinal
2020-08-22 23:52:20 +05:30
parent df2c013ab3
commit 57dfa048cf
2 changed files with 1 additions and 173 deletions

View File

@@ -1,4 +1,3 @@
#include "parser.hpp"
#include <functional>
#include <string>
@@ -30,6 +29,7 @@ private:
public:
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);
@@ -40,17 +40,6 @@ public:
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);
void write_and(bool debug);
void write_or(bool debug);
void write_not(bool debug);
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);

View File

@@ -359,167 +359,6 @@ void code_writer::write_eq_lt_gt(std::string op, bool debug)
this->ins_no += 6;
}
/*
void code_writer::write_add(bool debug)
{
if (debug)
{
outfile << "// add" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D+M" << std::endl;
this->ins_no += 6;
}
void code_writer::write_sub(bool debug)
{
if (debug)
{
outfile << "// sub" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=M-D" << std::endl;
this->ins_no += 6;
}
void code_writer::write_neg(bool debug)
{
if (debug)
{
outfile << "// neg" << std::endl;
}
outfile << "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=-M" << std::endl;
this->ins_no += 3;
}
void code_writer::write_and(bool debug)
{
if (debug)
{
outfile << "// and" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D&M" << std::endl;
this->ins_no += 6;
}
void code_writer::write_or(bool debug)
{
if (debug)
{
outfile << "// or" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D|M" << std::endl;
this->ins_no += 6;
}
void code_writer::write_not(bool debug)
{
if (debug)
{
outfile << "// not" << std::endl;
}
outfile << "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=!M" << std::endl;
this->ins_no += 3;
}
void code_writer::write_eq(bool debug)
{
if (debug)
{
outfile << "// eq" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "A=A-1" << std::endl
<< "D=M-D" << std::endl;
this->ins_no += 5;
outfile << "@" << this->ins_no + 6 << std::endl
<< "D;JEQ" << std::endl
<< "D=0" << std::endl;
this->ins_no += 3;
outfile << "@" << this->ins_no + 4 << std::endl
<< "0;JMP" << std::endl
<< "D=-1" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D" << std::endl;
this->ins_no += 6;
}
void code_writer::write_lt(bool debug)
{
if (debug)
{
outfile << "// lt" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "A=A-1" << std::endl
<< "D=M-D" << std::endl;
this->ins_no += 5;
outfile << "@" << this->ins_no + 6 << std::endl
<< "D;JLT" << std::endl
<< "D=0" << std::endl;
this->ins_no += 3;
outfile << "@" << this->ins_no + 4 << std::endl
<< "0;JMP" << std::endl
<< "D=-1" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D" << std::endl;
this->ins_no += 6;
}
void code_writer::write_gt(bool debug)
{
if (debug)
{
outfile << "// gt" << std::endl;
}
outfile << "@SP" << std::endl
<< "AM=M-1" << std::endl
<< "D=M" << std::endl
<< "A=A-1" << std::endl
<< "D=M-D" << std::endl;
this->ins_no += 5;
outfile << "@" << this->ins_no + 6 << std::endl
<< "D;JGT" << std::endl
<< "D=0" << std::endl;
this->ins_no += 3;
outfile << "@" << this->ins_no + 4 << std::endl
<< "0;JMP" << std::endl
<< "D=-1" << std::endl
<< "@SP" << std::endl
<< "A=M-1" << std::endl
<< "M=D" << std::endl;
this->ins_no += 6;
}
*/
void code_writer::write_init(bool debug)
{
if (debug)