Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:stefan:20071222101855

Diff

Diff from 1.6 to:

Annotations

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

Annotated File View

stefan
1.6
1 /*      $Id: local2.c,v 1.6 2007/12/22 10:18:56 stefan Exp $    */
ragge
1.1
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
ragge
1.2
36 # include "pass2.h"
ragge
1.1
37 # include "ctype.h"
38 /* a lot of the machine dependent parts of the second pass */
39
ragge
1.2
40 static void prtype(NODE *n);
41 static void acon(NODE *p);
42
43 /*
44  * Print out the prolog assembler.
45  * addto and regoff are already calculated.
46  */
47 void
48 prologue(struct interpass_prolog *ipp)
49 {
50         if (ipp->ipp_vis)
51                 printf("        .globl %s\n"ipp->ipp_name);
52         printf("        .align 4\n");
53         printf("%s:\n"ipp->ipp_name);
54         printf("        .word 0x%x\n"ipp->ipp_regs);
55         if (p2maxautooff)
56                 printf("        subl2 $%d,%%sp\n"p2maxautooff);
57 }
ragge
1.1
58
ragge
1.2
59 /*
60  * Called after all instructions in a function are emitted.
61  * Generates code for epilog here.
62  */
63 void
64 eoftn(struct interpass_prolog *ipp)
65 {
66         if (ipp->ipp_ip.ip_lbl == 0)
67                 return/* no code needs to be generated */
68         printf("        ret\n");
69 }
ragge
1.1
70
71 struct hoptab { int opmaskchar * opstring; } ioptab[] = {
72
ragge
1.2
73         { PLUS"add", },
74         { MINUS,        "sub", },
75         { MUL,  "mul", },
76         { DIV,  "div", },
77         { OR,   "bis", },
78         { ER,   "xor", },
79         { AND,  "bic", },
80         { -1""     },
81 };
ragge
1.1
82
ragge
1.2
83 void
ragge
1.1
84 hopcodefo ){
85         /* output the appropriate string from the above table */
86
87         register struct hoptab *q;
88
89         forq = ioptab;  q->opmask>=0; ++q ){
90                 ifq->opmask == o ){
91                         printf"%s"q->opstring );
92 /* tbl
93                         if( f == 'F' ) printf( "e" );
94                         else if( f == 'D' ) printf( "d" );
95    tbl */
96 /* tbl */
97                         switchf ) {
98                                 case 'L':
99                                 case 'W':
100                                 case 'B':
101                                 case 'D':
102                                 case 'F':
103                                         printf("%c"tolower(f));
104                                         break;
105
106                                 }
107 /* tbl */
108                         return;
109                         }
110                 }
111         cerror"no hoptab for %s"opst[o] );
112         }
113
114 char *
115 rnames[] = {  /* keyed to register number tokens */
116
ragge
1.2
117         "r0""r1""r2""r3""r4""r5",
ragge
1.1
118         "r6""r7""r8""r9""r10""r11",
119         "ap""fp""sp""pc",
ragge
1.2
120         /* The concatenated regs has the name of the lowest */
121         "r0""r1""r2""r3""r4""r5",
122         "r6""r7""r8""r9""r10"
ragge
1.1
123         };
124
ragge
1.2
125 int
ragge
1.1
126 tlen(pNODE *p;
127 {
ragge
1.2
128         switch(p->n_type) {
ragge
1.1
129                 case CHAR:
130                 case UCHAR:
131                         return(1);
132
133                 case SHORT:
134                 case USHORT:
135                         return(2);
136
137                 case DOUBLE:
ragge
1.2
138                 case LDOUBLE:
139                 case LONGLONG:
140                 case ULONGLONG:
ragge
1.1
141                         return(8);
142
143                 default:
144                         return(4);
145                 }
146 }
147
ragge
1.2
148 static int
149 mixtypes(NODE *pNODE *q)
ragge
1.1
150 {
ragge
1.2
151         TWORD tptq;
ragge
1.1
152
ragge
1.2
153         tp = p->n_type;
154         tq = q->n_type;
ragge
1.1
155
156         return( (tp==FLOAT || tp==DOUBLE) !=
157                 (tq==FLOAT || tq==DOUBLE) );
158 }
159
ragge
1.2
160 void
161 prtype(NODE *n)
ragge
1.1
162 {
ragge
1.2
163         switch (n->n_type)
ragge
1.1
164                 {
165                 case DOUBLE:
166                         printf("d");
167                         return;
168
169                 case FLOAT:
170                         printf("f");
171                         return;
172
173                 case LONG:
174                 case ULONG:
175                 case INT:
176                 case UNSIGNED:
177                         printf("l");
178                         return;
179
180                 case SHORT:
181                 case USHORT:
182                         printf("w");
183                         return;
184
185                 case CHAR:
186                 case UCHAR:
187                         printf("b");
188                         return;
189
190                 default:
ragge
1.2
191                         if ( !ISPTRn->n_type ) ) cerror("zzzcode- bad type");
ragge
1.1
192                         else {
193                                 printf("l");
194                                 return;
195                                 }
196                 }
197 }
198
ragge
1.2
199 void
ragge
1.1
200 zzzcodepc ) register NODE *p; {
ragge
1.2
201         int m;
202         int val;
ragge
1.1
203         switchc ){
204
205         case 'N':  /* logical ops, turned into 0-1 */
206                 /* use register given by register 1 */
ragge
1.2
207                 cbgen0m=getlab());
208                 deflabp->n_label );
209                 printf"       clrl    %s\n"rnames[getlrp'1' )->n_rval] );
ragge
1.1
210                 deflabm );
211                 return;
212
213         case 'A':
214                 {
215                 register NODE *l, *r;
216
ragge
1.2
217                 if (xdebuge2print(p0, &val, &val);
ragge
1.1
218                 r = getlr(p'R');
ragge
1.2
219                 if (optype(p->n_op) == LTYPE || p->n_op == UMUL) {
ragge
1.1
220                         l = resc;
ragge
1.2
221                         l->n_type = (r->n_type==FLOAT || r->n_type==DOUBLE ? DOUBLE : INT);
222                 } else
ragge
1.1
223                         l = getlr(p'L');
ragge
1.2
224                 if (r->n_op == ICON  && r->n_name[0] == '\0') {
225                         if (r->n_lval == 0) {
ragge
1.1
226                                 printf("clr");
227                                 prtype(l);
228                                 printf("        ");
ragge
1.2
229                                 adrput(stdoutl);
ragge
1.1
230                                 return;
ragge
1.2
231                         }
232                         if (r->n_lval < 0 && r->n_lval >= -63) {
ragge
1.1
233                                 printf("mneg");
234                                 prtype(l);
ragge
1.2
235                                 r->n_lval = -r->n_lval;
ragge
1.1
236                                 goto ops;
237                         }
ragge
1.2
238                         r->n_type = (r->n_lval < 0 ?
239                                         (r->n_lval >= -128 ? CHAR
240                                         : (r->n_lval >= -32768 ? SHORT
241                                         : INT )) : r->n_type);
242                         r->n_type = (r->n_lval >= 0 ?
243                                         (r->n_lval <= 63 ? INT
244                                         : ( r->n_lval <= 127 ? CHAR
245                                         : (r->n_lval <= 255 ? UCHAR
246                                         : (r->n_lval <= 32767 ? SHORT
247                                         : (r->n_lval <= 65535 ? USHORT
248                                         : INT ))))) : r->n_type );
249                         }
250                 if (l->n_op == REG && l->n_type != FLOAT && l->n_type != DOUBLE)
251                         l->n_type = INT;
ragge
1.1
252                 if (!mixtypes(l,r))
253                         {
254                         if (tlen(l) == tlen(r))
255                                 {
256                                 printf("mov");
257                                 prtype(l);
258                                 goto ops;
259                                 }
ragge
1.2
260                         else if (tlen(l) > tlen(r) && ISUNSIGNED(r->n_type))
ragge
1.1
261                                 {
262                                 printf("movz");
263                                 }
264                         else
265                                 {
266                                 printf("cvt");
267                                 }
268                         }
269                 else
270                         {
271                         printf("cvt");
272                         }
273                 prtype(r);
274                 prtype(l);
275         ops:
276                 printf("        ");
ragge
1.2
277                 adrput(stdoutr);
ragge
1.1
278                 printf(",");
ragge
1.2
279                 adrput(stdoutl);
ragge
1.1
280                 return;
281                 }
282
283         case 'C':       /* num words pushed on arg stack */
ragge
1.3
284                 if (p->n_op == STCALL || p->n_op == USTCALL)
285                         p->n_qual++;
286                 printf("$%d"p->n_qual);
287                 break;
ragge
1.1
288
289         case 'D':       /* INCR and DECR */
ragge
1.2
290                 zzzcode(p->n_left'A');
ragge
1.1
291                 printf("\n      ");
292
ragge
1.2
293 #if 0
ragge
1.1
294         case 'E':       /* INCR and DECR, FOREFF */
ragge
1.2
295                 if (p->n_right->n_lval == 1)
ragge
1.1
296                         {
ragge
1.2
297                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
298                         prtype(p->n_left);
ragge
1.1
299                         printf("        ");
ragge
1.2
300                         adrput(stdoutp->n_left);
ragge
1.1
301                         return;
302                         }
ragge
1.2
303                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
304                 prtype(p->n_left);
ragge
1.1
305                 printf("2       ");
ragge
1.2
306                 adrput(stdoutp->n_right);
ragge
1.1
307                 printf(",");
ragge
1.2
308                 adrput(p->n_left);
ragge
1.1
309                 return;
ragge
1.2
310 #endif
ragge
1.1
311
312         case 'F':       /* register type of right operand */
313                 {
314                 register NODE *n;
315                 extern int xdebug;
316                 register int ty;
317
318                 n = getlrp'R' );
ragge
1.2
319                 ty = n->n_type;
ragge
1.1
320
321                 if (xdebugprintf("->%d<-"ty);
322
323                 if ( ty==DOUBLEprintf("d");
324                 else if ( ty==FLOAT ) printf("f");
325                 else printf("l");
326                 return;
327                 }
328
ragge
1.3
329         case 'J'/* jump or ret? */
330                 {
331                         extern struct interpass_prolog *epp;
332                         struct interpass *ip =
333                             DLIST_PREV((struct interpass *)eppqelem);
334                         if (ip->type != IP_DEFLAB ||
335                             ip->ip_lbl != getlr(p'L')->n_lval)
336                                 expand(pFOREFF"jbr  LL");
337                         else
338                                 printf("ret");
339                 }
340                 break;
341
ragge
1.1
342         case 'L':       /* type of left operand */
343         case 'R':       /* type of right operand */
344                 {
345                 register NODE *n;
346                 extern int xdebug;
347
348                 n = getlr ( pc);
ragge
1.2
349                 if (xdebugprintf("->%d<-"n->n_type);
ragge
1.1
350
351                 prtype(n);
352                 return;
353                 }
354
355         case 'Z':       /* complement mask for bit instr */
ragge
1.2
356                 printf("$%Ld", ~p->n_right->n_lval);
ragge
1.1
357                 return;
358
359         case 'U':       /* 32 - n, for unsigned right shifts */
ragge
1.2
360                 printf("$" CONFMT32 - p->n_right->n_lval );
ragge
1.1
361                 return;
362
363         case 'T':       /* rounded structure length for arguments */
364                 {
365                 int size;
366
ragge
1.2
367                 size = p->n_stsize;
ragge
1.1
368                 SETOFFsize4);
369                 printf("$%d"size);
370                 return;
371                 }
372
373         case 'S':  /* structure assignment */
374                 {
375                         register NODE *l, *r;
ragge
1.2
376                         register int size;
ragge
1.1
377
ragge
1.2
378                         l = r = NULL/* XXX gcc */
379                         ifp->n_op == STASG ){
380                                 l = p->n_left;
381                                 r = p->n_right;
ragge
1.1
382
383                                 }
ragge
1.2
384                         else ifp->n_op == STARG ){  /* store an arg into a temporary */
ragge
1.1
385                                 l = getlrp'3' );
ragge
1.2
386                                 r = p->n_left;
ragge
1.1
387                                 }
388                         else cerror"STASG bad" );
389
ragge
1.2
390                         ifr->n_op == ICON ) r->n_op = NAME;
391                         else ifr->n_op == REG ) r->n_op = OREG;
392                         else ifr->n_op != OREG ) cerror"STASG-r" );
ragge
1.1
393
ragge
1.2
394                         size = p->n_stsize;
ragge
1.1
395
396                         ifsize <= 0 || size > 65535 )
397                                 cerror("structure size <0=0 or >65535");
398
399                         switch(size) {
400                                 case 1:
401                                         printf("        movb    ");
402                                         break;
403                                 case 2:
404                                         printf("        movw    ");
405                                         break;
406                                 case 4:
407                                         printf("        movl    ");
408                                         break;
409                                 case 8:
410                                         printf("        movq    ");
411                                         break;
412                                 default:
413                                         printf("        movc3   $%d,"size);
414                                         break;
415                         }
ragge
1.2
416                         adrput(stdoutr);
ragge
1.1
417                         printf(",");
ragge
1.2
418                         adrput(stdoutl);
ragge
1.1
419                         printf("\n");
420
ragge
1.2
421                         ifr->n_op == NAME ) r->n_op = ICON;
422                         else ifr->n_op == OREG ) r->n_op = REG;
ragge
1.1
423
424                         }
425                 break;
426
427         default:
ragge
1.2
428                 comperr("illegal zzzcode '%c'"c);
ragge
1.1
429                 }
430         }
431
ragge
1.2
432 void
433 rmoveint rt,int  rsTWORD t ){
ragge
1.1
434         printf"       %s      %s,%s\n",
435                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
436                 rnames[rs], rnames[rt] );
437         }
438
ragge
1.2
439 #if 0
ragge
1.1
440 setregs(){ /* set up temporary registers */
441         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
442         ;
443         }
444
445 szty(t){ /* size, in registers, needed to hold thing of type t */
446         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
447         }
ragge
1.2
448 #endif
ragge
1.1
449
ragge
1.2
450 int
ragge
1.1
451 rewfldp ) NODE *p; {
452         return(1);
453         }
454
ragge
1.2
455 #if 0
ragge
1.1
456 callreg(pNODE *p; {
457         returnR0 );
458         }
459
460 basep ) register NODE *p; {
461         register int o = p->op;
462
463         if( (o==ICON && p->name[0] != '\0')) return100 ); /* ie no base reg */
464         ifo==REG ) returnp->rval );
465     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
466                 returnp->left->rval );
467     ifo==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
468                 returnp->rval + 0200*1 );
469         ifo==INCR && p->left->op==REG ) returnp->left->rval + 0200*2 );
470         ifo==ASG MINUS && p->left->op==REGreturnp->left->rval + 0200*4 );
471         ifo==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
472           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
473                 returnp->left->left->rval + 0200*(1+2) );
474         return( -1 );
475         }
476
477 offsetptyl ) register NODE *pint tyl; {
478
479         iftyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) returnp->rval );
480         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
481               (p->right->op==ICON && p->right->name[0]=='\0')
482               && (1<<p->right->lval)==tyl))
483                 returnp->left->rval );
484         return( -1 );
485         }
ragge
1.2
486 #endif
ragge
1.1
487
ragge
1.2
488 #if 0
489 void
ragge
1.1
490 makeor2pqboregister NODE *p, *qregister int bo; {
491         register NODE *t;
492         NODE *f;
493
ragge
1.2
494         p->n_op = OREG;
495         f = p->n_left;  /* have to free this subtree later */
ragge
1.1
496
497         /* init base */
ragge
1.2
498         switch (q->n_op) {
ragge
1.1
499                 case ICON:
500                 case REG:
501                 case OREG:
502                         t = q;
503                         break;
504
505                 case MINUS:
ragge
1.2
506                         q->n_right->n_lval = -q->n_right->n_lval;
ragge
1.1
507                 case PLUS:
ragge
1.2
508                         t = q->n_right;
ragge
1.1
509                         break;
510
ragge
1.2
511                 case UMUL:
512                         t = q->n_left->n_left;
ragge
1.1
513                         break;
514
515                 default:
516                         cerror("illegal makeor2");
ragge
1.2
517                         t = NULL/* XXX gcc */
ragge
1.1
518         }
519
ragge
1.2
520         p->n_lval = t->n_lval;
521         p->n_name = t->n_name;
ragge
1.1
522
523         /* init offset */
ragge
1.2
524         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
ragge
1.1
525
526         tfree(f);
527         return;
528         }
529
ragge
1.2
530 int
ragge
1.1
531 canaddrp ) NODE *p; {
ragge
1.2
532         register int o = p->n_op;
ragge
1.1
533
ragge
1.2
534         ifo==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left)) ) return(1);
ragge
1.1
535         return(0);
536         }
537
538 shltypeop ) register NODE *p; {
ragge
1.2
539         returno== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left)) );
ragge
1.1
540         }
ragge
1.2
541 #endif
ragge
1.1
542
ragge
1.2
543 int
stefan
1.6
544 fldexpand(NODE *pint cookiechar **cp)
545 {
546         return 0;
547 }
548
549 int
ragge
1.1
550 flshapep ) register NODE *p; {
ragge
1.2
551         returnp->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
552                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
ragge
1.1
553         }
554
ragge
1.2
555 int
ragge
1.1
556 shtempp ) register NODE *p; {
ragge
1.2
557         ifp->n_op == STARG ) p = p->n_left;
558         returnp->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left)) );
ragge
1.1
559         }
560
ragge
1.2
561 int
ragge
1.1
562 shumulp ) register NODE *p; {
ragge
1.2
563         register int o;
ragge
1.1
564         extern int xdebug;
565
566         if (xdebug) {
ragge
1.2
567                  printf("\nshumul:op=%d,lop=%d,rop=%d"p->n_opp->n_left->n_opp->n_right->n_op);
568                 printf(" prname=%s,plty=%d, prlval=%lld\n"p->n_right->n_namep->n_left->n_typep->n_right->n_lval);
ragge
1.1
569                 }
570
571
ragge
1.2
572         o = p->n_op;
573         ifo == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON ) returnSTARNM );
ragge
1.1
574
ragge
1.2
575 #ifdef notyet
ragge
1.1
576         if( ( o == INCR || o == ASG MINUS ) &&
ragge
1.2
577             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
578             p->n_right->n_name[0] == '\0' )
ragge
1.1
579                 {
ragge
1.2
580                 switch (p->n_left->n_type)
ragge
1.1
581                         {
582                         case CHAR|PTR:
583                         case UCHAR|PTR:
584                                 o = 1;
585                                 break;
586
587                         case SHORT|PTR:
588                         case USHORT|PTR:
589                                 o = 2;
590                                 break;
591
592                         case INT|PTR:
593                         case UNSIGNED|PTR:
594                         case LONG|PTR:
595                         case ULONG|PTR:
596                         case FLOAT|PTR:
597                                 o = 4;
598                                 break;
599
600                         case DOUBLE|PTR:
601                                 o = 8;
602                                 break;
603
604                         default:
ragge
1.2
605                                 if ( ISPTR(p->n_left->n_type) ) {
ragge
1.1
606                                         o = 4;
607                                         break;
608                                         }
609                                 else return(0);
610                         }
ragge
1.2
611                 returnp->n_right->n_lval == o ? STARREG : 0);
ragge
1.1
612                 }
ragge
1.2
613 #endif
ragge
1.1
614
615         return0 );
616         }
617
ragge
1.2
618 void
ragge
1.1
619 adrconval ) CONSZ val; {
620         printf"$" );
621         printfCONFMTval );
622         }
623
ragge
1.2
624 void
625 conput(FILE *fpNODE *p)
626 {
627         switchp->n_op ){
ragge
1.1
628
629         case ICON:
630                 aconp );
631                 return;
632
633         case REG:
ragge
1.2
634                 printf"%s"rnames[p->n_rval] );
ragge
1.1
635                 return;
636
637         default:
638                 cerror"illegal conput" );
639                 }
640         }
641
ragge
1.2
642 void
ragge
1.1
643 insputp ) register NODE *p; {
644         cerror"insput" );
645         }
646
ragge
1.2
647 void
648 upputp , sizeregister NODE *p; {
ragge
1.1
649         cerror"upput" );
650         }
651
ragge
1.2
652 void
653 adrput(FILE *fpNODE *p)
654 {
ragge
1.1
655         register int r;
656         /* output an address, with offsets, from p */
657
ragge
1.2
658         ifp->n_op == FLD ){
659                 p = p->n_left;
ragge
1.1
660                 }
ragge
1.2
661         switchp->n_op ){
ragge
1.1
662
663         case NAME:
664                 aconp );
665                 return;
666
667         case ICON:
668                 /* addressable value of the constant */
ragge
1.2
669                 if (p->n_name[0] == '\0'/* uses xxxab */
670                         printf("$");
671                 acon(p);
ragge
1.1
672                 return;
673
674         case REG:
ragge
1.2
675                 printf"%s"rnames[p->n_rval] );
ragge
1.1
676                 return;
677
678         case OREG:
ragge
1.2
679                 r = p->n_rval;
ragge
1.1
680                 ifR2TEST(r) ){ /* double indexing */
681                         register int flags;
682
683                         flags = R2UPK3(r);
684                         ifflags & 1 ) printf("*");
685                         ifflags & 4 ) printf("-");
ragge
1.2
686                         ifp->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
ragge
1.1
687                         ifR2UPK1(r) != 100printf"(%s)"rnames[R2UPK1(r)] );
688                         ifflags & 2 ) printf("+");
689                         printf"[%s]"rnames[R2UPK2(r)] );
690                         return;
691                         }
692                 ifr == AP ){  /* in the argument region */
ragge
1.2
693                         ifp->n_lval <= 0 || p->n_name[0] != '\0' ) werror"bad arg temp" );
694                         printfCONFMTp->n_lval );
ragge
1.1
695                         printf"(ap)" );
696                         return;
697                         }
ragge
1.2
698                 ifp->n_lval != 0 || p->n_name[0] != '\0'aconp );
699                 printf"(%s)"rnames[p->n_rval] );
ragge
1.1
700                 return;
701
ragge
1.2
702         case UMUL:
ragge
1.1
703                 /* STARNM or STARREG found */
704                 iftshape(pSTARNM) ) {
705                         printf"*" );
ragge
1.2
706                         adrput(0,  p->n_left);
ragge
1.1
707                         }
708                 else {  /* STARREG - really auto inc or dec */
709                         register NODE *q;
710
711 /* tbl
ragge
1.2
712                         p = p->n_left;
713                         p->n_left->n_op = OREG;
714                         if( p->n_op == INCR ) {
715                                 adrput( p->n_left );
ragge
1.1
716                                 printf( "+" );
717                                 }
718                         else {
719                                 printf( "-" );
ragge
1.2
720                                 adrput( p->n_left );
ragge
1.1
721                                 }
722    tbl */
ragge
1.2
723 #ifdef notyet
724                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
725                                 rnames[p->n_left->n_left->n_rval], 
726                                 (p->n_left->n_op==INCR ? '+' : '\0') );
727 #else
728                         printf("%c(%s)%c"'-',
729                                 rnames[p->n_left->n_left->n_rval], 
730                                 '\0' );
731 #endif
732                         p->n_op = OREG;
733                         p->n_rval = p->n_left->n_left->n_rval;
734                         q = p->n_left;
735 #ifdef notyet
736
737                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
738 #else
739                         p->n_lval = 0;
740 #endif
741                         p->n_name[0] = '\0';
ragge
1.1
742                         tfree(q);
743                 }
744                 return;
745
746         default:
747                 cerror"illegal address" );
748                 return;
749         }
750
ragge
1.2
751 }
ragge
1.1
752
753 /*
ragge
1.2
754  * print out a constant
755  */
756 void
757 acon(NODE *p)
758 {
ragge
1.1
759
ragge
1.2
760         if (p->n_name[0] == '\0') {
761                 printf(CONFMTp->n_lval);
762         } else ifp->n_lval == 0 ) {
763                 printf("%s"p->n_name);
764         } else {
765                 printf("%s+"p->n_name);
766                 printf(CONFMTp->n_lval);
ragge
1.1
767         }
ragge
1.2
768 }
ragge
1.1
769
ragge
1.2
770 #if 0
ragge
1.1
771 genscallpcookie ) register NODE *p; {
772         /* structure valued call */
773         returngencallpcookie ) );
774         }
775
776 /* tbl */
777 int gc_numbytes;
778 /* tbl */
779
780 gencallpcookie ) register NODE *p; {
781         /* generate the call given by p */
782         register NODE *p1, *ptemp;
783         register temptemp1;
784         register m;
785
786         ifp->right ) temp = argsizep->right );
787         else temp = 0;
788
789         ifp->op == STCALL || p->op == UNARY STCALL ){
790                 /* set aside room for structure return */
791
792                 ifp->stsize > temp ) temp1 = p->stsize;
793                 else temp1 = temp;
794                 }
795
796         iftemp > maxargs ) maxargs = temp;
797         SETOFF(temp1,4);
798
799         ifp->right ){ /* make temp node, put offset in, and generate args */
800                 ptemp = talloc();
801                 ptemp->op = OREG;
802                 ptemp->lval = -1;
803                 ptemp->rval = SP;
804                 ptemp->name[0] = '\0';
805                 ptemp->rall = NOPREF;
806                 ptemp->su = 0;
807                 genargsp->rightptemp );
ragge
1.2
808                 nfree(ptemp);
ragge
1.1
809                 }
810
811         p1 = p->left;
812         ifp1->op != ICON ){
813                 ifp1->op != REG ){
814                         ifp1->op != OREG || R2TEST(p1->rval) ){
815                                 ifp1->op != NAME ){
816                                         orderp1INAREG );
817                                         }
818                                 }
819                         }
820                 }
821
822 /*
823         if( p1->op == REG && p->rval == R5 ){
824                 cerror( "call register overwrite" );
825                 }
826  */
827 /* tbl
828         setup gc_numbytes so reference to ZC works */
829
830         gc_numbytes = temp;
831 /* tbl */
832
833         p->op = UNARY CALL;
834         m = matchpINTAREG|INTBREG );
835 /* tbl
836         switch( temp ) {
837         case 0:
838                 break;
839         case 2:
840                 printf( "       tst     (sp)+\n" );
841                 break;
842         case 4:
843                 printf( "       cmp     (sp)+,(sp)+\n" );
844                 break;
845         default:
846                 printf( "       add     $%d,sp\n", temp);
847                 }
848    tbl */
849         return(m != MDONE);
850         }
ragge
1.2
851 #endif
ragge
1.1
852
ragge
1.2
853 static char *
ragge
1.1
854 ccbranches[] = {
ragge
1.2
855         "jeql",
856         "jneq",
857         "jleq",
858         "jlss",
859         "jgeq",
860         "jgtr",
861         "jlequ",
862         "jlssu",
863         "jgequ",
864         "jgtru",
865 };
ragge
1.1
866
ragge
1.2
867 /*
868  * printf conditional and unconditional branches
869  */
870 void
871 cbgen(int oint lab)
872 {
ragge
1.1
873
ragge
1.2
874         if (o == 0) {
875                 printf("        jbr     " LABFMT "\n"lab);
876         } else {
877                 if (o > UGT)
878                         comperr("bad conditional branch: %s"opst[o]);
879                 printf("\t%s\t" LABFMT "\n"ccbranches[o-EQ], lab);
ragge
1.1
880         }
ragge
1.2
881 }
ragge
1.1
882
ragge
1.2
883 static void
884 optim2(NODE *p)
885 {
ragge
1.1
886         /* do local tree transformations and optimizations */
887
888         register NODE *r;
889
ragge
1.2
890         switchp->n_op ) {
ragge
1.1
891
892         case AND:
893                 /* commute L and R to eliminate compliments and constants */
ragge
1.2
894                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
895                         r = p->n_left;
896                         p->n_left = p->n_right;
897                         p->n_right = r;
ragge
1.1
898                         }
ragge
1.2
899 #if 0
ragge
1.1
900         case ASG AND:
901                 /* change meaning of AND to ~R&L - bic on pdp11 */
ragge
1.2
902                 r = p->n_right;
ragge
1.1
903                 ifr->op==ICON && r->name[0]==0 ) { /* compliment constant */
904                         r->lval = ~r->lval;
905                         }
906                 else ifr->op==COMPL ) { /* ~~A => A */
907                         r->op = FREE;
908                         p->right = r->left;
909                         }
910                 else { /* insert complement node */
911                         p->right = talloc();
912                         p->right->op = COMPL;
913                         p->right->rall = NOPREF;
914                         p->right->type = r->type;
915                         p->right->left = r;
916                         p->right->right = NULL;
917                         }
918                 break;
ragge
1.2
919 #endif
ragge
1.1
920                 }
921         }
922
ragge
1.2
923 void
924 myreader(struct interpass *ipole)
925 {
926         struct interpass *ip;
ragge
1.1
927
ragge
1.2
928         DLIST_FOREACH(ipipoleqelem) {
929                 if (ip->type != IP_NODE)
930                         continue;
931                 walkf(ip->ip_nodeoptim2);
ragge
1.1
932         }
ragge
1.2
933 }
934
gmcgarry
1.4
935 void
936 mycanon(NODE *p)
937 {
938 }
939
940 void
941 myoptim(struct interpass *ip)
942 {
943 }
944
ragge
1.2
945 /*
ragge
1.3
946  * Return argument size in regs.
ragge
1.2
947  */
948 static int
949 argsiz(NODE *p)
950 {
951         TWORD t = p->n_type;
952
953         if (t == STRTY || t == UNIONTY)
ragge
1.3
954                 return p->n_stsize/(SZINT/SZCHAR);
955         return szty(t);
ragge
1.2
956 }
957
958 /*
959  * Last chance to do something before calling a function.
960  */
961 void
962 lastcall(NODE *p)
963 {
964         NODE *op = p;
965         int size = 0;
966
967         /* Calculate argument sizes */
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         op->n_qual = size/* XXX */
975 }
976
977 /*
978  * Return a class suitable for a specific type.
979  */
980 int
981 gclass(TWORD t)
982 {
983         return (szty(t) == 2 ? CLASSB : CLASSA);
984 }
985
986 /*
987  * For class c, find worst-case displacement of the number of
988  * registers in the array r[] indexed by class.
989  */
990 int
991 COLORMAP(int cint *r)
992 {
993         int num;
994
995         switch (c) {
996         case CLASSA:
997                 /* there are 12 classa, so min 6 classb are needed to block */
998                 num = r[CLASSB] * 2;
999                 num += r[CLASSA];
1000                 return num < 12;
1001         case CLASSB:
1002                 /* 6 classa may block all classb */
1003                 num = r[CLASSB] + r[CLASSA];
1004                 return num < 6;
1005         }
1006         comperr("COLORMAP");
1007         return 0/* XXX gcc */
1008 }
1009
1010 /*
1011  * Special shapes.
1012  */
1013 int
1014 special(NODE *pint shape)
1015 {
1016         return SRNOPE;
1017 }
gmcgarry
1.5
1018
1019 /*
1020  * Target-dependent command-line options.
1021  */
1022 void
1023 mflags(char *str)
1024 {
1025 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-02 15:58 +0200