Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20100407144549

Diff

Diff from 1.16 to:

Annotations

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

Annotated File View

ragge
1.16
1 /*      $Id: local2.c,v 1.16 2010/04/07 14:45:49 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;
ragge
1.14
380         char **rt;
mickey
1.1
381
382         switch (c) {
ragge
1.4
383 #if 0
mickey
1.1
384         case 'A'/* swap st0 and st1 if right is evaluated second */
385                 if ((p->n_su & DORIGHT) == 0) {
386                         if (logop(p->n_op))
387                                 printf("        fxch\n");
388                         else
389                                 printf("r");
390                 }
391                 break;
ragge
1.5
392 #endif
mickey
1.1
393
394         case 'C':  /* remove from stack after subroutine call */
395                 pr = p->n_qual;
396                 if (p->n_op == UCALL)
397                         return/* XXX remove ZC from UCALL */
398                 if (pr)
ragge
1.10
399                         printf("        addq $%d, %s\n"prrnames[RSP]);
mickey
1.1
400                 break;
401
402         case 'E'/* Perform bitfield sign-extension */
403                 bfext(p);
404                 break;
405
ragge
1.11
406 #if 0
mickey
1.1
407         case 'F'/* Structure argument */
408                 if (p->n_stalign != 0/* already on stack */
409                         starg(p);
410                 break;
ragge
1.7
411 #endif
412         case 'j'/* convert unsigned long to f/d */
413                 ultofd(p);
mickey
1.1
414                 break;
415
416         case 'M'/* Output sconv move, if needed */
417                 l = getlr(p'L');
418                 /* XXX fixneed: regnum */
419                 pr = DECRA(p->n_reg0);
420                 lr = DECRA(l->n_reg0);
ragge
1.6
421                 if (pr == lr)
422                         break;
423                 printf("        movb %s,%s\n"rbyte[lr], rbyte[pr]);
mickey
1.1
424                 l->n_rval = l->n_reg = p->n_reg/* XXX - not pretty */
425                 break;
426
ragge
1.6
427 #if 0
mickey
1.1
428         case 'N'/* output extended reg name */
429                 printf("%s"rnames[getlr(p'1')->n_rval]);
430                 break;
ragge
1.16
431 #endif
432
433         case 'P'/* Put hidden argument in rdi */
434                 printf("\tleaq -%d(%%rbp),%%rdi\n"stkpos);
435                 break;
436
437 #if 0
mickey
1.1
438
439         case 'S'/* emit eventual move after cast from longlong */
440                 pr = DECRA(p->n_reg0);
441                 lr = p->n_left->n_rval;
442                 switch (p->n_type) {
443                 case CHAR:
444                 case UCHAR:
445                         if (rnames[pr][2] == 'l' && rnames[lr][2] == 'x' &&
446                             rnames[pr][1] == rnames[lr][1])
447                                 break;
448                         if (rnames[lr][2] == 'x') {
449                                 printf("\tmovb %%%cl,%s\n",
450                                     rnames[lr][1], rnames[pr]);
451                                 break;
452                         }
453                         /* Must go via stack */
454                         s = BITOOR(freetemp(1));
455                         printf("\tmovl %%e%ci,%d(%%rbp)\n"rnames[lr][1], s);
456                         printf("\tmovb %d(%%rbp),%s\n"srnames[pr]);
457                         comperr("SCONV1 %s->%s"rnames[lr], rnames[pr]);
458                         break;
459
460                 case SHORT:
461                 case USHORT:
462                         if (rnames[lr][1] == rnames[pr][2] &&
463                             rnames[lr][2] == rnames[pr][3])
464                                 break;
465                         printf("\tmovw %%%c%c,%%%s\n",
466                             rnames[lr][1], rnames[lr][2], rnames[pr]+2);
467                         comperr("SCONV2 %s->%s"rnames[lr], rnames[pr]);
468                         break;
469                 case INT:
470                 case UNSIGNED:
471                         if (rnames[lr][1] == rnames[pr][2] &&
472                             rnames[lr][2] == rnames[pr][3])
473                                 break;
474                         printf("\tmovl %%e%c%c,%s\n",
475                                     rnames[lr][1], rnames[lr][2], rnames[pr]);
476                         comperr("SCONV3 %s->%s"rnames[lr], rnames[pr]);
477                         break;
478
479                 default:
480                         if (rnames[lr][1] == rnames[pr][2] &&
481                             rnames[lr][2] == rnames[pr][3])
482                                 break;
483                         comperr("SCONV4 %s->%s"rnames[lr], rnames[pr]);
484                         break;
485                 }
486                 break;
ragge
1.4
487 #endif
ragge
1.10
488         case 'Q'/* emit struct assign */
489                 /* XXX - optimize for small structs */
490                 printf("\tmovq $%d,%%rdx\n"p->n_stsize);
491                 expand(pINAREG"\tmovq AR,%rsi\n");
492                 expand(pINAREG"\tleaq AL,%rdi\n\n");
493                 printf("\tcall memcpy\n");
494                 break;
495
ragge
1.7
496         case 'R'/* print opname based on right type */
497         case 'L'/* print opname based on left type */
498                 switch (getlr(pc)->n_type) {
499                 case CHARcase UCHARs = 'b'break;
500                 case SHORTcase USHORTs = 'w'break;
501                 case INTcase UNSIGNEDs = 'l'break;
502                 defaults = 'q'break;
503                 printf("%c"s);
504                 }
505                 break;
ragge
1.14
506
507         case '8'/* special reg name printout (64-bit) */
508         case '1'/* special reg name printout (32-bit) */
ragge
1.7
509                 l = getlr(p'1');
ragge
1.14
510                 rt = c == '8' ? rnames : rlong;
511                 printf("%s"rt[l->n_rval]);
ragge
1.7
512                 break;
513
514         case 'g':
515                 p = p->n_left;
516                 /* FALLTHROUGH */
517         case 'f'/* float or double */
518                 printf("%c"p->n_type == FLOAT ? 's' : 'd');
519                 break;
520
521         case 'q'/* int or long */
522                 printf("%c"p->n_left->n_type == LONG ? 'q' : ' ');
523                 break;
524
mickey
1.1
525         default:
526                 comperr("zzzcode %c"c);
527         }
528 }
529
530 /*ARGSUSED*/
531 int
532 rewfld(NODE *p)
533 {
534         return(1);
535 }
536
537 int canaddr(NODE *);
538 int
539 canaddr(NODE *p)
540 {
541         int o = p->n_op;
542
543         if (o==NAME || o==REG || o==ICON || o==OREG ||
544             (o==UMUL && shumul(p->n_leftSOREG)))
545                 return(1);
546         return(0);
547 }
548
549 /*
550  * Does the bitfield shape match?
551  */
552 int
553 flshape(NODE *p)
554 {
555         int o = p->n_op;
556
557         if (o == OREG || o == REG || o == NAME)
558                 return SRDIR/* Direct match */
559         if (o == UMUL && shumul(p->n_leftSOREG))
560                 return SROREG/* Convert into oreg */
561         return SRREG/* put it into a register */
562 }
563
564 /* INTEMP shapes must not contain any temporary registers */
565 /* XXX should this go away now? */
566 int
567 shtemp(NODE *p)
568 {
569         return 0;
570 #if 0
571         int r;
572
573         if (p->n_op == STARG )
574                 p = p->n_left;
575
576         switch (p->n_op) {
577         case REG:
578                 return (!istreg(p->n_rval));
579
580         case OREG:
581                 r = p->n_rval;
582                 if (R2TEST(r)) {
583                         if (istreg(R2UPK1(r)))
584                                 return(0);
585                         r = R2UPK2(r);
586                 }
587                 return (!istreg(r));
588
589         case UMUL:
590                 p = p->n_left;
591                 return (p->n_op != UMUL && shtemp(p));
592         }
593
594         if (optype(p->n_op) != LTYPE)
595                 return(0);
596         return(1);
597 #endif
598 }
599
600 void
601 adrcon(CONSZ val)
602 {
603         printf("$" CONFMTval);
604 }
605
606 void
607 conput(FILE *fpNODE *p)
608 {
609         int val = p->n_lval;
610
611         switch (p->n_op) {
612         case ICON:
613                 if (p->n_name[0] != '\0') {
614                         fprintf(fp"%s"p->n_name);
615                         if (val)
616                                 fprintf(fp"+%d"val);
617                 } else
618                         fprintf(fp"%d"val);
619                 return;
620
621         default:
622                 comperr("illegal conput, p %p"p);
623         }
624 }
625
626 /*ARGSUSED*/
627 void
628 insput(NODE *p)
629 {
630         comperr("insput");
631 }
632
633 /*
634  * Write out the upper address, like the upper register of a 2-register
635  * reference, or the next memory location.
636  */
637 void
638 upput(NODE *pint size)
639 {
640
641         size /= SZCHAR;
642         switch (p->n_op) {
643         case REG:
644                 fprintf(stdout"%%%s", &rnames[p->n_rval][3]);
645                 break;
646
647         case NAME:
648         case OREG:
649                 p->n_lval += size;
650                 adrput(stdoutp);
651                 p->n_lval -= size;
652                 break;
653         case ICON:
654                 fprintf(stdout"$" CONFMTp->n_lval >> 32);
655                 break;
656         default:
657                 comperr("upput bad op %d size %d"p->n_opsize);
658         }
659 }
660
661 void
662 adrput(FILE *ioNODE *p)
663 {
664         int r;
ragge
1.5
665         char **rc;
mickey
1.1
666         /* output an address, with offsets, from p */
667
668         if (p->n_op == FLD)
669                 p = p->n_left;
670
671         switch (p->n_op) {
672
673         case NAME:
674                 if (p->n_name[0] != '\0') {
675                         fputs(p->n_nameio);
676                         if (p->n_lval != 0)
677                                 fprintf(io"+" CONFMTp->n_lval);
678                 } else
679                         fprintf(ioCONFMTp->n_lval);
680                 return;
681
682         case OREG:
683                 r = p->n_rval;
684                 if (p->n_name[0])
685                         printf("%s%s"p->n_namep->n_lval ? "+" : "");
686                 if (p->n_lval)
687                         fprintf(io"%d", (int)p->n_lval);
688                 if (R2TEST(r)) {
689                         fprintf(io"(%s,%s,8)"rnames[R2UPK1(r)],
690                             rnames[R2UPK2(r)]);
691                 } else
692                         fprintf(io"(%s)"rnames[p->n_rval]);
693                 return;
694         case ICON:
695 #ifdef PCC_DEBUG
696                 /* Sanitycheck for PIC, to catch adressable constants */
697                 if (kflag && p->n_name[0]) {
698                         static int foo;
699
700                         if (foo++ == 0) {
701                                 printf("\nfailing...\n");
702                                 fwalk(pe2print0);
703                                 comperr("pass2 conput");
704                         }
705                 }
706 #endif
707                 /* addressable value of the constant */
708                 fputc('$'io);
709                 conput(iop);
710                 return;
711
712         case REG:
713                 switch (p->n_type) {
ragge
1.5
714                 case CHAR:
715                 case UCHAR:
716                         rc = rbyte;
mickey
1.1
717                         break;
718                 case SHORT:
719                 case USHORT:
ragge
1.5
720                         rc = rshort;
721                         break;
722                 case INT:
723                 case UNSIGNED:
724                         rc = rlong;
mickey
1.1
725                         break;
726                 default:
ragge
1.5
727                         rc = rnames;
728                         break;
mickey
1.1
729                 }
ragge
1.5
730                 fprintf(io"%s"rc[p->n_rval]);
mickey
1.1
731                 return;
732
733         default:
734                 comperr("illegal address, op %d, node %p"p->n_opp);
735                 return;
736
737         }
738 }
739
740 static char *
741 ccbranches[] = {
742         "je",           /* jumpe */
743         "jne",          /* jumpn */
744         "jle",          /* jumple */
745         "jl",           /* jumpl */
746         "jge",          /* jumpge */
747         "jg",           /* jumpg */
748         "jbe",          /* jumple (jlequ) */
749         "jb",           /* jumpl (jlssu) */
750         "jae",          /* jumpge (jgequ) */
751         "ja",           /* jumpg (jgtru) */
752 };
753
754
755 /*   printf conditional and unconditional branches */
756 void
757 cbgen(int oint lab)
758 {
759         if (o < EQ || o > UGT)
760                 comperr("bad conditional branch: %s"opst[o]);
761         printf("        %s " LABFMT "\n"ccbranches[o-EQ], lab);
762 }
763
764 static void
765 fixcalls(NODE *pvoid *arg)
766 {
767         /* Prepare for struct return by allocating bounce space on stack */
768         switch (p->n_op) {
769         case STCALL:
770         case USTCALL:
771                 if (p->n_stsize+p2autooff > stkpos)
772                         stkpos = p->n_stsize+p2autooff;
773                 break;
774         }
775 }
776
777 void
778 myreader(struct interpass *ipole)
779 {
780         struct interpass *ip;
781
782         stkpos = p2autooff;
783         DLIST_FOREACH(ipipoleqelem) {
784                 if (ip->type != IP_NODE)
785                         continue;
786                 walkf(ip->ip_nodefixcalls0);
787         }
788         if (stkpos > p2autooff)
789                 p2autooff = stkpos;
790         if (stkpos > p2maxautooff)
791                 p2maxautooff = stkpos;
792         if (x2debug)
793                 printip(ipole);
794 }
795
796 /*
797  * Remove some PCONVs after OREGs are created.
798  */
799 static void
800 pconv2(NODE *pvoid *arg)
801 {
802         NODE *q;
803
804         if (p->n_op == PLUS) {
805                 if (p->n_type == (PTR|SHORT) || p->n_type == (PTR|USHORT)) {
806                         if (p->n_right->n_op != ICON)
807                                 return;
808                         if (p->n_left->n_op != PCONV)
809                                 return;
810                         if (p->n_left->n_left->n_op != OREG)
811                                 return;
812                         q = p->n_left->n_left;
813                         nfree(p->n_left);
814                         p->n_left = q;
815                         /*
816                          * This will be converted to another OREG later.
817                          */
818                 }
819         }
820 }
821
822 void
823 mycanon(NODE *p)
824 {
825         walkf(ppconv20);
826 }
827
828 void
829 myoptim(struct interpass *ip)
830 {
831 }
832
833 void
834 rmove(int sint dTWORD t)
835 {
836
837         switch (t) {
ragge
1.11
838         case INT:
839         case UNSIGNED:
840                 printf("        movl %s,%s\n"rlong[s], rlong[d]);
mickey
1.1
841                 break;
842         case CHAR:
843         case UCHAR:
ragge
1.4
844                 printf("        movb %s,%s\n"rbyte[s], rbyte[d]);
845                 break;
846         case SHORT:
847         case USHORT:
848                 printf("        movw %s,%s\n"rshort[s], rshort[d]);
mickey
1.1
849                 break;
850         case FLOAT:
ragge
1.11
851                 printf("        movss %s,%s\n"rnames[s], rnames[d]);
852                 break;
mickey
1.1
853         case DOUBLE:
ragge
1.11
854                 printf("        movsd %s,%s\n"rnames[s], rnames[d]);
855                 break;
mickey
1.1
856         case LDOUBLE:
857                 /* a=b()*c(); will generate this */
858                 comperr("bad float rmove: %d %d"sd);
859                 break;
860         default:
ragge
1.11
861                 printf("        movq %s,%s\n"rnames[s], rnames[d]);
862                 break;
mickey
1.1
863         }
864 }
865
866 /*
867  * For class c, find worst-case displacement of the number of
868  * registers in the array r[] indexed by class.
869  */
870 int
871 COLORMAP(int cint *r)
872 {
873
874         switch (c) {
875         case CLASSA:
ragge
1.4
876                 return r[CLASSA] < 14;
mickey
1.1
877         case CLASSB:
ragge
1.4
878                 return r[CLASSB] < 16;
mickey
1.1
879         }
880         return 0/* XXX gcc */
881 }
882
883 char *rnames[] = {
ragge
1.4
884         "%rax""%rdx""%rcx""%rbx""%rsi""%rdi""%rbp""%rsp",
885         "%r8""%r9""%r10""%r11""%r12""%r13""%r14""%r15",
886         "%xmm0""%xmm1""%xmm2""%xmm3""%xmm4""%xmm5""%xmm6""%xmm7",
887         "%xmm8""%xmm9""%xmm10""%xmm11""%xmm12""%xmm13""%xmm14",
888         "%xmm15",
889 };
890
891 /* register names for shorter sizes */
892 char *rbyte[] = {
893         "%al""%dl""%cl""%bl""%sil""%dil""%bpl""%spl",
894         "%r8b""%r9b""%r10b""%r11b""%r12b""%r13b""%r14b""%r15b"
895 };
896 char *rshort[] = {
897         "%ax""%dx""%cx""%bx""%si""%di""%bp""%sp",
898         "%r8w""%r9w""%r10w""%r11w""%r12w""%r13w""%r14w""%r15w"
899 };
900 char *rlong[] = {
mickey
1.1
901         "%eax""%edx""%ecx""%ebx""%esi""%edi""%ebp""%esp",
ragge
1.7
902         "%r8d""%r9d""%r10d""%r11d""%r12d""%r13d""%r14d""%r15d"
mickey
1.1
903 };
904
ragge
1.4
905
mickey
1.1
906 /*
907  * Return a class suitable for a specific type.
908  */
909 int
910 gclass(TWORD t)
911 {
ragge
1.4
912         if (t == FLOAT || t == DOUBLE || t == LDOUBLE)
mickey
1.1
913                 return CLASSB;
914         return CLASSA;
915 }
916
917 /*
918  * Calculate argument sizes.
919  */
920 void
921 lastcall(NODE *p)
922 {
923         NODE *op = p;
924         int size = 0;
925
926         p->n_qual = 0;
927         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
928                 return;
929         for (p = p->n_rightp->n_op == CMp = p->n_left)
930                 size += argsiz(p->n_right);
931         size += argsiz(p);
ragge
1.10
932         size = (size+15) & ~15;
933         if (size)
934                 printf("        subq $%d,%s\n"sizernames[RSP]);
mickey
1.1
935         op->n_qual = size/* XXX */
936 }
937
938 /*
939  * Special shapes.
940  */
941 int
942 special(NODE *pint shape)
943 {
944         int o = p->n_op;
945
946         switch (shape) {
947         case SFUNCALL:
948                 if (o == STCALL || o == USTCALL)
949                         return SRREG;
950                 break;
951         case SPCON:
952                 if (o != ICON || p->n_name[0] ||
953                     p->n_lval < 0 || p->n_lval > 0x7fffffff)
954                         break;
955                 return SRDIR;
956         case SMIXOR:
957                 return tshape(pSZERO);
958         case SMILWXOR:
959                 if (o != ICON || p->n_name[0] ||
960                     p->n_lval == 0 || p->n_lval & 0xffffffff)
961                         break;
962                 return SRDIR;
963         case SMIHWXOR:
964                 if (o != ICON || p->n_name[0] ||
965                      p->n_lval == 0 || (p->n_lval >> 32) != 0)
966                         break;
967                 return SRDIR;
ragge
1.12
968         case SCON32:
969                 if (o != ICON || p->n_name[0])
970                         break;
971                 if (p->n_lval < MIN_INT || p->n_lval > MAX_INT)
972                         break;
973                 return SRDIR;
974         default:
975                 cerror("special: %x\n"shape);
mickey
1.1
976         }
977         return SRNOPE;
978 }
979
980 /*
981  * Target-dependent command-line options.
982  */
983 void
984 mflags(char *str)
985 {
986 }
987
988 /*
989  * Do something target-dependent for xasm arguments.
990  */
991 int
992 myxasm(struct interpass *ipNODE *p)
993 {
ragge
1.15
994         return 0;
ragge
1.4
995 #if 0
mickey
1.1
996         struct interpass *ip2;
997         NODE *in = 0, *ut = 0;
998         TWORD t;
999         char *w;
1000         int reg;
1001         int cw;
1002
1003         cw = xasmcode(p->n_name);
1004         if (cw & (XASMASG|XASMINOUT))
1005                 ut = p->n_left;
1006         if ((cw & XASMASG) == 0)
1007                 in = p->n_left;
1008
1009         switch (XASMVAL(cw)) {
1010         case 'D'reg = EDIbreak;
1011         case 'S'reg = ESIbreak;
1012         case 'a'reg = EAXbreak;
1013         case 'b'reg = EBXbreak;
1014         case 'c'reg = ECXbreak;
1015         case 'd'reg = EDXbreak;
1016         case 't'reg = 0break;
1017         case 'u'reg = 1break;
1018         case 'A'reg = EAXEDXbreak;
1019         case 'q'/* XXX let it be CLASSA as for now */
1020                 p->n_name = tmpstrdup(p->n_name);
1021                 w = strchr(p->n_name'q');
1022                 *w = 'r';
1023                 return 0;
1024         default:
1025                 return 0;
1026         }
1027         p->n_name = tmpstrdup(p->n_name);
1028         for (w = p->n_name; *ww++)
1029                 ;
1030         w[-1] = 'r'/* now reg */
1031         t = p->n_left->n_type;
1032         if (reg == EAXEDX) {
1033                 p->n_label = CLASSC;
1034         } else {
1035                 p->n_label = CLASSA;
1036                 if (t == CHAR || t == UCHAR) {
1037                         p->n_label = CLASSB;
1038                         reg = reg * 2 + 8;
1039                 }
1040         }
1041         if (t == FLOAT || t == DOUBLE || t == LDOUBLE) {
1042                 p->n_label = CLASSD;
1043                 reg += 037;
1044         }
1045
1046         if (in && ut)
1047                 in = tcopy(in);
1048         p->n_left = mklnode(REG0regt);
1049         if (ut) {
1050                 ip2 = ipnode(mkbinode(ASSIGNuttcopy(p->n_left), t));
1051                 DLIST_INSERT_AFTER(ipip2qelem);
1052         }
1053         if (in) {
1054                 ip2 = ipnode(mkbinode(ASSIGNtcopy(p->n_left), int));
1055                 DLIST_INSERT_BEFORE(ipip2qelem);
1056         }
ragge
1.4
1057 #endif
mickey
1.1
1058         return 1;
1059 }
1060
1061 void
1062 targarg(char *wvoid *arg)
1063 {
ragge
1.4
1064 cerror("targarg");
1065 #if 0
mickey
1.1
1066         NODE **ary = arg;
1067         NODE *p, *q;
1068
1069         p = ary[(int)w[1]-'0']->n_left;
1070         if (optype(p->n_op) != LTYPE)
1071                 comperr("bad xarg op %d"p->n_op);
1072         q = tcopy(p);
1073         if (q->n_op == REG) {
1074                 if (*w == 'k') {
1075                         q->n_type = INT;
1076                 } else if (*w != 'w') {
1077                         if (q->n_type > UCHAR) {
1078                                 regno(q) = regno(q)*2+8;
1079                                 if (*w == 'h')
1080                                         regno(q)++;
1081                         }
1082                         q->n_type = INT;
1083                 } else
1084                         q->n_type = SHORT;
1085         }
1086         adrput(stdoutq);
1087         tfree(q);
ragge
1.4
1088 #endif
mickey
1.1
1089 }
1090
1091 /*
1092  * target-specific conversion of numeric arguments.
1093  */
1094 int
1095 numconv(void *ipvoid *p1void *q1)
1096 {
1097         NODE *p = p1, *q = q1;
1098         int cw = xasmcode(q->n_name);
1099
1100         switch (XASMVAL(cw)) {
1101         case 'a':
1102         case 'b':
1103         case 'c':
1104         case 'd':
1105                 p->n_name = tmpcalloc(2);
1106                 p->n_name[0] = XASMVAL(cw);
1107                 return 1;
1108         default:
1109                 return 0;
1110         }
1111 }
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-19 17:51 +0200