Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110628093331

Diff

Diff from 1.16 to:

Annotations

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

Annotated File View

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