Precalculate unary - if possible.

This commit is contained in:
steve 2002-04-14 03:55:25 +00:00
parent 84bf0cee59
commit 5cf7355c91
2 changed files with 32 additions and 6 deletions

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: PExpr.h,v 1.57 2002/04/13 02:33:17 steve Exp $"
#ident "$Id: PExpr.h,v 1.58 2002/04/14 03:55:25 steve Exp $"
#endif
# include <string>
@ -340,7 +340,7 @@ class PEUnary : public PExpr {
unsigned long decay,
Link::strength_t drive0,
Link::strength_t drive1) const;
virtual NetEUnary*elaborate_expr(Design*des, NetScope*,
virtual NetExpr*elaborate_expr(Design*des, NetScope*,
bool sys_task_arg =false) const;
virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const;
virtual verinum* eval_const(const Design*des, const NetScope*sc) const;
@ -487,6 +487,9 @@ class PECallFunction : public PExpr {
/*
* $Log: PExpr.h,v $
* Revision 1.58 2002/04/14 03:55:25 steve
* Precalculate unary - if possible.
*
* Revision 1.57 2002/04/13 02:33:17 steve
* Detect missing indices to memories (PR#421)
*

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.52 2002/04/13 02:33:17 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.53 2002/04/14 03:55:25 steve Exp $"
#endif
# include "config.h"
@ -652,7 +652,7 @@ NetETernary*PETernary::elaborate_expr(Design*des, NetScope*scope, bool) const
return res;
}
NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
{
NetExpr*ip = expr_->elaborate_expr(des, scope);
if (ip == 0) return 0;
@ -661,12 +661,31 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
* just like in PEBinary::elaborate_expr() ?
*/
NetEUnary*tmp;
NetExpr*tmp;
switch (op_) {
default:
tmp = new NetEUnary(op_, ip);
tmp->set_line(*this);
break;
case '-':
if (NetEConst*ipc = dynamic_cast<NetEConst*>(ip)) {
verinum val = ipc->value();
verinum zero (verinum::V0, val.len(), val.has_len());
val = zero - val;
val.has_sign(ipc->has_sign());
tmp = new NetEConst(val);
delete ip;
} else {
tmp = new NetEUnary(op_, ip);
tmp->set_line(*this);
}
break;
case '+':
tmp = ip;
break;
case '!': // Logical NOT
case '&': // Reduction AND
case '|': // Reduction OR
@ -677,6 +696,7 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
tmp = new NetEUReduce(op_, ip);
tmp->set_line(*this);
break;
case '~':
tmp = new NetEUBits(op_, ip);
tmp->set_line(*this);
@ -688,6 +708,9 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
* Revision 1.53 2002/04/14 03:55:25 steve
* Precalculate unary - if possible.
*
* Revision 1.52 2002/04/13 02:33:17 steve
* Detect missing indices to memories (PR#421)
*