Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.243
 
1.244
 
MAIN:ragge:20081116211741
 
reader.c
_>141141  * Check that the trees are in a suitable state for pass2.
 142142  */
 143143 static void
<>144 -sanitychecks(void)
  144+sanitychecks(struct p2env *p2e)
145145 {
 146146         struct interpass *ip;
 147147         int i;
 148148 #ifdef notyet
 149149         TMPMARK();
 150150 #endif
<>151 -        lbldef = tmpcalloc(sizeof(int) * (p2env.epp->ip_lblnum - p2env.ipp->ip_lblnum));
 152 -        lbluse = tmpcalloc(sizeof(int) * (p2env.epp->ip_lblnum - p2env.ipp->ip_lblnum));
  151+        lbldef = tmpcalloc(sizeof(int) * (p2e->epp->ip_lblnum - p2e->ipp->ip_lblnum));
  152+        lbluse = tmpcalloc(sizeof(int) * (p2e->epp->ip_lblnum - p2e->ipp->ip_lblnum));
153153 
 154154         DLIST_FOREACH(ip, &p2env.ipole, qelem) {
 155155                 if (ip->type == IP_DEFLAB) {
 156156                         i = ip->ip_lbl;
<>157 -                        if (i < p2env.ipp->ip_lblnum || i >= p2env.epp->ip_lblnum)
  157+                        if (i < p2e->ipp->ip_lblnum || i >= p2e->epp->ip_lblnum)
158158                                 cerror("label %d outside boundaries %d-%d",
<>159 -                                    i, p2env.ipp->ip_lblnum, p2env.epp->ip_lblnum);
 160 -                        lbldef[i-p2env.ipp->ip_lblnum] = 1;
  159+                                    i, p2e->ipp->ip_lblnum, p2e->epp->ip_lblnum);
  160+                        lbldef[i-p2e->ipp->ip_lblnum] = 1;
161161                 }
 162162                 if (ip->type == IP_NODE)
 163163                         walkf(ip->ip_node, cktree, 0);
 164164         }
<>165 -        for (i = 0; i < (p2env.epp->ip_lblnum - p2env.ipp->ip_lblnum); i++)
  165+        for (i = 0; i < (p2e->epp->ip_lblnum - p2e->ipp->ip_lblnum); i++)
166166                 if (lbluse[i] != 0 && lbldef[i] == 0)
 167167                         cerror("internal label %d not defined",
<>168 -                            i + p2env.ipp->ip_lblnum);
  168+                            i + p2e->ipp->ip_lblnum);
169169 
 170170 #ifdef notyet
 171171         TMPFREE();
     
 !
174174 #endif
 175175 
 176176 /*
<> 177+ * Look if a temporary comes from a on-stack argument, in that case
  178+ * use the already existing stack position instead of moving it to
  179+ * a new place, and remove the move-to-temp statement.
  180+ */
  181+static int
  182+stkarg(int tnr, int *soff)
  183+{
  184+        struct p2env *p2e = &p2env;
  185+        struct interpass *ip;
  186+        NODE *p;
  187+
  188+        ip = DLIST_NEXT((struct interpass *)p2e->ipp, qelem); /* first DEFLAB */
  189+        ip = DLIST_NEXT(ip, qelem); /* first NODE */
  190+
  191+        for (; ip->type != IP_DEFLAB; ip = DLIST_NEXT(ip, qelem)) {
  192+                if (ip->type != IP_NODE)
  193+                        continue;
  194+
  195+                p = ip->ip_node;
  196+#ifdef PCC_DEBUG
  197+                if (p->n_op != ASSIGN || p->n_left->n_op != TEMP)
  198+                        comperr("temparg");
  199+#endif
  200+                if (p->n_right->n_op != OREG && p->n_right->n_op != UMUL)
  201+                        continue; /* arg in register */
  202+                if (tnr != regno(p->n_left))
  203+                        continue; /* wrong assign */
  204+                p = p->n_right;
  205+                if (p->n_op == UMUL &&
  206+                    p->n_left->n_op == PLUS &&
  207+                    p->n_left->n_left->n_op == REG &&
  208+                    p->n_left->n_right->n_op == ICON)
  209+                        *soff = p->n_left->n_right->n_lval;
  210+                else if (p->n_op == OREG)
  211+                        *soff = p->n_lval;
  212+                else
  213+                        comperr("stkarg: bad arg");
  214+                tfree(ip->ip_node);
  215+                DLIST_REMOVE(ip, qelem);
  216+                return 1;
  217+        }
  218+        return 0;
  219+}
  220+
  221+/*
  222+ * See if an ADDROF is somewhere inside the expression tree.
  223+ * If so, fill in the offset table.
  224+ */
  225+static void
  226+findaof(NODE *p, void *arg)
  227+{
  228+        int *aof = arg;
  229+        int tnr;
  230+
  231+        if (p->n_op != ADDROF)
  232+                return;
  233+        tnr = regno(p->n_left);
  234+        if (aof[tnr])
  235+                return; /* already gotten stack address */
  236+        if (stkarg(tnr, &aof[tnr]))
  237+                return/* argument was on stack */
  238+        aof[tnr] = BITOOR(freetemp(szty(p->n_left->n_type)));
  239+}
  240+
  241+/*
177242  * Check if a node has side effects.
 178243  */
 179244 static int
     
 !
