annotate gen/complex.cpp @ 412:798ee94a0be7

Rework complex addition, substraction and multiplication. Division may need the same. Fixes run/c/cdouble_09_A,C,D and run/c/cfloat_09_A,C,D.
author Christian Kamm <kamm incasoftware de>
date Sun, 27 Jul 2008 17:53:49 +0200
parents 0e6b4d65d3f8
children 3c133dd1eda3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
16 Type* t = DtoDType(type);
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 {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
29 TY ty = DtoDType(t)->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) {
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
38 return (global.params.useFP80) ? LLType::X86_FP80Ty : LLType::DoubleTy;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
39 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
40 else {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
41 assert(0);
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 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
44
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
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
47 LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im)
104
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 assert(0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
50 const LLType* base = DtoComplexBaseType(ty);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
51
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
52 std::vector<LLConstant*> inits;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
53 inits.push_back(re);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
54 inits.push_back(im);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
55
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
56 const llvm::VectorType* vt = llvm::VectorType::get(base, 2);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
57 return llvm::ConstantVector::get(vt, inits);
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
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
60 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
61 {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
62 TY ty = DtoDType(_ty)->ty;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
63
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
64 llvm::ConstantFP* fre;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
65 llvm::ConstantFP* fim;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
66
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
67 Type* base = 0;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
68
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
69 if (ty == Tcomplex32) {
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
70 base = Type::tfloat32;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
71 }
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
72 else if (ty == Tcomplex64) {
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
73 base = Type::tfloat64;
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 == Tcomplex80) {
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
76 base = (global.params.useFP80) ? Type::tfloat80 : Type::tfloat64;
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
77 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
78
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
79 std::vector<LLConstant*> inits;
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
80 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
81 inits.push_back(DtoConstFP(base, im));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
82
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
83 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
84 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
85
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
86 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
87
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
88 LLValue* DtoRealPart(DValue* val)
104
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 assert(0);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
91 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp");
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
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
94 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
95
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
96 LLValue* DtoImagPart(DValue* val)
104
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 assert(0);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
99 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp");
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
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
102 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
103
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
104 DValue* DtoComplex(Loc& loc, Type* to, DValue* val)
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 Type* t = DtoDType(val->getType());
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
107
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
108 if (val->isComplex() || t->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
109 return DtoCastComplex(loc, val, to);
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
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
112 const LLType* base = DtoComplexBaseType(to);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
113
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
114 Type* baserety;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
115 Type* baseimty;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
116 TY ty = to->ty;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
117 if (ty == Tcomplex32) {
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
118 baserety = Type::tfloat32;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
119 baseimty = Type::timaginary32;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
120 } else if (ty == Tcomplex64) {
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
121 baserety = Type::tfloat64;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
122 baseimty = Type::timaginary64;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
123 } else if (ty == Tcomplex80) {
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
124 baserety = global.params.useFP80 ? Type::tfloat80 : Type::tfloat64;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
125 baseimty = global.params.useFP80 ? Type::timaginary80 : Type::timaginary64;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
126 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
127
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
128 if (t->isimaginary()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
129 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
130 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
131 else if (t->isfloating()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
132 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
133 }
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
134 else if (t->isintegral()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
135 return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty)));
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
136 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
137 assert(0);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
138 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
139
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
140 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
141
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
142 void DtoComplexAssign(LLValue* l, LLValue* r)
104
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 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
145 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
146 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
147
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
148 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im)
104
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 DtoStore(re, DtoGEPi(c,0,0,"tmp"));
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
151 DtoStore(im, DtoGEPi(c,0,1,"tmp"));
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
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
154 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
155
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
156 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
157 {
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
158 // get LLValues
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
159 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
160 re = cx->re;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
161 im = cx->im;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
162 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
163 else {
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
164 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
165 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
166 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
167 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
168
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
169 DValue* resolveLR(DValue* val, bool getlval)
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
170 {
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
171 if (DLRValue* lr = val->isLRValue()) {
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
172 if (getlval)
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
173 return lr->lvalue;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
174 else
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
175 return lr->rvalue;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
176 }
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
177 return val;
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
178 }
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
179
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
180 //////////////////////////////////////////////////////////////////////////////////////////
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
181
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
182 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
183 {
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
184 return
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
185 (t->ty != Timaginary32 &&
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
186 t->ty != Timaginary64 &&
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
187 t->ty != Timaginary80);
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
188 }
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
189
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
190 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
191 {
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
192 return
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
193 (t->ty == Timaginary32 ||
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
194 t->ty == Timaginary64 ||
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
195 t->ty == Timaginary80 ||
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
196 t->ty == Tcomplex32 ||
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
197 t->ty == Tcomplex64 ||
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
198 t->ty == Tcomplex80);
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
199 }
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
200
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
201 //////////////////////////////////////////////////////////////////////////////////////////
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
202
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
203 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
204 {
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
205 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
206 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false));
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 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
209
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
210 // lhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
211 DtoGetComplexParts(clhs, lhs_re, lhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
212 // rhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
213 DtoGetComplexParts(crhs, rhs_re, rhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
214
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
215 // add up
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
225 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
226 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
227 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
228 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
229 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
230 res_im = rhs_im;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
231
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
232 return new DComplexValue(type, res_re, res_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
233 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
234
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
235 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
236
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
237 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
238 {
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
239 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
240 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false));
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 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
243
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
244 // lhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
245 DtoGetComplexParts(clhs, lhs_re, lhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
246 // rhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
247 DtoGetComplexParts(crhs, rhs_re, rhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
248
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
249 // sub up
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
250 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
251 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
252 if(hasRe(rhstype))
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
253 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
254 else
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
255 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
256
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
257 if(hasIm(rhstype))
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
258 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
259 else
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
260 res_im = lhs_im;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
261
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
262 return new DComplexValue(type, res_re, res_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
263 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
264
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
265 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
266
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
267 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
268 {
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
269 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
270 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false));
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 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
273
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
274 // lhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
275 DtoGetComplexParts(clhs, lhs_re, lhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
276 // rhs values
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
277 DtoGetComplexParts(crhs, rhs_re, rhs_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
278
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
279 // mul up
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
280 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
281 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
282 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
283 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
284 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
285 Type* rhstype = rhs->getType();
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
286
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
287 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
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
296 if(rere && imim)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
297 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
298 else if(rere)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
299 res_re = rere;
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
300 else if(imim)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
301 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
302 else
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
303 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
304
412
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
305 if(reim && imre)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
306 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
307 else if(reim)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
308 res_im = reim;
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
309 else if(imre)
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
310 res_im = imre;
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
311 else
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
312 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
313
798ee94a0be7 Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
314 return new DComplexValue(type, res_re, res_im);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
315 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
316
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
317 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
318
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
319 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
320 {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
321 lhs = DtoComplex(loc, type, resolveLR(lhs, true));
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
322 rhs = DtoComplex(loc, type, resolveLR(rhs, false));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
323
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
324 llvm::Value *a, *b, *c, *d;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
325
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
326 // lhs values
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
327 DtoGetComplexParts(lhs, a, b);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
328 // rhs values
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
329 DtoGetComplexParts(rhs, c, d);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
330
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
331 llvm::Value *tmp1, *tmp2, *denom, *re, *im;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
332
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
333 tmp1 = gIR->ir->CreateMul(c, c, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
334 tmp2 = gIR->ir->CreateMul(d, d, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
335 denom = gIR->ir->CreateAdd(tmp1, tmp2, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
336
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
337 tmp1 = gIR->ir->CreateMul(a, c, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
338 tmp2 = gIR->ir->CreateMul(b, d, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
339 re = gIR->ir->CreateAdd(tmp1, tmp2, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
340 re = gIR->ir->CreateFDiv(re, denom, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
341
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
342 tmp1 = gIR->ir->CreateMul(b, c, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
343 tmp2 = gIR->ir->CreateMul(a, d, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
344 im = gIR->ir->CreateSub(tmp1, tmp2, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
345 im = gIR->ir->CreateFDiv(im, denom, "tmp");
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
346
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
347 return new DComplexValue(type, re, im);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
348 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
349
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
350 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
351
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
352 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
353 {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
354 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
355
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
356 llvm::Value *a, *b, *re, *im;
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
357
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
358 // values
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
359 DtoGetComplexParts(val, a, b);
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
360
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
361 // sub up
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
362 re = gIR->ir->CreateNeg(a, "tmp");
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
363 im = gIR->ir->CreateNeg(b, "tmp");
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
364
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
365 return new DComplexValue(type, re, im);
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
366 }
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
367
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
368 //////////////////////////////////////////////////////////////////////////////////////////
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 133
diff changeset
369
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
370 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
371 {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
372 Type* type = lhs->getType();
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
373
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
374 lhs = DtoComplex(loc, type, resolveLR(lhs, false));
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
375 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
376
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
377 llvm::Value *a, *b, *c, *d;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
378
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
379 // lhs values
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
380 DtoGetComplexParts(lhs, a, b);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
381 // rhs values
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
382 DtoGetComplexParts(rhs, c, d);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
383
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 104
diff changeset
384 // select predicate
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
385 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
386 if (op == TOKequal)
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
387 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
388 else
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
389 cmpop = llvm::FCmpInst::FCMP_UNE;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
390
364
8014dbd24605 [svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents: 359
diff changeset
391 // (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
392 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
393 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
394
8014dbd24605 [svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents: 359
diff changeset
395 if (op == TOKequal)
8014dbd24605 [svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents: 359
diff changeset
396 return gIR->ir->CreateAnd(b1,b2,"tmp");
8014dbd24605 [svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents: 359
diff changeset
397 else
8014dbd24605 [svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents: 359
diff changeset
398 return gIR->ir->CreateOr(b1,b2,"tmp");
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff changeset
399 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
400
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
401 //////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
402
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 364
diff changeset
403 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
404 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
405 Type* to = DtoDType(_to);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
406 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
407 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
408 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
409 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
410
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
411 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
412 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
413 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
414
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
415 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
416 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
417 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
418 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
419 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
420 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
421 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
422 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
423 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
424 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
425 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
426
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
427 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
428 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
429
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
430 // 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
431 // so we need to give it storage, or fix the system that handles this stuff (DLRValue)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
432 LLValue* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
433 DtoComplexSet(mem, re, im);
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 303
diff changeset
434 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
435 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
436 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
437 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
438 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
439 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
440 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
441 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
442 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
443 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
444 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
445 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
446 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
447 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
448 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
449 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
450 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
451 assert(0);
303
4aa2b6753059 [svn r324] Small indentation fixes.
ChristianK
parents: 244
diff changeset
452 }
4aa2b6753059 [svn r324] Small indentation fixes.
ChristianK
parents: 244
diff changeset
453