Add the $is_signed function.

This commit is contained in:
steve 2004-08-26 03:51:51 +00:00
parent e2b94947f5
commit 49366d1334
2 changed files with 33 additions and 1 deletions

View File

@ -364,6 +364,11 @@ IEEE1364 standard, but have well defined meaning, and also sometimes
gives nonstandard (but extended) meanings to some features of the
language that are defined.
$is_signed(<expr>)
This system function returns 1 if the expression contained is
signed, or 0 otherwise. This is mostly of use for compiler
regression tests.
$sizeof(<expr>)
$bits(<expr>)
The $bits system function returns the size in bits of the

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: elab_expr.cc,v 1.88 2004/06/17 16:06:18 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.89 2004/08/26 03:52:07 steve Exp $"
#endif
# include "config.h"
@ -221,6 +221,30 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
return sub;
}
/* Interpret the internal $is_signed system function to return
a single bit flag -- 1 if the expression is signed, 0
otherwise. The subexpression is elaborated but not
evaluated. */
if (strcmp(path_.peek_name(0), "$is_signed") == 0) {
if ((parms_.count() != 1) || (parms_[0] == 0)) {
cerr << get_line() << ": error: The $is_signed() function "
<< "takes exactly one(1) argument." << endl;
des->errors += 1;
return 0;
}
PExpr*expr = parms_[0];
NetExpr*sub = expr->elaborate_expr(des, scope, true);
verinum val (sub->has_sign()? verinum::V1 : verinum::V0, 1);
delete sub;
sub = new NetEConst(val);
sub->set_line(*this);
return sub;
}
/* Get the return type of the system function by looking it up
in the sfunc_table. */
const struct sfunc_return_type*sfunc_info
@ -967,6 +991,9 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
* Revision 1.89 2004/08/26 03:52:07 steve
* Add the $is_signed function.
*
* Revision 1.88 2004/06/17 16:06:18 steve
* Help system function signedness survive elaboration.
*