Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20090522121959

Diff

Diff from 1.5 to:

Annotations

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

Annotated File View

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