-
Notifications
You must be signed in to change notification settings - Fork 1
/
GlobalDefinition.h
44 lines (37 loc) · 1.12 KB
/
GlobalDefinition.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
#ifndef GLOBAL_DEFINITION_H_INCLUDED
#define GLOBAL_DEFINITION_H_INCLUDED
#include "Symbol.h"
#include "Type.h"
#include "Instruction.h"
#include <vector>
#include <fstream>
/*
Define the global definition structures. GlobalDefinition has three subclasses, StructureDefine, ExtVarDefine and Function. Function are defined in a separated file.
*/
class Instruction;
class GlobalDefinition {
protected:
Symbol* symbol;
public:
GlobalDefinition(Symbol* symbol) : symbol(symbol) {}
virtual void Emit(ofstream& os) = 0;
virtual void Optimize() = 0;
};
class StructDefine : public GlobalDefinition {
public:
StructDefine(Symbol* structSymbol) : GlobalDefinition(structSymbol) {}
void Emit(ofstream& os);
void Optimize() {};
};
class ExtVarDefine : public GlobalDefinition {
private:
void GenArrayInitializer(Type* type, int& valueConsumed, ofstream& os);
std::vector<Instruction*>* values;
std::vector<int>* dimensionSizes;
public:
ExtVarDefine(Symbol* var, std::vector<Instruction*>* values)
: GlobalDefinition(var), values(values) {}
void Emit(ofstream& os);
void Optimize() {};
};
#endif