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