72
|
1 module dmd.ComplexExp;
|
|
2
|
114
|
3 import dmd.common;
|
72
|
4 import dmd.Expression;
|
|
5 import dmd.InterState;
|
|
6 import dmd.Type;
|
|
7 import dmd.OutBuffer;
|
|
8 import dmd.Loc;
|
|
9 import dmd.Scope;
|
|
10 import dmd.IRState;
|
|
11 import dmd.HdrGenState;
|
0
|
12 import dmd.Type;
|
|
13 import dmd.TOK;
|
|
14 import dmd.TY;
|
|
15 import dmd.Port;
|
|
16 import dmd.Complex;
|
72
|
17
|
|
18 import dmd.backend.dt_t;
|
0
|
19 import dmd.backend.elem;
|
|
20 import dmd.backend.Util;
|
|
21 import dmd.backend.TYM;
|
|
22 import dmd.backend.mTY;
|
72
|
23
|
0
|
24 class ComplexExp : Expression
|
|
25 {
|
|
26 Complex!(real) value;
|
|
27
|
|
28 this(Loc loc, Complex!(real) value, Type type)
|
72
|
29 {
|
0
|
30 super(loc, TOK.TOKcomplex80, ComplexExp.sizeof);
|
|
31 this.value = value;
|
|
32 this.type = type;
|
|
33 //printf("ComplexExp.ComplexExp(%s)\n", toChars());
|
|
34 }
|
|
35
|
72
|
36 override bool equals(Object o)
|
0
|
37 {
|
|
38 assert(false);
|
|
39 }
|
|
40
|
72
|
41 override Expression semantic(Scope sc)
|
0
|
42 {
|
|
43 if (!type)
|
|
44 type = Type.tcomplex80;
|
|
45 else
|
|
46 type = type.semantic(loc, sc);
|
|
47 return this;
|
|
48 }
|
|
49
|
72
|
50 override Expression interpret(InterState istate)
|
0
|
51 {
|
|
52 assert(false);
|
|
53 }
|
|
54
|
72
|
55 override string toChars()
|
0
|
56 {
|
|
57 assert(false);
|
|
58 }
|
|
59
|
72
|
60 override ulong toInteger()
|
0
|
61 {
|
|
62 return cast(ulong) toReal();
|
|
63 }
|
|
64
|
72
|
65 override ulong toUInteger()
|
0
|
66 {
|
|
67 return cast(long) toReal();
|
|
68 }
|
|
69
|
72
|
70 override real toReal()
|
0
|
71 {
|
|
72 return value.re;
|
|
73 }
|
|
74
|
72
|
75 override real toImaginary()
|
0
|
76 {
|
|
77 return value.im;
|
|
78 }
|
|
79
|
72
|
80 override Complex!(real) toComplex()
|
0
|
81 {
|
|
82 return value;
|
|
83 }
|
|
84
|
72
|
85 override Expression castTo(Scope sc, Type t)
|
0
|
86 {
|
|
87 Expression e = this;
|
|
88 if (type != t)
|
|
89 {
|
|
90 if (type.iscomplex() && t.iscomplex())
|
|
91 {
|
|
92 e = copy();
|
|
93 e.type = t;
|
|
94 }
|
|
95 else
|
|
96 e = Expression.castTo(sc, t);
|
|
97 }
|
|
98 return e;
|
|
99 }
|
|
100
|
72
|
101 override int isConst()
|
0
|
102 {
|
53
|
103 return 1;
|
0
|
104 }
|
|
105
|
72
|
106 override bool isBool(bool result)
|
0
|
107 {
|
|
108 assert(false);
|
|
109 }
|
|
110
|
72
|
111 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
112 {
|
|
113 assert(false);
|
|
114 }
|
|
115
|
72
|
116 override void toMangleBuffer(OutBuffer buf)
|
0
|
117 {
|
|
118 assert(false);
|
|
119 }
|
|
120 version (_DH) {
|
|
121
|
|
122 OutBuffer hexp;
|
|
123 }
|
|
124
|
72
|
125 override elem* toElem(IRState* irs)
|
0
|
126 {
|
|
127 eve c;
|
|
128 tym_t ty;
|
|
129
|
|
130 //printf("ComplexExp.toElem(%p) %s\n", this, toChars());
|
|
131
|
|
132 ///memset(&c, 0, c.sizeof);
|
|
133
|
|
134 ty = type.totym();
|
|
135 switch (tybasic(ty))
|
|
136 {
|
|
137 case TYcfloat:
|
|
138 {
|
|
139 c.Vcfloat.re = cast(float) value.re;
|
|
140 if (Port.isSignallingNan(value.re)) {
|
|
141 (cast(uint*)&c.Vcfloat.re)[0] &= 0xFFBFFFFFL;
|
|
142 std.stdio.writeln("float.re is snan");
|
|
143 }
|
|
144 c.Vcfloat.im = cast(float) value.im;
|
|
145 if (Port.isSignallingNan(value.im)) {
|
|
146 (cast(uint*)&c.Vcfloat.im)[0] &= 0xFFBFFFFFL;
|
|
147 std.stdio.writeln("float.im is snan");
|
|
148 }
|
|
149 break;
|
|
150 }
|
|
151
|
|
152 case TYcdouble:
|
|
153 {
|
|
154 c.Vcdouble.re = cast(double) value.re;
|
|
155 if (Port.isSignallingNan(value.re)) {
|
|
156 std.stdio.writeln("double.re is snan");
|
|
157 (cast(uint*)&c.Vcdouble.re)[1] &= 0xFFF7FFFFL;
|
|
158 }
|
|
159 c.Vcdouble.im = cast(double) value.im;
|
|
160 if (Port.isSignallingNan(value.im)) {
|
|
161 (cast(uint*)&c.Vcdouble.im)[1] &= 0xFFF7FFFFL;
|
|
162 std.stdio.writeln("double.im is snan");
|
|
163 }
|
|
164 break;
|
|
165 }
|
|
166
|
|
167 case TYcldouble:
|
|
168 {
|
|
169 static if (true) {
|
|
170 c.Vcldouble = value;
|
|
171 } else {
|
|
172 {
|
|
173 ushort* p = cast(ushort*)&c.Vcldouble;
|
|
174 for (int i = 0; i < (LNGDBLSIZE*2)/2; i++) printf("%04x ", p[i]);
|
|
175 printf("\n");
|
|
176 }
|
|
177 c.Vcldouble.im = im;
|
|
178 {
|
|
179 ushort* p = cast(ushort*)&c.Vcldouble;
|
|
180 for (int i = 0; i < (LNGDBLSIZE*2)/2; i++) printf("%04x ", p[i]);
|
|
181 printf("\n");
|
|
182 }
|
|
183 c.Vcldouble.re = re;
|
|
184 {
|
|
185 ushort* p = cast(ushort*)&c.Vcldouble;
|
|
186 for (int i = 0; i < (LNGDBLSIZE*2)/2; i++) printf("%04x ", p[i]);
|
|
187 printf("\n");
|
|
188 }
|
|
189 }
|
|
190 break;
|
|
191 }
|
|
192
|
|
193 default:
|
|
194 assert(0);
|
|
195 }
|
|
196 return el_const(ty, &c);
|
|
197 }
|
|
198
|
|
199 static private char[6] zeropad;
|
|
200
|
72
|
201 override dt_t** toDt(dt_t** pdt)
|
0
|
202 {
|
|
203 //printf("ComplexExp.toDt() '%s'\n", toChars());
|
|
204 float fvalue;
|
|
205 double dvalue;
|
|
206 real evalue;
|
|
207
|
|
208 switch (type.toBasetype().ty)
|
|
209 {
|
|
210 case Tcomplex32:
|
|
211 fvalue = value.re;
|
|
212 pdt = dtnbytes(pdt,4,cast(char*)&fvalue);
|
|
213 fvalue = value.im;
|
|
214 pdt = dtnbytes(pdt,4,cast(char*)&fvalue);
|
|
215 break;
|
|
216
|
|
217 case Tcomplex64:
|
|
218 dvalue = value.re;
|
|
219 pdt = dtnbytes(pdt,8,cast(char*)&dvalue);
|
|
220 dvalue = value.im;
|
|
221 pdt = dtnbytes(pdt,8,cast(char*)&dvalue);
|
|
222 break;
|
|
223
|
|
224 case Tcomplex80:
|
|
225 evalue = value.re;
|
|
226 pdt = dtnbytes(pdt,REALSIZE - REALPAD,cast(char*)&evalue);
|
|
227 pdt = dtnbytes(pdt,REALPAD,zeropad.ptr);
|
|
228 evalue = value.im;
|
|
229 pdt = dtnbytes(pdt,REALSIZE - REALPAD, cast(char*)&evalue);
|
|
230 pdt = dtnbytes(pdt,REALPAD,zeropad.ptr);
|
|
231 break;
|
|
232
|
|
233 default:
|
|
234 assert(0);
|
|
235 break;
|
|
236 }
|
|
237 return pdt;
|
|
238 }
|
|
239 }
|
|
240
|