Mercurial > projects > ldc
annotate gen/irstate.h @ 54:28e99b04a132 trunk
[svn r58] Fixed cond expression resulting in a non-basic type.
Fixed identity expression for dynamic arrays.
Revamped the system to keep track of lvalues and rvalues and their relations.
Typedef declaration now generate the custom typeinfo.
Other bugfixes.
author | lindquist |
---|---|
date | Wed, 24 Oct 2007 01:37:34 +0200 |
parents | 8b0e809563df |
children | b706170e24a9 |
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> | |
7 | |
8 #include "root.h" | |
9 | |
10 // global ir state for current module | |
11 struct IRState; | |
12 extern IRState* gIR; | |
13 extern llvm::TargetData* gTargetData; | |
14 | |
15 struct TypeFunction; | |
16 struct TypeStruct; | |
17 struct ClassDeclaration; | |
18 struct FuncDeclaration; | |
19 struct Module; | |
20 struct TypeStruct; | |
21 | |
40 | 22 /* |
23 struct LLVMValue | |
24 { | |
25 std::vector<llvm::Value*> vals; | |
26 }; | |
27 */ | |
28 | |
1 | 29 // represents a scope |
30 struct IRScope | |
31 { | |
32 llvm::BasicBlock* begin; | |
33 llvm::BasicBlock* end; | |
40 | 34 LLVMBuilder builder; |
1 | 35 |
36 IRScope(); | |
37 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | |
38 }; | |
39 | |
6 | 40 // represents a struct or class |
40 | 41 struct IRStruct |
1 | 42 { |
43 typedef std::vector<const llvm::Type*> TypeVector; | |
44 typedef std::vector<llvm::Constant*> ConstantVector; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
15
diff
changeset
|
45 typedef std::vector<FuncDeclaration*> FuncDeclVec; |
1 | 46 |
47 public: | |
48 IRStruct(); | |
6 | 49 IRStruct(Type*); |
1 | 50 |
6 | 51 Type* type; |
1 | 52 TypeVector fields; |
53 ConstantVector inits; | |
54 llvm::PATypeHolder recty; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
15
diff
changeset
|
55 FuncDeclVec funcs; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
15
diff
changeset
|
56 bool queueFuncs; |
1 | 57 }; |
58 | |
40 | 59 // represents a finally block |
60 struct IRFinally | |
61 { | |
62 llvm::BasicBlock* bb; | |
63 bool ret; | |
64 llvm::Value* retval; | |
65 | |
66 IRFinally(); | |
67 IRFinally(llvm::BasicBlock* b); | |
68 }; | |
69 | |
70 // represents a function | |
71 struct IRFunction | |
72 { | |
73 llvm::Function* func; | |
74 llvm::Instruction* allocapoint; | |
75 FuncDeclaration* decl; | |
76 TypeFunction* type; | |
77 | |
78 // finally blocks | |
79 typedef std::vector<IRFinally> FinallyVec; | |
80 FinallyVec finallys; | |
81 | |
82 IRFunction(FuncDeclaration*); | |
83 }; | |
84 | |
85 struct IRBuilderHelper | |
86 { | |
87 IRState* state; | |
88 LLVMBuilder* operator->(); | |
89 }; | |
90 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
91 struct IRExp |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
92 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
93 Expression* e1; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
94 Expression* e2; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
95 llvm::Value* v; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
96 IRExp(); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
97 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
|
98 }; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
99 |
1 | 100 // represents the module |
40 | 101 struct IRState |
1 | 102 { |
103 IRState(); | |
104 | |
105 // module | |
106 Module* dmodule; | |
107 llvm::Module* module; | |
108 | |
109 // functions | |
40 | 110 typedef std::vector<IRFunction> FunctionVector; |
111 FunctionVector functions; | |
112 IRFunction& func(); | |
113 | |
1 | 114 llvm::Function* topfunc(); |
115 TypeFunction* topfunctype(); | |
116 llvm::Instruction* topallocapoint(); | |
117 | |
118 // structs | |
119 typedef std::vector<IRStruct> StructVector; | |
120 StructVector structs; | |
121 IRStruct& topstruct(); | |
122 | |
123 // classes TODO move into IRClass | |
124 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
125 ClassDeclVec classes; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
126 |
1 | 127 // D main function |
128 bool emitMain; | |
129 llvm::Function* mainFunc; | |
130 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
131 // expression l/r value handling |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
132 typedef std::vector<IRExp> ExpVec; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
133 ExpVec exps; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
134 IRExp* topexp(); |
1 | 135 |
136 // basic block scopes | |
137 std::vector<IRScope> scopes; | |
138 IRScope& scope(); | |
139 llvm::BasicBlock* scopebegin(); | |
140 llvm::BasicBlock* scopeend(); | |
141 llvm::BasicBlock* scopebb(); | |
142 bool scopereturned(); | |
143 | |
144 // loop blocks | |
145 typedef std::vector<IRScope> BBVec; | |
146 BBVec loopbbs; | |
147 | |
148 // this holds the array being indexed or sliced so $ will work | |
149 // might be a better way but it works. problem is I only get a | |
150 // VarDeclaration for __dollar, but I can't see how to get the | |
151 // array pointer from this :( | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
152 std::vector<llvm::Value*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
153 |
40 | 154 // builder helper |
155 IRBuilderHelper ir; | |
1 | 156 }; |
157 | |
158 #endif // LLVMDC_GEN_IRSTATE_H |