-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (74 loc) · 1.73 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include "tokenscanner.hpp"
#include "command.hpp"
using namespace std;
int main(int argc, char *argv[])
{
init();
ifstream fin;
fin.open(argv[1]);
string s;
tokenscanner ts;
while (getline(fin, s)) code.push_back(s);
fin.close();
reg[sp] = SIZE;
int cnt = 0, Size = code.size();
while(cnt < Size){
while(cnt < Size){
ts.set(code[cnt++]);
s = ts.nextToken();
if(s == ".text") break;
if (s == "") continue;
int len = s.size();
if(s[len - 1] == ':'){
s.erase(len - 1, 1);
lable[s] = heapLen;
if (s == "main") break;
}
else{
command CMD = parse(code[cnt - 1]);
dataExcute(CMD);
}
}
while(cnt < Size){
ts.set(code[cnt++]);
s = ts.nextToken();
if(s == ".data") break;
if (s == "") continue;
int len = s.size();
if(s[len - 1] == ':'){
s.erase(len - 1, 1);
lable[s] = cnt;
}
}
}
for (int i = 0; i < Size; ++i) {
ts.set(code[i]);
COMMAND.regiSize = 0;
COMMAND.flag = false;
COMMAND.type = insType[ts.nextToken()];
while (ts.hasMoreTokens()) {
s = ts.nextToken();
if (s[0] == '$') COMMAND.regi[COMMAND.regiSize++] = regType[s];
else if (s[0] == '_') COMMAND.Lable = lable[s];
else if (s[0] == '-' || (s[0] <= '9' && s[0] >= '0')) {
COMMAND.num = to_int(s);
COMMAND.flag = true;
}
}
CMD.push_back(COMMAND);
}
reg[pc] = lable["main"];
while(true){
WB();
MA();
E();
IDDP();
IF();
if(shutdown) break;
}
return 0;
}