Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030803211559

Diff

Diff from 1.37 to:

Annotations

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

Annotated File View

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