ACSE 2.0.2
Advanced Compiler System for Education (basic documentation)
Loading...
Searching...
No Matches
program.h
Go to the documentation of this file.
1
3
4#ifndef PROGRAM_H
5#define PROGRAM_H
6
7#include <stdio.h>
8#include <stdbool.h>
9#include "list.h"
10
28typedef int t_regID;
29
31#define REG_INVALID ((t_regID)(-1))
33#define REG_0 ((t_regID)(0))
34
35
41
42
47typedef struct {
49 unsigned int labelID;
52 char *name;
54 bool global;
57 bool isAlias;
58} t_label;
59
61typedef struct {
63 t_regID ID;
66 t_listNode *mcRegWhitelist;
67} t_instrArg;
68
70typedef struct {
71 t_label *label;
72 int opcode;
73 t_instrArg *rDest;
74 t_instrArg *rSrc1;
75 t_instrArg *rSrc2;
76 int immediate;
77 t_label *addressParam;
79 char *comment;
80} t_instruction;
81
84typedef struct t_symbol {
88 char *ID;
91 t_label *label;
94} t_symbol;
95
106
107
110
112t_program *newProgram(void);
113
116void deleteProgram(t_program *program);
117
119
120
123
127t_label *createLabel(t_program *program);
128
132void assignLabel(t_program *program, t_label *label);
133
140void setLabelName(t_program *program, t_label *label, const char *name);
141
146char *getLabelName(t_label *label);
147
149
150
153
158
179t_instruction *genInstruction(t_program *program, int opcode, t_regID rd,
180 t_regID rs1, t_regID rs2, t_label *label, int immediate);
181
186void removeInstructionAt(t_program *program, t_listNode *instrLi);
187
189
190
193
201 t_program *program, char *ID, t_symbolType type, int arraySize);
202
208t_symbol *getSymbol(t_program *program, char *ID);
209
214bool isArray(t_symbol *symbol);
215
217
218
221
224void genEpilog(t_program *program);
225
229void programDump(t_program *program, FILE *fout);
230
232
237#endif
A node belonging a list.
Definition list.h:39
unsigned int firstUnusedLblID
Next unused label ID.
Definition program.h:103
t_symbolType type
A valid data type.
Definition program.h:86
t_listNode * instructions
List of instructions.
Definition program.h:100
int arraySize
For arrays only, the size of the array.
Definition program.h:93
t_listNode * labels
List of all labels.
Definition program.h:99
t_listNode * symbols
Symbol table.
Definition program.h:101
t_label * pendingLabel
Next pending label to assign.
Definition program.h:104
char * ID
Symbol name (should never be a NULL pointer or an empty string "").
Definition program.h:88
t_regID firstUnusedReg
Next unused register ID.
Definition program.h:102
t_label * label
Definition program.h:91
void setLabelName(t_program *program, t_label *label, const char *name)
void assignLabel(t_program *program, t_label *label)
t_regID getNewRegister(t_program *program)
bool isArray(t_symbol *symbol)
t_symbol * getSymbol(t_program *program, char *ID)
void programDump(t_program *program, FILE *fout)
void genEpilog(t_program *program)
t_label * createLabel(t_program *program)
void removeInstructionAt(t_program *program, t_listNode *instrLi)
t_symbol * createSymbol(t_program *program, char *ID, t_symbolType type, int arraySize)
char * getLabelName(t_label *label)
t_instruction * genInstruction(t_program *program, int opcode, t_regID rd, t_regID rs1, t_regID rs2, t_label *label, int immediate)
int t_regID
Type for register identifiers.
Definition program.h:28
t_symbolType
Definition program.h:37
@ TYPE_INT_ARRAY
‘int’ array type.
Definition program.h:39
@ TYPE_INT
‘int’ scalar type.
Definition program.h:38
A double-linked list.