Mercurial > projects > ldc
comparison gen/irstate.h @ 136:0e28624814e8 trunk
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
author | lindquist |
---|---|
date | Thu, 17 Jan 2008 03:15:12 +0100 |
parents | fd7ad91fd713 |
children | 8f704cb9969b |
comparison
equal
deleted
inserted
replaced
135:176bd52b3cf5 | 136:0e28624814e8 |
---|---|
1 #ifndef LLVMDC_GEN_IRSTATE_H | 1 #ifndef LLVMDC_GEN_IRSTATE_H |
2 #define LLVMDC_GEN_IRSTATE_H | 2 #define LLVMDC_GEN_IRSTATE_H |
3 | 3 |
4 #include <stack> | |
5 #include <vector> | 4 #include <vector> |
6 #include <deque> | |
7 #include <map> | |
8 #include <list> | 5 #include <list> |
9 | 6 |
10 #include "root.h" | 7 #include "root.h" |
11 #include "aggregate.h" | 8 #include "aggregate.h" |
9 | |
10 #include "ir/irfunction.h" | |
11 #include "ir/irstruct.h" | |
12 #include "ir/irvar.h" | |
12 | 13 |
13 // global ir state for current module | 14 // global ir state for current module |
14 struct IRState; | 15 struct IRState; |
15 extern IRState* gIR; | 16 extern IRState* gIR; |
16 extern const llvm::TargetData* gTargetData; | 17 extern const llvm::TargetData* gTargetData; |
21 struct FuncDeclaration; | 22 struct FuncDeclaration; |
22 struct Module; | 23 struct Module; |
23 struct TypeStruct; | 24 struct TypeStruct; |
24 struct BaseClass; | 25 struct BaseClass; |
25 | 26 |
26 /* | |
27 struct LLVMValue | |
28 { | |
29 std::vector<llvm::Value*> vals; | |
30 }; | |
31 */ | |
32 | |
33 // represents a scope | 27 // represents a scope |
34 struct IRScope | 28 struct IRScope |
35 { | 29 { |
36 llvm::BasicBlock* begin; | 30 llvm::BasicBlock* begin; |
37 llvm::BasicBlock* end; | 31 llvm::BasicBlock* end; |
38 LLVMBuilder builder; | 32 LLVMBuilder builder; |
39 | 33 |
40 IRScope(); | 34 IRScope(); |
41 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | 35 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); |
42 }; | |
43 | |
44 struct IRInterface : Object | |
45 { | |
46 BaseClass* base; | |
47 ClassDeclaration* decl; | |
48 | |
49 const llvm::StructType* vtblTy; | |
50 llvm::ConstantStruct* vtblInit; | |
51 llvm::GlobalVariable* vtbl; | |
52 | |
53 const llvm::StructType* infoTy; | |
54 llvm::ConstantStruct* infoInit; | |
55 llvm::Constant* info; | |
56 | |
57 IRInterface(BaseClass* b, const llvm::StructType* vt) | |
58 { | |
59 base = b; | |
60 decl = b->base; | |
61 vtblTy = vt; | |
62 vtblInit = NULL; | |
63 vtbl = NULL; | |
64 infoTy = NULL; | |
65 infoInit = NULL; | |
66 info = NULL; | |
67 } | |
68 }; | |
69 | |
70 // represents a struct or class | |
71 struct IRStruct : Object | |
72 { | |
73 struct Offset | |
74 { | |
75 VarDeclaration* var; | |
76 const llvm::Type* type; | |
77 llvm::Constant* init; | |
78 | |
79 Offset(VarDeclaration* v, const llvm::Type* ty) | |
80 : var(v), type(ty), init(NULL) {} | |
81 }; | |
82 | |
83 typedef std::multimap<unsigned, Offset> OffsetMap; | |
84 typedef std::vector<VarDeclaration*> VarDeclVector; | |
85 typedef std::map<ClassDeclaration*, IRInterface*> InterfaceMap; | |
86 typedef InterfaceMap::iterator InterfaceIter; | |
87 | |
88 public: | |
89 IRStruct(Type*); | |
90 | |
91 Type* type; | |
92 llvm::PATypeHolder recty; | |
93 OffsetMap offsets; | |
94 VarDeclVector defaultFields; | |
95 | |
96 InterfaceMap interfaces; | |
97 const llvm::ArrayType* interfaceInfosTy; | |
98 llvm::GlobalVariable* interfaceInfos; | |
99 | |
100 bool defined; | |
101 bool constinited; | |
102 }; | |
103 | |
104 // represents a finally block | |
105 struct IRFinally | |
106 { | |
107 llvm::BasicBlock* bb; | |
108 llvm::BasicBlock* retbb; | |
109 | |
110 IRFinally(); | |
111 IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb); | |
112 }; | |
113 | |
114 // represents a function | |
115 struct IRFunction : Object | |
116 { | |
117 llvm::Function* func; | |
118 llvm::Instruction* allocapoint; | |
119 FuncDeclaration* decl; | |
120 TypeFunction* type; | |
121 | |
122 // finally blocks | |
123 typedef std::vector<IRFinally> FinallyVec; | |
124 FinallyVec finallys; | |
125 llvm::Value* finallyretval; | |
126 | |
127 bool defined; | |
128 | |
129 IRFunction(FuncDeclaration*); | |
130 }; | 36 }; |
131 | 37 |
132 struct IRBuilderHelper | 38 struct IRBuilderHelper |
133 { | 39 { |
134 IRState* state; | 40 IRState* state; |
142 DValue* v; | 48 DValue* v; |
143 IRExp(); | 49 IRExp(); |
144 IRExp(Expression* l, Expression* r, DValue* val); | 50 IRExp(Expression* l, Expression* r, DValue* val); |
145 }; | 51 }; |
146 | 52 |
147 // represents a global variable | |
148 struct IRGlobal : Object | |
149 { | |
150 VarDeclaration* var; | |
151 llvm::PATypeHolder type; | |
152 | |
153 IRGlobal(VarDeclaration* v); | |
154 }; | |
155 | |
156 // represents the module | 53 // represents the module |
157 struct IRState | 54 struct IRState |
158 { | 55 { |
159 IRState(); | 56 IRState(); |
160 | 57 |
161 // module | 58 // module |
162 Module* dmodule; | 59 Module* dmodule; |
163 llvm::Module* module; | 60 llvm::Module* module; |
164 | 61 |
165 // functions | 62 // functions |
166 typedef std::vector<IRFunction*> FunctionVector; | 63 typedef std::vector<IrFunction*> FunctionVector; |
167 FunctionVector functions; | 64 FunctionVector functions; |
168 IRFunction* func(); | 65 IrFunction* func(); |
169 | 66 |
170 llvm::Function* topfunc(); | 67 llvm::Function* topfunc(); |
171 TypeFunction* topfunctype(); | 68 TypeFunction* topfunctype(); |
172 llvm::Instruction* topallocapoint(); | 69 llvm::Instruction* topallocapoint(); |
173 | 70 |
174 // structs | 71 // structs |
175 typedef std::vector<IRStruct*> StructVector; | 72 typedef std::vector<IrStruct*> StructVector; |
176 StructVector structs; | 73 StructVector structs; |
177 IRStruct* topstruct(); | 74 IrStruct* topstruct(); |
178 | 75 |
179 // classes TODO move into IRClass | 76 // classes TODO move into IRClass |
180 typedef std::vector<ClassDeclaration*> ClassDeclVec; | 77 typedef std::vector<ClassDeclaration*> ClassDeclVec; |
181 ClassDeclVec classes; | 78 ClassDeclVec classes; |
182 | 79 |