244309 void
 245310 pass2_compile(struct interpass *ip)
 246311 {
<> 312+        struct p2env *p2e = &p2env;
  313+        int *addrp;
  314+
247315         if (ip->type == IP_PROLOG) {
<>248 -                memset(&p2env, 0, sizeof(struct p2env));
  316+                memset(p2e, 0, sizeof(struct p2env));
249317                 tmpsave = NULL;
<>250 -                p2env.ipp = (struct interpass_prolog *)ip;
 251 -                DLIST_INIT(&p2env.ipole, qelem);
  318+                p2e->ipp = (struct interpass_prolog *)ip;
  319+                DLIST_INIT(&p2e->ipole, qelem);
252320         }
<>253 -        DLIST_INSERT_BEFORE(&p2env.ipole, ip, qelem);
  321+        DLIST_INSERT_BEFORE(&p2e->ipole, ip, qelem);
254322         if (ip->type != IP_EPILOG)
 255323                 return;
 256324 
 257325 #ifdef PCC_DEBUG
 258326         if (e2debug) {
 259327                 printf("Entering pass2\n");
<>260 -                printip(&p2env.ipole);
  328+                printip(&p2e->ipole);
261329         }
 262330 #endif
 263331 
<>264 -        p2env.epp = (struct interpass_prolog *)DLIST_PREV(&p2env.ipole, qelem);
 265 -        p2maxautooff = p2autooff = p2env.epp->ipp_autos;
  332+        p2e->epp = (struct interpass_prolog *)DLIST_PREV(&p2e->ipole, qelem);
  333+        p2maxautooff = p2autooff = p2e->epp->ipp_autos;
266334 
 267335 #ifdef PCC_DEBUG
<>268 -        sanitychecks();
  336+        sanitychecks(p2e);
269337 #endif
<>270 -        myreader(&p2env.ipole); /* local massage of input */
  338+        myreader(&p2e->ipole); /* local massage of input */
271339 
<>272 -        DLIST_FOREACH(ip, &p2env.ipole, qelem) {
  340+        /*
  341+         * Do initial modification of the trees.  Two loops;
  342+         * - first, search for ADDROF of TEMPs, these must be
  343+         *   converterd to OREGs on stack.
  344+         * - second, do the actual conversions, in case of not xtemps
  345+         *   convert all temporaries to stack references.
  346+         */
  347+#ifdef notyet
  348+        TMPMARK();
  349+#endif
  350+        if (p2e->epp->ip_tmpnum != p2e->ipp->ip_tmpnum) {
  351+                addrp = tmpcalloc(sizeof(int) *
  352+                    (p2e->epp->ip_tmpnum - p2e->ipp->ip_tmpnum));
  353+                addrp -= p2e->ipp->ip_tmpnum;
  354+        } else
  355+                addrp = NULL;
  356+        if (xtemps) {
  357+                DLIST_FOREACH(ip, &p2e->ipole, qelem) {
  358+                        if (ip->type == IP_NODE)
  359+                                walkf(ip->ip_node, findaof, addrp);
  360+                }
  361+        }
  362+        DLIST_FOREACH(ip, &p2e->ipole, qelem) {
  363+                if (ip->type == IP_NODE)
  364+                        walkf(ip->ip_node, deltemp, addrp);
  365+        }
  366+
  367+#ifdef notyet
  368+        TMPFREE();
  369+#endif
  370+
  371+#ifdef PCC_DEBUG
  372+        if (e2debug) {
  373+                printf("Efter ADDROF/TEMP\n");
  374+                printip(&p2e->ipole);
  375+        }
  376+#endif
  377+
  378+#if 0
  379+        DLIST_FOREACH(ip, &p2e->ipole, qelem) {
273380                 if (ip->type != IP_NODE)
 274381                         continue;
 275382                 if (xtemps == 0)
 276383                         walkf(ip->ip_node, deltemp, 0);
 277384         }
<> 385+#endif
  386+
278387         DLIST_INIT(&prepole, qelem);
<>279 -        DLIST_FOREACH(ip, &p2env.ipole, qelem) {
  388+        DLIST_FOREACH(ip, &p2e->ipole, qelem) {
280389                 if (ip->type != IP_NODE)
 281390                         continue;
 282391                 canon(ip->ip_node);
     
 !
291400                 }
 292401         }
 293402 
<>294 -        fixxasm(&p2env); /* setup for extended asm */
  403+        fixxasm(p2e); /* setup for extended asm */
295404 
<>296 -        optimize(&p2env);
 297 -        ngenregs(&p2env);
  405+        optimize(p2e);
  406+        ngenregs(p2e);
298407 
<>299 -        DLIST_FOREACH(ip, &p2env.ipole, qelem)
  408+        DLIST_FOREACH(ip, &p2e->ipole, qelem)
300409                 emit(ip);
 301410 }
 302411 
     
 !
10031112 void
 10041113 deltemp(NODE *p, void *arg)
 10051114 {
<>1006 -        struct tmpsave *w;
  1115+        int *aor = arg;
10071116         NODE *l, *r;
 10081117 
 10091118         if (p->n_op == TEMP) {
<>1010 -                /* Check if already existing */
 1011 -                for (w = tmpsave; w; w = w->next)
 1012 -                        if (w->tempno == regno(p))
 1013 -                                break;
 1014 -                if (w == NULL) {
 1015 -                        /* new on stack */
 1016 -                        w = tmpalloc(sizeof(struct tmpsave));
 1017 -                        w->tempno = regno(p);
 1018 -                        w->tempaddr = BITOOR(freetemp(szty(p->n_type)));
 1019 -                        w->next = tmpsave;
 1020 -                        tmpsave = w;
  1119+                if (aor[regno(p)] == 0) {
  1120+                        if (xtemps)
  1121+                                return;
  1122+                        aor[regno(p)] = BITOOR(freetemp(szty(p->n_type)));
10211123                 }
 10221124                 l = mklnode(REG, 0, FPREG, INCREF(p->n_type));
<>1023 -                r = mklnode(ICON, w->tempaddr, 0, INT);
  1125+                r = mklnode(ICON, aor[regno(p)], 0, INT);
10241126                 p->n_left = mkbinode(PLUS, l, r, INCREF(p->n_type));
 10251127                 p->n_op = UMUL;
<>1026 -        } else if (p->n_op == ADDROF && p->n_left->n_op != NAME) {
 1027 -                /* TEMPs are already converted to OREGs */
 1028 -                if ((l = p->n_left)->n_op != OREG)
 1029 -                        comperr("bad U&");
  1128+        } else if (p->n_op == ADDROF && p->n_left->n_op == OREG) {
10301129                 p->n_op = PLUS;
<> 1130+                l = p->n_left;
10311131                 l->n_op = REG;
 10321132                 l->n_type = INCREF(l->n_type);
 10331133                 p->n_right = mklnode(ICON, l->n_lval, 0, INT);
<> 1134+        } else if (p->n_op == ADDROF && p->n_left->n_op == UMUL) {
  1135+                l = p->n_left;
  1136+                *p = *p->n_left->n_left;
  1137+                nfree(l->n_left);
  1138+                nfree(l);
<_10341139         }
 10351140 }
 10361141 
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-02 18:37 +0200