-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
77 lines (66 loc) · 1.38 KB
/
main.cc
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
#include "mipsim.hpp"
#include "unistd.h"
Memory<Data8,Data32> imem(0x400000);
Memory<Data8,Data32> dmem(0xffff0000);
Memory<Data32,Data32> rf(32, Data32(0));
Register pc;
Options opts;
int main(int argc, char ** argv) {
int c;
string filename;
while ((c = getopt(argc, argv, "pdiwsc:f:")) != -1) {
switch(c) {
case 'p':
opts.program = true;
break;
case 'd':
opts.dump = true;
break;
case 'i':
opts.instrs = true;
break;
case 'w':
opts.writes = true;
break;
case 's':
opts.stats = true;
break;
case 'c':
caches = Caches(atoi(optarg));
break;
case 'f':
filename = optarg;
break;
}
}
if (filename == "") {
cerr << "ERROR: no source file specified; "
<< "run this program with -f filename" << endl;
exit(1);
}
op_init();
parse(filename.c_str());
if (opts.program) {
cout << "Instructions:" << endl;
imem.dump(INSTRUCTIONS);
}
cout << "Starting at PC " << hex << pc << endl;
while(imem.inRange(pc)) {
if (opts.instrs) {
cout << "Executing: " << pc << ": ";
Data32::printI(imem[pc]);
}
execute();
}
if (opts.dump) {
cout << "DATA:" << endl;
dmem.dump(DATA);
cout << "RF:" << endl;
rf.dump(DATA);
}
if (opts.stats) {
stats.print();
caches.printStats();
}
return 0;
}