Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110627115025

Diff

Diff from 1.13 to:

Annotations

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

Annotated File View

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