Support $signed cast of expressions.
This commit is contained in:
parent
e20acfc9f9
commit
51db00fb44
25
elab_expr.cc
25
elab_expr.cc
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#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
|
#endif
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
@ -162,6 +162,26 @@ NetEBinary* PEBinary::elaborate_expr_base_(Design*des,
|
||||||
*/
|
*/
|
||||||
NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
|
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;
|
unsigned wid = 32;
|
||||||
|
|
||||||
if (strcmp(path_.peek_name(0), "$time") == 0)
|
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 $
|
* $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
|
* Revision 1.47 2001/12/29 20:41:30 steve
|
||||||
* Allow escaped $ in identifiers.
|
* Allow escaped $ in identifiers.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
27
netlist.cc
27
netlist.cc
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#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
|
#endif
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
@ -1789,7 +1789,7 @@ const NetScope* NetUTask::task() const
|
||||||
}
|
}
|
||||||
|
|
||||||
NetExpr::NetExpr(unsigned w)
|
NetExpr::NetExpr(unsigned w)
|
||||||
: width_(w)
|
: width_(w), signed_flag_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1799,7 +1799,12 @@ NetExpr::~NetExpr()
|
||||||
|
|
||||||
bool NetExpr::has_sign() const
|
bool NetExpr::has_sign() const
|
||||||
{
|
{
|
||||||
return false;
|
return signed_flag_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetExpr::cast_signed(bool flag)
|
||||||
|
{
|
||||||
|
signed_flag_ = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetExpr::has_width() const
|
bool NetExpr::has_width() const
|
||||||
|
|
@ -2046,6 +2051,7 @@ NetEConcat* NetEConcat::dup_expr() const
|
||||||
NetEConst::NetEConst(const verinum&val)
|
NetEConst::NetEConst(const verinum&val)
|
||||||
: NetExpr(val.len()), value_(val)
|
: NetExpr(val.len()), value_(val)
|
||||||
{
|
{
|
||||||
|
cast_signed(value_.has_sign());
|
||||||
}
|
}
|
||||||
|
|
||||||
NetEConst::~NetEConst()
|
NetEConst::~NetEConst()
|
||||||
|
|
@ -2057,11 +2063,6 @@ const verinum& NetEConst::value() const
|
||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetEConst::has_sign() const
|
|
||||||
{
|
|
||||||
return value_.has_sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetEConst::has_width() const
|
bool NetEConst::has_width() const
|
||||||
{
|
{
|
||||||
return value_.has_len();
|
return value_.has_len();
|
||||||
|
|
@ -2214,6 +2215,7 @@ NetESignal::NetESignal(NetNet*n)
|
||||||
lsi_ = 0;
|
lsi_ = 0;
|
||||||
net_->incr_eref();
|
net_->incr_eref();
|
||||||
set_line(*n);
|
set_line(*n);
|
||||||
|
cast_signed(net_->get_signed());
|
||||||
}
|
}
|
||||||
|
|
||||||
NetESignal::NetESignal(NetNet*n, unsigned m, unsigned l)
|
NetESignal::NetESignal(NetNet*n, unsigned m, unsigned l)
|
||||||
|
|
@ -2224,6 +2226,7 @@ NetESignal::NetESignal(NetNet*n, unsigned m, unsigned l)
|
||||||
lsi_ = l;
|
lsi_ = l;
|
||||||
net_->incr_eref();
|
net_->incr_eref();
|
||||||
set_line(*n);
|
set_line(*n);
|
||||||
|
cast_signed(net_->get_signed());
|
||||||
}
|
}
|
||||||
|
|
||||||
NetESignal::~NetESignal()
|
NetESignal::~NetESignal()
|
||||||
|
|
@ -2236,11 +2239,6 @@ string NetESignal::name() const
|
||||||
return net_->name();
|
return net_->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetESignal::has_sign() const
|
|
||||||
{
|
|
||||||
return net_->get_signed();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned NetESignal::bit_count() const
|
unsigned NetESignal::bit_count() const
|
||||||
{
|
{
|
||||||
return msi_ - lsi_ + 1;
|
return msi_ - lsi_ + 1;
|
||||||
|
|
@ -2407,6 +2405,9 @@ const NetProc*NetTaskDef::proc() const
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: netlist.cc,v $
|
* $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
|
* Revision 1.178 2001/12/03 04:47:15 steve
|
||||||
* Parser and pform use hierarchical names as hname_t
|
* Parser and pform use hierarchical names as hname_t
|
||||||
* objects instead of encoded strings.
|
* objects instead of encoded strings.
|
||||||
|
|
|
||||||
14
netlist.h
14
netlist.h
|
|
@ -19,7 +19,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -847,7 +847,8 @@ class NetExpr : public LineInfo {
|
||||||
|
|
||||||
// This method returns true if the expression is
|
// This method returns true if the expression is
|
||||||
// signed. Unsigned expressions return false.
|
// 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
|
// This returns true if the expression has a definite
|
||||||
// width. This is generally true, but in some cases the
|
// width. This is generally true, but in some cases the
|
||||||
|
|
@ -880,6 +881,7 @@ class NetExpr : public LineInfo {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned width_;
|
unsigned width_;
|
||||||
|
bool signed_flag_;
|
||||||
|
|
||||||
private: // not implemented
|
private: // not implemented
|
||||||
NetExpr(const NetExpr&);
|
NetExpr(const NetExpr&);
|
||||||
|
|
@ -901,7 +903,6 @@ class NetEConst : public NetExpr {
|
||||||
|
|
||||||
virtual bool set_width(unsigned w);
|
virtual bool set_width(unsigned w);
|
||||||
|
|
||||||
virtual bool has_sign() const;
|
|
||||||
virtual bool has_width() const;
|
virtual bool has_width() const;
|
||||||
|
|
||||||
virtual void expr_scan(struct expr_scan_t*) 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(NetNet*n, unsigned msi, unsigned lsi);
|
||||||
~NetESignal();
|
~NetESignal();
|
||||||
|
|
||||||
// a NetESignal expression is signed if the NetNet that it
|
|
||||||
// refers to is signed.
|
|
||||||
bool has_sign() const;
|
|
||||||
|
|
||||||
string name() const;
|
string name() const;
|
||||||
virtual bool set_width(unsigned);
|
virtual bool set_width(unsigned);
|
||||||
|
|
||||||
|
|
@ -2867,6 +2864,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: netlist.h,v $
|
* $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
|
* Revision 1.227 2001/12/03 04:47:15 steve
|
||||||
* Parser and pform use hierarchical names as hname_t
|
* Parser and pform use hierarchical names as hname_t
|
||||||
* objects instead of encoded strings.
|
* objects instead of encoded strings.
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) & !defined(macintosh)
|
#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
|
#endif
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
@ -127,7 +127,7 @@ void dll_target::expr_const(const NetEConst*net)
|
||||||
char*bits;
|
char*bits;
|
||||||
expr_->type_ = IVL_EX_NUMBER;
|
expr_->type_ = IVL_EX_NUMBER;
|
||||||
expr_->width_= net->expr_width();
|
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_);
|
expr_->u_.number_.bits_ = bits = (char*)malloc(expr_->width_);
|
||||||
for (idx = 0 ; idx < expr_->width_ ; idx += 1)
|
for (idx = 0 ; idx < expr_->width_ ; idx += 1)
|
||||||
switch (val.get(idx)) {
|
switch (val.get(idx)) {
|
||||||
|
|
@ -347,6 +347,9 @@ void dll_target::expr_unary(const NetEUnary*net)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: t-dll-expr.cc,v $
|
* $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
|
* Revision 1.20 2001/10/23 04:22:41 steve
|
||||||
* Support bit selects of non-0 lsb for vectors.
|
* Support bit selects of non-0 lsb for vectors.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue