-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathST.h
98 lines (79 loc) · 2.6 KB
/
ST.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
/*-------------------------------------------------------------------------
SYMBOL TABLE RECORD
-------------------------------------------------------------------------*/
typedef enum {INT, ARRAY, FUNCTION} Type;
struct symrec
{
char *name; /* name of symbol */
int scope; /* name of scope */
int length; /* Length of array or Functions number of params */
int offset; /* data offset */
/*FUNCTION PARAMS*/
int position; /* Position of param in function */
int inner_scope; /*Scope inside this function*/
/*TYPE*/
Type type;
struct symrec *next; /* link field */
};
typedef struct symrec symrec;
symrec * getsymOnCurrentScope (char *sym_name);
symrec * getsymArgument (int position, int scope);
symrec * getsym (char *sym_name, int scope, int previous_level);
symrec * putsym (char *sym_name, int length, int position, Type type);
symrec * create_reference (char *sym_name, int position, Type type);
char * getScopeName(int scope);
/*-------------------------------------------------------------------------
STACK TO STORE SCOPES
-------------------------------------------------------------------------*/
#define STACK_MAX 100
struct scope_stack {
int data[STACK_MAX];
int size;
int num_scopes;
};
typedef struct scope_stack scope_stack;
void initScopeStack();
int getCurrentScope();
int getPreviousScope(int previous_level);
void pushScope();
void popScope();
/*-------------------------------------------------------------------------
REFERENCES OF ARRAYS
-------------------------------------------------------------------------*/
#define STACK_REFERENCES_MAX 100
struct reference_struct {
char* origin_var;
int origin_scope;
char* source_var;
int source_scope;
};
typedef struct reference_struct r_struct;
struct reference_stack {
r_struct * data[STACK_REFERENCES_MAX];
int size;
};
typedef struct reference_stack r_stack;
void initReferenceStack();
void pushReference(r_struct * r_struck);
r_struct * popReference();
int getReferencesSize();
/*-------------------------------------------------------------------------
STACK TO STORE BACKPATCH OFFSETS (Backpatch = bp)
-------------------------------------------------------------------------*/
#define STACK_BP_MAX 100
struct bp_struct {
char* name; // VAR
int operation; // STORE_SUBS = 0 LD_SUBS = 1
int label;
int scope;
};
typedef struct bp_struct bp_struct;
struct bp_stack {
bp_struct * data[STACK_BP_MAX];
int size;
};
typedef struct bp_stack bp_stack;
void initBPStack();
void pushBP(bp_struct * bp_struck);
bp_struct * popBP();
int getBPSize();