-
Notifications
You must be signed in to change notification settings - Fork 0
/
ops.h
118 lines (105 loc) · 1.56 KB
/
ops.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef BIFFLE_OPS_H
#define BIFFLE_OPS_H
#include <stdio.h>
#include "functions.h"
#define generic_op(op) void op_##op(int target1, int target2) {\
gen_header();\
op(target1, target2);\
footer();\
}
#define single_op(op) void op_##op(int target) {\
gen_header();\
op(target);\
footer();\
}
#define dummy(fun) void bif_##fun(int one, int two) {\
printf("%s %d %d\n", #fun, one, two);\
}
static int op_idx = 0;
int ret_pos = 0;
void gen_header();
void footer();
single_op(move);
generic_op(ADD);
generic_op(SUB);
generic_op(MULT);
generic_op(DIV);
generic_op(SET);
generic_op(COMP);
generic_op(BIF);
generic_op(MOD);
generic_op(CNE);
generic_op(MOV);
generic_op(ADDI);
generic_op(SUBI);
generic_op(LOAD);
generic_op(STORE);
single_op(PUSH);
single_op(PRINTN);
single_op(POP);
single_op(PUT);
single_op(GETC);
single_op(INC);
single_op(DEC);
void op_PRINT(char* str)
{
gen_header();
PRINT(str);
footer();
}
void op_DEBUG(int dest)
{
gen_header();
move(dest);
printf("#");
footer();
}
void op_JUMP(int target)
{
gen_header();
JUMP(target);
footer();
}
void op_hlt()
{
gen_header();
SET(hlt, 0);
SET(pc, 0);
footer();
}
void op_NOOP()
{
gen_header();
footer();
}
void op_CALL(int target)
{
gen_header();
JUMP(target);
SET(sc, op_idx + 1);
footer();
}
void op_RET()
{
gen_header();
SET(pc, 0);
ADD(pc, sc);
footer();
}
void gen_header()
{
SET(tmp3, op_idx);
SET(tmp4, 0);
ADD(tmp4, pc);
COMP(tmp3, tmp4);
move(tmp3);
cell_while();
}
void footer()
{
INC(pc);
SET(tmp3, 0);
cell_end();
printf("\n");
}
#endif