diff options
author | Peter Johnson <peter@tortall.net> | 2001-11-01 03:51:26 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2001-11-01 03:51:26 +0000 |
commit | 79e945c33c1ebc4c1946d1df32ed02bec2b9fb4e (patch) | |
tree | a824df270a52a3858cc21ecd3d303d02d5c4f3d4 /libyasm | |
parent | ad7cbcea04cd2011d352f0e3a9984f43fdfd565f (diff) | |
download | yasm-79e945c33c1ebc4c1946d1df32ed02bec2b9fb4e.tar.gz |
Optimize expression building a bit in expr_new() by eliminating IDENT's here.
This saves a lot of extra unnecessary recursions when the expr gets to the
simplification stage.
svn path=/trunk/yasm/; revision=310
Diffstat (limited to 'libyasm')
-rw-r--r-- | libyasm/expr.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/libyasm/expr.c b/libyasm/expr.c index 938a6b2c..17a73738 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -96,7 +96,7 @@ static int expr_traverse_leaves_in(expr *e, void *d, int (*func) (ExprItem *ei, void *d)); /* allocate a new expression node, with children as defined. - * If it's a unary operator, put the element on the right */ + * If it's a unary operator, put the element in left and set right=NULL. */ expr * expr_new(ExprOp op, ExprItem *left, ExprItem *right) { @@ -108,17 +108,37 @@ expr_new(ExprOp op, ExprItem *left, ExprItem *right) ptr->terms[0].type = EXPR_NONE; ptr->terms[1].type = EXPR_NONE; if (left) { - memcpy(&ptr->terms[0], left, sizeof(ExprItem)); + ptr->terms[0] = *left; /* structure copy */ xfree(left); ptr->numterms++; + + /* Search downward until we find something *other* than an + * IDENT, then bring it up to the current level. + */ + while (ptr->terms[0].type == EXPR_EXPR && + ptr->terms[0].data.expn->op == EXPR_IDENT) { + expr *sube = ptr->terms[0].data.expn; + ptr->terms[0] = sube->terms[0]; /* structure copy */ + xfree(sube); + } } else { InternalError(_("Right side of expression must exist")); } if (right) { - memcpy(&ptr->terms[1], right, sizeof(ExprItem)); + ptr->terms[1] = *right; /* structure copy */ xfree(right); ptr->numterms++; + + /* Search downward until we find something *other* than an + * IDENT, then bring it up to the current level. + */ + while (ptr->terms[1].type == EXPR_EXPR && + ptr->terms[1].data.expn->op == EXPR_IDENT) { + expr *sube = ptr->terms[1].data.expn; + ptr->terms[1] = sube->terms[0]; /* structure copy */ + xfree(sube); + } } ptr->filename = in_filename; |