Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20071026150641

Diff

Diff from 1.2 to:

Annotations

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

Annotated File View

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