Mercurial > projects > ldc
annotate gen/irstate.h @ 77:714057ff2dbb trunk
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
author | lindquist |
---|---|
date | Wed, 31 Oct 2007 09:34:18 +0100 |
parents | b706170e24a9 |
children | 3587401b6eeb |
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; | |
72 bool ret; | |
73 llvm::Value* retval; | |
74 | |
75 IRFinally(); | |
76 IRFinally(llvm::BasicBlock* b); | |
77 }; | |
78 | |
79 // represents a function | |
80 struct IRFunction | |
81 { | |
82 llvm::Function* func; | |
83 llvm::Instruction* allocapoint; | |
84 FuncDeclaration* decl; | |
85 TypeFunction* type; | |
86 | |
87 // finally blocks | |
88 typedef std::vector<IRFinally> FinallyVec; | |
89 FinallyVec finallys; | |
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; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
104 llvm::Value* v; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
105 IRExp(); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
106 IRExp(Expression* l, Expression* r, llvm::Value* val); |
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 :( | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
161 std::vector<llvm::Value*> 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; | |
1 | 165 }; |
166 | |
167 #endif // LLVMDC_GEN_IRSTATE_H |