forked from yekyam/AsmInterpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteCompiler.h
64 lines (53 loc) · 1.23 KB
/
ByteCompiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef ASMI_BCOMPILER
#define ASMI_BCOMPILER
#include <cstdint>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include "AsmI.h"
enum
{
FLAGS,
HELP,
MOV_V,
MOV_R,
OR,
AND,
XOR,
ADD,
CMP,
PUSH,
POP,
SUB,
DIV,
MUL,
AL_C,
BL_C,
CL_C,
};
class ByteCompiler
{
uint8_t value_stack[1024];
uint8_t instruction_stack[1024];
std::string compiledBytes;
std::vector<std::string> code;
std::vector<std::string> commands = { "FLAGS", "HELP", "MOV", "MOV_V", "OR", "AND", "XOR", "ADD", "CMP", "PUSH", "POP", "SUB", "DIV", "MUL", "AL", "BL", "CL", "NULL" };
public:
//Code order is:
// Call Ctor, compile code, execute code
ByteCompiler();
//Read in lines from a file, calls parser
ByteCompiler(const std::string& fileNameToCompile);
//Read in lines, parse lines
void handleInput(std::string& input);
//Compiles code to byte code
void compile(const std::string& fileNameOUT);
//Runs code, takes in an AsmI reference to run commands and store their result
void execute(AsmI& asmi, const std::string& fileNameIN);
//For debugging, prints the bytes that are stores in the compiled bytes string
void printBytes();
//For debugging, prints code produced by the parser
void printCode();
};
#endif