Mercurial > projects > ldc
comparison gen/complex.cpp @ 399:0e6b4d65d3f8
Give error messages for invalid casts.
This required passing Loc information to certain functions.
Fixes nocompile/b/bug_cgcs_354_A/B.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 26 Jul 2008 17:19:16 +0200 |
parents | 8014dbd24605 |
children | 798ee94a0be7 |
comparison
equal
deleted
inserted
replaced
398:811f82dfddbd | 399:0e6b4d65d3f8 |
---|---|
99 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); | 99 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); |
100 } | 100 } |
101 | 101 |
102 ////////////////////////////////////////////////////////////////////////////////////////// | 102 ////////////////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
104 DValue* DtoComplex(Type* to, DValue* val) | 104 DValue* DtoComplex(Loc& loc, Type* to, DValue* val) |
105 { | 105 { |
106 Type* t = DtoDType(val->getType()); | 106 Type* t = DtoDType(val->getType()); |
107 | 107 |
108 if (val->isComplex() || t->iscomplex()) { | 108 if (val->isComplex() || t->iscomplex()) { |
109 return DtoCastComplex(val, to); | 109 return DtoCastComplex(loc, val, to); |
110 } | 110 } |
111 | 111 |
112 const LLType* base = DtoComplexBaseType(to); | 112 const LLType* base = DtoComplexBaseType(to); |
113 | 113 |
114 Type* baserety; | 114 Type* baserety; |
124 baserety = global.params.useFP80 ? Type::tfloat80 : Type::tfloat64; | 124 baserety = global.params.useFP80 ? Type::tfloat80 : Type::tfloat64; |
125 baseimty = global.params.useFP80 ? Type::timaginary80 : Type::timaginary64; | 125 baseimty = global.params.useFP80 ? Type::timaginary80 : Type::timaginary64; |
126 } | 126 } |
127 | 127 |
128 if (t->isimaginary()) { | 128 if (t->isimaginary()) { |
129 return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(val, baseimty)->getRVal()); | 129 return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(loc, val, baseimty)->getRVal()); |
130 } | 130 } |
131 else if (t->isfloating()) { | 131 else if (t->isfloating()) { |
132 return new DComplexValue(to, DtoCastFloat(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); | 132 return new DComplexValue(to, DtoCastFloat(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
133 } | 133 } |
134 else if (t->isintegral()) { | 134 else if (t->isintegral()) { |
135 return new DComplexValue(to, DtoCastInt(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); | 135 return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
136 } | 136 } |
137 assert(0); | 137 assert(0); |
138 } | 138 } |
139 | 139 |
140 ////////////////////////////////////////////////////////////////////////////////////////// | 140 ////////////////////////////////////////////////////////////////////////////////////////// |
177 return val; | 177 return val; |
178 } | 178 } |
179 | 179 |
180 ////////////////////////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////////////////////////// |
181 | 181 |
182 DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs) | 182 DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
183 { | 183 { |
184 lhs = DtoComplex(type, resolveLR(lhs, true)); | 184 lhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
185 rhs = DtoComplex(type, resolveLR(rhs, false)); | 185 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
186 | 186 |
187 llvm::Value *a, *b, *c, *d, *re, *im; | 187 llvm::Value *a, *b, *c, *d, *re, *im; |
188 | 188 |
189 // lhs values | 189 // lhs values |
190 DtoGetComplexParts(lhs, a, b); | 190 DtoGetComplexParts(lhs, a, b); |
198 return new DComplexValue(type, re, im); | 198 return new DComplexValue(type, re, im); |
199 } | 199 } |
200 | 200 |
201 ////////////////////////////////////////////////////////////////////////////////////////// | 201 ////////////////////////////////////////////////////////////////////////////////////////// |
202 | 202 |
203 DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs) | 203 DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
204 { | 204 { |
205 lhs = DtoComplex(type, resolveLR(lhs, true)); | 205 lhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
206 rhs = DtoComplex(type, resolveLR(rhs, false)); | 206 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
207 | 207 |
208 llvm::Value *a, *b, *c, *d, *re, *im; | 208 llvm::Value *a, *b, *c, *d, *re, *im; |
209 | 209 |
210 // lhs values | 210 // lhs values |
211 DtoGetComplexParts(lhs, a, b); | 211 DtoGetComplexParts(lhs, a, b); |
219 return new DComplexValue(type, re, im); | 219 return new DComplexValue(type, re, im); |
220 } | 220 } |
221 | 221 |
222 ////////////////////////////////////////////////////////////////////////////////////////// | 222 ////////////////////////////////////////////////////////////////////////////////////////// |
223 | 223 |
224 DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs) | 224 DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
225 { | 225 { |
226 lhs = DtoComplex(type, resolveLR(lhs, true)); | 226 lhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
227 rhs = DtoComplex(type, resolveLR(rhs, false)); | 227 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
228 | 228 |
229 llvm::Value *a, *b, *c, *d; | 229 llvm::Value *a, *b, *c, *d; |
230 | 230 |
231 // lhs values | 231 // lhs values |
232 DtoGetComplexParts(lhs, a, b); | 232 DtoGetComplexParts(lhs, a, b); |
246 return new DComplexValue(type, re, im); | 246 return new DComplexValue(type, re, im); |
247 } | 247 } |
248 | 248 |
249 ////////////////////////////////////////////////////////////////////////////////////////// | 249 ////////////////////////////////////////////////////////////////////////////////////////// |
250 | 250 |
251 DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs) | 251 DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
252 { | 252 { |
253 lhs = DtoComplex(type, resolveLR(lhs, true)); | 253 lhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
254 rhs = DtoComplex(type, resolveLR(rhs, false)); | 254 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
255 | 255 |
256 llvm::Value *a, *b, *c, *d; | 256 llvm::Value *a, *b, *c, *d; |
257 | 257 |
258 // lhs values | 258 // lhs values |
259 DtoGetComplexParts(lhs, a, b); | 259 DtoGetComplexParts(lhs, a, b); |
279 return new DComplexValue(type, re, im); | 279 return new DComplexValue(type, re, im); |
280 } | 280 } |
281 | 281 |
282 ////////////////////////////////////////////////////////////////////////////////////////// | 282 ////////////////////////////////////////////////////////////////////////////////////////// |
283 | 283 |
284 DValue* DtoComplexNeg(Type* type, DValue* val) | 284 DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val) |
285 { | 285 { |
286 val = DtoComplex(type, resolveLR(val, false)); | 286 val = DtoComplex(loc, type, resolveLR(val, false)); |
287 | 287 |
288 llvm::Value *a, *b, *re, *im; | 288 llvm::Value *a, *b, *re, *im; |
289 | 289 |
290 // values | 290 // values |
291 DtoGetComplexParts(val, a, b); | 291 DtoGetComplexParts(val, a, b); |
297 return new DComplexValue(type, re, im); | 297 return new DComplexValue(type, re, im); |
298 } | 298 } |
299 | 299 |
300 ////////////////////////////////////////////////////////////////////////////////////////// | 300 ////////////////////////////////////////////////////////////////////////////////////////// |
301 | 301 |
302 LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) | 302 LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs) |
303 { | 303 { |
304 Type* type = lhs->getType(); | 304 Type* type = lhs->getType(); |
305 | 305 |
306 lhs = DtoComplex(type, resolveLR(lhs, false)); | 306 lhs = DtoComplex(loc, type, resolveLR(lhs, false)); |
307 rhs = DtoComplex(type, resolveLR(rhs, false)); | 307 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
308 | 308 |
309 llvm::Value *a, *b, *c, *d; | 309 llvm::Value *a, *b, *c, *d; |
310 | 310 |
311 // lhs values | 311 // lhs values |
312 DtoGetComplexParts(lhs, a, b); | 312 DtoGetComplexParts(lhs, a, b); |
330 return gIR->ir->CreateOr(b1,b2,"tmp"); | 330 return gIR->ir->CreateOr(b1,b2,"tmp"); |
331 } | 331 } |
332 | 332 |
333 ////////////////////////////////////////////////////////////////////////////////////////// | 333 ////////////////////////////////////////////////////////////////////////////////////////// |
334 | 334 |
335 DValue* DtoCastComplex(DValue* val, Type* _to) | 335 DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) |
336 { | 336 { |
337 Type* to = DtoDType(_to); | 337 Type* to = DtoDType(_to); |
338 Type* vty = val->getType(); | 338 Type* vty = val->getType(); |
339 if (to->iscomplex()) { | 339 if (to->iscomplex()) { |
340 if (vty->size() == to->size()) | 340 if (vty->size() == to->size()) |
368 else if (to->isimaginary()) { | 368 else if (to->isimaginary()) { |
369 if (val->isComplex()) | 369 if (val->isComplex()) |
370 return new DImValue(to, val->isComplex()->im); | 370 return new DImValue(to, val->isComplex()->im); |
371 LLValue* v = val->getRVal(); | 371 LLValue* v = val->getRVal(); |
372 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); | 372 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); |
373 return DtoCastFloat(im, to); | 373 return DtoCastFloat(loc, im, to); |
374 } | 374 } |
375 else if (to->isfloating()) { | 375 else if (to->isfloating()) { |
376 if (val->isComplex()) | 376 if (val->isComplex()) |
377 return new DImValue(to, val->isComplex()->re); | 377 return new DImValue(to, val->isComplex()->re); |
378 LLValue* v = val->getRVal(); | 378 LLValue* v = val->getRVal(); |
379 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); | 379 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); |
380 return DtoCastFloat(re, to); | 380 return DtoCastFloat(loc, re, to); |
381 } | 381 } |
382 else | 382 else |
383 assert(0); | 383 assert(0); |
384 } | 384 } |
385 | 385 |