-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse.h
81 lines (71 loc) · 1.91 KB
/
parse.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
#include <bits/stdc++.h>
using namespace std;
#ifndef parse_H
#define parse_H
class parser{
private:
ifstream fileInput;
string line;
int lineNum = 0;
map <string, int> textLabels;
int dataLoc = 268435456; //0x10000000
// all functions to be used in the constructor
vector<string> extractPC(string); // For Branch Table Mode
vector<string> extractOffset(string); //
void removeComments();
void strip();
void Character_Check(string word, int lineNum);
void Label_Error(int lineNum);
void Label_Exists_Error(int lineNum);
void labelToOffset();
void replaceReg();
void handleData();
void storeData(vector<string> dataLine, int increase);
vector<string> convert(bool DorT);
// making regMap to replace the register names with the register numbers
map<string, string> regMap = {
{"ra", "x1"},
{"sp", "x2"},
{"gp", "x3"},
{"tp", "x4"},
{"t0", "x5"},
{"t1", "x6"},
{"t2", "x7"},
{"s0", "x8"},
{"fp", "x8"},
{"s1", "x9"},
{"a0", "x10"},
{"a1", "x11"},
{"a2", "x12"},
{"a3", "x13"},
{"a4", "x14"},
{"a5", "x15"},
{"a6", "x16"},
{"a7", "x17"},
{"s2", "x18"},
{"s3", "x19"},
{"s4", "x20"},
{"s5", "x21"},
{"s6", "x22"},
{"s7", "x23"},
{"s8", "x24"},
{"s9", "x25"},
{"s10", "x26"},
{"s11", "x27"},
{"t3", "x28"},
{"t4", "x29"},
{"t5", "x30"},
{"t6", "x31"}
};
public:
// all the variables and containers to be used in the constructor
vector<pair<vector<string>, int>> code;
vector<vector<string>> dataCode;
map<string, int> dataLabels;
bool error = false;
string raiseError;
// constructor
parser(string path, int mode);
void print(int mode);
};
#endif