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