Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110628073847

Diff

Diff from 1.15 to:

Annotations

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

Annotated File View

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