Mercurial > projects > ldc
annotate gen/complex.cpp @ 581:8a8ee1f6b268
Only link default native backend by default.
Use the new option --add-backend to link in additional targets.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 07 Sep 2008 15:30:34 +0200 |
parents | a34078905d01 |
children | fbb1a366cfbc |
rev | line source |
---|---|
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
1 #include "gen/llvm.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
2 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
3 #include "mtype.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
4 #include "declaration.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
5 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
6 #include "gen/complex.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
7 #include "gen/tollvm.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
8 #include "gen/llvmhelpers.h" |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
9 #include "gen/irstate.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
10 #include "gen/dvalue.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
11 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
12 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
13 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
14 const llvm::StructType* DtoComplexType(Type* type) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
15 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
16 Type* t = type->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
17 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
18 const LLType* base = DtoComplexBaseType(t); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
19 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
20 std::vector<const LLType*> types; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
21 types.push_back(base); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
22 types.push_back(base); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
23 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
24 return llvm::StructType::get(types); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
25 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
26 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
27 const LLType* DtoComplexBaseType(Type* t) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
28 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
29 TY ty = t->toBasetype()->ty; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
30 const LLType* base; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
31 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
32 return LLType::FloatTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
33 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
34 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
35 return LLType::DoubleTy; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
36 } |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
37 else if (ty == Tcomplex80) { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
38 if (global.params.cpu == ARCHx86) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
39 return LLType::X86_FP80Ty; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
40 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
41 return LLType::DoubleTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
42 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
43 else { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
44 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
45 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
46 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
47 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
48 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
49 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
50 LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
51 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
52 assert(0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
53 const LLType* base = DtoComplexBaseType(ty); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
54 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
55 std::vector<LLConstant*> inits; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
56 inits.push_back(re); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
57 inits.push_back(im); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
58 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
59 const llvm::VectorType* vt = llvm::VectorType::get(base, 2); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
60 return llvm::ConstantVector::get(vt, inits); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
61 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
62 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
63 LLConstant* DtoConstComplex(Type* _ty, long double re, long double im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
64 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
65 TY ty = _ty->toBasetype()->ty; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
66 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
67 llvm::ConstantFP* fre; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
68 llvm::ConstantFP* fim; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
69 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
70 Type* base = 0; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
71 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
72 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
73 base = Type::tfloat32; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
74 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
75 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
76 base = Type::tfloat64; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
77 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
78 else if (ty == Tcomplex80) { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
79 base = Type::tfloat80; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
80 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
81 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
82 std::vector<LLConstant*> inits; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
83 inits.push_back(DtoConstFP(base, re)); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
84 inits.push_back(DtoConstFP(base, im)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
85 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
86 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
87 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
88 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
89 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
90 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
91 LLValue* DtoRealPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
92 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
93 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
94 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
95 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
96 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
97 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
98 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
99 LLValue* DtoImagPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
100 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
101 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
102 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
103 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
104 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
105 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
106 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
107 DValue* DtoComplex(Loc& loc, Type* to, DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
108 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
109 Type* t = val->getType()->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
110 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
111 if (val->isComplex() || t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
112 return DtoCastComplex(loc, val, to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
113 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
114 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
115 const LLType* base = DtoComplexBaseType(to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
116 |
359 | 117 Type* baserety; |
118 Type* baseimty; | |
119 TY ty = to->ty; | |
120 if (ty == Tcomplex32) { | |
121 baserety = Type::tfloat32; | |
122 baseimty = Type::timaginary32; | |
123 } else if (ty == Tcomplex64) { | |
124 baserety = Type::tfloat64; | |
125 baseimty = Type::timaginary64; | |
126 } else if (ty == Tcomplex80) { | |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
127 baserety = Type::tfloat80; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
128 baseimty = Type::timaginary80; |
359 | 129 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
130 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
131 if (t->isimaginary()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
132 return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(loc, val, baseimty)->getRVal()); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
133 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
134 else if (t->isfloating()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
135 return new DComplexValue(to, DtoCastFloat(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
136 } |
359 | 137 else if (t->isintegral()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
138 return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
359 | 139 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
140 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
141 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
142 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
143 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
144 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
145 void DtoComplexAssign(LLValue* l, LLValue* r) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
146 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
147 DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
148 DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
149 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
150 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
151 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
152 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
153 DtoStore(re, DtoGEPi(c,0,0,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
154 DtoStore(im, DtoGEPi(c,0,1,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
155 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
156 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
157 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
158 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
159 void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im) |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
160 { |
359 | 161 // get LLValues |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
162 if (DComplexValue* cx = c->isComplex()) { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
163 re = cx->re; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
164 im = cx->im; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
165 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
166 else { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
167 re = DtoLoad(DtoGEPi(c->getRVal(),0,0,"tmp")); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
168 im = DtoLoad(DtoGEPi(c->getRVal(),0,1,"tmp")); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
169 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
170 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
171 |
359 | 172 DValue* resolveLR(DValue* val, bool getlval) |
173 { | |
174 if (DLRValue* lr = val->isLRValue()) { | |
175 if (getlval) | |
176 return lr->lvalue; | |
177 else | |
178 return lr->rvalue; | |
179 } | |
180 return val; | |
181 } | |
182 | |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
183 ////////////////////////////////////////////////////////////////////////////////////////// |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
184 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
185 bool hasRe(Type* t) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
186 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
187 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
188 (t->ty != Timaginary32 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
189 t->ty != Timaginary64 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
190 t->ty != Timaginary80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
191 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
192 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
193 bool hasIm(Type* t) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
194 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
195 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
196 (t->ty == Timaginary32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
197 t->ty == Timaginary64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
198 t->ty == Timaginary80 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
199 t->ty == Tcomplex32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
200 t->ty == Tcomplex64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
201 t->ty == Tcomplex80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
202 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
203 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
204 ////////////////////////////////////////////////////////////////////////////////////////// |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
205 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
206 DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
207 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
208 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
209 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
210 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
211 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
212 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
213 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
214 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
215 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
216 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
217 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
218 // add up |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
219 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
220 Type* rhstype = rhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
221 if(hasRe(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
222 res_re = gIR->ir->CreateAdd(lhs_re, rhs_re, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
223 else if(hasRe(lhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
224 res_re = lhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
225 else // either hasRe(rhstype) or no re at all (then use any) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
226 res_re = rhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
227 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
228 if(hasIm(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
229 res_im = gIR->ir->CreateAdd(lhs_im, rhs_im, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
230 else if(hasIm(lhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
231 res_im = lhs_im; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
232 else // either hasIm(rhstype) or no im at all (then use any) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
233 res_im = rhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
234 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
235 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
236 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
237 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
238 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
239 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
240 DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
241 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
242 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
243 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
244 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
245 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
246 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
247 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
248 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
249 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
250 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
251 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
252 // sub up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
253 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
254 Type* rhstype = rhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
255 if(hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
256 res_re = gIR->ir->CreateSub(lhs_re, rhs_re, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
257 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
258 res_re = lhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
259 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
260 if(hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
261 res_im = gIR->ir->CreateSub(lhs_im, rhs_im, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
262 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
263 res_im = lhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
264 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
265 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
266 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
267 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
268 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
269 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
270 DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
271 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
272 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
273 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
274 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
275 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
276 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
277 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
278 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
279 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
280 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
281 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
282 // mul up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
283 llvm::Value *rere = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
284 llvm::Value *reim = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
285 llvm::Value *imre = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
286 llvm::Value *imim = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
287 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
288 Type* rhstype = rhs->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
289 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
290 if(hasRe(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
291 rere = gIR->ir->CreateMul(lhs_re, rhs_re, "rere_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
292 if(hasRe(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
293 reim = gIR->ir->CreateMul(lhs_re, rhs_im, "reim_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
294 if(hasIm(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
295 imre = gIR->ir->CreateMul(lhs_im, rhs_re, "imre_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
296 if(hasIm(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
297 imim = gIR->ir->CreateMul(lhs_im, rhs_im, "imim_mul"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
298 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
299 if(rere && imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
300 res_re = gIR->ir->CreateSub(rere, imim, "rere_imim_sub"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
301 else if(rere) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
302 res_re = rere; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
303 else if(imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
304 res_re = gIR->ir->CreateNeg(imim, "imim_neg"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
305 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
306 res_re = hasRe(lhstype) ? rhs_re : lhs_re; // null! |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
307 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
308 if(reim && imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
309 res_im = gIR->ir->CreateAdd(reim, imre, "reim_imre_add"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
310 else if(reim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
311 res_im = reim; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
312 else if(imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
313 res_im = imre; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
314 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
315 res_im = hasRe(lhstype) ? rhs_im : lhs_re; // null! |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
316 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
317 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
318 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
319 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
320 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
321 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
322 DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
323 { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
324 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
325 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
326 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
327 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
328 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
329 // lhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
330 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
331 // rhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
332 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
333 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
334 Type* lhstype = lhs->getType(); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
335 Type* rhstype = rhs->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
336 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
337 // if divisor is only real, division is simple |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
338 if(hasRe(rhstype) && !hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
339 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
340 res_re = gIR->ir->CreateFDiv(lhs_re, rhs_re, "re_divby_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
341 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
342 res_re = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
343 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
344 res_im = gIR->ir->CreateFDiv(lhs_im, rhs_re, "im_divby_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
345 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
346 res_im = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
347 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
348 // if divisor is only imaginary, division is simple too |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
349 else if(!hasRe(rhstype) && hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
350 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
351 res_im = gIR->ir->CreateNeg(gIR->ir->CreateFDiv(lhs_re, rhs_im, "re_divby_im"), "neg"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
352 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
353 res_im = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
354 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
355 res_re = gIR->ir->CreateFDiv(lhs_im, rhs_im, "im_divby_im"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
356 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
357 res_re = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
358 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
359 // full division |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
360 else { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
361 llvm::Value *tmp1, *tmp2, *denom; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
362 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
363 if(hasRe(lhstype) && hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
364 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
365 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
366 res_re = gIR->ir->CreateAdd(tmp1, tmp2, "rere_plus_imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
367 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
368 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
369 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
370 res_im = gIR->ir->CreateSub(tmp2, tmp1, "imre_sub_reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
371 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
372 else if(hasRe(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
373 res_re = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
374 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
375 res_im = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
376 res_im = gIR->ir->CreateNeg(res_im); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
377 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
378 else if(hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
379 res_re = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
380 res_im = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
381 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
382 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
383 assert(0 && "lhs has neither real nor imaginary part"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
384 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
385 tmp1 = gIR->ir->CreateMul(rhs_re, rhs_re, "rhs_resq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
386 tmp2 = gIR->ir->CreateMul(rhs_im, rhs_im, "rhs_imsq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
387 denom = gIR->ir->CreateAdd(tmp1, tmp2, "denom"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
388 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
389 res_re = gIR->ir->CreateFDiv(res_re, denom, "res_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
390 res_im = gIR->ir->CreateFDiv(res_im, denom, "res_im"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
391 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
392 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
393 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
394 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
395 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
396 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
397 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
398 DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val) |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
399 { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
400 val = DtoComplex(loc, type, resolveLR(val, false)); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
401 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
402 llvm::Value *a, *b, *re, *im; |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
403 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
404 // values |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
405 DtoGetComplexParts(val, a, b); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
406 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
407 // sub up |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
408 re = gIR->ir->CreateNeg(a, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
409 im = gIR->ir->CreateNeg(b, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
410 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
411 return new DComplexValue(type, re, im); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
412 } |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
413 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
414 ////////////////////////////////////////////////////////////////////////////////////////// |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
415 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
416 LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
417 { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
418 Type* type = lhs->getType(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
419 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
420 lhs = DtoComplex(loc, type, resolveLR(lhs, false)); |
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
421 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
422 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
423 llvm::Value *a, *b, *c, *d; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
424 |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
425 // lhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
426 DtoGetComplexParts(lhs, a, b); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
427 // rhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
428 DtoGetComplexParts(rhs, c, d); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
429 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
430 // select predicate |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
431 llvm::FCmpInst::Predicate cmpop; |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
432 if (op == TOKequal) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
433 cmpop = llvm::FCmpInst::FCMP_OEQ; |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
434 else |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
435 cmpop = llvm::FCmpInst::FCMP_UNE; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
436 |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
437 // (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im) |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
438 LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
439 LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
440 |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
441 if (op == TOKequal) |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
442 return gIR->ir->CreateAnd(b1,b2,"tmp"); |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
443 else |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
444 return gIR->ir->CreateOr(b1,b2,"tmp"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
445 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
446 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
447 ////////////////////////////////////////////////////////////////////////////////////////// |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
448 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
449 DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
450 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
451 Type* to = _to->toBasetype(); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
452 Type* vty = val->getType(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
453 if (to->iscomplex()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
454 if (vty->size() == to->size()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
455 return val; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
456 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
457 llvm::Value *re, *im; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
458 DtoGetComplexParts(val, re, im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
459 const LLType* toty = DtoComplexBaseType(to); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
460 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
461 if (to->size() < vty->size()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
462 re = gIR->ir->CreateFPTrunc(re, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
463 im = gIR->ir->CreateFPTrunc(im, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
464 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
465 else if (to->size() > vty->size()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
466 re = gIR->ir->CreateFPExt(re, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
467 im = gIR->ir->CreateFPExt(im, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
468 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
469 else { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
470 return val; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
471 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
472 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
473 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
474 return new DComplexValue(_to, re, im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
475 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
476 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
477 // so we need to give it storage, or fix the system that handles this stuff (DLRValue) |
479
672eb4893b55
Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
478 LLValue* mem = DtoAlloca(DtoType(_to), "castcomplextmp"); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
479 DtoComplexSet(mem, re, im); |
359 | 480 return new DLRValue(val, new DImValue(_to, mem)); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
481 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
482 else if (to->isimaginary()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
483 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
484 return new DImValue(to, val->isComplex()->im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
485 LLValue* v = val->getRVal(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
486 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
487 return DtoCastFloat(loc, im, to); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
488 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
489 else if (to->isfloating()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
490 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
491 return new DImValue(to, val->isComplex()->re); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
492 LLValue* v = val->getRVal(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
493 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
494 return DtoCastFloat(loc, re, to); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
495 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
496 else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
497 assert(0); |
303 | 498 } |
499 |