-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.h
55 lines (43 loc) · 962 Bytes
/
code.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
#ifndef __code_h__
#define __code_h__
typedef enum { I_ATRIB, I_PLUS, I_ADDI, I_MINUS, I_SUBI, I_DIV, I_MULT, I_MOD, I_NEG, I_LABEL, I_GOTO, I_IF, I_BEQ, I_BNE, I_BGT, I_BGE, I_BLT, I_BLE, I_OR, I_ORI, I_AND, I_ANDI, I_NOT, I_PRINT, I_READ, I_LOAD, I_STORE } OpKind;
struct _Atom
{
enum
{
NUMBER,
STRING,
EMPTY
} kind;
union
{
int value;
char* name;
} u;
};
typedef struct _Atom Atom;
struct _Instr
{
OpKind op;
Atom* el1;
Atom* el2;
Atom* el3;
Atom* el4;
struct _Instr* next;
};
typedef struct _Instr Instr;
struct _InstrList
{
Instr* first;
Instr* last;
};
typedef struct _InstrList InstrList;
Atom* atom_value(int value);
Atom* atom_name(char* name);
Atom* atom_empty();
Instr* mkInstr(OpKind op, Atom* el1, Atom* el2, Atom* el3, Atom* el4);
InstrList* mkInstrList(Instr* head, InstrList* tail);
InstrList* append(InstrList* l1, InstrList* l2);
void printInstrList(InstrList* list);
InstrList* compileCmd(Cmd* cmd);
#endif