Mercurial > projects > ldc
annotate gen/irstate.h @ 40:8b0e809563df trunk
[svn r44] Lots of bug fixes.
New array literal support
New array ~= operator support (for single element)
New with statement support
More...
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 07:43:21 +0200 |
parents | 2841234d2aea |
children | 28e99b04a132 |
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 | |
1 | 91 // represents the module |
40 | 92 struct IRState |
1 | 93 { |
94 IRState(); | |
95 | |
96 // module | |
97 Module* dmodule; | |
98 llvm::Module* module; | |
99 | |
100 // functions | |
40 | 101 typedef std::vector<IRFunction> FunctionVector; |
102 FunctionVector functions; | |
103 IRFunction& func(); | |
104 | |
1 | 105 llvm::Function* topfunc(); |
106 TypeFunction* topfunctype(); | |
107 llvm::Instruction* topallocapoint(); | |
108 | |
109 // structs | |
110 typedef std::vector<IRStruct> StructVector; | |
111 StructVector structs; | |
112 IRStruct& topstruct(); | |
113 | |
114 // classes TODO move into IRClass | |
115 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
116 ClassDeclVec classes; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
117 |
1 | 118 // D main function |
119 bool emitMain; | |
120 llvm::Function* mainFunc; | |
121 | |
122 // L-values | |
123 bool inLvalue; | |
124 typedef std::vector<llvm::Value*> LvalVec; | |
125 LvalVec lvals; | |
126 llvm::Value* toplval(); | |
127 | |
128 // basic block scopes | |
129 std::vector<IRScope> scopes; | |
130 IRScope& scope(); | |
131 llvm::BasicBlock* scopebegin(); | |
132 llvm::BasicBlock* scopeend(); | |
133 llvm::BasicBlock* scopebb(); | |
134 bool scopereturned(); | |
135 | |
136 // loop blocks | |
137 typedef std::vector<IRScope> BBVec; | |
138 BBVec loopbbs; | |
139 | |
140 // this holds the array being indexed or sliced so $ will work | |
141 // might be a better way but it works. problem is I only get a | |
142 // VarDeclaration for __dollar, but I can't see how to get the | |
143 // array pointer from this :( | |
144 LvalVec arrays; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
145 |
40 | 146 // builder helper |
147 IRBuilderHelper ir; | |
1 | 148 }; |
149 | |
150 #endif // LLVMDC_GEN_IRSTATE_H |