summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-09-22 14:41:42 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-09-22 14:41:42 +0000
commitc5e4e121ed8fb666deddb96a068168d2bbdfddc7 (patch)
tree8d577b04785d385d4ac19693531eee481d916e8d
parent2f4c0f7fcd17f93623ae8c6f7faebd9d1dc00dad (diff)
Pull form ragge's repo:
Repair delusesless() so that it will prepend subexpressions correctly.
-rw-r--r--usr.bin/pcc/mip/reader.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/usr.bin/pcc/mip/reader.c b/usr.bin/pcc/mip/reader.c
index 96adfb16c79..11b980e8988 100644
--- a/usr.bin/pcc/mip/reader.c
+++ b/usr.bin/pcc/mip/reader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reader.c,v 1.2 2007/09/15 22:04:39 ray Exp $ */
+/* $OpenBSD: reader.c,v 1.3 2007/09/22 14:41:41 otto Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -86,6 +86,7 @@ int p2autooff, p2maxautooff;
NODE *nodepole;
FILE *prfil;
+static struct interpass prepole;
void saveip(struct interpass *ip);
void deljumps(void);
@@ -181,12 +182,8 @@ deluseless(NODE *p)
r = deluseless(p->n_right);
nfree(p);
if (l && r) {
- /* Put left on queue first */
- ip = tmpalloc(sizeof(*ip));
- ip->type = IP_NODE;
- ip->lineno = 0; /* XXX */
- ip->ip_node = l;
- pass2_compile(ip);
+ ip = ipnode(l);
+ DLIST_INSERT_AFTER(&prepole, ip, qelem);
return r;
} else if (l)
return l;
@@ -231,13 +228,21 @@ pass2_compile(struct interpass *ip)
if (xtemps == 0)
walkf(ip->ip_node, deltemp);
}
+ DLIST_INIT(&prepole, qelem);
DLIST_FOREACH(ip, &ipole, qelem) {
if (ip->type != IP_NODE)
continue;
canon(ip->ip_node);
walkf(ip->ip_node, cktree);
- if ((ip->ip_node = deluseless(ip->ip_node)) == NULL)
+ if ((ip->ip_node = deluseless(ip->ip_node)) == NULL) {
DLIST_REMOVE(ip, qelem);
+ } else while (!DLIST_ISEMPTY(&prepole, qelem)) {
+ struct interpass *ipp;
+
+ ipp = DLIST_NEXT(&prepole, qelem);
+ DLIST_REMOVE(ipp, qelem);
+ DLIST_INSERT_BEFORE(ip, ipp, qelem);
+ }
}
optimize(&ipole);