Mercurial > projects > ldc
annotate gen/irstate.h @ 99:a676a7743642 trunk
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
author | lindquist |
---|---|
date | Thu, 15 Nov 2007 00:24:44 +0100 |
parents | 6789050b5ad1 |
children | 5071469303d4 |
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 |
40 | 42 struct IRStruct |
1 | 43 { |
73 | 44 struct Offset |
45 { | |
46 VarDeclaration* var; | |
47 llvm::Constant* init; | |
48 | |
49 Offset(VarDeclaration* v, llvm::Constant* i) | |
50 : var(v), init(i) {} | |
51 }; | |
52 | |
53 typedef std::vector<FuncDeclaration*> FuncDeclVector; | |
54 typedef std::multimap<unsigned, Offset> OffsetMap; | |
1 | 55 |
56 public: | |
57 IRStruct(); | |
6 | 58 IRStruct(Type*); |
1 | 59 |
6 | 60 Type* type; |
1 | 61 llvm::PATypeHolder recty; |
73 | 62 FuncDeclVector funcs; |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
15
diff
changeset
|
63 bool queueFuncs; |
73 | 64 |
65 OffsetMap offsets; | |
1 | 66 }; |
67 | |
40 | 68 // represents a finally block |
69 struct IRFinally | |
70 { | |
71 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
|
72 llvm::BasicBlock* retbb; |
40 | 73 |
74 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
|
75 IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb); |
40 | 76 }; |
77 | |
78 // represents a function | |
79 struct IRFunction | |
80 { | |
81 llvm::Function* func; | |
82 llvm::Instruction* allocapoint; | |
83 FuncDeclaration* decl; | |
84 TypeFunction* type; | |
85 | |
86 // finally blocks | |
87 typedef std::vector<IRFinally> FinallyVec; | |
88 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
|
89 llvm::Value* finallyretval; |
40 | 90 |
91 IRFunction(FuncDeclaration*); | |
92 }; | |
93 | |
94 struct IRBuilderHelper | |
95 { | |
96 IRState* state; | |
97 LLVMBuilder* operator->(); | |
98 }; | |
99 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
100 struct IRExp |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
101 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
102 Expression* e1; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
103 Expression* e2; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
104 DValue* v; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
105 IRExp(); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
106 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
|
107 }; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
108 |
1 | 109 // represents the module |
40 | 110 struct IRState |
1 | 111 { |
112 IRState(); | |
113 | |
114 // module | |
115 Module* dmodule; | |
116 llvm::Module* module; | |
117 | |
118 // functions | |
40 | 119 typedef std::vector<IRFunction> FunctionVector; |
120 FunctionVector functions; | |
121 IRFunction& func(); | |
122 | |
1 | 123 llvm::Function* topfunc(); |
124 TypeFunction* topfunctype(); | |
125 llvm::Instruction* topallocapoint(); | |
126 | |
127 // structs | |
128 typedef std::vector<IRStruct> StructVector; | |
129 StructVector structs; | |
130 IRStruct& topstruct(); | |
131 | |
132 // classes TODO move into IRClass | |
133 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
134 ClassDeclVec classes; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
135 |
1 | 136 // D main function |
137 bool emitMain; | |
138 llvm::Function* mainFunc; | |
139 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
140 // expression l/r value handling |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
141 typedef std::vector<IRExp> ExpVec; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
142 ExpVec exps; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
143 IRExp* topexp(); |
1 | 144 |
145 // basic block scopes | |
146 std::vector<IRScope> scopes; | |
147 IRScope& scope(); | |
148 llvm::BasicBlock* scopebegin(); | |
149 llvm::BasicBlock* scopeend(); | |
150 llvm::BasicBlock* scopebb(); | |
151 bool scopereturned(); | |
152 | |
153 // loop blocks | |
154 typedef std::vector<IRScope> BBVec; | |
155 BBVec loopbbs; | |
156 | |
157 // this holds the array being indexed or sliced so $ will work | |
158 // might be a better way but it works. problem is I only get a | |
159 // VarDeclaration for __dollar, but I can't see how to get the | |
160 // 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
|
161 std::vector<DValue*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
162 |
40 | 163 // builder helper |
164 IRBuilderHelper ir; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
165 |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
166 // functions queued for lazy definition |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
167 typedef std::vector<FuncDeclaration*> FuncDeclVector; |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
168 FuncDeclVector funcQueue; |
1 | 169 }; |
170 | |
171 #endif // LLVMDC_GEN_IRSTATE_H |