Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20090611165743

Diff

Diff from 1.13 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/arch/amd64/local2.c

Annotated File View

ragge
1.13
1 /*      $Id: local2.c,v 1.13 2009/06/11 16:57:43 ragge Exp $    */
mickey
1.1
2 /*
3  * Copyright (c) 2008 Michael Shalayeff
4  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 # include "pass2.h"
31 # include <ctype.h>
32 # include <string.h>
33
34 static int stkpos;
35
36 void
37 deflab(int label)
38 {
39         printf(LABFMT ":\n"label);
40 }
41
ragge
1.11
42 static int regoff[MAXREGS];
mickey
1.1
43 static TWORD ftype;
ragge
1.4
44 char *rbyte[], *rshort[], *rlong[];
mickey
1.1
45
46 /*
47  * Print out the prolog assembler.
48  * addto and regoff are already calculated.
49  */
50 static void
51 prtprolog(struct interpass_prolog *ippint addto)
52 {
53         int i;
54
ragge
1.5
55         /* XXX should look if there is any need to emit this */
mickey
1.2
56         printf("\tpushq %%rbp\n");
57         printf("\tmovq %%rsp,%%rbp\n");
ragge
1.10
58         addto = (addto+15) & ~15/* 16-byte aligned */
mickey
1.1
59         if (addto)
mickey
1.2
60                 printf("\tsubq $%d,%%rsp\n"addto);
ragge
1.10
61
62         /* save permanent registers */
mickey
1.1
63         for (i = 0i < MAXREGSi++)
ragge
1.10
64                 if (TESTBIT(ipp->ipp_regsi))
ragge
1.11
65                         fprintf(stdout"\tmovq %s,-%d(%s)\n",
mickey
1.1
66                             rnames[i], regoff[i], rnames[FPREG]);
ragge
1.4
67 }
mickey
1.1
68
69 /*
70  * calculate stack size and offsets
71  */
72 static int
73 offcalc(struct interpass_prolog *ipp)
74 {
75         int iaddto;
76
77         addto = p2maxautooff;
78         if (addto >= AUTOINIT/SZCHAR)
79                 addto -= AUTOINIT/SZCHAR;
80         for (i = 0i < MAXREGSi++)
81                 if (TESTBIT(ipp->ipp_regsi)) {
ragge
1.10
82                         addto += SZLONG/SZCHAR;
mickey
1.1
83                         regoff[i] = addto;
84                 }
85         return addto;
86 }
87
88 void
89 prologue(struct interpass_prolog *ipp)
90 {
91         int addto;
92
93         ftype = ipp->ipp_type;
94
95 #ifdef LANG_F77
96         if (ipp->ipp_vis)
97                 printf("        .globl %s\n"ipp->ipp_name);
ragge
1.10
98         printf("        .align 16\n");
mickey
1.1
99         printf("%s:\n"ipp->ipp_name);
100 #endif
101         /*
102          * We here know what register to save and how much to 
103          * add to the stack.
104          */
105         addto = offcalc(ipp);
106         prtprolog(ippaddto);
107 }
108
109 void
110 eoftn(struct interpass_prolog *ipp)
111 {
112         int i;
113
114         if (ipp->ipp_ip.ip_lbl == 0)
115                 return/* no code needs to be generated */
116
117         /* return from function code */
118         for (i = 0i < MAXREGSi++)
119                 if (TESTBIT(ipp->ipp_regsi))
ragge
1.10
120                         fprintf(stdout"       movq -%d(%s),%s\n",
mickey
1.1
121                             regoff[i], rnames[FPREG], rnames[i]);
122
123         /* struct return needs special treatment */
124         if (ftype == STRTY || ftype == UNIONTY) {
125                 printf("        movl 8(%%ebp),%%eax\n");
126                 printf("        leave\n");
127                 printf("        ret $%d\n"4);
128         } else {
129                 printf("        leave\n");
ragge
1.11
130                 printf("        ret\n");
mickey
1.1
131         }
ragge
1.10
132         printf("\t.size %s,.-%s\n"ipp->ipp_nameipp->ipp_name);
mickey
1.1
133 }
134
135 /*
136  * add/sub/...
137  *
138  * Param given:
139  */
140 void
141 hopcode(int fint o)
142 {
143         char *str;
144
145         switch (o) {
146         case PLUS:
147                 str = "add";
148                 break;
149         case MINUS:
150                 str = "sub";
151                 break;
152         case AND:
153                 str = "and";
154                 break;
155         case OR:
156                 str = "or";
157                 break;
158         case ER:
159                 str = "xor";
160                 break;
161         default:
162                 comperr("hopcode2: %d"o);
163                 str = 0/* XXX gcc */
164         }
165         printf("%s%c"strf);
166 }
167
168 /*
169  * Return type size in bytes.  Used by R2REGS, arg 2 to offset().
170  */
171 int
mickey
1.2
172 tlen(NODE *p)
mickey
1.1
173 {
174         switch(p->n_type) {
175                 case CHAR:
176                 case UCHAR:
177                         return(1);
178
179                 case SHORT:
180                 case USHORT:
181                         return(SZSHORT/SZCHAR);
182
183                 case DOUBLE:
184                         return(SZDOUBLE/SZCHAR);
185
186                 case INT:
187                 case UNSIGNED:
188                         return(SZINT/SZCHAR);
189
190                 case LONG:
191                 case ULONG:
192                 case LONGLONG:
193                 case ULONGLONG:
194                         return SZLONGLONG/SZCHAR;
195
196                 default:
197                         if (!ISPTR(p->n_type))
198                                 comperr("tlen type %d not pointer");
199                         return SZPOINT(p->n_type)/SZCHAR;
200                 }
201 }
202
gmcgarry
1.3
203 #if 0
mickey
1.1
204 /*
205  * Emit code to compare two longlong numbers.
206  */
207 static void
208 twollcomp(NODE *p)
209 {
210         int o = p->n_op;
mickey
1.2
211         int s = getlab2();
mickey
1.1
212         int e = p->n_label;
213         int cb1cb2;
214
215         if (o >= ULE)
216                 o -= (ULE-LE);
217         switch (o) {
218         case NE:
219                 cb1 = 0;
220                 cb2 = NE;
221                 break;
222         case EQ:
223                 cb1 = NE;
224                 cb2 = 0;
225                 break;
226         case LE:
227         case LT:
228                 cb1 = GT;
229                 cb2 = LT;
230                 break;
231         case GE:
232         case GT:
233                 cb1 = LT;
234                 cb2 = GT;
235                 break;
236         
237         default:
238                 cb1 = cb2 = 0/* XXX gcc */
239         }
240         if (p->n_op >= ULE)
241                 cb1 += 4cb2 += 4;
242         expand(p0"  cmpl UR,UL\n");
243         if (cb1cbgen(cb1s);
244         if (cb2cbgen(cb2e);
245         expand(p0"  cmpl AR,AL\n");
246         cbgen(p->n_ope);
247         deflab(s);
248 }
gmcgarry
1.3
249 #endif
mickey
1.1
250
251 int
252 fldexpand(NODE *pint cookiechar **cp)
253 {
254         CONSZ val;
255
256         if (p->n_op == ASSIGN)
257                 p = p->n_left;
258         switch (**cp) {
259         case 'S':
260                 printf("%d"UPKFSZ(p->n_rval));
261                 break;
262         case 'H':
263                 printf("%d"UPKFOFF(p->n_rval));
264                 break;
265         case 'M':
266         case 'N':
267                 val = (CONSZ)1 << UPKFSZ(p->n_rval);
268                 --val;
269                 val <<= UPKFOFF(p->n_rval);
ragge
1.13
270                 if (p->n_type > UNSIGNED)
271                         printf("0x%llx", (**cp == 'M' ? val : ~val));
272                 else
273                         printf("0x%llx", (**cp == 'M' ? val : ~val)&0xffffffff);
mickey
1.1
274                 break;
275         default:
276                 comperr("fldexpand");
277         }
278         return 1;
279 }
280
281 static void
282 bfext(NODE *p)
283 {
284         int ch = 0sz = 0;
285
286         if (ISUNSIGNED(p->n_right->n_type))
287                 return;
288         switch (p->n_right->n_type) {
289         case CHAR:
290                 ch = 'b';
291                 sz = 8;
292                 break;
293         case SHORT:
294                 ch = 'w';
295                 sz = 16;
296                 break;
297         case INT:
298                 ch = 'l';
299                 sz = 32;
300                 break;
301         case LONG:
302                 ch = 'q';
303                 sz = 64;
304                 break;
305         default:
306                 comperr("bfext");
307         }
308
309         sz -= UPKFSZ(p->n_left->n_rval);
310         printf("\tshl%c $%d,"chsz);
311         adrput(stdoutgetlr(p'D'));
312         printf("\n\tsar%c $%d,"chsz);
313         adrput(stdoutgetlr(p'D'));
314         printf("\n");
315 }
ragge
1.11
316 #if 0
mickey
1.1
317
318 /*
319  * Push a structure on stack as argument.
320  * the scratch registers are already free here
321  */
322 static void
323 starg(NODE *p)
324 {
325         FILE *fp = stdout;
326
327         fprintf(fp"   subl $%d,%%esp\n"p->n_stsize);
328         fprintf(fp"   pushl $%d\n"p->n_stsize);
329         expand(p0"  pushl AL\n");
330         expand(p0"  leal 8(%esp),A1\n");
331         expand(p0"  pushl A1\n");
332         fprintf(fp"   call memcpy\n");
333         fprintf(fp"   addl $12,%%esp\n");
334 }
335
ragge
1.7
336 #endif
mickey
1.1
337 /*
ragge
1.7
338  * Generate code to convert an unsigned long to xmm float/double.
mickey
1.1
339  */
340 static void
ragge
1.7
341 ultofd(NODE *p)
mickey
1.1
342 {
343
ragge
1.7
344 #define E(x)    expand(p, 0, x)
345         E("     movq AL,A1\n");
ragge
1.9
346         E("     testq A1,A1\n");
ragge
1.7
347         E("     js 2f\n");
348         E("     cvtsi2sZfq A1,A3\n");
349         E("     jmp 3f\n");
350         E("2:\n");
351         E("     movq A1,A2\n");
352         E("     shrq A2\n");
ragge
1.9
353         E("     andq $1,A1\n");
ragge
1.7
354         E("     orq A1,A2\n");
355         E("     cvtsi2sZfq A2,A3\n");
356         E("     addsZf A3,A3\n");
357         E("3:\n");
358 #undef E
mickey
1.1
359 }
360
361 static int
362 argsiz(NODE *p)
363 {
364         TWORD t = p->n_type;
365
ragge
1.10
366         if (p->n_left->n_op == REG)
367                 return 0/* not on stack */
mickey
1.1
368         if (t == LDOUBLE)
369                 return 16;
370         if (t == STRTY || t == UNIONTY)
371                 return p->n_stsize;
ragge
1.10
372         return 8;
mickey
1.1
373 }
374
375 void
376 zzzcode(NODE *pint c)
377 {
ragge
1.6
378         NODE *l;
ragge
1.7
379         int prlrs;
mickey
1.1
380
381         switch (c) {
ragge
1.4
382 #if 0
mickey
1.1
383         case 'A'/* swap st0 and st1 if right is evaluated second */
384                 if ((p->n_su & DORIGHT) == 0) {
385                         if (logop(p->n_op))
386                                 printf("        fxch\n");
387                         else
388                                 printf("r");
389                 }
390                 break;
ragge
1.5
391 #endif
mickey
1.1
392
393         case 'C':  /* remove from stack after subroutine call */
394                 pr = p->n_qual;
395                 if (p->n_op == STCALL || p->n_op == USTCALL)
ragge
1.10
396                         pr += 4/* XXX */
mickey
1.1
397                 if (p->n_op == UCALL)
398                         return/* XXX remove ZC from UCALL */
399                 if (pr)
ragge
1.10
400                         printf("        addq $%d, %s\n"prrnames[RSP]);
mickey
1.1
401                 break;
402
403         case 'E'/* Perform bitfield sign-extension */
404                 bfext(p);
405                 break;
406
ragge
1.11
407 #if 0
mickey
1.1
408         case 'F'/* Structure argument */
409                 if (p->n_stalign != 0/* already on stack */
410                         starg(p);
411                 break;
ragge
1.7
412 #endif
413         case 'j'/* convert unsigned long to f/d */
414                 ultofd(p);
mickey
1.1
415                 break;
416
417         case 'M'/* Output sconv move, if needed */
418                 l = getlr(p'L');
419                 /* XXX fixneed: regnum */
420                 pr = DECRA(p->n_reg0);
421                 lr = DECRA(l->n_reg0);
ragge
1.6
422                 if (pr == lr)
423                         break;
424                 printf("        movb %s,%s\n"rbyte[lr], rbyte[pr]);
mickey
1.1
425                 l->n_rval = l->n_reg = p->n_reg/* XXX - not pretty */
426                 break;
427
ragge
1.6
428 #if 0
mickey
1.1
429         case 'N'/* output extended reg name */
430                 printf("%s"rnames[getlr(p'1')->n_rval]);
431                 break;
432
433         case 'S'/* emit eventual move after cast from longlong */
434                 pr = DECRA(p->n_reg0);
435                 lr = p->n_left->n_rval;
436                 switch (p->n_type) {
437                 case CHAR:
438                 case UCHAR:
439                         if (rnames[pr][2] == 'l' && rnames[lr][2] == 'x' &&
440                             rnames[pr][1] == rnames[lr][1])
441                                 break;
442                         if (rnames[lr][2] == 'x') {
443                                 printf("\tmovb %%%cl,%s\n",
444                                     rnames[lr][1], rnames[pr]);
445                                 break;
446                         }
447                         /* Must go via stack */
448                         s = BITOOR(freetemp(1));
449                         printf("\tmovl %%e%ci,%d(%%rbp)\n"rnames[lr][1], s);
450                         printf("\tmovb %d(%%rbp),%s\n"srnames[pr]);
451                         comperr("SCONV1 %s->%s"rnames[lr], rnames[pr]);
452                         break;
453
454                 case SHORT:
455                 case USHORT:
456                         if (rnames[lr][1] == rnames[pr][2] &&
457                             rnames[lr][2] == rnames[pr][3])
458                                 break;
459                         printf("\tmovw %%%c%c,%%%s\n",
460                             rnames[lr][1], rnames[lr][2], rnames[pr]+2);
461                         comperr("SCONV2 %s->%s"rnames[lr], rnames[pr]);
462                         break;
463                 case INT:
464                 case UNSIGNED:
465                         if (rnames[lr][1] == rnames[pr][2] &&
466                             rnames[lr][2] == rnames[pr][3])
467                                 break;
468                         printf("\tmovl %%e%c%c,%s\n",
469                                     rnames[lr][1], rnames[lr][2], rnames[pr]);
470                         comperr("SCONV3 %s->%s"rnames[lr], rnames[pr]);
471                         break;
472
473                 default:
474                         if (rnames[lr][1] == rnames[pr][2] &&
475                             rnames[lr][2] == rnames[pr][3])
476                                 break;
477                         comperr("SCONV4 %s->%s"rnames[lr], rnames[pr]);
478                         break;
479                 }
480                 break;
ragge
1.4
481 #endif
ragge
1.10
482         case 'Q'/* emit struct assign */
483                 /* XXX - optimize for small structs */
484                 printf("\tmovq $%d,%%rdx\n"p->n_stsize);
485                 expand(pINAREG"\tmovq AR,%rsi\n");
486                 expand(pINAREG"\tleaq AL,%rdi\n\n");
487                 printf("\tcall memcpy\n");
488                 break;
489
ragge
1.7
490         case 'R'/* print opname based on right type */
491         case 'L'/* print opname based on left type */
492                 switch (getlr(pc)->n_type) {
493                 case CHARcase UCHARs = 'b'break;
494                 case SHORTcase USHORTs = 'w'break;
495                 case INTcase UNSIGNEDs = 'l'break;
496                 defaults = 'q'break;
497                 printf("%c"s);
498                 }
499                 break;
500         case '1'/* special reg name printout */
501                 l = getlr(p'1');
502                 printf("%s"rlong[l->n_rval]);
503                 break;
504
505         case 'g':
506                 p = p->n_left;
507                 /* FALLTHROUGH */
508         case 'f'/* float or double */
509                 printf("%c"p->n_type == FLOAT ? 's' : 'd');
510                 break;
511
512         case 'q'/* int or long */
513                 printf("%c"p->n_left->n_type == LONG ? 'q' : ' ');
514                 break;
515
mickey
1.1
516         default:
517                 comperr("zzzcode %c"c);
518         }
519 }
520
521 /*ARGSUSED*/
522 int
523 rewfld(NODE *p)
524 {
525         return(1);
526 }
527
528 int canaddr(NODE *);
529 int
530 canaddr(NODE *p)
531 {
532         int o = p->n_op;
533
534         if (o==NAME || o==REG || o==ICON || o==OREG ||
535             (o==UMUL && shumul(p->n_leftSOREG)))
536                 return(1);
537         return(0);
538 }
539
540 /*
541  * Does the bitfield shape match?
542  */
543 int
544 flshape(NODE *p)
545 {
546         int o = p->n_op;
547
548         if (o == OREG || o == REG || o == NAME)
549                 return SRDIR/* Direct match */
550         if (o == UMUL && shumul(p->n_leftSOREG))
551                 return SROREG/* Convert into oreg */
552         return SRREG/* put it into a register */
553 }
554
555 /* INTEMP shapes must not contain any temporary registers */
556 /* XXX should this go away now? */
557 int
558 shtemp(NODE *p)
559 {
560         return 0;
561 #if 0
562         int r;
563
564         if (p->n_op == STARG )
565                 p = p->n_left;
566
567         switch (p->n_op) {
568         case REG:
569                 return (!istreg(p->n_rval));
570
571         case OREG:
572                 r = p->n_rval;
573                 if (R2TEST(r)) {
574                         if (istreg(R2UPK1(r)))
575                                 return(0);
576                         r = R2UPK2(r);
577                 }
578                 return (!istreg(r));
579
580         case UMUL:
581                 p = p->n_left;
582                 return (p->n_op != UMUL && shtemp(p));
583         }
584
585         if (optype(p->n_op) != LTYPE)
586                 return(0);
587         return(1);
588 #endif
589 }
590
591 void
592 adrcon(CONSZ val)
593 {
594         printf("$" CONFMTval);
595 }
596
597 void
598 conput(FILE *fpNODE *p)
599 {
600         int val = p->n_lval;
601
602         switch (p->n_op) {
603         case ICON:
604                 if (p->n_name[0] != '\0') {
605                         fprintf(fp"%s"p->n_name);
606                         if (val)
607                                 fprintf(fp"+%d"val);
608                 } else
609                         fprintf(fp"%d"val);
610                 return;
611
612         default:
613                 comperr("illegal conput, p %p"p);
614         }
615 }
616
617 /*ARGSUSED*/
618 void
619 insput(NODE *p)
620 {
621         comperr("insput");
622 }
623
624 /*
625  * Write out the upper address, like the upper register of a 2-register
626  * reference, or the next memory location.
627  */
628 void
629 upput(NODE *pint size)
630 {
631
632         size /= SZCHAR;
633         switch (p->n_op) {
634         case REG:
635                 fprintf(stdout"%%%s", &rnames[p->n_rval][3]);
636                 break;
637
638         case NAME:
639         case OREG:
640                 p->n_lval += size;
641                 adrput(stdoutp);
642                 p->n_lval -= size;
643                 break;
644         case ICON:
645                 fprintf(stdout"$" CONFMTp->n_lval >> 32);
646                 break;
647         default:
648                 comperr("upput bad op %d size %d"p->n_opsize);
649         }
650 }
651
652 void
653 adrput(FILE *ioNODE *p)
654 {
655         int r;
ragge
1.5
656         char **rc;
mickey
1.1
657         /* output an address, with offsets, from p */
658
659         if (p->n_op == FLD)
660                 p = p->n_left;
661
662         switch (p->n_op) {
663
664         case NAME:
665                 if (p->n_name[0] != '\0') {
666                         fputs(p->n_nameio);
667                         if (p->n_lval != 0)
668                                 fprintf(io"+" CONFMTp->n_lval);
669                 } else
670                         fprintf(ioCONFMTp->n_lval);
671                 return;
672
673         case OREG:
674                 r = p->n_rval;
675                 if (p->n_name[0])
676                         printf("%s%s"p->n_namep->n_lval ? "+" : "");
677                 if (p->n_lval)
678                         fprintf(io"%d", (int)p->n_lval);
679                 if (R2TEST(r)) {
680                         fprintf(io"(%s,%s,8)"rnames[R2UPK1(r)],
681                             rnames[R2UPK2(r)]);
682                 } else
683                         fprintf(io"(%s)"rnames[p->n_rval]);
684                 return;
685         case ICON:
686 #ifdef PCC_DEBUG
687                 /* Sanitycheck for PIC, to catch adressable constants */
688                 if (kflag && p->n_name[0]) {
689                         static int foo;
690
691                         if (foo++ == 0) {
692                                 printf("\nfailing...\n");
693                                 fwalk(pe2print0);
694                                 comperr("pass2 conput");
695                         }
696                 }
697 #endif
698                 /* addressable value of the constant */
699                 fputc('$'io);
700                 conput(iop);
701                 return;
702
703         case REG:
704                 switch (p->n_type) {
ragge
1.5
705                 case CHAR:
706                 case UCHAR:
707                         rc = rbyte;
mickey
1.1
708                         break;
709                 case SHORT:
710                 case USHORT:
ragge
1.5
711                         rc = rshort;
712                         break;
713                 case INT:
714                 case UNSIGNED:
715                         rc = rlong;
mickey
1.1
716                         break;
717                 default:
ragge
1.5
718                         rc = rnames;
719                         break;
mickey
1.1
720                 }
ragge
1.5
721                 fprintf(io"%s"rc[p->n_rval]);
mickey
1.1
722                 return;
723
724         default:
725                 comperr("illegal address, op %d, node %p"p->n_opp);
726                 return;
727
728         }
729 }
730
731 static char *
732 ccbranches[] = {
733         "je",           /* jumpe */
734         "jne",          /* jumpn */
735         "jle",          /* jumple */
736         "jl",           /* jumpl */
737         "jge",          /* jumpge */
738         "jg",           /* jumpg */
739         "jbe",          /* jumple (jlequ) */
740         "jb",           /* jumpl (jlssu) */
741         "jae",          /* jumpge (jgequ) */
742         "ja",           /* jumpg (jgtru) */
743 };
744
745
746 /*   printf conditional and unconditional branches */
747 void
748 cbgen(int oint lab)
749 {
750         if (o < EQ || o > UGT)
751                 comperr("bad conditional branch: %s"opst[o]);
752         printf("        %s " LABFMT "\n"ccbranches[o-EQ], lab);
753 }
754
755 static void
756 fixcalls(NODE *pvoid *arg)
757 {
758         /* Prepare for struct return by allocating bounce space on stack */
759         switch (p->n_op) {
760         case STCALL:
761         case USTCALL:
762                 if (p->n_stsize+p2autooff > stkpos)
763                         stkpos = p->n_stsize+p2autooff;
764                 break;
765         }
766 }
767
768 void
769 myreader(struct interpass *ipole)
770 {
771         struct interpass *ip;
772
773         stkpos = p2autooff;
774         DLIST_FOREACH(ipipoleqelem) {
775                 if (ip->type != IP_NODE)
776                         continue;
777                 walkf(ip->ip_nodefixcalls0);
778         }
779         if (stkpos > p2autooff)
780                 p2autooff = stkpos;
781         if (stkpos > p2maxautooff)
782                 p2maxautooff = stkpos;
783         if (x2debug)
784                 printip(ipole);
785 }
786
787 /*
788  * Remove some PCONVs after OREGs are created.
789  */
790 static void
791 pconv2(NODE *pvoid *arg)
792 {
793         NODE *q;
794
795         if (p->n_op == PLUS) {
796                 if (p->n_type == (PTR|SHORT) || p->n_type == (PTR|USHORT)) {
797                         if (p->n_right->n_op != ICON)
798                                 return;
799                         if (p->n_left->n_op != PCONV)
800                                 return;
801                         if (p->n_left->n_left->n_op != OREG)
802                                 return;
803                         q = p->n_left->n_left;
804                         nfree(p->n_left);
805                         p->n_left = q;
806                         /*
807                          * This will be converted to another OREG later.
808                          */
809                 }
810         }
811 }
812
813 void
814 mycanon(NODE *p)
815 {
816         walkf(ppconv20);
817 }
818
819 void
820 myoptim(struct interpass *ip)
821 {
822 }
823
824 void
825 rmove(int sint dTWORD t)
826 {
827
828         switch (t) {
ragge
1.11
829         case INT:
830         case UNSIGNED:
831                 printf("        movl %s,%s\n"rlong[s], rlong[d]);
mickey
1.1
832                 break;
833         case CHAR:
834         case UCHAR:
ragge
1.4
835                 printf("        movb %s,%s\n"rbyte[s], rbyte[d]);
836                 break;
837         case SHORT:
838         case USHORT:
839                 printf("        movw %s,%s\n"rshort[s], rshort[d]);
mickey
1.1
840                 break;
841         case FLOAT:
ragge
1.11
842                 printf("        movss %s,%s\n"rnames[s], rnames[d]);
843                 break;
mickey
1.1
844         case DOUBLE:
ragge
1.11
845                 printf("        movsd %s,%s\n"rnames[s], rnames[d]);
846                 break;
mickey
1.1
847         case LDOUBLE:
848                 /* a=b()*c(); will generate this */
849                 comperr("bad float rmove: %d %d"sd);
850                 break;
851         default:
ragge
1.11
852                 printf("        movq %s,%s\n"rnames[s], rnames[d]);
853                 break;
mickey
1.1
854         }
855 }
856
857 /*
858  * For class c, find worst-case displacement of the number of
859  * registers in the array r[] indexed by class.
860  */
861 int
862 COLORMAP(int cint *r)
863 {
864
865         switch (c) {
866         case CLASSA:
ragge
1.4
867                 return r[CLASSA] < 14;
mickey
1.1
868         case CLASSB:
ragge
1.4
869                 return r[CLASSB] < 16;
mickey
1.1
870         }
871         return 0/* XXX gcc */
872 }
873
874 char *rnames[] = {
ragge
1.4
875         "%rax""%rdx""%rcx""%rbx""%rsi""%rdi""%rbp""%rsp",
876         "%r8""%r9""%r10""%r11""%r12""%r13""%r14""%r15",
877         "%xmm0""%xmm1""%xmm2""%xmm3""%xmm4""%xmm5""%xmm6""%xmm7",
878         "%xmm8""%xmm9""%xmm10""%xmm11""%xmm12""%xmm13""%xmm14",
879         "%xmm15",
880 };
881
882 /* register names for shorter sizes */
883 char *rbyte[] = {
884         "%al""%dl""%cl""%bl""%sil""%dil""%bpl""%spl",
885         "%r8b""%r9b""%r10b""%r11b""%r12b""%r13b""%r14b""%r15b"
886 };
887 char *rshort[] = {
888         "%ax""%dx""%cx""%bx""%si""%di""%bp""%sp",
889         "%r8w""%r9w""%r10w""%r11w""%r12w""%r13w""%r14w""%r15w"
890 };
891 char *rlong[] = {
mickey
1.1
892         "%eax""%edx""%ecx""%ebx""%esi""%edi""%ebp""%esp",
ragge
1.7
893         "%r8d""%r9d""%r10d""%r11d""%r12d""%r13d""%r14d""%r15d"
mickey
1.1
894 };
895
ragge
1.4
896
mickey
1.1
897 /*
898  * Return a class suitable for a specific type.
899  */
900 int
901 gclass(TWORD t)
902 {
ragge
1.4
903         if (t == FLOAT || t == DOUBLE || t == LDOUBLE)
mickey
1.1
904                 return CLASSB;
905         return CLASSA;
906 }
907
908 /*
909  * Calculate argument sizes.
910  */
911 void
912 lastcall(NODE *p)
913 {
914         NODE *op = p;
915         int size = 0;
916
917         p->n_qual = 0;
918         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
919                 return;
920         for (p = p->n_rightp->n_op == CMp = p->n_left)
921                 size += argsiz(p->n_right);
922         size += argsiz(p);
ragge
1.10
923         size = (size+15) & ~15;
924         if (size)
925                 printf("        subq $%d,%s\n"sizernames[RSP]);
mickey
1.1
926         op->n_qual = size/* XXX */
927 }
928
929 /*
930  * Special shapes.
931  */
932 int
933 special(NODE *pint shape)
934 {
935         int o = p->n_op;
936
937         switch (shape) {
938         case SFUNCALL:
939                 if (o == STCALL || o == USTCALL)
940                         return SRREG;
941                 break;
942         case SPCON:
943                 if (o != ICON || p->n_name[0] ||
944                     p->n_lval < 0 || p->n_lval > 0x7fffffff)
945                         break;
946                 return SRDIR;
947         case SMIXOR:
948                 return tshape(pSZERO);
949         case SMILWXOR:
950                 if (o != ICON || p->n_name[0] ||
951                     p->n_lval == 0 || p->n_lval & 0xffffffff)
952                         break;
953                 return SRDIR;
954         case SMIHWXOR:
955                 if (o != ICON || p->n_name[0] ||
956                      p->n_lval == 0 || (p->n_lval >> 32) != 0)
957                         break;
958                 return SRDIR;
ragge
1.12
959         case SCON32:
960                 if (o != ICON || p->n_name[0])
961                         break;
962                 if (p->n_lval < MIN_INT || p->n_lval > MAX_INT)
963                         break;
964                 return SRDIR;
965         default:
966                 cerror("special: %x\n"shape);
mickey
1.1
967         }
968         return SRNOPE;
969 }
970
971 /*
972  * Target-dependent command-line options.
973  */
974 void
975 mflags(char *str)
976 {
977 }
978
979 /*
980  * Do something target-dependent for xasm arguments.
981  */
982 int
983 myxasm(struct interpass *ipNODE *p)
984 {
ragge
1.4
985 cerror("myxasm");
986 #if 0
mickey
1.1
987         struct interpass *ip2;
988         NODE *in = 0, *ut = 0;
989         TWORD t;
990         char *w;
991         int reg;
992         int cw;
993
994         cw = xasmcode(p->n_name);
995         if (cw & (XASMASG|XASMINOUT))
996                 ut = p->n_left;
997         if ((cw & XASMASG) == 0)
998                 in = p->n_left;
999
1000         switch (XASMVAL(cw)) {
1001         case 'D'reg = EDIbreak;
1002         case 'S'reg = ESIbreak;
1003         case 'a'reg = EAXbreak;
1004         case 'b'reg = EBXbreak;
1005         case 'c'reg = ECXbreak;
1006         case 'd'reg = EDXbreak;
1007         case 't'reg = 0break;
1008         case 'u'reg = 1break;
1009         case 'A'reg = EAXEDXbreak;
1010         case 'q'/* XXX let it be CLASSA as for now */
1011                 p->n_name = tmpstrdup(p->n_name);
1012                 w = strchr(p->n_name'q');
1013                 *w = 'r';
1014                 return 0;
1015         default:
1016                 return 0;
1017         }
1018         p->n_name = tmpstrdup(p->n_name);
1019         for (w = p->n_name; *ww++)
1020                 ;
1021         w[-1] = 'r'/* now reg */
1022         t = p->n_left->n_type;
1023         if (reg == EAXEDX) {
1024                 p->n_label = CLASSC;
1025         } else {
1026                 p->n_label = CLASSA;
1027                 if (t == CHAR || t == UCHAR) {
1028                         p->n_label = CLASSB;
1029                         reg = reg * 2 + 8;
1030                 }
1031         }
1032         if (t == FLOAT || t == DOUBLE || t == LDOUBLE) {
1033                 p->n_label = CLASSD;
1034                 reg += 037;
1035         }
1036
1037         if (in && ut)
1038                 in = tcopy(in);
1039         p->n_left = mklnode(REG0regt);
1040         if (ut) {
1041                 ip2 = ipnode(mkbinode(ASSIGNuttcopy(p->n_left), t));
1042                 DLIST_INSERT_AFTER(ipip2qelem);
1043         }
1044         if (in) {
1045                 ip2 = ipnode(mkbinode(ASSIGNtcopy(p->n_left), int));
1046                 DLIST_INSERT_BEFORE(ipip2qelem);
1047         }
ragge
1.4
1048 #endif
mickey
1.1
1049         return 1;
1050 }
1051
1052 void
1053 targarg(char *wvoid *arg)
1054 {
ragge
1.4
1055 cerror("targarg");
1056 #if 0
mickey
1.1
1057         NODE **ary = arg;
1058         NODE *p, *q;
1059
1060         p = ary[(int)w[1]-'0']->n_left;
1061         if (optype(p->n_op) != LTYPE)
1062                 comperr("bad xarg op %d"p->n_op);
1063         q = tcopy(p);
1064         if (q->n_op == REG) {
1065                 if (*w == 'k') {
1066                         q->n_type = INT;
1067                 } else if (*w != 'w') {
1068                         if (q->n_type > UCHAR) {
1069                                 regno(q) = regno(q)*2+8;
1070                                 if (*w == 'h')
1071                                         regno(q)++;
1072                         }
1073                         q->n_type = INT;
1074                 } else
1075                         q->n_type = SHORT;
1076         }
1077         adrput(stdoutq);
1078         tfree(q);
ragge
1.4
1079 #endif
mickey
1.1
1080 }
1081
1082 /*
1083  * target-specific conversion of numeric arguments.
1084  */
1085 int
1086 numconv(void *ipvoid *p1void *q1)
1087 {
1088         NODE *p = p1, *q = q1;
1089         int cw = xasmcode(q->n_name);
1090
1091         switch (XASMVAL(cw)) {
1092         case 'a':
1093         case 'b':
1094         case 'c':
1095         case 'd':
1096                 p->n_name = tmpcalloc(2);
1097                 p->n_name[0] = XASMVAL(cw);
1098                 return 1;
1099         default:
1100                 return 0;
1101         }
1102 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-01 23:09 +0200