-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathreg_code.h
More file actions
40 lines (35 loc) · 1.17 KB
/
reg_code.h
File metadata and controls
40 lines (35 loc) · 1.17 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
/*
* register machine intermediate opcode
*/
#define LOADI 1 // LOADI r,i load int
#define LOADA 2 // LOADA r,n load arg
#define LOADL 3 // LOADL r,n load local var
#define STOREA 4 // STOREA r,n store arg
#define STOREL 5 // STOREL r,n store local var
#define ADD 6 // ADD t,r1,r2
#define SUB 7 // SUB t,r1,r2
#define MUL 8 // MUL t,r1,r2
//#define DIV 8 // DIV t,r1,r2
#define GT 9 // GT t,r1,r2
#define LT 10 // LT r,r1,r2
#define BEQ0 11 // BQ r,L branch if eq 0
#define JUMP 12 // JUMP L
#define ARG 13 // ARG r,n set Argument
#define CALL 14 // CALL r,func
#define RET 15 // RET r return
#define PRINTLN 16 // PRINTLN r,L println function
#define LABEL 17 // LABEL L label
#define LOADS 18 // load string label
#define LOADADDR 19
#define LOAD 20
#define STORE 21
char *code_name(int code);
int get_code(char *name);
void initGenCode();
void genCode1(int opcode, int operand1);
void genCode2(int opcode, int operand1, int operand2);
void genCode3(int opcode, int operand1, int operand2, int operand3);
void genCodeS(int opcode, int operand1, int operand2, char *s);
void genFuncCode(char *entry_name, int n_local);
int genString(char *s);
int genStatic(int a);