-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.h
96 lines (85 loc) · 1.49 KB
/
Utilities.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
#pragma once
#include "Pch.h"
#include "AstNode.h"
#include "ValueError.h"
#include "MemStore.h"
class AstNode;
class MemStore;
enum class Opcodes {
NONE = -1,
MOV = OPCODES,
SUB,
ADD,
MUL,
DIV,
INC,
DEC,
OR,
AND,
XOR,
NOT,
NOP,
SHL,
SHR,
ROL,
ROR,
PUSH,
POP,
CMP,
JNZ,
JZ,
JNE,
JE,
JNS,
JS,
JNO,
JO,
JNP,
JP,
JAE,
JBE,
CLI,
STI,
LOOP,
XCHG,
INT
};
enum class Operators {
none = -1,
mns = OPERATORS,
pls,
mul,
comma,
space,
colon,
DB,
DW,
DD
};
/*
* This class help us to make the Interpreter code more clean and easy to read and write.
*/
class Utilities {
public:
static bool isOpcode(string op);
static bool isOperator(char ch);
static bool isIgnored(char ch);
static bool isSizeSign(string ss);
static Opcodes getOpcode(string op);
static Operators getOperator(char ch);
static unsigned int StringToDec(string num);
static unsigned int HexStringToDec(string num);
static unsigned int BinStringToDec(string num);
static unsigned int OctStringToDec(string num);
static void cleanString(string& str);
static bool validparams(AstNode* opcode, int params);
static bool validOperators(AstNode* opcode, int operators);
static string getParam(AstNode* opcode, int param);
static int getSignSize(string sign);
static void toLower(string& str);
static void toUpper(string& str);
static map<string, Opcodes> OpcodesChars;
static map<string, Operators> SizeSigns;
static map<char, Operators> OperatorsChars;
static map<char, Operators> IgnoredChars;
};