mirror of
https://github.com/avinal/The-Hack-Assembler.git
synced 2026-01-10 23:28:33 +05:30
headers added
This commit is contained in:
20
include/code.hpp
Normal file
20
include/code.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef CODE_HPP
|
||||||
|
#define CODE_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
class code
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const std::string mnemonic;
|
||||||
|
|
||||||
|
public:
|
||||||
|
code(std::string mno) : mnemonic(mno) {}
|
||||||
|
~code();
|
||||||
|
std::array<char, 3> dest();
|
||||||
|
std::array<char, 7> comp();
|
||||||
|
std::array<char, 3> jump();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
26
include/parser.hpp
Normal file
26
include/parser.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef PARSER_HPP
|
||||||
|
#define PARSER_HPP
|
||||||
|
|
||||||
|
#include "code.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
class parser : public code
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::ifstream asmfile;
|
||||||
|
|
||||||
|
public:
|
||||||
|
parser(std::string input_file);
|
||||||
|
~parser();
|
||||||
|
|
||||||
|
bool has_more_commands();
|
||||||
|
void advance();
|
||||||
|
char command_type();
|
||||||
|
std::string symbol();
|
||||||
|
std::array<char, 3> dest();
|
||||||
|
std::array<char, 7> comp();
|
||||||
|
std::array<char, 3> jump();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
21
include/symbol_table.hpp
Normal file
21
include/symbol_table.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef SYMBOL_TABLE_HPP
|
||||||
|
#define SYMBOL_TABLE_HPP
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class symbol_table
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, int> symbols;
|
||||||
|
|
||||||
|
public:
|
||||||
|
symbol_table();
|
||||||
|
~symbol_table();
|
||||||
|
|
||||||
|
void add_entry(std::string symbol, int address);
|
||||||
|
bool contains(std::string symbol);
|
||||||
|
int get_address(std::string symbol);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user