-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
160 lines (136 loc) · 2.46 KB
/
parser.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* VICasm Assembler by h34ting4ppliance
*
* parser.h
*
* Parser headers.
*/
#ifndef PARSER_H
#define PARSER_H
#include <cstdint>
#include <string>
// Type definition
typedef uint16_t WORD;
typedef uint8_t BYTE;
// Commands
typedef enum
{
C_NONE,
// CPU Instruction set.
HALT, NOP,
PUSH, PUSHA, POP, POPA,
MOV,
ADD, SUB, AND, OR, XOR,
INC, DEC, SL, SR,
CP,
JP, JC, JZ, JN, CALL, RET,
DUMP_R, DUMP_M,
SLP,
SWAP,
// Assembler-wide commands.
DEFINE,
INCLUDE,
BIN,
ORG,
DB,
LBL,
DBG
} Commands;
typedef enum
{
A_NONE,
// Registers
BIT8_REG,
BIT16_REG,
SP_REG,
// Pointers
NUM_POINTER,
REG_POINTER,
DEF_POINTER,
// Constants
DEF_CONST,
NUM_CONST,
// Other
STRING
} Arguments;
// Registers
typedef enum
{
R_NONE,
A,
B,
C,
D,
E,
H,
L,
REG16,
HL,
BC,
DE,
SP
} Registers;
// Argument union
union ARGct
{
WORD i;
char* s;
};
// Parsed assembly argument
class ASMArgument
{
public:
// Init function
void init(std::string);
// Raw string
std::string raw;
// Argument type
Arguments argtype;
// Argument content
union ARGct content;
};
// Parsed assembly command
class ASMCommand
{
public:
// Init function
void init(std::string, size_t);
// Check if the command matches a template
bool match(
const Commands, const size_t, ...);
// Raw string
std::string raw;
// Line number
size_t linenum;
// Command type
Commands cmd;
// Number of arguments
size_t arsize;
// Arguments
ASMArgument *args;
};
// Parsed assembly file
class ASMFile
{
public:
// Init function
ASMFile (std::string);
// File name
std::string filename;
// Number of lines
size_t lsize;
// Array of parsed commands
ASMCommand* commands;
};
// Binary file
class ASMBinary
{
public:
// Init function
ASMBinary (const char*);
// File name
std::string filename;
// File content
std::string content;
};
#endif