Support $signed cast of expressions.

This commit is contained in:
steve 2001-12-31 00:08:14 +00:00
parent e20acfc9f9
commit 51db00fb44
4 changed files with 50 additions and 23 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: elab_expr.cc,v 1.47 2001/12/29 20:41:30 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.48 2001/12/31 00:08:14 steve Exp $"
#endif
# include "config.h"
@ -162,6 +162,26 @@ NetEBinary* PEBinary::elaborate_expr_base_(Design*des,
*/
NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
{
/* Catch the special case that the system function is the
$signed function. This function is special, in that it does
not lead to executable code but takes the single parameter
and makes it into a signed expression. No bits are changed,
it just changes the interpretation. */
if (strcmp(path_.peek_name(0), "$signed") == 0) {
if ((parms_.count() != 1) || (parms_[0] == 0)) {
cerr << get_line() << ": error: The $signed() function "
<< "takes exactly one(1) argument." << endl;
des->errors += 1;
return 0;
}
PExpr*expr = parms_[0];
NetExpr*sub = expr->elaborate_expr(des, scope);
sub->cast_signed(true);
return sub;
}
unsigned wid = 32;
if (strcmp(path_.peek_name(0), "$time") == 0)
@ -651,6 +671,9 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope) const
/*
* $Log: elab_expr.cc,v $
* Revision 1.48 2001/12/31 00:08:14 steve
* Support $signed cast of expressions.
*
* Revision 1.47 2001/12/29 20:41:30 steve
* Allow escaped $ in identifiers.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: netlist.cc,v 1.178 2001/12/03 04:47:15 steve Exp $"
#ident "$Id: netlist.cc,v 1.179 2001/12/31 00:08:14 steve Exp $"
#endif
# include "config.h"
@ -1789,7 +1789,7 @@ const NetScope* NetUTask::task() const
}
NetExpr::NetExpr(unsigned w)
: width_(w)
: width_(w), signed_flag_(false)
{
}
@ -1799,7 +1799,12 @@ NetExpr::~NetExpr()
bool NetExpr::has_sign() const
{
return false;
return signed_flag_;
}
void NetExpr::cast_signed(bool flag)
{
signed_flag_ = flag;
}
bool NetExpr::has_width() const
@ -2046,6 +2051,7 @@ NetEConcat* NetEConcat::dup_expr() const
NetEConst::NetEConst(const verinum&val)
: NetExpr(val.len()), value_(val)
{
cast_signed(value_.has_sign());
}
NetEConst::~NetEConst()
@ -2057,11 +2063,6 @@ const verinum& NetEConst::value() const
return value_;
}
bool NetEConst::has_sign() const
{
return value_.has_sign();
}
bool NetEConst::has_width() const
{
return value_.has_len();
@ -2214,6 +2215,7 @@ NetESignal::NetESignal(NetNet*n)
lsi_ = 0;
net_->incr_eref();
set_line(*n);
cast_signed(net_->get_signed());
}
NetESignal::NetESignal(NetNet*n, unsigned m, unsigned l)
@ -2224,6 +2226,7 @@ NetESignal::NetESignal(NetNet*n, unsigned m, unsigned l)
lsi_ = l;
net_->incr_eref();
set_line(*n);
cast_signed(net_->get_signed());
}
NetESignal::~NetESignal()
@ -2236,11 +2239,6 @@ string NetESignal::name() const
return net_->name();
}
bool NetESignal::has_sign() const
{
return net_->get_signed();
}
unsigned NetESignal::bit_count() const
{
return msi_ - lsi_ + 1;
@ -2407,6 +2405,9 @@ const NetProc*NetTaskDef::proc() const
/*
* $Log: netlist.cc,v $
* Revision 1.179 2001/12/31 00:08:14 steve
* Support $signed cast of expressions.
*
* Revision 1.178 2001/12/03 04:47:15 steve
* Parser and pform use hierarchical names as hname_t
* objects instead of encoded strings.

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: netlist.h,v 1.227 2001/12/03 04:47:15 steve Exp $"
#ident "$Id: netlist.h,v 1.228 2001/12/31 00:08:14 steve Exp $"
#endif
/*
@ -847,7 +847,8 @@ class NetExpr : public LineInfo {
// This method returns true if the expression is
// signed. Unsigned expressions return false.
virtual bool has_sign() const;
bool has_sign() const;
void cast_signed(bool flag);
// This returns true if the expression has a definite
// width. This is generally true, but in some cases the
@ -880,6 +881,7 @@ class NetExpr : public LineInfo {
private:
unsigned width_;
bool signed_flag_;
private: // not implemented
NetExpr(const NetExpr&);
@ -901,7 +903,6 @@ class NetEConst : public NetExpr {
virtual bool set_width(unsigned w);
virtual bool has_sign() const;
virtual bool has_width() const;
virtual void expr_scan(struct expr_scan_t*) const;
@ -2501,10 +2502,6 @@ class NetESignal : public NetExpr {
NetESignal(NetNet*n, unsigned msi, unsigned lsi);
~NetESignal();
// a NetESignal expression is signed if the NetNet that it
// refers to is signed.
bool has_sign() const;
string name() const;
virtual bool set_width(unsigned);
@ -2867,6 +2864,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/*
* $Log: netlist.h,v $
* Revision 1.228 2001/12/31 00:08:14 steve
* Support $signed cast of expressions.
*
* Revision 1.227 2001/12/03 04:47:15 steve
* Parser and pform use hierarchical names as hname_t
* objects instead of encoded strings.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) & !defined(macintosh)
#ident "$Id: t-dll-expr.cc,v 1.20 2001/10/23 04:22:41 steve Exp $"
#ident "$Id: t-dll-expr.cc,v 1.21 2001/12/31 00:08:14 steve Exp $"
#endif
# include "config.h"
@ -127,7 +127,7 @@ void dll_target::expr_const(const NetEConst*net)
char*bits;
expr_->type_ = IVL_EX_NUMBER;
expr_->width_= net->expr_width();
expr_->signed_ = val.has_sign()? 1 : 0;
expr_->signed_ = net->has_sign()? 1 : 0;
expr_->u_.number_.bits_ = bits = (char*)malloc(expr_->width_);
for (idx = 0 ; idx < expr_->width_ ; idx += 1)
switch (val.get(idx)) {
@ -347,6 +347,9 @@ void dll_target::expr_unary(const NetEUnary*net)
/*
* $Log: t-dll-expr.cc,v $
* Revision 1.21 2001/12/31 00:08:14 steve
* Support $signed cast of expressions.
*
* Revision 1.20 2001/10/23 04:22:41 steve
* Support bit selects of non-0 lsb for vectors.
*