Mercurial > projects > ldc
annotate gen/irstate.h @ 109:5ab8e92611f9 trunk
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
author | lindquist |
---|---|
date | Wed, 21 Nov 2007 04:13:15 +0100 |
parents | 288fe1029e1f |
children | 27b9f749d9fe |
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: | |
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(); | |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
103
diff
changeset
|
161 llvm::BasicBlock* scopebb(); |
1 | 162 llvm::BasicBlock* scopeend(); |
163 bool scopereturned(); | |
164 | |
165 // loop blocks | |
166 typedef std::vector<IRScope> BBVec; | |
167 BBVec loopbbs; | |
168 | |
169 // this holds the array being indexed or sliced so $ will work | |
170 // might be a better way but it works. problem is I only get a | |
171 // VarDeclaration for __dollar, but I can't see how to get the | |
172 // 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
|
173 std::vector<DValue*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
174 |
40 | 175 // builder helper |
176 IRBuilderHelper ir; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
177 |
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
|
178 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
|
179 // 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
|
180 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
|
181 // 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
|
182 DsymbolList declareList; |
100 | 183 // 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
|
184 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
|
185 // 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
|
186 DsymbolList defineList; |
1 | 187 }; |
188 | |
189 #endif // LLVMDC_GEN_IRSTATE_H |