From: Peter Johnson Date: Sun, 18 Nov 2001 15:51:47 +0000 (-0000) Subject: New function: expr_get_symrec(). X-Git-Tag: v0.1.0~192 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29f7d9a917336b2d06a2f4c84fedd81c70d76cb4;p=yasm New function: expr_get_symrec(). svn path=/trunk/yasm/; revision=338 --- diff --git a/libyasm/expr.c b/libyasm/expr.c index ebacf7f5..0ca5f0a2 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -815,6 +815,20 @@ expr_get_intnum(expr **ep) } /*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ +/*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ +const symrec * +expr_get_symrec(expr **ep, int simplify) +{ + if (simplify) + *ep = expr_simplify(*ep); + + if ((*ep)->op == EXPR_IDENT && (*ep)->terms[0].type == EXPR_SYM) + return (*ep)->terms[0].data.sym; + else + return (symrec *)NULL; +} +/*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ + void expr_print(expr *e) { diff --git a/libyasm/expr.h b/libyasm/expr.h index 25149938..73fa151b 100644 --- a/libyasm/expr.h +++ b/libyasm/expr.h @@ -62,6 +62,13 @@ void expr_expand_equ(expr *e); */ /*@dependent@*/ /*@null@*/ const intnum *expr_get_intnum(expr **ep); +/* Gets the symrec value of e if the expression is just an integer. If the + * expression is more complex, returns NULL. Simplifies the expr first if + * simplify is nonzero. + */ +/*@dependent@*/ /*@null@*/ const symrec *expr_get_symrec(expr **ep, + int simplify); + void expr_print(expr *); #endif diff --git a/src/expr.c b/src/expr.c index ebacf7f5..0ca5f0a2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -815,6 +815,20 @@ expr_get_intnum(expr **ep) } /*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ +/*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ +const symrec * +expr_get_symrec(expr **ep, int simplify) +{ + if (simplify) + *ep = expr_simplify(*ep); + + if ((*ep)->op == EXPR_IDENT && (*ep)->terms[0].type == EXPR_SYM) + return (*ep)->terms[0].data.sym; + else + return (symrec *)NULL; +} +/*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ + void expr_print(expr *e) { diff --git a/src/expr.h b/src/expr.h index 25149938..73fa151b 100644 --- a/src/expr.h +++ b/src/expr.h @@ -62,6 +62,13 @@ void expr_expand_equ(expr *e); */ /*@dependent@*/ /*@null@*/ const intnum *expr_get_intnum(expr **ep); +/* Gets the symrec value of e if the expression is just an integer. If the + * expression is more complex, returns NULL. Simplifies the expr first if + * simplify is nonzero. + */ +/*@dependent@*/ /*@null@*/ const symrec *expr_get_symrec(expr **ep, + int simplify); + void expr_print(expr *); #endif