annotate gen/irstate.h @ 98:6789050b5ad1 trunk

[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references. Now uses the DMD _adEq(void[], void[], TypeInfo) runtime function for array equality comparison.
author lindquist
date Wed, 14 Nov 2007 23:39:10 +0100
parents 61615fa85940
children 5071469303d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1 #ifndef LLVMDC_GEN_IRSTATE_H
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2 #define LLVMDC_GEN_IRSTATE_H
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 #include <stack>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 #include <vector>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 #include <deque>
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
7 #include <map>
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 #include "root.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 // global ir state for current module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12 struct IRState;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
13 extern IRState* gIR;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
14 extern const llvm::TargetData* gTargetData;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16 struct TypeFunction;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 struct TypeStruct;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 struct ClassDeclaration;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
19 struct FuncDeclaration;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 struct Module;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 struct TypeStruct;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
23 /*
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
24 struct LLVMValue
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
25 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
26 std::vector<llvm::Value*> vals;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
27 };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
28 */
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
29
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 // represents a scope
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 struct IRScope
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33 llvm::BasicBlock* begin;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34 llvm::BasicBlock* end;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
35 LLVMBuilder builder;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 IRScope();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
38 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39 };
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 1
diff changeset
41 // represents a struct or class
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
42 struct IRStruct
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43 {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
44 struct Offset
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
45 {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
46 VarDeclaration* var;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
47 llvm::Constant* init;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
48
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
49 Offset(VarDeclaration* v, llvm::Constant* i)
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
50 : var(v), init(i) {}
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
51 };
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
52
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
53 typedef std::vector<FuncDeclaration*> FuncDeclVector;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
54 typedef std::multimap<unsigned, Offset> OffsetMap;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
55
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 public:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 IRStruct();
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 1
diff changeset
58 IRStruct(Type*);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 1
diff changeset
60 Type* type;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
61 llvm::PATypeHolder recty;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
62 FuncDeclVector funcs;
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 15
diff changeset
63 bool queueFuncs;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
64
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
65 OffsetMap offsets;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66 };
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
68 // represents a finally block
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
69 struct IRFinally
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
70 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
73
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
76 };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
77
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
78 // represents a function
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
79 struct IRFunction
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
80 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
81 llvm::Function* func;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
82 llvm::Instruction* allocapoint;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
83 FuncDeclaration* decl;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
84 TypeFunction* type;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
85
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
86 // finally blocks
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
87 typedef std::vector<IRFinally> FinallyVec;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
90
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
91 IRFunction(FuncDeclaration*);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
92 };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
93
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
94 struct IRBuilderHelper
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
95 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
96 IRState* state;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
97 LLVMBuilder* operator->();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
98 };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 // represents the module
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
110 struct IRState
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 IRState();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
114 // module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 Module* dmodule;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116 llvm::Module* module;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
118 // functions
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
119 typedef std::vector<IRFunction> FunctionVector;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
120 FunctionVector functions;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
121 IRFunction& func();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
122
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
123 llvm::Function* topfunc();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
124 TypeFunction* topfunctype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
125 llvm::Instruction* topallocapoint();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
126
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
127 // structs
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
128 typedef std::vector<IRStruct> StructVector;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
129 StructVector structs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
130 IRStruct& topstruct();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
131
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
132 // classes TODO move into IRClass
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
133 typedef std::vector<ClassDeclaration*> ClassDeclVec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
134 ClassDeclVec classes;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 6
diff changeset
135
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
136 // D main function
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 bool emitMain;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
138 llvm::Function* mainFunc;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145 // basic block scopes
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
146 std::vector<IRScope> scopes;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
147 IRScope& scope();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
148 llvm::BasicBlock* scopebegin();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
149 llvm::BasicBlock* scopeend();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
150 llvm::BasicBlock* scopebb();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 bool scopereturned();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
153 // loop blocks
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 typedef std::vector<IRScope> BBVec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
155 BBVec loopbbs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 // this holds the array being indexed or sliced so $ will work
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158 // might be a better way but it works. problem is I only get a
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
159 // VarDeclaration for __dollar, but I can't see how to get the
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
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
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
163 // builder helper
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169 };
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
170
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 #endif // LLVMDC_GEN_IRSTATE_H