Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110623134823

Diff

Diff from 1.12 to:

Annotations

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

Annotated File View

ragge
1.12
1 /*      $Id: local2.c,v 1.12 2011/06/23 13:48:23 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                 if (p->n_op == STCALL || p->n_op == USTCALL)
281                         p->n_qual++;
282                 printf("$%d"p->n_qual);
283                 break;
ragge
1.1
284
285         case 'D':       /* INCR and DECR */
ragge
1.2
286                 zzzcode(p->n_left'A');
ragge
1.1
287                 printf("\n      ");
288
ragge
1.2
289 #if 0
ragge
1.1
290         case 'E':       /* INCR and DECR, FOREFF */
ragge
1.2
291                 if (p->n_right->n_lval == 1)
ragge
1.1
292                         {
ragge
1.2
293                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
294                         prtype(p->n_left);
ragge
1.1
295                         printf("        ");
ragge
1.2
296                         adrput(stdoutp->n_left);
ragge
1.1
297                         return;
298                         }
ragge
1.2
299                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
300                 prtype(p->n_left);
ragge
1.1
301                 printf("2       ");
ragge
1.2
302                 adrput(stdoutp->n_right);
ragge
1.1
303                 printf(",");
ragge
1.2
304                 adrput(p->n_left);
ragge
1.1
305                 return;
ragge
1.2
306 #endif
ragge
1.1
307
308         case 'F':       /* register type of right operand */
309                 {
310                 register NODE *n;
311                 extern int xdebug;
312                 register int ty;
313
314                 n = getlrp'R' );
ragge
1.2
315                 ty = n->n_type;
ragge
1.1
316
317                 if (xdebugprintf("->%d<-"ty);
318
319                 if ( ty==DOUBLEprintf("d");
320                 else if ( ty==FLOAT ) printf("f");
321                 else printf("l");
322                 return;
323                 }
324
ragge
1.3
325         case 'J'/* jump or ret? */
326                 {
327                         struct interpass *ip =
ragge
1.12
328                             DLIST_PREV((struct interpass *)p2env.eppqelem);
ragge
1.3
329                         if (ip->type != IP_DEFLAB ||
330                             ip->ip_lbl != getlr(p'L')->n_lval)
331                                 expand(pFOREFF"jbr  LL");
332                         else
333                                 printf("ret");
334                 }
335                 break;
336
ragge
1.1
337         case 'L':       /* type of left operand */
338         case 'R':       /* type of right operand */
339                 {
340                 register NODE *n;
341                 extern int xdebug;
342
343                 n = getlr ( pc);
ragge
1.2
344                 if (xdebugprintf("->%d<-"n->n_type);
ragge
1.1
345
346                 prtype(n);
347                 return;
348                 }
349
350         case 'Z':       /* complement mask for bit instr */
ragge
1.2
351                 printf("$%Ld", ~p->n_right->n_lval);
ragge
1.1
352                 return;
353
354         case 'U':       /* 32 - n, for unsigned right shifts */
ragge
1.2
355                 printf("$" CONFMT32 - p->n_right->n_lval );
ragge
1.1
356                 return;
357
358         case 'T':       /* rounded structure length for arguments */
359                 {
360                 int size;
361
ragge
1.2
362                 size = p->n_stsize;
ragge
1.1
363                 SETOFFsize4);
364                 printf("$%d"size);
365                 return;
366                 }
367
368         case 'S':  /* structure assignment */
369                 {
370                         register NODE *l, *r;
ragge
1.2
371                         register int size;
ragge
1.1
372
ragge
1.2
373                         l = r = NULL/* XXX gcc */
374                         ifp->n_op == STASG ){
375                                 l = p->n_left;
376                                 r = p->n_right;
ragge
1.1
377
378                                 }
ragge
1.2
379                         else ifp->n_op == STARG ){  /* store an arg into a temporary */
ragge
1.1
380                                 l = getlrp'3' );
ragge
1.2
381                                 r = p->n_left;
ragge
1.1
382                                 }
383                         else cerror"STASG bad" );
384
ragge
1.2
385                         ifr->n_op == ICON ) r->n_op = NAME;
386                         else ifr->n_op == REG ) r->n_op = OREG;
387                         else ifr->n_op != OREG ) cerror"STASG-r" );
ragge
1.1
388
ragge
1.2
389                         size = p->n_stsize;
ragge
1.1
390
391                         ifsize <= 0 || size > 65535 )
392                                 cerror("structure size <0=0 or >65535");
393
394                         switch(size) {
395                                 case 1:
396                                         printf("        movb    ");
397                                         break;
398                                 case 2:
399                                         printf("        movw    ");
400                                         break;
401                                 case 4:
402                                         printf("        movl    ");
403                                         break;
404                                 case 8:
405                                         printf("        movq    ");
406                                         break;
407                                 default:
408                                         printf("        movc3   $%d,"size);
409                                         break;
410                         }
ragge
1.2
411                         adrput(stdoutr);
ragge
1.1
412                         printf(",");
ragge
1.2
413                         adrput(stdoutl);
ragge
1.1
414                         printf("\n");
415
ragge
1.2
416                         ifr->n_op == NAME ) r->n_op = ICON;
417                         else ifr->n_op == OREG ) r->n_op = REG;
ragge
1.1
418
419                         }
420                 break;
421
422         default:
ragge
1.2
423                 comperr("illegal zzzcode '%c'"c);
ragge
1.1
424                 }
425         }
426
ragge
1.2
427 void
428 rmoveint rt,int  rsTWORD t ){
ragge
1.1
429         printf"       %s      %s,%s\n",
430                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
431                 rnames[rs], rnames[rt] );
432         }
433
ragge
1.2
434 #if 0
ragge
1.1
435 setregs(){ /* set up temporary registers */
436         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
437         ;
438         }
439
440 szty(t){ /* size, in registers, needed to hold thing of type t */
441         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
442         }
ragge
1.2
443 #endif
ragge
1.1
444
ragge
1.2
445 int
ragge
1.1
446 rewfldp ) NODE *p; {
447         return(1);
448         }
449
ragge
1.2
450 #if 0
ragge
1.1
451 callreg(pNODE *p; {
452         returnR0 );
453         }
454
455 basep ) register NODE *p; {
456         register int o = p->op;
457
458         if( (o==ICON && p->name[0] != '\0')) return100 ); /* ie no base reg */
459         ifo==REG ) returnp->rval );
460     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
461                 returnp->left->rval );
462     ifo==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
463                 returnp->rval + 0200*1 );
464         ifo==INCR && p->left->op==REG ) returnp->left->rval + 0200*2 );
465         ifo==ASG MINUS && p->left->op==REGreturnp->left->rval + 0200*4 );
466         ifo==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
467           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
468                 returnp->left->left->rval + 0200*(1+2) );
469         return( -1 );
470         }
471
472 offsetptyl ) register NODE *pint tyl; {
473
474         iftyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) returnp->rval );
475         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
476               (p->right->op==ICON && p->right->name[0]=='\0')
477               && (1<<p->right->lval)==tyl))
478                 returnp->left->rval );
479         return( -1 );
480         }
ragge
1.2
481 #endif
ragge
1.1
482
ragge
1.2
483 #if 0
484 void
ragge
1.1
485 makeor2pqboregister NODE *p, *qregister int bo; {
486         register NODE *t;
487         NODE *f;
488
ragge
1.2
489         p->n_op = OREG;
490         f = p->n_left;  /* have to free this subtree later */
ragge
1.1
491
492         /* init base */
ragge
1.2
493         switch (q->n_op) {
ragge
1.1
494                 case ICON:
495                 case REG:
496                 case OREG:
497                         t = q;
498                         break;
499
500                 case MINUS:
ragge
1.2
501                         q->n_right->n_lval = -q->n_right->n_lval;
ragge
1.1
502                 case PLUS:
ragge
1.2
503                         t = q->n_right;
ragge
1.1
504                         break;
505
ragge
1.2
506                 case UMUL:
507                         t = q->n_left->n_left;
ragge
1.1
508                         break;
509
510                 default:
511                         cerror("illegal makeor2");
ragge
1.2
512                         t = NULL/* XXX gcc */
ragge
1.1
513         }
514
ragge
1.2
515         p->n_lval = t->n_lval;
516         p->n_name = t->n_name;
ragge
1.1
517
518         /* init offset */
ragge
1.2
519         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
ragge
1.1
520
521         tfree(f);
522         return;
523         }
524
ragge
1.2
525 int
ragge
1.1
526 canaddrp ) NODE *p; {
ragge
1.2
527         register int o = p->n_op;
ragge
1.1
528
ragge
1.8
529         ifo==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_leftSTARNM|SOREG)) ) return(1);
ragge
1.1
530         return(0);
531         }
532
533 shltypeop ) register NODE *p; {
ragge
1.8
534         returno== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_leftSTARNM|SOREG)) );
ragge
1.1
535         }
ragge
1.2
536 #endif
ragge
1.1
537
ragge
1.2
538 int
stefan
1.6
539 fldexpand(NODE *pint cookiechar **cp)
540 {
541         return 0;
542 }
543
544 int
ragge
1.1
545 flshapep ) register NODE *p; {
ragge
1.2
546         returnp->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
547                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
ragge
1.1
548         }
549
ragge
1.2
550 int
ragge
1.1
551 shtempp ) register NODE *p; {
ragge
1.2
552         ifp->n_op == STARG ) p = p->n_left;
ragge
1.8
553         returnp->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_leftSTARNM|SOREG)) );
ragge
1.1
554         }
555
ragge
1.2
556 int
ragge
1.8
557 shumulpshape ) register NODE *pint shape; {
ragge
1.2
558         register int o;
ragge
1.1
559         extern int xdebug;
560
561         if (xdebug) {
ragge
1.2
562                  printf("\nshumul:op=%d,lop=%d,rop=%d"p->n_opp->n_left->n_opp->n_right->n_op);
563                 printf(" prname=%s,plty=%d, prlval=%lld\n"p->n_right->n_namep->n_left->n_typep->n_right->n_lval);
ragge
1.1
564                 }
565
566
ragge
1.2
567         o = p->n_op;
ragge
1.8
568         ifo == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
569                 if (shape & STARNM)
570                         return SRDIR;
ragge
1.1
571
ragge
1.2
572 #ifdef notyet
ragge
1.1
573         if( ( o == INCR || o == ASG MINUS ) &&
ragge
1.2
574             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
575             p->n_right->n_name[0] == '\0' )
ragge
1.1
576                 {
ragge
1.2
577                 switch (p->n_left->n_type)
ragge
1.1
578                         {
579                         case CHAR|PTR:
580                         case UCHAR|PTR:
581                                 o = 1;
582                                 break;
583
584                         case SHORT|PTR:
585                         case USHORT|PTR:
586                                 o = 2;
587                                 break;
588
589                         case INT|PTR:
590                         case UNSIGNED|PTR:
591                         case LONG|PTR:
592                         case ULONG|PTR:
593                         case FLOAT|PTR:
594                                 o = 4;
595                                 break;
596
597                         case DOUBLE|PTR:
598                                 o = 8;
599                                 break;
600
601                         default:
ragge
1.2
602                                 if ( ISPTR(p->n_left->n_type) ) {
ragge
1.1
603                                         o = 4;
604                                         break;
605                                         }
606                                 else return(0);
607                         }
ragge
1.2
608                 returnp->n_right->n_lval == o ? STARREG : 0);
ragge
1.1
609                 }
ragge
1.2
610 #endif
ragge
1.1
611
ragge
1.8
612         returnSRNOPE );
ragge
1.1
613         }
614
ragge
1.2
615 void
ragge
1.1
616 adrconval ) CONSZ val; {
617         printf"$" );
618         printfCONFMTval );
619         }
620
ragge
1.2
621 void
622 conput(FILE *fpNODE *p)
623 {
624         switchp->n_op ){
ragge
1.1
625
626         case ICON:
627                 aconp );
628                 return;
629
630         case REG:
ragge
1.2
631                 printf"%s"rnames[p->n_rval] );
ragge
1.1
632                 return;
633
634         default:
635                 cerror"illegal conput" );
636                 }
637         }
638
ragge
1.2
639 void
ragge
1.1
640 insputp ) register NODE *p; {
641         cerror"insput" );
642         }
643
ragge
1.2
644 void
645 upputp , sizeregister NODE *p; {
ragge
1.1
646         cerror"upput" );
647         }
648
ragge
1.2
649 void
650 adrput(FILE *fpNODE *p)
651 {
ragge
1.1
652         register int r;
653         /* output an address, with offsets, from p */
654
ragge
1.2
655         ifp->n_op == FLD ){
656                 p = p->n_left;
ragge
1.1
657                 }
ragge
1.2
658         switchp->n_op ){
ragge
1.1
659
660         case NAME:
661                 aconp );
662                 return;
663
664         case ICON:
665                 /* addressable value of the constant */
ragge
1.2
666                 if (p->n_name[0] == '\0'/* uses xxxab */
667                         printf("$");
668                 acon(p);
ragge
1.1
669                 return;
670
671         case REG:
ragge
1.2
672                 printf"%s"rnames[p->n_rval] );
ragge
1.1
673                 return;
674
675         case OREG:
ragge
1.2
676                 r = p->n_rval;
ragge
1.1
677                 ifR2TEST(r) ){ /* double indexing */
678                         register int flags;
679
680                         flags = R2UPK3(r);
681                         ifflags & 1 ) printf("*");
682                         ifflags & 4 ) printf("-");
ragge
1.2
683                         ifp->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
ragge
1.1
684                         ifR2UPK1(r) != 100printf"(%s)"rnames[R2UPK1(r)] );
685                         ifflags & 2 ) printf("+");
686                         printf"[%s]"rnames[R2UPK2(r)] );
687                         return;
688                         }
689                 ifr == AP ){  /* in the argument region */
ragge
1.2
690                         ifp->n_lval <= 0 || p->n_name[0] != '\0' ) werror"bad arg temp" );
691                         printfCONFMTp->n_lval );
ragge
1.1
692                         printf"(ap)" );
693                         return;
694                         }
ragge
1.2
695                 ifp->n_lval != 0 || p->n_name[0] != '\0'aconp );
696                 printf"(%s)"rnames[p->n_rval] );
ragge
1.1
697                 return;
698
ragge
1.2
699         case UMUL:
ragge
1.1
700                 /* STARNM or STARREG found */
701                 iftshape(pSTARNM) ) {
702                         printf"*" );
ragge
1.2
703                         adrput(0,  p->n_left);
ragge
1.1
704                         }
705                 else {  /* STARREG - really auto inc or dec */
706                         register NODE *q;
707
708 /* tbl
ragge
1.2
709                         p = p->n_left;
710                         p->n_left->n_op = OREG;
711                         if( p->n_op == INCR ) {
712                                 adrput( p->n_left );
ragge
1.1
713                                 printf( "+" );
714                                 }
715                         else {
716                                 printf( "-" );
ragge
1.2
717                                 adrput( p->n_left );
ragge
1.1
718                                 }
719    tbl */
ragge
1.2
720 #ifdef notyet
721                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
722                                 rnames[p->n_left->n_left->n_rval], 
723                                 (p->n_left->n_op==INCR ? '+' : '\0') );
724 #else
725                         printf("%c(%s)%c"'-',
726                                 rnames[p->n_left->n_left->n_rval], 
727                                 '\0' );
728 #endif
729                         p->n_op = OREG;
730                         p->n_rval = p->n_left->n_left->n_rval;
731                         q = p->n_left;
732 #ifdef notyet
733
734                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
735 #else
736                         p->n_lval = 0;
737 #endif
738                         p->n_name[0] = '\0';
ragge
1.1
739                         tfree(q);
740                 }
741                 return;
742
743         default:
744                 cerror"illegal address" );
745                 return;
746         }
747
ragge
1.2
748 }
ragge
1.1
749
750 /*
ragge
1.2
751  * print out a constant
752  */
753 void
754 acon(NODE *p)
755 {
ragge
1.1
756
ragge
1.2
757         if (p->n_name[0] == '\0') {
758                 printf(CONFMTp->n_lval);
759         } else ifp->n_lval == 0 ) {
760                 printf("%s"p->n_name);
761         } else {
762                 printf("%s+"p->n_name);
763                 printf(CONFMTp->n_lval);
ragge
1.1
764         }
ragge
1.2
765 }
ragge
1.1
766
ragge
1.2
767 #if 0
ragge
1.1
768 genscallpcookie ) register NODE *p; {
769         /* structure valued call */
770         returngencallpcookie ) );
771         }
772
773 /* tbl */
774 int gc_numbytes;
775 /* tbl */
776
777 gencallpcookie ) register NODE *p; {
778         /* generate the call given by p */
779         register NODE *p1, *ptemp;
780         register temptemp1;
781         register m;
782
783         ifp->right ) temp = argsizep->right );
784         else temp = 0;
785
786         ifp->op == STCALL || p->op == UNARY STCALL ){
787                 /* set aside room for structure return */
788
789                 ifp->stsize > temp ) temp1 = p->stsize;
790                 else temp1 = temp;
791                 }
792
793         iftemp > maxargs ) maxargs = temp;
794         SETOFF(temp1,4);
795
796         ifp->right ){ /* make temp node, put offset in, and generate args */
797                 ptemp = talloc();
798                 ptemp->op = OREG;
799                 ptemp->lval = -1;
800                 ptemp->rval = SP;
801                 ptemp->name[0] = '\0';
802                 ptemp->rall = NOPREF;
803                 ptemp->su = 0;
804                 genargsp->rightptemp );
ragge
1.2
805                 nfree(ptemp);
ragge
1.1
806                 }
807
808         p1 = p->left;
809         ifp1->op != ICON ){
810                 ifp1->op != REG ){
811                         ifp1->op != OREG || R2TEST(p1->rval) ){
812                                 ifp1->op != NAME ){
813                                         orderp1INAREG );
814                                         }
815                                 }
816                         }
817                 }
818
819 /*
820         if( p1->op == REG && p->rval == R5 ){
821                 cerror( "call register overwrite" );
822                 }
823  */
824 /* tbl
825         setup gc_numbytes so reference to ZC works */
826
827         gc_numbytes = temp;
828 /* tbl */
829
830         p->op = UNARY CALL;
831         m = matchpINTAREG|INTBREG );
832 /* tbl
833         switch( temp ) {
834         case 0:
835                 break;
836         case 2:
837                 printf( "       tst     (sp)+\n" );
838                 break;
839         case 4:
840                 printf( "       cmp     (sp)+,(sp)+\n" );
841                 break;
842         default:
843                 printf( "       add     $%d,sp\n", temp);
844                 }
845    tbl */
846         return(m != MDONE);
847         }
ragge
1.2
848 #endif
ragge
1.1
849
ragge
1.2
850 static char *
ragge
1.1
851 ccbranches[] = {
ragge
1.2
852         "jeql",
853         "jneq",
854         "jleq",
855         "jlss",
856         "jgeq",
857         "jgtr",
858         "jlequ",
859         "jlssu",
860         "jgequ",
861         "jgtru",
862 };
ragge
1.1
863
ragge
1.2
864 /*
865  * printf conditional and unconditional branches
866  */
867 void
868 cbgen(int oint lab)
869 {
ragge
1.1
870
ragge
1.2
871         if (o == 0) {
872                 printf("        jbr     " LABFMT "\n"lab);
873         } else {
874                 if (o > UGT)
875                         comperr("bad conditional branch: %s"opst[o]);
876                 printf("\t%s\t" LABFMT "\n"ccbranches[o-EQ], lab);
ragge
1.1
877         }
ragge
1.2
878 }
ragge
1.1
879
ragge
1.2
880 static void
ragge
1.10
881 optim2(NODE *pvoid *arg)
ragge
1.2
882 {
ragge
1.1
883         /* do local tree transformations and optimizations */
884
885         register NODE *r;
886
ragge
1.2
887         switchp->n_op ) {
ragge
1.1
888
889         case AND:
890                 /* commute L and R to eliminate compliments and constants */
ragge
1.2
891                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
892                         r = p->n_left;
893                         p->n_left = p->n_right;
894                         p->n_right = r;
ragge
1.1
895                         }
ragge
1.2
896 #if 0
ragge
1.1
897         case ASG AND:
898                 /* change meaning of AND to ~R&L - bic on pdp11 */
ragge
1.2
899                 r = p->n_right;
ragge
1.1
900                 ifr->op==ICON && r->name[0]==0 ) { /* compliment constant */
901                         r->lval = ~r->lval;
902                         }
903                 else ifr->op==COMPL ) { /* ~~A => A */
904                         r->op = FREE;
905                         p->right = r->left;
906                         }
907                 else { /* insert complement node */
908                         p->right = talloc();
909                         p->right->op = COMPL;
910                         p->right->rall = NOPREF;
911                         p->right->type = r->type;
912                         p->right->left = r;
913                         p->right->right = NULL;
914                         }
915                 break;
ragge
1.2
916 #endif
ragge
1.1
917                 }
918         }
919
ragge
1.2
920 void
921 myreader(struct interpass *ipole)
922 {
923         struct interpass *ip;
ragge
1.1
924
ragge
1.2
925         DLIST_FOREACH(ipipoleqelem) {
926                 if (ip->type != IP_NODE)
927                         continue;
ragge
1.10
928                 walkf(ip->ip_nodeoptim20);
ragge
1.1
929         }
ragge
1.2
930 }
931
gmcgarry
1.4
932 void
933 mycanon(NODE *p)
934 {
935 }
936
937 void
938 myoptim(struct interpass *ip)
939 {
940 }
941
ragge
1.2
942 /*
ragge
1.3
943  * Return argument size in regs.
ragge
1.2
944  */
945 static int
946 argsiz(NODE *p)
947 {
948         TWORD t = p->n_type;
949
950         if (t == STRTY || t == UNIONTY)
ragge
1.3
951                 return p->n_stsize/(SZINT/SZCHAR);
952         return szty(t);
ragge
1.2
953 }
954
955 /*
956  * Last chance to do something before calling a function.
957  */
958 void
959 lastcall(NODE *p)
960 {
961         NODE *op = p;
962         int size = 0;
963
964         /* Calculate argument sizes */
965         p->n_qual = 0;
966         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
967                 return;
968         for (p = p->n_rightp->n_op == CMp = p->n_left)
969                 size += argsiz(p->n_right);
970         size += argsiz(p);
971         op->n_qual = size/* XXX */
972 }
973
974 /*
975  * Return a class suitable for a specific type.
976  */
977 int
978 gclass(TWORD t)
979 {
980         return (szty(t) == 2 ? CLASSB : CLASSA);
981 }
982
983 /*
984  * For class c, find worst-case displacement of the number of
985  * registers in the array r[] indexed by class.
986  */
987 int
988 COLORMAP(int cint *r)
989 {
990         int num;
991
992         switch (c) {
993         case CLASSA:
994                 /* there are 12 classa, so min 6 classb are needed to block */
995                 num = r[CLASSB] * 2;
996                 num += r[CLASSA];
997                 return num < 12;
998         case CLASSB:
999                 /* 6 classa may block all classb */
1000                 num = r[CLASSB] + r[CLASSA];
1001                 return num < 6;
1002         }
1003         comperr("COLORMAP");
1004         return 0/* XXX gcc */
1005 }
1006
1007 /*
1008  * Special shapes.
1009  */
1010 int
1011 special(NODE *pint shape)
1012 {
1013         return SRNOPE;
1014 }
gmcgarry
1.5
1015
1016 /*
1017  * Target-dependent command-line options.
1018  */
1019 void
1020 mflags(char *str)
1021 {
1022 }
ragge
1.7
1023 /*
1024  * Do something target-dependent for xasm arguments.
1025