Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20071126002646

Diff

Diff from 1.5 to:

Annotations

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

Annotated File View

gmcgarry
1.5
1 /*      $Id: local2.c,v 1.5 2007/11/26 00:26:47 gmcgarry 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
ragge
1.1
544 flshapep ) register NODE *p; {
ragge
1.2
545         returnp->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
546                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
ragge
1.1
547         }
548
ragge
1.2
549 int
ragge
1.1
550 shtempp ) register NODE *p; {
ragge
1.2
551         ifp->n_op == STARG ) p = p->n_left;
552         returnp->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left)) );
ragge
1.1
553         }
554
ragge
1.2
555 int
ragge
1.1
556 shumulp ) register NODE *p; {
ragge
1.2
557         register int o;
ragge
1.1
558         extern int xdebug;
559
560         if (xdebug) {
ragge
1.2
561                  printf("\nshumul:op=%d,lop=%d,rop=%d"p->n_opp->n_left->n_opp->n_right->n_op);
562                 printf(" prname=%s,plty=%d, prlval=%lld\n"p->n_right->n_namep->n_left->n_typep->n_right->n_lval);
ragge
1.1
563                 }
564
565
ragge
1.2
566         o = p->n_op;
567         ifo == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON ) returnSTARNM );
ragge
1.1
568
ragge
1.2
569 #ifdef notyet
ragge
1.1
570         if( ( o == INCR || o == ASG MINUS ) &&
ragge
1.2
571             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
572             p->n_right->n_name[0] == '\0' )
ragge
1.1
573                 {
ragge
1.2
574                 switch (p->n_left->n_type)
ragge
1.1
575                         {
576                         case CHAR|PTR:
577                         case UCHAR|PTR:
578                                 o = 1;
579                                 break;
580
581                         case SHORT|PTR:
582                         case USHORT|PTR:
583                                 o = 2;
584                                 break;
585
586                         case INT|PTR:
587                         case UNSIGNED|PTR:
588                         case LONG|PTR:
589                         case ULONG|PTR:
590                         case FLOAT|PTR:
591                                 o = 4;
592                                 break;
593
594                         case DOUBLE|PTR:
595                                 o = 8;
596                                 break;
597
598                         default:
ragge
1.2
599                                 if ( ISPTR(p->n_left->n_type) ) {
ragge
1.1
600                                         o = 4;
601                                         break;
602                                         }
603                                 else return(0);
604                         }
ragge
1.2
605                 returnp->n_right->n_lval == o ? STARREG : 0);
ragge
1.1
606                 }
ragge
1.2
607 #endif
ragge
1.1
608
609         return0 );
610         }
611
ragge
1.2
612 void
ragge
1.1
613 adrconval ) CONSZ val; {
614         printf"$" );
615         printfCONFMTval );
616         }
617
ragge
1.2
618 void
619 conput(FILE *fpNODE *p)
620 {
621         switchp->n_op ){
ragge
1.1
622
623         case ICON:
624                 aconp );
625                 return;
626
627         case REG:
ragge
1.2
628                 printf"%s"rnames[p->n_rval] );
ragge
1.1
629                 return;
630
631         default:
632                 cerror"illegal conput" );
633                 }
634         }
635
ragge
1.2
636 void
ragge
1.1
637 insputp ) register NODE *p; {
638         cerror"insput" );
639         }
640
ragge
1.2
641 void
642 upputp , sizeregister NODE *p; {
ragge
1.1
643         cerror"upput" );
644         }
645
ragge
1.2
646 void
647 adrput(FILE *fpNODE *p)
648 {
ragge
1.1
649         register int r;
650         /* output an address, with offsets, from p */
651
ragge
1.2
652         ifp->n_op == FLD ){
653                 p = p->n_left;
ragge
1.1
654                 }
ragge
1.2
655         switchp->n_op ){
ragge
1.1
656
657         case NAME:
658                 aconp );
659                 return;
660
661         case ICON:
662                 /* addressable value of the constant */
ragge
1.2
663                 if (p->n_name[0] == '\0'/* uses xxxab */
664                         printf("$");
665                 acon(p);
ragge
1.1
666                 return;
667
668         case REG:
ragge
1.2
669                 printf"%s"rnames[p->n_rval] );
ragge
1.1
670                 return;
671
672         case OREG:
ragge
1.2
673                 r = p->n_rval;
ragge
1.1
674                 ifR2TEST(r) ){ /* double indexing */
675                         register int flags;
676
677                         flags = R2UPK3(r);
678                         ifflags & 1 ) printf("*");
679                         ifflags & 4 ) printf("-");
ragge
1.2
680                         ifp->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
ragge
1.1
681                         ifR2UPK1(r) != 100printf"(%s)"rnames[R2UPK1(r)] );
682                         ifflags & 2 ) printf("+");
683                         printf"[%s]"rnames[R2UPK2(r)] );
684                         return;
685                         }
686                 ifr == AP ){  /* in the argument region */
ragge
1.2
687                         ifp->n_lval <= 0 || p->n_name[0] != '\0' ) werror"bad arg temp" );
688                         printfCONFMTp->n_lval );
ragge
1.1
689                         printf"(ap)" );
690                         return;
691                         }
ragge
1.2
692                 ifp->n_lval != 0 || p->n_name[0] != '\0'aconp );
693                 printf"(%s)"rnames[p->n_rval] );
ragge
1.1
694                 return;
695
ragge
1.2
696         case UMUL:
ragge
1.1
697                 /* STARNM or STARREG found */
698                 iftshape(pSTARNM) ) {
699                         printf"*" );
ragge
1.2
700                         adrput(0,  p->n_left);
ragge
1.1
701                         }
702                 else {  /* STARREG - really auto inc or dec */
703                         register NODE *q;
704
705 /* tbl
ragge
1.2
706                         p = p->n_left;
707                         p->n_left->n_op = OREG;
708                         if( p->n_op == INCR ) {
709                                 adrput( p->n_left );
ragge
1.1
710                                 printf( "+" );
711                                 }
712                         else {
713                                 printf( "-" );
ragge
1.2
714                                 adrput( p->n_left );
ragge
1.1
715                                 }
716    tbl */
ragge
1.2
717 #ifdef notyet
718                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
719                                 rnames[p->n_left->n_left->n_rval], 
720                                 (p->n_left->n_op==INCR ? '+' : '\0') );
721 #else
722                         printf("%c(%s)%c"'-',
723                                 rnames[p->n_left->n_left->n_rval], 
724                                 '\0' );
725 #endif
726                         p->n_op = OREG;
727                         p->n_rval = p->n_left->n_left->n_rval;
728                         q = p->n_left;
729 #ifdef notyet
730
731                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
732 #else
733                         p->n_lval = 0;
734 #endif
735                         p->n_name[0] = '\0';
ragge
1.1
736                         tfree(q);
737                 }
738                 return;
739
740         default:
741                 cerror"illegal address" );
742                 return;
743         }
744
ragge
1.2
745 }
ragge
1.1
746
747 /*
ragge
1.2
748  * print out a constant
749  */
750 void
751 acon(NODE *p)
752 {
ragge
1.1
753
ragge
1.2
754         if (p->n_name[0] == '\0') {
755                 printf(CONFMTp->n_lval);
756         } else ifp->n_lval == 0 ) {
757                 printf("%s"p->n_name);
758         } else {
759                 printf("%s+"p->n_name);
760                 printf(CONFMTp->n_lval);
ragge
1.1
761         }
ragge
1.2
762 }
ragge
1.1
763
ragge
1.2
764 #if 0
ragge
1.1
765 genscallpcookie ) register NODE *p; {
766         /* structure valued call */
767         returngencallpcookie ) );
768         }
769
770 /* tbl */
771 int gc_numbytes;
772 /* tbl */
773
774 gencallpcookie ) register NODE *p; {
775         /* generate the call given by p */
776         register NODE *p1, *ptemp;
777         register temptemp1;
778         register m;
779
780         ifp->right ) temp = argsizep->right );
781         else temp = 0;
782
783         ifp->op == STCALL || p->op == UNARY STCALL ){
784                 /* set aside room for structure return */
785
786                 ifp->stsize > temp ) temp1 = p->stsize;
787                 else temp1 = temp;
788                 }
789
790         iftemp > maxargs ) maxargs = temp;
791         SETOFF(temp1,4);
792
793         ifp->right ){ /* make temp node, put offset in, and generate args */
794                 ptemp = talloc();
795                 ptemp->op = OREG;
796                 ptemp->lval = -1;
797                 ptemp->rval = SP;
798                 ptemp->name[0] = '\0';
799                 ptemp->rall = NOPREF;
800                 ptemp->su = 0;
801                 genargsp->rightptemp );
ragge
1.2
802                 nfree(ptemp);
ragge
1.1
803                 }
804
805         p1 = p->left;
806         ifp1->op != ICON ){
807                 ifp1->op != REG ){
808                         ifp1->op != OREG || R2TEST(p1->rval) ){
809                                 ifp1->op != NAME ){
810                                         orderp1INAREG );
811                                         }
812                                 }
813                         }
814                 }
815
816 /*
817         if( p1->op == REG && p->rval == R5 ){
818                 cerror( "call register overwrite" );
819                 }
820  */
821 /* tbl
822         setup gc_numbytes so reference to ZC works */
823
824         gc_numbytes = temp;
825 /* tbl */
826
827         p->op = UNARY CALL;
828         m = matchpINTAREG|INTBREG );
829 /* tbl
830         switch( temp ) {
831         case 0:
832                 break;
833         case 2:
834                 printf( "       tst     (sp)+\n" );
835                 break;
836         case 4:
837                 printf( "       cmp     (sp)+,(sp)+\n" );
838                 break;
839         default:
840                 printf( "       add     $%d,sp\n", temp);
841                 }
842    tbl */
843         return(m != MDONE);
844         }
ragge
1.2
845 #endif
ragge
1.1
846
ragge
1.2
847 static char *
ragge
1.1
848 ccbranches[] = {
ragge
1.2
849         "jeql",
850         "jneq",
851         "jleq",
852         "jlss",
853         "jgeq",
854         "jgtr",
855         "jlequ",
856         "jlssu",
857         "jgequ",
858         "jgtru",
859 };
ragge
1.1
860
ragge
1.2
861 /*
862  * printf conditional and unconditional branches
863  */
864 void
865 cbgen(int oint lab)
866 {
ragge
1.1
867
ragge
1.2
868         if (o == 0) {
869                 printf("        jbr     " LABFMT "\n"lab);
870         } else {
871                 if (o > UGT)
872                         comperr("bad conditional branch: %s"opst[o]);
873                 printf("\t%s\t" LABFMT "\n"ccbranches[o-EQ], lab);
ragge
1.1
874         }
ragge
1.2
875 }
ragge
1.1
876
ragge
1.2
877 static void
878 optim2(NODE *p)
879 {
ragge
1.1
880         /* do local tree transformations and optimizations */
881
882         register NODE *r;
883
ragge
1.2
884         switchp->n_op ) {
ragge
1.1
885
886         case AND:
887                 /* commute L and R to eliminate compliments and constants */
ragge
1.2
888                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
889                         r = p->n_left;
890                         p->n_left = p->n_right;
891                         p->n_right = r;
ragge
1.1
892                         }
ragge
1.2
893 #if 0
ragge
1.1
894         case ASG AND:
895                 /* change meaning of AND to ~R&L - bic on pdp11 */
ragge
1.2
896                 r = p->n_right;
ragge
1.1
897                 ifr->op==ICON && r->name[0]==0 ) { /* compliment constant */
898                         r->lval = ~r->lval;
899                         }
900                 else ifr->op==COMPL ) { /* ~~A => A */
901                         r->op = FREE;
902                         p->right = r->left;
903                         }
904                 else { /* insert complement node */
905                         p->right = talloc();
906                         p->right->op = COMPL;
907                         p->right->rall = NOPREF;
908                         p->right->type = r->type;
909                         p->right->left = r;
910                         p->right->right = NULL;
911                         }
912                 break;
ragge
1.2
913 #endif
ragge
1.1
914                 }
915         }
916
ragge
1.2
917 void
918 myreader(struct interpass *ipole)
919 {
920         struct interpass *ip;
ragge
1.1
921
ragge
1.2
922         DLIST_FOREACH(ipipoleqelem) {
923                 if (ip->type != IP_NODE)
924                         continue;
925                 walkf(ip->ip_nodeoptim2);
ragge
1.1
926         }
ragge
1.2
927 }
928
gmcgarry
1.4
929 void
930 mycanon(NODE *p)
931 {
932 }
933
934 void
935 myoptim(struct interpass *ip)
936 {
937 }
938
ragge
1.2
939 /*
ragge
1.3
940  * Return argument size in regs.
ragge
1.2
941  */
942 static int
943 argsiz(NODE *p)
944 {
945         TWORD t = p->n_type;
946
947         if (t == STRTY || t == UNIONTY)
ragge
1.3
948                 return p->n_stsize/(SZINT/SZCHAR);
949         return szty(t);
ragge
1.2
950 }
951
952 /*
953  * Last chance to do something before calling a function.
954  */
955 void
956 lastcall(NODE *p)
957 {
958         NODE *op = p;
959         int size = 0;
960
961         /* Calculate argument sizes */
962         p->n_qual = 0;
963         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
964                 return;
965         for (p = p->n_rightp->n_op == CMp = p->n_left)
966                 size += argsiz(p->n_right);
967         size += argsiz(p);
968         op->n_qual = size/* XXX */
969 }
970
971 /*
972  * Return a class suitable for a specific type.
973  */
974 int
975 gclass(TWORD t)
976 {
977         return (szty(t) == 2 ? CLASSB : CLASSA);
978 }
979
980 /*
981  * For class c, find worst-case displacement of the number of
982  * registers in the array r[] indexed by class.
983  */
984 int
985 COLORMAP(int cint *r)
986 {
987         int num;
988
989         switch (c) {
990         case CLASSA:
991                 /* there are 12 classa, so min 6 classb are needed to block */
992                 num = r[CLASSB] * 2;
993                 num += r[CLASSA];
994                 return num < 12;
995         case CLASSB:
996                 /* 6 classa may block all classb */
997                 num = r[CLASSB] + r[CLASSA];
998                 return num < 6;
999         }
1000         comperr("COLORMAP");
1001         return 0/* XXX gcc */
1002 }
1003
1004 /*
1005  * Special shapes.
1006  */
1007 int
1008 special(NODE *pint shape)
1009 {
1010         return SRNOPE;
1011 }
gmcgarry
1.5
1012
1013 /*
1014  * Target-dependent command-line options.
1015  */
1016 void
1017 mflags(char *str)
1018 {
1019 }
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-21 19:01 +0100