mirror of
https://github.com/avinal/The-VM-to-HACK-Translator.git
synced 2026-01-09 22:58:33 +05:30
folder reorganised
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
|
||||
#include "parser.hpp"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
typedef std::vector<std::string> lots_of_files;
|
||||
|
||||
const std::unordered_map<std::string, std::string> 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:
|
||||
lots_of_files files;
|
||||
std::vector<vmcommand> commands;
|
||||
std::ofstream outfile;
|
||||
std::string current_file = "";
|
||||
std::string current_function = "";
|
||||
int ins_no = -1;
|
||||
bool dbg = true;
|
||||
bool is_dir = false;
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
};
|
||||
34
parser.hpp
34
parser.hpp
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <fstream>
|
||||
#include "vutility.hpp"
|
||||
|
||||
enum c_type
|
||||
{
|
||||
C_ARITHMETIC,
|
||||
C_PUSH,
|
||||
C_POP,
|
||||
C_LABEL,
|
||||
C_GOTO,
|
||||
C_IF,
|
||||
C_FUNCTION,
|
||||
C_RETURN,
|
||||
C_CALL
|
||||
};
|
||||
|
||||
typedef std::tuple<c_type, std::string, int> vmcommand;
|
||||
|
||||
class parser
|
||||
{
|
||||
private:
|
||||
std::string input_file;
|
||||
std::vector<vmcommand> parsed;
|
||||
|
||||
public:
|
||||
bool change_file(std::string name);
|
||||
std::vector<vmcommand> get_commands();
|
||||
c_type command_type(std::string com);
|
||||
void parse();
|
||||
};
|
||||
13
vutility.hpp
13
vutility.hpp
@@ -1,13 +0,0 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include<sstream>
|
||||
class vutility
|
||||
{
|
||||
private:
|
||||
vutility() {}
|
||||
|
||||
public:
|
||||
static std::vector<std::string> split(std::string str, char delimit);
|
||||
static std::string trim(std::string str);
|
||||
};
|
||||
Reference in New Issue
Block a user