From adfc2e10c969115df94dbe29d291274deb2ca595 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 18 Mar 2002 08:00:39 +0000 Subject: [PATCH] Add expr_get_floatnum(). svn path=/trunk/yasm/; revision=529 --- libyasm/expr.c | 13 +++++++++++++ libyasm/expr.h | 6 ++++++ src/expr.c | 13 +++++++++++++ src/expr.h | 6 ++++++ 4 files changed, 38 insertions(+) diff --git a/libyasm/expr.c b/libyasm/expr.c index 119e36b1..d4774087 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -845,6 +845,19 @@ expr_get_intnum(expr **ep) } /*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ +/*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ +const floatnum * +expr_get_floatnum(expr **ep) +{ + *ep = expr_simplify(*ep); + + if ((*ep)->op == EXPR_IDENT && (*ep)->terms[0].type == EXPR_FLOAT) + return (*ep)->terms[0].data.flt; + else + return (floatnum *)NULL; +} +/*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ + /*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ const symrec * expr_get_symrec(expr **ep, int simplify) diff --git a/libyasm/expr.h b/libyasm/expr.h index 76476866..d76a5d4f 100644 --- a/libyasm/expr.h +++ b/libyasm/expr.h @@ -66,6 +66,12 @@ void expr_expand_labelequ(expr *e, const section *srcsect, int withstart, */ /*@dependent@*/ /*@null@*/ const intnum *expr_get_intnum(expr **ep); +/* Gets the float value of e if the expression is just an float. If the + * expression is more complex (contains anything other than floats, ie + * integers, non-valued labels, registers), returns NULL. + */ +/*@dependent@*/ /*@null@*/ const floatnum *expr_get_floatnum(expr **ep); + /* Gets the symrec value of e if the expression is just an symbol. If the * expression is more complex, returns NULL. Simplifies the expr first if * simplify is nonzero. diff --git a/src/expr.c b/src/expr.c index 119e36b1..d4774087 100644 --- a/src/expr.c +++ b/src/expr.c @@ -845,6 +845,19 @@ expr_get_intnum(expr **ep) } /*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ +/*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ +const floatnum * +expr_get_floatnum(expr **ep) +{ + *ep = expr_simplify(*ep); + + if ((*ep)->op == EXPR_IDENT && (*ep)->terms[0].type == EXPR_FLOAT) + return (*ep)->terms[0].data.flt; + else + return (floatnum *)NULL; +} +/*@=unqualifiedtrans =nullderef -nullstate -onlytrans@*/ + /*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ const symrec * expr_get_symrec(expr **ep, int simplify) diff --git a/src/expr.h b/src/expr.h index 76476866..d76a5d4f 100644 --- a/src/expr.h +++ b/src/expr.h @@ -66,6 +66,12 @@ void expr_expand_labelequ(expr *e, const section *srcsect, int withstart, */ /*@dependent@*/ /*@null@*/ const intnum *expr_get_intnum(expr **ep); +/* Gets the float value of e if the expression is just an float. If the + * expression is more complex (contains anything other than floats, ie + * integers, non-valued labels, registers), returns NULL. + */ +/*@dependent@*/ /*@null@*/ const floatnum *expr_get_floatnum(expr **ep); + /* Gets the symrec value of e if the expression is just an symbol. If the * expression is more complex, returns NULL. Simplifies the expr first if * simplify is nonzero. -- 2.50.0