-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.cc
More file actions
107 lines (104 loc) · 1.89 KB
/
compile.cc
File metadata and controls
107 lines (104 loc) · 1.89 KB
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
#include "datatypes.h"
#include "jit.h"
#include "reader.h"
#include "simulator.h"
#include <iostream>
#include <sstream>
#include <stack>
void debug_inst(const Instruction &inst) {
switch (inst.type) {
case READC:
std::cout << "READC";
break;
case READN:
std::cout << "READN";
break;
case WRITEC:
std::cout << "WRITEC";
break;
case WRITEN:
std::cout << "WRITEN";
break;
case PUSH:
std::cout << "PUSH";
break;
case DUP:
std::cout << "DUP";
break;
case SWAP:
std::cout << "SWAP";
break;
case DISCARD:
std::cout << "DISCARD";
break;
case COPY:
std::cout << "COPY";
break;
case SLIDE:
std::cout << "SLIDE";
break;
case ADD:
std::cout << "ADD";
break;
case SUB:
std::cout << "SUB";
break;
case MUL:
std::cout << "MUL";
break;
case DIV:
std::cout << "DIV";
break;
case MOD:
std::cout << "MOD";
break;
case MARK:
std::cout << "MARK";
break;
case CALL:
std::cout << "CALL";
break;
case JUMP:
std::cout << "JUMP";
break;
case JZ:
std::cout << "JZ";
break;
case JN:
std::cout << "JN";
break;
case RET:
std::cout << "RET";
break;
case END:
std::cout << "END";
break;
case STORE:
std::cout << "STORE";
break;
case RETRIEVE:
std::cout << "RETRIEVE";
break;
}
std::cout << " " << inst.arg << "\n";
}
int main(int argc, char *argv[]) {
std::ios::sync_with_stdio(false);
if (argc != 3 || (argv[1][0] != 't' && argv[1][0] != 'f')) {
std::cout << "Usage: " << argv[0] << " <use_jit:t|f> <filename>"
<< std::endl;
return 1;
}
try {
Reader reader{argv[2]};
if (argv[1][0] == 't') {
jit(reader.get_program());
} else {
simulate(reader.get_program());
}
} catch (char const *exc) {
std::cerr << exc << std::endl;
return 2;
}
return 0;
}