From 49366d1334b5c80cbf949b8c2bb82786d831a7c4 Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 26 Aug 2004 03:51:51 +0000 Subject: [PATCH] Add the $is_signed function. --- README.txt | 5 +++++ elab_expr.cc | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 2db9eb32d..646877abc 100644 --- a/README.txt +++ b/README.txt @@ -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() + This system function returns 1 if the expression contained is + signed, or 0 otherwise. This is mostly of use for compiler + regression tests. + $sizeof() $bits() The $bits system function returns the size in bits of the diff --git a/elab_expr.cc b/elab_expr.cc index dd780a66e..9820d1a7b 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -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. *