Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030804105953

Diff

Diff from 1.39 to:

Annotations

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

Annotated File View

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