Mercurial > projects > ldc
annotate gen/irstate.h @ 100:5071469303d4 trunk
[svn r104] TONS OF FIXES.
Split up declaration, constant initializer gen and definition for globals, structs, classes and functions.
Improved ClassInfo support (not complete), not in vtable yet.
Fixed a bunch of forward reference problems.
Much more. Major commit! :)
author | lindquist |
---|---|
date | Fri, 16 Nov 2007 08:21:47 +0100 |
parents | 6789050b5ad1 |
children | 027b8d8b71ec |
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> |
1 | 8 |
9 #include "root.h" | |
10 | |
11 // global ir state for current module | |
12 struct IRState; | |
13 extern IRState* gIR; | |
73 | 14 extern const llvm::TargetData* gTargetData; |
1 | 15 |
16 struct TypeFunction; | |
17 struct TypeStruct; | |
18 struct ClassDeclaration; | |
19 struct FuncDeclaration; | |
20 struct Module; | |
21 struct TypeStruct; | |
22 | |
40 | 23 /* |
24 struct LLVMValue | |
25 { | |
26 std::vector<llvm::Value*> vals; | |
27 }; | |
28 */ | |
29 | |
1 | 30 // represents a scope |
31 struct IRScope | |
32 { | |
33 llvm::BasicBlock* begin; | |
34 llvm::BasicBlock* end; | |
40 | 35 LLVMBuilder builder; |
1 | 36 |
37 IRScope(); | |
38 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | |
39 }; | |
40 | |
6 | 41 // represents a struct or class |
100 | 42 struct IRStruct : Object |
1 | 43 { |
73 | 44 struct Offset |
45 { | |
46 VarDeclaration* var; | |
100 | 47 const llvm::Type* type; |
73 | 48 llvm::Constant* init; |
49 | |
100 | 50 Offset(VarDeclaration* v, const llvm::Type* ty) |
51 : var(v), type(ty), init(NULL) {} | |
73 | 52 }; |
53 | |
54 typedef std::multimap<unsigned, Offset> OffsetMap; | |
100 | 55 typedef std::vector<VarDeclaration*> VarDeclVector; |
1 | 56 |
57 public: | |
58 IRStruct(); | |
6 | 59 IRStruct(Type*); |
1 | 60 |
6 | 61 Type* type; |
1 | 62 llvm::PATypeHolder recty; |
100 | 63 OffsetMap offsets; |
64 VarDeclVector defaultFields; | |
73 | 65 |
100 | 66 bool defined; |
67 bool constinited; | |
1 | 68 }; |
69 | |
40 | 70 // represents a finally block |
71 struct IRFinally | |
72 { | |
73 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
|
74 llvm::BasicBlock* retbb; |
40 | 75 |
76 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
|
77 IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb); |
40 | 78 }; |
79 | |
80 // represents a function | |
100 | 81 struct IRFunction : Object |
40 | 82 { |
83 llvm::Function* func; | |
84 llvm::Instruction* allocapoint; | |
85 FuncDeclaration* decl; | |
86 TypeFunction* type; | |
87 | |
88 // finally blocks | |
89 typedef std::vector<IRFinally> FinallyVec; | |
90 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
|
91 llvm::Value* finallyretval; |
40 | 92 |
100 | 93 bool defined; |
94 | |
40 | 95 IRFunction(FuncDeclaration*); |
96 }; | |
97 | |
98 struct IRBuilderHelper | |
99 { | |
100 IRState* state; | |
101 LLVMBuilder* operator->(); | |
102 }; | |
103 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
104 struct IRExp |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
105 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
106 Expression* e1; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
107 Expression* e2; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
108 DValue* v; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
109 IRExp(); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
110 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
|
111 }; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
112 |
100 | 113 // represents a global variable |
114 struct IRGlobal : Object | |
115 { | |
116 VarDeclaration* var; | |
117 llvm::PATypeHolder type; | |
118 | |
119 IRGlobal(VarDeclaration* v); | |
120 }; | |
121 | |
1 | 122 // represents the module |
40 | 123 struct IRState |
1 | 124 { |
125 IRState(); | |
126 | |
127 // module | |
128 Module* dmodule; | |
129 llvm::Module* module; | |
130 | |
131 // functions | |
100 | 132 typedef std::vector<IRFunction*> FunctionVector; |
40 | 133 FunctionVector functions; |
100 | 134 IRFunction* func(); |
40 | 135 |
1 | 136 llvm::Function* topfunc(); |
137 TypeFunction* topfunctype(); | |
138 llvm::Instruction* topallocapoint(); | |
139 | |
140 // structs | |
100 | 141 typedef std::vector<IRStruct*> StructVector; |
1 | 142 StructVector structs; |
100 | 143 IRStruct* topstruct(); |
1 | 144 |
145 // classes TODO move into IRClass | |
146 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
147 ClassDeclVec classes; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
148 |
1 | 149 // D main function |
150 bool emitMain; | |
151 llvm::Function* mainFunc; | |
152 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
153 // expression l/r value handling |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
154 typedef std::vector<IRExp> ExpVec; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
155 ExpVec exps; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
156 IRExp* topexp(); |
1 | 157 |
158 // basic block scopes | |
159 std::vector<IRScope> scopes; | |
160 IRScope& scope(); | |
161 llvm::BasicBlock* scopebegin(); | |
162 llvm::BasicBlock* scopeend(); | |
163 llvm::BasicBlock* scopebb(); | |
164 bool scopereturned(); | |
165 | |
166 // loop blocks | |
167 typedef std::vector<IRScope> BBVec; | |
168 BBVec loopbbs; | |
169 | |
170 // this holds the array being indexed or sliced so $ will work | |
171 // might be a better way but it works. problem is I only get a | |
172 // VarDeclaration for __dollar, but I can't see how to get the | |
173 // 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
|
174 std::vector<DValue*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
175 |
40 | 176 // builder helper |
177 IRBuilderHelper ir; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
178 |
100 | 179 typedef std::vector<Dsymbol*> DsymbolVector; |
180 // dsymbols that need constant initializers constructed | |
181 DsymbolVector constInitQueue; | |
182 // dsymbols that need definitions (symbols in current module) | |
183 DsymbolVector defineQueue; | |
1 | 184 }; |
185 | |
186 #endif // LLVMDC_GEN_IRSTATE_H |