annotate dmd/codegen/Util.d @ 73:ef02e2e203c2

Updating to dmd2.033
author korDen
date Sat, 28 Aug 2010 19:42:41 +0400
parents f708f0452e81
children 7e0d548de9e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Loc;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
4 import dmd.Id;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.RET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Global;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
18 import dmd.Module;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TemplateMixin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.DsymbolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.STR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.TF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.TYFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import std.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import core.stdc.string;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
59 import core.stdc.stdlib;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
61 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
62
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 * Call a function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 elem* callfunc(Loc loc,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 IRState* irs,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 int directcall, // 1: don't do virtual call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 Type tret, // return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 elem *ec, // evaluates to function address
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 Type ectype, // original type of ec
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 FuncDeclaration fd, // if !=null, this is the function being called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 Type t, // TypeDelegate or TypeFunction for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 elem* ehidden, // if !=null, this is the 'hidden' argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 Array arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 elem* ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 elem* ethis = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 elem* eside = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 tym_t ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 tym_t tyret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 RET retmethod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 int reverse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 TypeFunction tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 OPER op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 printf("callfunc(directcall = %d, tret = '%s', ec = %p, fd = %p)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 directcall, tret.toChars(), ec, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 printf("ec: "); elem_print(ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 printf("fd = '%s'\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (t.ty == TY.Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 // A delegate consists of:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 // { Object *this; Function *funcptr; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 assert(!fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 assert(t.nextOf().ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 tf = cast(TypeFunction)t.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 ethis = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 ec = el_same(&ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ethis = el_una(OPER.OP64_32, TYM.TYnptr, ethis); // get this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 ec = array_toPtr(t, ec); // get funcptr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 ec = el_una(OPER.OPind, tf.totym(), ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 assert(t.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 tf = cast(TypeFunction)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 retmethod = tf.retStyle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ty = ec.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ty = fd.toSymbol().Stype.Tty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 reverse = tyrevfunc(ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 ep = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 // j=1 if _arguments[] is first argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 int j = (tf.linkage == LINK.LINKd && tf.varargs == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 for (i = 0; i < arguments.dim ; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 elem* ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 arg = cast(Expression)arguments.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //printf("\targ[%d]: %s\n", i, arg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 size_t nparams = Argument.dim(tf.parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (i - j < nparams && i >= j)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 Argument p = Argument.getNth(tf.parameters, i - j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (p.storageClass & (STC.STCout | STC.STCref))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 // Convert argument to a pointer,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 // use AddrExp.toElem()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 Expression ae = arg.addressOf(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 ea = ae.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 ea = arg.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (tybasic(ea.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 ea = el_una(OPER.OPstrpar, TYM.TYstruct, ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 ea.Enumbytes = ea.E1.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 assert(ea.Enumbytes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 if (reverse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 ep = el_param(ep,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 ep = el_param(ea,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 if (retmethod == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (!ehidden)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 // Don't have one, so create one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 type* tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (tf.next.toBasetype().ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 tt = tf.next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 tt = type_fake(tf.next.totym());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 Symbol* stmp = symbol_genauto(tt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 ehidden = el_ptr(stmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && tf.linkage != LINK.LINKd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 ; // ehidden goes last on Linux/OSX C++
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 if (ep)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 static if (false) { // BUG: implement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 if (reverse && type_mangle(tfunc) == mTYman.mTYman_cpp) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 ep = el_param(ehidden,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 ep = el_param(ep,ehidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 ep = el_param(ep,ehidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 ep = ehidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 ehidden = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 if (fd && fd.isMember2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 InterfaceDeclaration intd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 Symbol* sfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 ad = fd.isThis();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 ethis = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 if (ad.isStructDeclaration() && tybasic(ec.Ety) != TYM.TYnptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 ethis = addressElem(ec, ectype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 // Evaluate ec for side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 eside = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 sfunc = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (!fd.isVirtual() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 directcall || // BUG: fix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 fd.isFinal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 // make static call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 ec = el_var(sfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 // make virtual call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 elem* ev;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 uint vindex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 assert(ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 ev = el_same(&ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 ev = el_una(OPER.OPind, TYM.TYnptr, ev);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 vindex = fd.vtblIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 // Build *(ev + vindex * 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 ec = el_bin(OPER.OPadd, TYM.TYnptr, ev, el_long(TYM.TYint, vindex * 4));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 ec = el_una(OPER.OPind, TYM.TYnptr, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ec = el_una(OPER.OPind, tybasic(sfunc.Stype.Tty), ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 else if (fd && fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 assert(!ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 ethis = getEthis(Loc(0), irs, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 ep = el_param(ep, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 if (ehidden)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 ep = el_param(ep, ehidden); // if ehidden goes last
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 tyret = tret.totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 // Look for intrinsic functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (ec.Eoper == OPER.OPvar && (op = intrinsic_oper(ec.EV.sp.Vsym.Sident.ptr)) != OPER.OPMAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 el_free(ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (OTbinary(op))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 ep.Eoper = op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 ep.Ety = tyret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 e = ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 if (op == OPER.OPscale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 elem *et = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 e.E1() = el_una(OPER.OPd_ld, TYM.TYldouble, e.E1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 e.E1() = el_una(OPER.OPs32_d, TYM.TYdouble, e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 e.E2() = et;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 else if (op == OPER.OPyl2x || op == OPER.OPyl2xp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 elem *et = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 e.E1() = e.E2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 e.E2() = et;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 e = el_una(op,tyret,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 else if (ep)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 e = el_bin(tf.ispure ? OPER.OPcallns : OPER.OPcall, tyret, ec, ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 e = el_una(tf.ispure ? OPER.OPucallns : OPER.OPucall, tyret, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 if (retmethod == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 e = el_una(OPER.OPind, tyret, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 if (tf.isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 e = el_una(OPER.OPind, tyret, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (tybasic(tyret) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 e.Enumbytes = cast(uint)tret.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 e = el_combine(eside, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 * Fake a struct symbol.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 Classsym* fake_classsym(Identifier id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 TYPE* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 Classsym* scc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 scc = cast(Classsym*)symbol_calloc(toStringz(id.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 scc.Sclass = SC.SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 scc.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 scc.Sstruct.Sstructalign = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 //scc.Sstruct.ptrtype = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 scc.Sstruct.Sflags = STR.STRglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 t = type_alloc(TYM.TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 t.Tflags |= TF.TFsizeunknown | TF.TFforward;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 t.Ttag = scc; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 assert(t.Tmangle == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 t.Tmangle = mTYman.mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 scc.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 slist_add(scc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 return scc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 * Return elem that evaluates to the static frame pointer for function fd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 * If fd is a member function, the returned expression will compute the value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 * of fd's 'this' variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 * This routine is critical for implementing nested functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 elem* getEthis(Loc loc, IRState* irs, Dsymbol fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 elem* ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 FuncDeclaration thisfd = irs.getFunc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 Dsymbol fdparent = fd.toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 //printf("getEthis(thisfd = '%s', fd = '%s', fdparent = '%s')\n", thisfd.toChars(), fd.toChars(), fdparent.toChars());
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
355 if (fdparent == thisfd ||
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
356 /* These two are compiler generated functions for the in and out contracts,
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
357 * and are called from an overriding function, not just the one they're
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
358 * nested inside, so this hack is so they'll pass
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
359 */
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
360 fd.ident == Id.require || fd.ident == Id.ensure)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 /* Going down one nesting level, i.e. we're calling
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 * a nested function from its enclosing function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 if (irs.sclosure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 ethis = el_var(irs.sclosure);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 if (irs.sthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 // We have a 'this' pointer for the current function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 /* If no variables in the current function's frame are
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 * referenced by nested functions, then we can 'skip'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 * adding this frame into the linked list of stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 * frames.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 bool cond = (thisfd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 bool cond = thisfd.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 if (cond)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 /* Local variables are referenced, can't skip.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 * Address of 'this' gives the 'this' for the nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 * function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 ethis = el_una(OPER.OPaddr, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 /* No 'this' pointer for current function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 * use null if no references to the current function's frame
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 ethis = el_long(TYM.TYnptr, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 bool cond = (thisfd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 bool cond = thisfd.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 if (cond)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 /* OPframeptr is an operator that gets the frame pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 * for the current function, i.e. for the x86 it gets
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 * the value of EBP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 ethis.Eoper = OPER.OPframeptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 }
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
414
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
415 //if (fdparent != thisfd) ethis = el_bin(OPadd, TYnptr, ethis, el_long(TYint, 0x18));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 if (!irs.sthis) // if no frame pointer for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 fd.error(loc, "is a nested function and cannot be accessed from %s", irs.getFunc().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 ethis = el_long(TYM.TYnptr, 0); // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 Dsymbol s = thisfd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 while (fd != s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 /* Go up a nesting level, i.e. we need to find the 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 * of an enclosing function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 * Our 'enclosing function' may also be an inner class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 //printf("\ts = '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 thisfd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 if (thisfd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 /* Enclosing function is a function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 if (fdparent == s.toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 if (thisfd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 FuncDeclaration p = s.toParent2().isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 bool cond = !p || p.closureVars.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 bool cond = !p || p.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 if (cond) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 else if (thisfd.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 // Error should have been caught by front end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 /* Enclosed by an aggregate. That means the current
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 * function must be a member function of that aggregate.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 StructDeclaration sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 AggregateDeclaration ad = s.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 if (!ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 goto Lnoframe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 if (cd && fd.isClassDeclaration() && fd.isClassDeclaration().isBaseOf(cd, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 sd = s.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 if (fd == sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 if (!ad.isNested() || !ad.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 Lnoframe:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 irs.getFunc().error(loc, "cannot get frame pointer to %s", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 return el_long(TYM.TYnptr, 0); // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 ethis = el_bin(OPER.OPadd, TYM.TYnptr, ethis, el_long(TYM.TYint, ad.vthis.offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 if (fdparent == s.toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 if (auto fdd = s.toParent2().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 /* Remember that frames for functions that have no
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 * nested references are skipped in the linked list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 * of frames.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 bool cond = (fdd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 bool cond = fdd.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 if (cond) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 s = s.toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 assert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 printf("ethis:\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 elem_print(ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 return ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 * Convert array to a pointer to the data.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 elem* array_toPtr(Type t, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 //printf("array_toPtr()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 case TY.Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 case TY.Tdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 if (e.Eoper == OPER.OPcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 e.E2() = array_toPtr(t, e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 else if (e.Eoper == OPER.OPpair)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 e.Eoper = OPER.OPcomma;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 e = el_una(OPER.OPmsw, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 e = el_bin(OPER.OPadd, TYM.TYnptr, e, el_long(TYM.TYint, 4));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 e = el_una(OPER.OPind, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 ///t.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 * Take address of an elem.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 elem* addressElem(elem* e, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 elem** pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 //printf("addressElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 for (pe = &e; (*pe).Eoper == OPER.OPcomma; pe = &(*pe).E2()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 if ((*pe).Eoper != OPER.OPvar && (*pe).Eoper != OPER.OPind)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 Symbol* stmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 elem* eeq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 elem* ee = *pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 type* tx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 // Convert to ((tmp=ee),tmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 TY ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 if (t && ((ty = t.toBasetype().ty) == TY.Tstruct || ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 tx = t.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 tx = type_fake(ee.Ety);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 stmp = symbol_genauto(tx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 eeq = el_bin(OPER.OPeq,ee.Ety,el_var(stmp),ee);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 if (tybasic(ee.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 eeq.Eoper = OPER.OPstreq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 eeq.Enumbytes = ee.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 else if (tybasic(ee.Ety) == TYM.TYarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 eeq.Eoper = OPER.OPstreq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 eeq.Ety = TYM.TYstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 eeq.Ejty = cast(ubyte)eeq.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 eeq.Enumbytes = cast(uint)t.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 *pe = el_bin(OPER.OPcomma, ee.Ety, eeq, el_var(stmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 * Convert intrinsic function to operator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 * Returns that operator, -1 if not an intrinsic function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 extern (C++) extern int intrinsic_op(char* name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 OPER intrinsic_oper(const(char)* name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 int result = intrinsic_op(cast(char*)name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 if (result == -1) return OPER.OPMAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 return cast(OPER)result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 elem* Dsymbol_toElem(Dsymbol s, IRState *irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 elem *e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 Symbol* sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 AttribDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 VarDeclaration vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 StructDeclaration sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 TemplateMixin tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 TupleDeclaration td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 TypedefDeclaration tyd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 //printf("Dsymbol_toElem() %s\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 ad = s.isAttribDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 Array decl = ad.include(null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 if (decl && decl.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 for (size_t i = 0; i < decl.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 s = cast(Dsymbol)decl.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 e = el_combine(e, Dsymbol_toElem(s, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 else if ((vd = s.isVarDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 if (s != vd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 return Dsymbol_toElem(s, irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 if (vd.isStatic() || vd.storage_class & (STC.STCextern | STC.STCtls | STC.STCgshared))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 vd.toObjFile(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 sp = s.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 symbol_add(sp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 //printf("\tadding symbol '%s'\n", sp.Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 ExpInitializer ie = vd.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 if (ie) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 e = ie.exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 else if ((cd = s.isClassDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 irs.deferToObj.push(cast(void*)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 else if ((sd = s.isStructDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 irs.deferToObj.push(cast(void*)sd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 else if ((fd = s.isFuncDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 //printf("function %s\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 irs.deferToObj.push(cast(void*)fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 else if ((tm = s.isTemplateMixin()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 //printf("%s\n", tm.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 if (tm.members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 for (size_t i = 0; i < tm.members.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 Dsymbol sm = cast(Dsymbol)tm.members.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 e = el_combine(e, Dsymbol_toElem(sm, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 else if ((td = s.isTupleDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 for (size_t i = 0; i < td.objects.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 Object o = cast(Object)td.objects.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 ///if (o.dyncast() == DYNCAST_EXPRESSION)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 if (Expression eo = cast(Expression)o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 if (eo.op == TOK.TOKdsymbol)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 DsymbolExp se = cast(DsymbolExp)eo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 e = el_combine(e, Dsymbol_toElem(se.s, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 else if ((tyd = s.isTypedefDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 irs.deferToObj.push(cast(void*)tyd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 * Given an expression e that is an array,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 * determine and set the 'length' variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 * lengthVar Symbol of 'length' variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 * &e expression that is the array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 * t1 Type of the array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 * e is rewritten to avoid side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 * expression that initializes 'length'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 elem* resolveLengthVar(VarDeclaration lengthVar, elem** pe, Type t1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 //printf("resolveLengthVar()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 elem* einit = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 if (lengthVar && !(lengthVar.storage_class & STC.STCconst))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 elem* elength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 Symbol* slength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if (t1.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 TypeSArray tsa = cast(TypeSArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 long length = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 elength = el_long(TYM.TYuint, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 else if (t1.ty == TY.Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 elength = *pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 *pe = el_same(&elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 elength = el_una(OPER.OP64_32, TYM.TYuint, elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 slength = lengthVar.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 //symbol_add(slength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 einit = el_bin(OPER.OPeq, TYM.TYuint, el_var(slength), elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 return einit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 * Set an array pointed to by eptr to evalue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 * eptr[0..edim] = evalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 * eptr where to write the data to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 * evalue value to write
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 * edim number of times to write evalue to eptr[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 * tb type of evalue
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 elem* setArray(elem* eptr, elem* edim, Type tb, elem* evalue, IRState* irs, int op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 int r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 int sz = cast(int)tb.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 if (tb.ty == TY.Tfloat80 || tb.ty == TY.Timaginary80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 r = RTLSYM.RTLSYM_MEMSET80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 else if (tb.ty == TY.Tcomplex80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 r = RTLSYM.RTLSYM_MEMSET160;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 else if (tb.ty == TY.Tcomplex64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 r = RTLSYM.RTLSYM_MEMSET128;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 switch (sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 case 1: r = RTLSYM.RTLSYM_MEMSET8; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 case 2: r = RTLSYM.RTLSYM_MEMSET16; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 case 4: r = RTLSYM.RTLSYM_MEMSET32; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 case 8: r = RTLSYM.RTLSYM_MEMSET64; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 default: r = RTLSYM.RTLSYM_MEMSETN; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 /* Determine if we need to do postblit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 if (op != TOK.TOKblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 StructDeclaration sd = needsPostblit(tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 if (sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 /* Need to do postblit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 * void *_d_arraysetassign(void *p, void *value, int dim, TypeInfo ti);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 r = (op == TOK.TOKconstruct) ? RTLSYM.RTLSYM_ARRAYSETCTOR : RTLSYM.RTLSYM_ARRAYSETASSIGN;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 evalue = el_una(OPER.OPaddr, TYM.TYnptr, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 Expression ti = tb.getTypeInfo(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 elem* eti = ti.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 e = el_params(eti, edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 if (r == RTLSYM.RTLSYM_MEMSETN)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 // void *_memsetn(void *p, void *value, int dim, int sizelem)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 evalue = el_una(OPER.OPaddr, TYM.TYnptr, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 elem *esz = el_long(TYM.TYint, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 e = el_params(esz, edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 if (sz > 1 && sz <= 8 && evalue.Eoper == OPER.OPconst && el_allbits(evalue, 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 r = RTLSYM.RTLSYM_MEMSET8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 edim = el_bin(OPER.OPmul, TYM.TYuint, edim, el_long(TYM.TYuint, sz));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 if (tybasic(evalue.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 evalue = el_una(OPER.OPstrpar, TYM.TYstruct, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 evalue.Enumbytes = evalue.E1.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 assert(evalue.Enumbytes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 // Be careful about parameter side effect ordering
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 if (r == RTLSYM.RTLSYM_MEMSET8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 e = el_param(edim, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 e = el_bin(OPER.OPmemset, TYM.TYnptr, eptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 e = el_params(edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 /*************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 * Initialize the hidden aggregate member, vthis, with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 * the context pointer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 * *(ey + ad.vthis.offset) = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 elem* setEthis(Loc loc, IRState* irs, elem* ey, AggregateDeclaration ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 elem* ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 FuncDeclaration thisfd = irs.getFunc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 Dsymbol cdp = ad.toParent2(); // class/func we're nested in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 //printf("setEthis(ad = %s, cdp = %s, thisfd = %s)\n", ad.toChars(), cdp.toChars(), thisfd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 if (cdp is thisfd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 /* Class we're new'ing is a local class in this function:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 * void thisfd() { class ad { } }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 if (irs.sclosure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 ethis = el_var(irs.sclosure);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 else if (irs.sthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 if (thisfd.closureVars.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 /// } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 /// if (thisfd.nestedFrameRef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 ethis = el_ptr(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 ethis = el_long(TYM.TYnptr, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 if (thisfd.closureVars.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 /// } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 /// if (thisfd.nestedFrameRef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 ethis.Eoper = OPER.OPframeptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 else if (thisfd.vthis && (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 cdp == thisfd.toParent2() || (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 cdp.isClassDeclaration() && cdp.isClassDeclaration().isBaseOf(thisfd.toParent2().isClassDeclaration(), &offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 /* Class we're new'ing is at the same level as thisfd
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 assert(offset == 0); // BUG: should handle this case
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 ethis = getEthis(loc, irs, ad.toParent2());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 ethis = el_una(OPER.OPaddr, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 ey = el_bin(OPER.OPadd, TYM.TYnptr, ey, el_long(TYM.TYint, ad.vthis.offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 ey = el_una(OPER.OPind, TYM.TYnptr, ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 ey = el_bin(OPER.OPeq, TYM.TYnptr, ey, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 return ey;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 * Determine if t is an array of structs that need a postblit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 StructDeclaration needsPostblit(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 while (t.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 t = t.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 if (t.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 StructDeclaration sd = (cast(TypeStruct)t).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 if (sd.postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 return sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 * Convert array to a dynamic array.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 elem* array_toDarray(Type t, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 uint dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 elem* ef = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 elem* ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 //printf("array_toDarray(t = %s)\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 dim = cast(uint)(cast(TypeSArray)t).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 e = el_pair(TYM.TYullong, el_long(TYM.TYint, dim), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 switch (e.Eoper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 case OPER.OPconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 size_t len = tysize[tybasic(e.Ety)];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 elem* es = el_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 es.Eoper = OPER.OPstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 // Match MEM_PH_FREE for OPstring in ztc\el.c
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
1012 es.EV.ss.Vstring = cast(char*)malloc(len); /// !
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 memcpy(es.EV.ss.Vstring, &e.EV, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 es.EV.ss.Vstrlen = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 es.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 case OPER.OPvar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 case OPER.OPcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 ef = el_combine(ef, e.E1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 ex = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 e = e.E2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 ex.E1() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 ex.E2() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 el_free(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 case OPER.OPind:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 ex = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 e = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 ex.E1() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 ex.E2() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 el_free(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 // Copy expression to a variable and take the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 // address of that variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 Symbol* stmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 tym_t ty = tybasic(e.Ety);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 if (ty == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 if (e.Enumbytes == 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 ty = TYM.TYint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 else if (e.Enumbytes == 8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 ty = TYM.TYllong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 e.Ety = ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 stmp = symbol_genauto(type_fake(ty));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 e = el_bin(OPER.OPeq, e.Ety, el_var(stmp), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 e = el_bin(OPER.OPcomma, TYM.TYnptr, e, el_una(OPER.OPaddr, TYM.TYnptr, el_var(stmp)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 dim = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 e = el_pair(TYM.TYullong, el_long(TYM.TYint, dim), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 return el_combine(ef, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 elem* sarray_toDarray(Loc loc, Type tfrom, Type tto, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 //printf("sarray_toDarray()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 elem* elen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 uint dim = cast(uint)(cast(TypeSArray)tfrom).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 if (tto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 uint fsize = cast(uint)tfrom.nextOf().size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 uint tsize = cast(uint)tto.nextOf().size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 if ((dim * fsize) % tsize != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 error(loc, "cannot cast %s to %s since sizes don't line up", tfrom.toChars(), tto.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 dim = (dim * fsize) / tsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 elen = el_long(TYM.TYint, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 e = el_pair(TYM.TYullong, elen, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 elem* eval_Darray(IRState* irs, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 elem* ex = e.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 return array_toDarray(e.type, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 /***********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 * Generate code to set index into scope table.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 void setScopeIndex(Blockx* blx, block* b, int scope_index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 version (SEH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 block_appendexp(b, nteh_setScopeTableIndex(blx, scope_index));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 * Create a static symbol we can hang DT initializers onto.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 Symbol* static_sym()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 t = type_alloc(TYint);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 s = symbol_calloc("internal");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 s.Sclass = SCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 s.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 s.Sflags |= SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 version (ELFOBJ_OR_MACHOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1133 s.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 * Convert label to block.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 block* labelToBlock(Loc loc, Blockx *blx, LabelDsymbol label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 LabelStatement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 if (!label.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 error(loc, "undefined label %s", label.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 s = label.statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 if (!s.lblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 s.lblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 if (s.isReturnLabel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 s.lblock.Btry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 return s.lblock;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1161 }
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1162
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1163 /*******************************************
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1164 * Generate elem to zero fill contents of Symbol stmp
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1165 * from *poffset..offset2.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1166 * May store anywhere from 0..maxoff, as this function
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1167 * tries to use aligned int stores whereever possible.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1168 * Update *poffset to end of initialized hole; *poffset will be >= offset2.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1169 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1170
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1171 elem* fillHole(Symbol* stmp, size_t* poffset, size_t offset2, size_t maxoff)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1172 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1173 elem* e = null;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1174 int basealign = 1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1175
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1176 while (*poffset < offset2)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1177 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1178 tym_t ty;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1179 elem* e1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1180
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1181 if (tybasic(stmp.Stype.Tty) == TYnptr)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1182 e1 = el_var(stmp);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1183 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1184 e1 = el_ptr(stmp);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1185
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1186 if (basealign)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1187 *poffset &= ~3;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1188
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1189 basealign = 1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1190 size_t sz = maxoff - *poffset;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1191 switch (sz)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1192 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1193 case 1: ty = TYchar; break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1194 case 2: ty = TYshort; break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1195 case 3:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1196 ty = TYshort;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1197 basealign = 0;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1198 break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1199 default:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1200 ty = TYlong;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1201 break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1202 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1203 e1 = el_bin(OPadd, TYnptr, e1, el_long(TYsize_t, *poffset));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1204 e1 = el_una(OPind, ty, e1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1205 e1 = el_bin(OPeq, ty, e1, el_long(ty, 0));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1206 e = el_combine(e, e1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1207 *poffset += tysize[ty];
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1208 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1209 return e;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1210 }