-
Notifications
You must be signed in to change notification settings - Fork 0
/
intercode.h
78 lines (67 loc) · 1.39 KB
/
intercode.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
#ifndef INTERCODE
#define INTERCODE
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
struct Operand_def{
enum{
OP_VARI,
OP_TEMP,
OP_LABEL,
OP_FUNC,
OP_CONST
} kind;
union{
int no_vari;
int no_label;
char *func_name;
int val_const;
} u;
};
typedef struct Operand_def Operand;
struct InterCode_def{
enum{
LABEL,
FUNC,
ASSIGN_VAL2VAL,
ADD,
SUB,
MULTI,
DIV,
ASSIGN_ADD2VAL,
ASSIGN_PNT2VAL,
ASSIGN_VAL2PNT,
GOTO,
GOTO_COND,
RETURN,
DEC,
ARG,
CALL,
PARAM,
READ,
WRITE
} kind;
struct{
Operand op1, op2, op3;
char rel[3];
} u;
};
typedef struct InterCode_def InterCode;
void PrintCode(InterCode code, FILE* f);
InterCode GenCode(int kind, Operand op1, Operand p2, Operand op3, char rel[]);
////------------////
struct InterCodeNode_def{
InterCode node_;
struct InterCodeNode_def *prev, *next;
};
typedef struct InterCodeNode_def InterCodeNode;
struct InterCodeList_def{
InterCodeNode* head_;
InterCodeNode* tail_;
};
typedef struct InterCodeList_def InterCodeList;
InterCodeList* CodeListInit();
void AddInterCode(InterCodeList* self, InterCode code);
void PrintCodeList(InterCodeList* self, FILE* f);
#endif