Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20090522143935

Diff

Diff from 1.6 to:

Annotations

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

Annotated File View

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