Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20090708141228

Diff

Diff from 1.15 to:

Annotations

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

Annotated File View

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