Mercurial > projects > ldc
comparison gen/dvalue.h @ 213:7816aafeea3c trunk
[svn r229] Updated the object.d implementation to the latest Tango.
Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array.
Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 .
Cleaned up some type code.
Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant.
Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
author | lindquist |
---|---|
date | Fri, 30 May 2008 19:32:04 +0200 |
parents | 336ec4f4bbb3 |
children | 20446d22f832 |
comparison
equal
deleted
inserted
replaced
212:4c2689d57ba4 | 213:7816aafeea3c |
---|---|
37 // base class for d-values | 37 // base class for d-values |
38 struct DValue : Object | 38 struct DValue : Object |
39 { | 39 { |
40 virtual Type* getType() = 0; | 40 virtual Type* getType() = 0; |
41 | 41 |
42 virtual llvm::Value* getLVal() { assert(0); return 0; } | 42 virtual LLValue* getLVal() { assert(0); return 0; } |
43 virtual llvm::Value* getRVal() { assert(0); return 0; } | 43 virtual LLValue* getRVal() { assert(0); return 0; } |
44 | 44 |
45 virtual DImValue* isIm() { return NULL; } | 45 virtual DImValue* isIm() { return NULL; } |
46 virtual DConstValue* isConst() { return NULL; } | 46 virtual DConstValue* isConst() { return NULL; } |
47 virtual DNullValue* isNull() { return NULL; } | 47 virtual DNullValue* isNull() { return NULL; } |
48 virtual DVarValue* isVar() { return NULL; } | 48 virtual DVarValue* isVar() { return NULL; } |
64 | 64 |
65 // immediate d-value | 65 // immediate d-value |
66 struct DImValue : DValue | 66 struct DImValue : DValue |
67 { | 67 { |
68 Type* type; | 68 Type* type; |
69 llvm::Value* val; | 69 LLValue* val; |
70 bool inplace; | 70 bool inplace; |
71 | 71 |
72 DImValue(Type* t, llvm::Value* v, bool in_place = false) { type = t; val = v; inplace = in_place; } | 72 DImValue(Type* t, LLValue* v, bool in_place = false) { type = t; val = v; inplace = in_place; } |
73 | 73 |
74 virtual llvm::Value* getRVal() { assert(val); return val; } | 74 virtual LLValue* getRVal() { assert(val); return val; } |
75 | 75 |
76 virtual Type* getType() { assert(type); return type; } | 76 virtual Type* getType() { assert(type); return type; } |
77 virtual DImValue* isIm() { return this; } | 77 virtual DImValue* isIm() { return this; } |
78 | 78 |
79 virtual bool inPlace() { return inplace; } | 79 virtual bool inPlace() { return inplace; } |
81 | 81 |
82 // constant d-value | 82 // constant d-value |
83 struct DConstValue : DValue | 83 struct DConstValue : DValue |
84 { | 84 { |
85 Type* type; | 85 Type* type; |
86 llvm::Constant* c; | 86 LLConstant* c; |
87 | 87 |
88 DConstValue(Type* t, llvm::Constant* con) { type = t; c = con; } | 88 DConstValue(Type* t, LLConstant* con) { type = t; c = con; } |
89 | 89 |
90 virtual llvm::Value* getRVal(); | 90 virtual LLValue* getRVal(); |
91 | 91 |
92 virtual Type* getType() { assert(type); return type; } | 92 virtual Type* getType() { assert(type); return type; } |
93 virtual DConstValue* isConst() { return this; } | 93 virtual DConstValue* isConst() { return this; } |
94 }; | 94 }; |
95 | 95 |
96 // null d-value | 96 // null d-value |
97 struct DNullValue : DConstValue | 97 struct DNullValue : DConstValue |
98 { | 98 { |
99 DNullValue(Type* t, llvm::Constant* con) : DConstValue(t,con) {} | 99 DNullValue(Type* t, LLConstant* con) : DConstValue(t,con) {} |
100 virtual DNullValue* isNull() { return this; } | 100 virtual DNullValue* isNull() { return this; } |
101 }; | 101 }; |
102 | 102 |
103 // variable d-value | 103 // variable d-value |
104 struct DVarValue : DValue | 104 struct DVarValue : DValue |
105 { | 105 { |
106 Type* type; | 106 Type* type; |
107 VarDeclaration* var; | 107 VarDeclaration* var; |
108 llvm::Value* val; | 108 LLValue* val; |
109 llvm::Value* rval; | 109 LLValue* rval; |
110 bool lval; | 110 bool lval; |
111 | 111 |
112 DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue); | 112 DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue); |
113 DVarValue(Type* vd, llvm::Value* lv, llvm::Value* rv); | 113 DVarValue(Type* vd, LLValue* lv, LLValue* rv); |
114 DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue); | 114 DVarValue(Type* t, LLValue* llvmValue, bool lvalue); |
115 | 115 |
116 virtual llvm::Value* getLVal(); | 116 virtual LLValue* getLVal(); |
117 virtual llvm::Value* getRVal(); | 117 virtual LLValue* getRVal(); |
118 | 118 |
119 virtual Type* getType() { assert(type); return type; } | 119 virtual Type* getType() { assert(type); return type; } |
120 virtual DVarValue* isVar() { return this; } | 120 virtual DVarValue* isVar() { return this; } |
121 }; | 121 }; |
122 | 122 |
123 // field d-value | 123 // field d-value |
124 struct DFieldValue : DVarValue | 124 struct DFieldValue : DVarValue |
125 { | 125 { |
126 DFieldValue(Type* t, llvm::Value* llvmValue, bool l) : DVarValue(t, llvmValue, l) {} | 126 DFieldValue(Type* t, LLValue* llvmValue, bool l) : DVarValue(t, llvmValue, l) {} |
127 virtual DFieldValue* isField() { return this; } | 127 virtual DFieldValue* isField() { return this; } |
128 }; | 128 }; |
129 | 129 |
130 // this d-value | 130 // this d-value |
131 struct DThisValue : DVarValue | 131 struct DThisValue : DVarValue |
132 { | 132 { |
133 DThisValue(VarDeclaration* vd, llvm::Value* llvmValue) : DVarValue(vd, llvmValue, true) {} | 133 DThisValue(VarDeclaration* vd, LLValue* llvmValue) : DVarValue(vd, llvmValue, true) {} |
134 virtual DThisValue* isThis() { return this; } | 134 virtual DThisValue* isThis() { return this; } |
135 }; | 135 }; |
136 | 136 |
137 // array length d-value | 137 // array length d-value |
138 struct DArrayLenValue : DVarValue | 138 struct DArrayLenValue : DVarValue |
139 { | 139 { |
140 DArrayLenValue(Type* t, llvm::Value* llvmValue) : DVarValue(t, llvmValue, true) {} | 140 DArrayLenValue(Type* t, LLValue* llvmValue) : DVarValue(t, llvmValue, true) {} |
141 virtual DArrayLenValue* isArrayLen() { return this; } | 141 virtual DArrayLenValue* isArrayLen() { return this; } |
142 }; | 142 }; |
143 | 143 |
144 // slice d-value | 144 // slice d-value |
145 struct DSliceValue : DValue | 145 struct DSliceValue : DValue |
146 { | 146 { |
147 Type* type; | 147 Type* type; |
148 llvm::Value* len; | 148 LLValue* len; |
149 llvm::Value* ptr; | 149 LLValue* ptr; |
150 | 150 |
151 DSliceValue(Type* t, llvm::Value* l, llvm::Value* p) { type=t; ptr=p; len=l; } | 151 DSliceValue(Type* t, LLValue* l, LLValue* p) { type=t; ptr=p; len=l; } |
152 | 152 |
153 virtual Type* getType() { assert(type); return type; } | 153 virtual Type* getType() { assert(type); return type; } |
154 virtual DSliceValue* isSlice() { return this; } | 154 virtual DSliceValue* isSlice() { return this; } |
155 }; | 155 }; |
156 | 156 |
157 // function d-value | 157 // function d-value |
158 struct DFuncValue : DValue | 158 struct DFuncValue : DValue |
159 { | 159 { |
160 Type* type; | 160 Type* type; |
161 FuncDeclaration* func; | 161 FuncDeclaration* func; |
162 llvm::Value* val; | 162 LLValue* val; |
163 llvm::Value* vthis; | 163 LLValue* vthis; |
164 unsigned cc; | 164 unsigned cc; |
165 | 165 |
166 DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt = 0); | 166 DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0); |
167 | 167 |
168 virtual llvm::Value* getLVal(); | 168 virtual LLValue* getLVal(); |
169 virtual llvm::Value* getRVal(); | 169 virtual LLValue* getRVal(); |
170 | 170 |
171 virtual Type* getType() { assert(type); return type; } | 171 virtual Type* getType() { assert(type); return type; } |
172 virtual DFuncValue* isFunc() { return this; } | 172 virtual DFuncValue* isFunc() { return this; } |
173 }; | 173 }; |
174 | 174 |
175 // l-value and r-value pair d-value | 175 // l-value and r-value pair d-value |
176 struct DLRValue : DValue | 176 struct DLRValue : DValue |
177 { | 177 { |
178 Type* ltype; | 178 Type* ltype; |
179 llvm::Value* lval; | 179 LLValue* lval; |
180 Type* rtype; | 180 Type* rtype; |
181 llvm::Value* rval; | 181 LLValue* rval; |
182 | 182 |
183 DLRValue(Type* lt, llvm::Value* l, Type* rt, llvm::Value* r) { | 183 DLRValue(Type* lt, LLValue* l, Type* rt, LLValue* r) { |
184 ltype = lt; | 184 ltype = lt; |
185 lval = l; | 185 lval = l; |
186 rtype = rt; | 186 rtype = rt; |
187 rval = r; | 187 rval = r; |
188 } | 188 } |
189 | 189 |
190 virtual llvm::Value* getLVal() { assert(lval); return lval; } | 190 virtual LLValue* getLVal() { assert(lval); return lval; } |
191 virtual llvm::Value* getRVal() { assert(rval); return rval; } | 191 virtual LLValue* getRVal() { assert(rval); return rval; } |
192 | 192 |
193 Type* getLType() { return ltype; } | 193 Type* getLType() { return ltype; } |
194 Type* getRType() { return rtype; } | 194 Type* getRType() { return rtype; } |
195 virtual Type* getType() { return getRType(); } | 195 virtual Type* getType() { return getRType(); } |
196 virtual DLRValue* isLRValue() { return this; } | 196 virtual DLRValue* isLRValue() { return this; } |
198 | 198 |
199 // complex number immediate d-value (much like slice) | 199 // complex number immediate d-value (much like slice) |
200 struct DComplexValue : DValue | 200 struct DComplexValue : DValue |
201 { | 201 { |
202 Type* type; | 202 Type* type; |
203 llvm::Value* re; | 203 LLValue* re; |
204 llvm::Value* im; | 204 LLValue* im; |
205 | 205 |
206 DComplexValue(Type* t, llvm::Value* r, llvm::Value* i) { | 206 DComplexValue(Type* t, LLValue* r, LLValue* i) { |
207 type = t; | 207 type = t; |
208 re = r; | 208 re = r; |
209 im = i; | 209 im = i; |
210 } | 210 } |
211 | 211 |