Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030730112747

Diff

Diff from 1.30 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/mip/reader.c

Annotated File View

ragge
1.2
1 #if 0
ragge
1.1
2 static char *sccsid ="@(#)reader.c      4.8 (Berkeley) 12/10/87";
ragge
1.2
3 #endif
ragge
1.1
4
5 # include "pass2.h"
6
7 /*      some storage declarations */
ragge
1.26
8 /*
9  * TODO: re-invent autoincr()/deltest()
10  */
ragge
1.1
11
12 int nrecur;
13 int lflag;
ragge
1.9
14 int x2debug;
ragge
1.1
15 int udebug = 0;
16
17 OFFSZ tmpoff;  /* offset for first temporary, in bits for current block */
18 OFFSZ maxoff;  /* maximum temporary offset over all blocks in current ftn, in bits */
19 int maxtreg;
20
21 NODE *stotree;
22 int stocook;
23
24 OFFSZ baseoff = 0;
25 OFFSZ maxtemp = 0;
26
ragge
1.23
27 static struct templst {
28         struct templst *next;
29         int tempnr;
30         int tempoff;
31 } *templst;
32
ragge
1.10
33 int e2print(NODE *pint downint *aint *b);
ragge
1.29
34 void cbranch(NODE *pint false);
ragge
1.26
35
36 #ifdef PCC_DEBUG
37 static void
38 cktree(NODE *p)
39 {
40         if (p->n_op > MAXOP)
41                 cerror("op %d slipped through"p->n_op);
42 }
43 #endif
ragge
1.8
44
ragge
1.17
45 static void
ragge
1.2
46 p2compile(NODE *p)
47 {
ragge
1.15
48 #if !defined(MULTIPASS)
49         extern char *ftitle;
50 #endif
ragge
1.1
51
ragge
1.14
52         if (lflag)
53                 lineid(linenoftitle);
54
ragge
1.1
55         /* generate code for the tree p */
ragge
1.26
56 #ifdef PCC_DEBUG
57         walkf(pcktree);
58         if (e2debug)
59                 fwalk(pe2print0);
60 #endif
ragge
1.25
61
ragge
1.1
62 # ifdef MYREADER
63         MYREADER(p);  /* do your own laundering of the input */
64 # endif
65         nrecur = 0;
ragge
1.25
66         codgen(pFOREFF);
ragge
1.1
67         reclaimpRNULL0 );
68         allchk();
69         /* can't do tcheck here; some stuff (e.g., attributes) may be around from first pass */
70         /* first pass will do it... */
ragge
1.2
71 }
ragge
1.1
72
ragge
1.17
73 static void newblock(int myregint aoff);
74 static void epilogue(int regsint autosint retlab);
75
ragge
1.2
76 void
ragge
1.17
77 pass2_compile(struct interpass *ip)
78 {
79         switch (ip->type) {
80         case IP_NODE:
81                 p2compile(ip->ip_node);
ragge
1.21
82                 tfree(ip->ip_node);
ragge
1.17
83                 break;
84         case IP_PROLOG:
85                 prologue(ip->ip_regsip->ip_auto);
86                 break;
87         case IP_NEWBLK:
88                 newblock(ip->ip_regsip->ip_auto);
89                 break;
90         case IP_EPILOG:
91                 epilogue(ip->ip_regsip->ip_autoip->ip_retl);
ragge
1.18
92                 break;
93         case IP_LOCCTR:
94                 setlocc(ip->ip_locc);
95                 break;
96         case IP_DEFLAB:
97                 deflab(ip->ip_lbl);
98                 break;
99         case IP_DEFNAM:
100                 defname(ip->ip_nameip->ip_vis);
101                 break;
ragge
1.17
102         default:
103                 cerror("pass2_compile %d"ip->type);
104         }
105 }
106
107 static void
ragge
1.16
108 newblock(int myregint aoff)
ragge
1.2
109 {
ragge
1.1
110         static int myftn = -1;
111
ragge
1.30
112         tmpoff = baseoff = aoff;
ragge
1.1
113         maxtreg = myreg;
114         ifmyftn != ftnno ){ /* beginning of function */
115                 maxoff = baseoff;
116                 myftn = ftnno;
117                 maxtemp = 0;
118                 }
119         else {
120                 ifbaseoff > maxoff ) maxoff = baseoff;
121                 /* maxoff at end of ftn is max of autos and temps over all blocks */
122                 }
123         setregs();
ragge
1.2
124 }
ragge
1.1
125
ragge
1.17
126 static void
ragge
1.16
127 epilogue(int regsint autosint retlab)
ragge
1.2
128 {
ragge
1.16
129         SETOFF(maxoffALSTACK);
ragge
1.23
130         templst = NULL;
ragge
1.16
131         eoftn(regsautosretlab);
ragge
1.2
132 }
ragge
1.1
133
ragge
1.2
134 /*
135  * generate the code for p;
136  * order may call codgen recursively
137  * cookie is used to describe the context
138  */
139 void
140 codgen(NODE *pint cookie)
141 {
ragge
1.1
142
ragge
1.8
143         for (;;) {
ragge
1.1
144                 canon(p);  /* creats OREG from * if possible and does sucomp */
145                 stotree = NIL;
ragge
1.30
146 #ifdef PCC_DEBUG
ragge
1.8
147                 if (e2debug) {
148                         printf("store called on:\n");
149                         fwalk(pe2print0);
150                 }
ragge
1.30
151 #endif
ragge
1.1
152                 store(p);
153                 ifstotree==NIL ) break;
154
155                 /* because it's minimal, can do w.o. stores */
156
157                 orderstotreestocook );
ragge
1.2
158         }
ragge
1.1
159         orderpcookie );
ragge
1.2
160 }
ragge
1.1
161
ragge
1.30
162 #ifdef PCC_DEBUG
ragge
1.1
163 char *cnames[] = {
164         "SANY",
165         "SAREG",
166         "STAREG",
167         "SBREG",
168         "STBREG",
169         "SCC",
170         "SNAME",
171         "SCON",
172         "SFLD",
173         "SOREG",
174         "STARNM",
175         "STARREG",
176         "INTEMP",
177         "FORARG",
178         "SWADD",
179         0,
180         };
181
ragge
1.2
182 /*
183  * print a nice-looking description of cookie
184  */
185 void
186 prcook(int cookie)
187 {
ragge
1.1
188         int iflag;
189
190         ifcookie & SPECIAL ){
191                 ifcookie == SZERO ) printf"SZERO" );
192                 else ifcookie == SONE ) printf"SONE" );
193                 else ifcookie == SMONE ) printf"SMONE" );
ragge
1.30
194                 else ifcookie == SCCON ) printf"SCCON" ); /* XXX 4.4 */
195                 else ifcookie == SSCON ) printf"SSCON" ); /* XXX 4.4 */
196                 else ifcookie == SSOREG ) printf"SSOREG" ); /* XXX 4.4 */
ragge
1.1
197                 else printf"SPECIAL+%d"cookie & ~SPECIAL );
198                 return;
199                 }
200
201         flag = 0;
202         fori=0cnames[i]; ++i ){
203                 ifcookie & (1<<i) ){
204                         ifflag ) printf"|" );
205                         ++flag;
206                         printfcnames[i] );
207                         }
208                 }
209
ragge
1.2
210 }
ragge
1.30
211 #endif
ragge
1.1
212
213 int odebug = 0;
214
ragge
1.2
215 void
216 order(NODE *pint cook)
217 {
218         int otym;
ragge
1.1
219         int cookie;
ragge
1.2
220         NODE *p1, *p2;
ragge
1.1
221
ragge
1.8
222         /*
223          * by this time, p should be able to be generated without stores;
224          * the only question is how
225          */
ragge
1.1
226         again:
227
ragge
1.13
228         if (p->n_op == FREE)
ragge
1.19
229                 cerror("order");        /* whole tree was done */
ragge
1.1
230         cookie = cook;
231         rcount();
232         canon(p);
ragge
1.13
233         rallo(pp->n_rall);
ragge
1.1
234
ragge
1.30
235 #ifdef PCC_DEBUG
ragge
1.8
236         if (odebug) {
237                 printf("order(%p, "p);
238                 prcook(cookie);
239                 printf(")\n");
240                 fwalk(pe2print0);
241         }
ragge
1.30
242 #endif
ragge
1.1
243
ragge
1.13
244         o = p->n_op;
ragge
1.1
245         ty = optype(o);
246
247         /* first of all, for most ops, see if it is in the table */
248
249         /* look for ops */
250
ragge
1.13
251         switch (m = p->n_op) {
ragge
1.1
252
253         default:
254                 /* look for op in table */
ragge
1.8
255                 for (;;) {
256                         if ((m = match(pcookie)) == MDONE)
257                                 goto cleanup;
258                         else if (m == MNOPE) {
259                                 if (!(cookie = nextcook(pcookie)))
260                                         goto nomat;
ragge
1.1
261                                 continue;
ragge
1.8
262                         } else
263                                 break;
264                 }
ragge
1.1
265                 break;
266
267         case FORCE:
268         case CBRANCH:
269         case UNARY CALL:
270         case CALL:
271         case UNARY STCALL:
272         case STCALL:
273         case UNARY FORTCALL:
274         case FORTCALL:
275                 /* don't even go near the table... */
276                 ;
277
ragge
1.8
278         }
ragge
1.25
279         /*
ragge
1.8
280          * get here to do rewriting if no match or
281          * fall through from above for hard ops
282          */
ragge
1.1
283
ragge
1.13
284         p1 = p->n_left;
ragge
1.8
285         if (ty == BITYPE)
ragge
1.13
286                 p2 = p->n_right;
ragge
1.8
287         else
288                 p2 = NIL;
ragge
1.1
289         
ragge
1.30
290 #ifdef PCC_DEBUG
ragge
1.8
291         if (odebug) {
292                 printf("order(%p, "p);
293                 prcook(cook);
294                 printf("), cookie ");
295                 prcook(cookie);
296                 printf(", rewrite %s\n"opst[m]);
297         }
ragge
1.30
298 #endif
ragge
1.8
299         switch (m) {
ragge
1.1
300         default:
301                 nomat:
ragge
1.13
302                 cerror"no table entry for op %s"opst[p->n_op] );
ragge
1.1
303
304         case FORCE:
305                 /* recurse, letting the work be done by rallo */
306                 cook = INTAREG|INTBREG;
ragge
1.19
307                 order(p->n_leftcook);
308                 reclaim(pRLEFTcook);
ragge
1.1
309                 goto again;
310
311         case CBRANCH:
ragge
1.13
312                 o = p2->n_lval;
ragge
1.29
313                 cbranchp1o );
ragge
1.19
314                 nfree(p2);
315                 nfree(p);
ragge
1.1
316                 return;
317
318         case FLD:       /* fields of funny type */
ragge
1.13
319                 if ( p1->n_op == UNARY MUL ){
320                         offstarp1->n_left );
ragge
1.1
321                         goto again;
322                         }
323
324         case UNARY MINUS:
ragge
1.30
325                 orderp1INBREG|INAREG);
ragge
1.1
326                 goto again;
327
328         case NAME:
329                 /* all leaves end up here ... */
330                 ifo == REG ) goto nomat;
331                 orderpINTAREG|INTBREG );
332                 goto again;
333
334         case INIT:
ragge
1.12
335                 uerror("init: illegal initialization");
ragge
1.1
336                 return;
337
338         case UNARY FORTCALL:
ragge
1.13
339                 p->n_right = NIL;
ragge
1.1
340         case FORTCALL:
ragge
1.13
341                 o = p->n_op = UNARY FORTCALL;
ragge
1.1
342                 ifgenfcallpcookie ) ) goto nomat;
343                 goto cleanup;
344
345         case UNARY CALL:
ragge
1.13
346                 p->n_right = NIL;
ragge
1.1
347         case CALL:
ragge
1.13
348                 o = p->n_op = UNARY CALL;
ragge
1.1
349                 ifgencallpcookie ) ) goto nomat;
350                 goto cleanup;
351
352         case UNARY STCALL:
ragge
1.13
353                 p->n_right = NIL;
ragge
1.1
354         case STCALL:
ragge
1.13
355                 o = p->n_op = UNARY STCALL;
ragge
1.1
356                 ifgenscallpcookie ) ) goto nomat;
357                 goto cleanup;
358
359                 /* if arguments are passed in register, care must be taken that reclaim
ragge
1.2
360                  * not throw away the register which now has the result... */
ragge
1.1
361
362         case UNARY MUL:
363                 ifcook == FOREFF ){
364                         /* do nothing */
ragge
1.13
365                         orderp->n_leftFOREFF );
ragge
1.19
366                         nfree(p);
ragge
1.1
367                         return;
ragge
1.19
368                 }
ragge
1.30
369                 offstarp->n_left );
370 #if 0
371                 canon(p);
372                 ifcanaddr(p) && cook != INTEMP )
373                         goto cleanup;
ragge
1.1
374 #endif
375                 goto again;
376
377         case INCR:  /* INCR and DECR */
378                 ifsetincr(p) ) goto again;
379
380                 /* x++ becomes (x += 1) -1; */
381
382                 ifcook & FOREFF ){  /* result not needed so inc or dec and be done with it */
383                         /* x++ => x += 1 */
ragge
1.13
384                         p->n_op = (p->n_op==INCR)?ASG PLUS:ASG MINUS;
ragge
1.1
385                         goto again;
386                         }
387
388                 p1 = tcopy(p);
ragge
1.13
389                 reclaimp->n_leftRNULL0 );
390                 p->n_left = p1;
391                 p1->n_op = (p->n_op==INCR)?ASG PLUS:ASG MINUS;
392                 p->n_op = (p->n_op==INCR)?MINUS:PLUS;
ragge
1.1
393                 goto again;
394
395         case STASG:
396                 ifsetstrp ) ) goto again;
397                 goto nomat;
398
399         case ASG PLUS:  /* and other assignment ops */
400                 ifsetasop(p) ) goto again;
401
402                 /* there are assumed to be no side effects in LHS */
403
404                 p2 = tcopy(p);
ragge
1.13
405                 p->n_op = ASSIGN;
406                 reclaimp->n_rightRNULL0 );
407                 p->n_right = p2;
ragge
1.1
408                 canon(p);
ragge
1.13
409                 rallopp->n_rall );
ragge
1.1
410
ragge
1.30
411 #ifdef PCC_DEBUG
ragge
1.8
412                 ifodebug ) fwalkpe2print0 );
ragge
1.30
413 #endif
ragge
1.1
414
ragge
1.13
415                 orderp2->n_leftINTBREG|INTAREG );
ragge
1.1
416                 orderp2INTBREG|INTAREG );
417                 goto again;
418
419         case ASSIGN:
ragge
1.8
420                 if (setasg(p))
421                         goto again;
ragge
1.1
422                 goto nomat;
423
424
425         case BITYPE:
426                 ifsetbinp ) ) goto again;
427                 /* try to replace binary ops by =ops */
428                 switch(o){
429
430                 case PLUS:
431                 case MINUS:
432                 case MUL:
433                 case DIV:
434                 case MOD:
435                 case AND:
436                 case OR:
437                 case ER:
438                 case LS:
439                 case RS:
ragge
1.13
440                         p->n_op = ASG o;
ragge
1.1
441                         goto again;
442                         }
443                 goto nomat;
444
445                 }
446
447         cleanup:
448
449         /* if it is not yet in the right state, put it there */
450
451         ifcook & FOREFF ){
452                 reclaimpRNULL0 );
453                 return;
454                 }
455
ragge
1.13
456         ifp->n_op==FREE ) return;
ragge
1.1
457
458         iftshapepcook ) ) return;
459
460         if( (m=match(p,cook) ) == MDONE ) return;
461
462         /* we are in bad shape, try one last chance */
ragge
1.8
463         if (lastchance(pcook))
464                 goto again;
ragge
1.1
465
466         goto nomat;
ragge
1.8
467 }
ragge
1.1
468
469 int callflag;
470 int fregs;
471
ragge
1.2
472 void
473 storep ) NODE *p; {
ragge
1.1
474
475         /* find a subtree of p which should be stored */
476
ragge
1.2
477         int oty;
ragge
1.1
478
ragge
1.13
479         o = p->n_op;
ragge
1.1
480         ty = optype(o);
481
482         ifty == LTYPE ) return;
483
484         switcho ){
485
486         case UNARY CALL:
487         case UNARY FORTCALL:
488         case UNARY STCALL:
489                 ++callflag;
490                 break;
491
492         case UNARY MUL:
ragge
1.13
493                 if (asgop(p->n_left->n_op))
494                         stoasg(p->n_leftUNARY MUL);
ragge
1.1
495                 break;
496
497         case CALL:
498         case FORTCALL:
499         case STCALL:
ragge
1.13
500                 storep->n_left );
501                 stoargp->n_righto );
ragge
1.1
502                 ++callflag;
503                 return;
504
505         case CBRANCH:   /* to prevent complicated expressions on the LHS from being stored */
ragge
1.13
506                 constorep->n_left );
ragge
1.1
507                 return;
508
509                 }
510
ragge
1.11
511         if (ty == UTYPE) {
ragge
1.13
512                 store(p->n_left);
ragge
1.1
513                 return;
ragge
1.11
514         }
ragge
1.1
515
ragge
1.13
516         if (asgop(p->n_right->n_op))
517                 stoasg(p->n_righto);
ragge
1.1
518
ragge
1.13
519         ifp->n_su>fregs ){ /* must store */
ragge
1.1
520                 mkadrsp );  /* set up stotree and stocook to subtree
521                                  that must be stored */
522                 }
523
ragge
1.13
524         storep->n_right );
525         storep->n_left );
ragge
1.1
526         }
527
ragge
1.2
528 /*
529  * store conditional expressions
530  * the point is, avoid storing expressions in conditional
531  * conditional context, since the evaluation order is predetermined
532  */
533 void
534 constore(NODE *p)
535 {
ragge
1.1
536         storep );
ragge
1.2
537 }
ragge
1.1
538
ragge
1.2
539 /* mark off calls below the current node */
540 void
541 markcall(NODE *p)
542 {
ragge
1.1
543
544         again:
ragge
1.13
545         switchp->n_op ){
ragge
1.1
546
547         case UNARY CALL:
548         case UNARY STCALL:
549         case UNARY FORTCALL:
550         case CALL:
551         case STCALL:
552         case FORTCALL:
553                 ++callflag;
554                 return;
555
556                 }
557
ragge
1.13
558         switchoptypep->n_op ) ){
ragge
1.1
559
560         case BITYPE:
ragge
1.13
561                 markcallp->n_right );
ragge
1.1
562         case UTYPE:
ragge
1.13
563                 p = p->n_left;
ragge
1.1
564                 /* eliminate recursion (aren't I clever...) */
565                 goto again;
566         case LTYPE:
567                 return;
568                 }
569
ragge
1.2
570 }
ragge
1.1
571
ragge
1.2
572 void
573 stoarg(NODE *pint calltype)
574 {
ragge
1.1
575         /* arrange to store the args */
ragge
1.13
576         ifp->n_op == CM ){
577                 stoargp->n_leftcalltype );
578                 p = p->n_right ;
ragge
1.1
579                 }
580         ifcalltype == CALL ){
581                 STOARG(p);
582                 }
583         else ifcalltype == STCALL ){
584                 STOSTARG(p);
585                 }
586         else {
587                 STOFARG(p);
588                 }
589         callflag = 0;
590         store(p);
ragge
1.30
591 #ifdef NO_NESTCALLS
ragge
1.1
592         ifcallflag ){ /* prevent two calls from being active at once  */
593                 SETSTO(p,INTEMP);
594                 store(p); /* do again to preserve bottom up nature....  */
ragge
1.2
595         }
ragge
1.1
596 #endif
ragge
1.2
597 }
ragge
1.1
598
599 int negrel[] = { NEEQGTGELTLEUGTUGEULTULE } ;  /* negatives of relationals */
600
ragge
1.2
601 /*
602  * evaluate p for truth value, and branch to true or false
603  * accordingly: label <0 means fall through
604  */
605
606 void
ragge
1.29
607 cbranch(NODE *pint false)
ragge
1.2
608 {
ragge
1.29
609         switch (p->n_op) {
ragge
1.1
610
611         case ULE:
612         case ULT:
613         case UGE:
614         case UGT:
615         case EQ:
616         case NE:
617         case LE:
618         case LT:
619         case GE:
620         case GT:
ragge
1.29
621                 p->n_op = negrel[p->n_op - EQ];
622                 p->n_label = false;
623                 codgen(pFORCC);
624                 reclaim(pRNULL0);
ragge
1.1
625                 return;
626
627         case ICON:
ragge
1.29
628                 if (p->n_type != FLOAT && p->n_type != DOUBLE) {
629                         if ((p->n_lval == 0) && (p->n_name[0] == 0))
630                                 cbgen(0false'I');
ragge
1.19
631                         nfree(p);
ragge
1.1
632                         return;
ragge
1.19
633                 }
ragge
1.1
634                 /* fall through to default with other strange constants */
635
636         default:
637                 /* get condition codes */
ragge
1.29
638                 codgen(pFORCC);
639                 cbgen(EQfalse'I');
640                 reclaim(pRNULL0);
ragge
1.1
641                 return;
642
643         }
ragge
1.29
644 }
ragge
1.1
645
ragge
1.2
646 void
647 rcount()
648 /* count recursions */
ragge
1.1
649         if( ++nrecur > NRECUR ){
650                 cerror"expression causes compiler loop: try simplifying" );
651         }
ragge
1.2
652 }
ragge
1.1
653
ragge
1.30
654 #ifdef PCC_DEBUG
ragge
1.2
655 int
ragge
1.8
656 e2print(NODE *pint downint *aint *b)
ragge
1.2
657 {
ragge
1.1
658
659         *a = *b = down+1;
660         whiledown >= 2 ){
661                 printf"\t" );
662                 down -= 2;
663                 }
664         ifdown-- ) printf"    " );
665
666
ragge
1.13
667         printf"%p) %s"popst[p->n_op] );
668         switchp->n_op ) { /* special cases */
ragge
1.1
669
670         case REG:
ragge
1.13
671                 printf" %s"rnames[p->n_rval] );
ragge
1.1
672                 break;
673
ragge
1.23
674         case TEMP:
675                 printf(" %d", (int)p->n_lval);
676                 break;
677
ragge
1.1
678         case ICON:
679         case NAME:
680         case OREG:
681                 printf" " );
682                 adrputp );
683                 break;
684
685         case STCALL:
686         case UNARY STCALL:
687         case STARG:
688         case STASG:
ragge
1.13
689                 printf" size=%d"p->n_stsize );
690                 printf" align=%d"p->n_stalign );
ragge
1.1
691                 break;
692                 }
693
694         printf", " );
ragge
1.13
695         tprintp->n_type );
ragge
1.1
696         printf", " );
ragge
1.13
697         ifp->n_rall == NOPREF ) printf"NOPREF" );
ragge
1.1
698         else {
ragge
1.13
699                 ifp->n_rall & MUSTDO ) printf"MUSTDO " );
ragge
1.1
700                 else printf"PREF " );
ragge
1.13
701                 printf"%s"rnames[p->n_rall&~MUSTDO]);
ragge
1.1
702                 }
ragge
1.13
703         printf", SU= %d\n"p->n_su );
ragge
1.2
704         return 0;
705 }
ragge
1.30
706 #endif
ragge
1.1
707
708 #ifndef FIELDOPS
ragge
1.7
709 /*
710  * do this if there is no special hardware support for fields
711  */
712 static int
713 ffld(NODE *pint downint *down1int *down2 )
714 {
715         /*
716          * look for fields that are not in an lvalue context,
717          * and rewrite them...
718          */
719         NODE *shp;
720         int sovty;
ragge
1.1
721
ragge
1.13
722         *down1 =  asgopp->n_op );
ragge
1.1
723         *down2 = 0;
724
ragge
1.13
725         if( !down && p->n_op == FLD ){ /* rewrite the node */
ragge
1.1
726
ragge
1.7
727                 if( !rewfld(p) ) return 0;
ragge
1.1
728
ragge
1.13
729                 ty = (szty(p->n_type) == 2)? LONGINT;
730                 v = p->n_rval;
ragge
1.1
731                 s = UPKFSZ(v);
732 # ifdef RTOLBYTES
733                 o = UPKFOFF(v);  /* amount to shift */
734 # else
ragge
1.13
735                 o = szty(p->n_type)*SZINT - s - UPKFOFF(v);  /* amount to shift */
ragge
1.1
736 #endif
737
738                 /* make & mask part */
739
ragge
1.13
740                 p->n_left->n_type = ty;
ragge
1.1
741
ragge
1.13
742                 p->n_op = AND;
743                 p->n_right = talloc();
744                 p->n_right->n_op = ICON;
745                 p->n_right->n_rall = NOPREF;
746                 p->n_right->n_type = ty;
747                 p->n_right->n_lval = 1;
748                 p->n_right->n_rval = 0;
749                 p->n_right->n_name = "";
750                 p->n_right->n_lval <<= s;
751                 p->n_right->n_lval--;
ragge
1.1
752
753                 /* now, if a shift is needed, do it */
754
755                 ifo != 0 ){
756                         shp = talloc();
ragge
1.13
757                         shp->n_op = RS;
758                         shp->n_rall = NOPREF;
759                         shp->n_type = ty;
760                         shp->n_left = p->n_left;
761                         shp->n_right = talloc();
762                         shp->n_right->n_op = ICON;
763                         shp->n_right->n_rall = NOPREF;
764                         shp->n_right->n_type = ty;
765                         shp->n_right->n_rval = 0;
766                         shp->n_right->n_lval = o;  /* amount to shift */
767                         shp->n_right->n_name = "";
768                         p->n_left = shp;
ragge
1.1
769                         /* whew! */
770                 }
771         }
ragge
1.7
772         return 0;
773 }
ragge
1.1
774 #endif
775
ragge
1.23
776 /*
777  * change left TEMPs into OREGs
778  * look for situations where we can turn * into OREG
779  */
ragge
1.2
780 void
781 oreg2(NODE *p)
782 {
ragge
1.1
783
784         NODE *q;
ragge
1.2
785         int r;
786         char *cp;
787         NODE *ql, *qr;
ragge
1.1
788         CONSZ temp;
ragge
1.23
789
790         /*
791          * the size of a TEMP is on multiples of the reg size.
792          */
793         if (p->n_op == TEMP) {
794                 struct templst *w = templst;
795                 p->n_op = OREG;
796                 p->n_rval = FPREG;
797                 while (w != NULL) {
798                         if (w->tempnr == p->n_lval)
799                                 break;
800                         w = w->next;
801                 }
802                 if (w == NULL) {
803                         w = tmpalloc(sizeof(struct templst));
804                         w->tempnr = p->n_lval;
805                         w->tempoff = BITOOR(freetemp(szty(p->n_type)));
806                         w->next = templst;
807                         templst = w;
808                 }
809                 p->n_lval = w->tempoff;
810                 p->n_name = "";
811                 return;
812         }
ragge
1.1
813
ragge
1.13
814         if (p->n_op == UNARY MUL) {
815                 q = p->n_left;
816                 if (q->n_op == REG) {
817                         temp = q->n_lval;
818                         r = q->n_rval;
819                         cp = q->n_name;
ragge
1.1
820                         goto ormake;
ragge
1.12
821                 }
ragge
1.1
822
ragge
1.13
823                 if (q->n_op != PLUS && q->n_op != MINUS)
ragge
1.12
824                         return;
ragge
1.13
825                 ql = q->n_left;
826                 qr = q->n_right;
ragge
1.1
827
828 #ifdef R2REGS
829
830                 /* look for doubly indexed expressions */
831
ragge
1.13
832                 ifq->n_op == PLUS) {
ragge
1.7
833                         int i;
ragge
1.1
834                         if( (r=base(ql))>=0 && (i=offset(qrtlen(p)))>=0) {
835                                 makeor2(pqlri);
836                                 return;
ragge
1.12
837                         } else if((r=base(qr))>=0 && (i=offset(qltlen(p)))>=0) {
ragge
1.1
838                                 makeor2(pqrri);
839                                 return;
840                         }
ragge
1.12
841                 }
ragge
1.1
842
843
844 #endif
845
ragge
1.13
846                 if( (q->n_op==PLUS || q->n_op==MINUS) && qr->n_op == ICON &&
847                                 ql->n_op==REG && szty(qr->n_type)==1) {
848                         temp = qr->n_lval;
849                         ifq->n_op == MINUS ) temp = -temp;
850                         r = ql->n_rval;
851                         temp += ql->n_lval;
852                         cp = qr->n_name;
853                         if( *cp && ( q->n_op == MINUS || *ql->n_name ) ) return;
854                         if( !*cp ) cp = ql->n_name;
ragge
1.1
855
856                         ormake:
ragge
1.13
857                         ifnotoffp->n_typertempcp ) ) return;
858                         p->n_op = OREG;
859                         p->n_rval = r;
860                         p->n_lval = temp;
861                         p->n_name = cp;
ragge
1.1
862                         tfree(q);
863                         return;
864                 }
865         }
ragge
1.12
866 }
ragge
1.1
867
ragge
1.2
868 void
ragge
1.1
869 canon(pNODE *p; {
870         /* put p in canonical form */
871
872 #ifndef FIELDOPS
873         fwalkpffld0 ); /* look for field operators */
874 # endif
875         walkfporeg2 );  /* look for and create OREG nodes */
876 #ifdef MYCANON
877         MYCANON(p);  /* your own canonicalization routine(s) */
878 #endif
879         walkfpsucomp );  /* do the Sethi-Ullman computation */
880
ragge
1.2
881 }
ragge
1.1
882
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-10-31 14:39 +0100