Mercurial > projects > ldc
annotate gen/irstate.h @ 116:fd7ad91fd713 trunk
[svn r120] ModuleInfo implementation is now almost complete.
Fixed some nasty static array-initializer bugs.
Fixed bug in DtoArrayLen and DtoArrayPtr for full slices of static arrays.
author | lindquist |
---|---|
date | Sun, 25 Nov 2007 18:55:52 +0100 |
parents | 27b9f749d9fe |
children | 0e28624814e8 |
rev | line source |
---|---|
1 | 1 #ifndef LLVMDC_GEN_IRSTATE_H |
2 #define LLVMDC_GEN_IRSTATE_H | |
3 | |
4 #include <stack> | |
5 #include <vector> | |
6 #include <deque> | |
73 | 7 #include <map> |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
8 #include <list> |
1 | 9 |
10 #include "root.h" | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
11 #include "aggregate.h" |
1 | 12 |
13 // global ir state for current module | |
14 struct IRState; | |
15 extern IRState* gIR; | |
73 | 16 extern const llvm::TargetData* gTargetData; |
1 | 17 |
18 struct TypeFunction; | |
19 struct TypeStruct; | |
20 struct ClassDeclaration; | |
21 struct FuncDeclaration; | |
22 struct Module; | |
23 struct TypeStruct; | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
24 struct BaseClass; |
1 | 25 |
40 | 26 /* |
27 struct LLVMValue | |
28 { | |
29 std::vector<llvm::Value*> vals; | |
30 }; | |
31 */ | |
32 | |
1 | 33 // represents a scope |
34 struct IRScope | |
35 { | |
36 llvm::BasicBlock* begin; | |
37 llvm::BasicBlock* end; | |
40 | 38 LLVMBuilder builder; |
1 | 39 |
40 IRScope(); | |
41 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | |
42 }; | |
43 | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
44 struct IRInterface : Object |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
45 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
46 BaseClass* base; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
47 ClassDeclaration* decl; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
48 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
49 const llvm::StructType* vtblTy; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
50 llvm::ConstantStruct* vtblInit; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
51 llvm::GlobalVariable* vtbl; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
52 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
53 const llvm::StructType* infoTy; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
54 llvm::ConstantStruct* infoInit; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
55 llvm::Constant* info; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
56 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
57 IRInterface(BaseClass* b, const llvm::StructType* vt) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
58 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
59 base = b; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
60 decl = b->base; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
61 vtblTy = vt; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
62 vtblInit = NULL; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
63 vtbl = NULL; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
64 infoTy = NULL; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
65 infoInit = NULL; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
66 info = NULL; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
67 } |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
68 }; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
69 |
6 | 70 // represents a struct or class |
100 | 71 struct IRStruct : Object |
1 | 72 { |
73 | 73 struct Offset |
74 { | |
75 VarDeclaration* var; | |
100 | 76 const llvm::Type* type; |
73 | 77 llvm::Constant* init; |
78 | |
100 | 79 Offset(VarDeclaration* v, const llvm::Type* ty) |
80 : var(v), type(ty), init(NULL) {} | |
73 | 81 }; |
82 | |
83 typedef std::multimap<unsigned, Offset> OffsetMap; | |
100 | 84 typedef std::vector<VarDeclaration*> VarDeclVector; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
85 typedef std::map<ClassDeclaration*, IRInterface*> InterfaceMap; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
86 typedef InterfaceMap::iterator InterfaceIter; |
1 | 87 |
88 public: | |
6 | 89 IRStruct(Type*); |
1 | 90 |
6 | 91 Type* type; |
1 | 92 llvm::PATypeHolder recty; |
100 | 93 OffsetMap offsets; |
94 VarDeclVector defaultFields; | |
73 | 95 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
96 InterfaceMap interfaces; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
97 const llvm::ArrayType* interfaceInfosTy; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
98 llvm::GlobalVariable* interfaceInfos; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
99 |
100 | 100 bool defined; |
101 bool constinited; | |
1 | 102 }; |
103 | |
40 | 104 // represents a finally block |
105 struct IRFinally | |
106 { | |
107 llvm::BasicBlock* bb; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
108 llvm::BasicBlock* retbb; |
40 | 109 |
110 IRFinally(); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
111 IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb); |
40 | 112 }; |
113 | |
114 // represents a function | |
100 | 115 struct IRFunction : Object |
40 | 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; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
125 llvm::Value* finallyretval; |
40 | 126 |
100 | 127 bool defined; |
128 | |
40 | 129 IRFunction(FuncDeclaration*); |
130 }; | |
131 | |
132 struct IRBuilderHelper | |
133 { | |
134 IRState* state; | |
135 LLVMBuilder* operator->(); | |
136 }; | |
137 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
138 struct IRExp |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
139 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
140 Expression* e1; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
141 Expression* e2; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
142 DValue* v; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
143 IRExp(); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
144 IRExp(Expression* l, Expression* r, DValue* val); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
145 }; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
146 |
100 | 147 // represents a global variable |
148 struct IRGlobal : Object | |
149 { | |
150 VarDeclaration* var; | |
151 llvm::PATypeHolder type; | |
152 | |
153 IRGlobal(VarDeclaration* v); | |
154 }; | |
155 | |
1 | 156 // represents the module |
40 | 157 struct IRState |
1 | 158 { |
159 IRState(); | |
160 | |
161 // module | |
162 Module* dmodule; | |
163 llvm::Module* module; | |
164 | |
165 // functions | |
100 | 166 typedef std::vector<IRFunction*> FunctionVector; |
40 | 167 FunctionVector functions; |
100 | 168 IRFunction* func(); |
40 | 169 |
1 | 170 llvm::Function* topfunc(); |
171 TypeFunction* topfunctype(); | |
172 llvm::Instruction* topallocapoint(); | |
173 | |
174 // structs | |
100 | 175 typedef std::vector<IRStruct*> StructVector; |
1 | 176 StructVector structs; |
100 | 177 IRStruct* topstruct(); |
1 | 178 |
179 // classes TODO move into IRClass | |
180 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
181 ClassDeclVec classes; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
182 |
1 | 183 // D main function |
184 bool emitMain; | |
185 llvm::Function* mainFunc; | |
186 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
187 // expression l/r value handling |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
188 typedef std::vector<IRExp> ExpVec; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
189 ExpVec exps; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
190 IRExp* topexp(); |
1 | 191 |
192 // basic block scopes | |
193 std::vector<IRScope> scopes; | |
194 IRScope& scope(); | |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
103
diff
changeset
|
195 llvm::BasicBlock* scopebb(); |
1 | 196 llvm::BasicBlock* scopeend(); |
197 bool scopereturned(); | |
198 | |
199 // loop blocks | |
200 typedef std::vector<IRScope> BBVec; | |
201 BBVec loopbbs; | |
202 | |
203 // this holds the array being indexed or sliced so $ will work | |
204 // might be a better way but it works. problem is I only get a | |
205 // VarDeclaration for __dollar, but I can't see how to get the | |
206 // array pointer from this :( | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
207 std::vector<DValue*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
208 |
40 | 209 // builder helper |
210 IRBuilderHelper ir; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
211 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
212 typedef std::list<Dsymbol*> DsymbolList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
213 // dsymbols that need to be resolved |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
214 DsymbolList resolveList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
215 // dsymbols that need to be declared |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
216 DsymbolList declareList; |
100 | 217 // dsymbols that need constant initializers constructed |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
218 DsymbolList constInitList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
219 // dsymbols that need definitions |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
220 DsymbolList defineList; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
221 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
222 // static ctors/dtors/unittests |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
223 typedef std::vector<FuncDeclaration*> FuncDeclVector; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
224 FuncDeclVector ctors; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
225 FuncDeclVector dtors; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
226 FuncDeclVector unitTests; |
1 | 227 }; |
228 | |
229 #endif // LLVMDC_GEN_IRSTATE_H |