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