Get offsets into indexed part selects correct.

This commit is contained in:
steve 2007-04-01 05:28:26 +00:00
parent ea74940be4
commit 0168502bbb
1 changed files with 29 additions and 5 deletions

View File

@ -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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: elab_expr.cc,v 1.123 2007/03/26 19:23:13 steve Exp $" #ident "$Id: elab_expr.cc,v 1.124 2007/04/01 05:28:26 steve Exp $"
#endif #endif
# include "config.h" # include "config.h"
@ -1205,8 +1205,19 @@ NetExpr* PEIdent::elaborate_expr_net_idx_up_(Design*des, NetScope*scope,
// signal itself. // signal itself.
if (net->sig()->sb_to_idx(lsv) == 0 && wid == net->vector_width()) if (net->sig()->sb_to_idx(lsv) == 0 && wid == net->vector_width())
return net; return net;
// Otherwise, make a part select that covers the right range.
NetExpr*ex = new NetEConst(verinum(net->sig()->sb_to_idx(lsv)));
NetESelect*ss = new NetESelect(net, ex, wid);
ss->set_line(*this);
delete base;
return ss;
} }
if (long offset = net->lsi())
base = make_add_expr(base, 0-offset);
NetESelect*ss = new NetESelect(net, base, wid); NetESelect*ss = new NetESelect(net, base, wid);
ss->set_line(*this); ss->set_line(*this);
@ -1243,18 +1254,28 @@ NetExpr* PEIdent::elaborate_expr_net_idx_do_(Design*des, NetScope*scope,
// If the part select convers exactly the entire // If the part select convers exactly the entire
// vector, then do not bother with it. Return the // vector, then do not bother with it. Return the
// signal itself. // signal itself.
if (net->sig()->sb_to_idx(lsv) == (wid-1) if (net->sig()->sb_to_idx(lsv) == (wid-1) && wid == net->vector_width())
&& wid == net->vector_width())
return net; return net;
// Otherwise, make a part select that covers the right range.
NetExpr*ex = new NetEConst(verinum(net->sig()->sb_to_idx(lsv)-wid+1));
NetESelect*ss = new NetESelect(net, ex, wid);
ss->set_line(*this);
delete base;
return ss;
} }
NetExpr*base_adjusted = wid > 1? make_add_expr(base,1-wid) : base; long offset = net->lsi();
NetExpr*base_adjusted = wid > 1
? make_add_expr(base,1-(long)wid-offset)
: (offset == 0? base : make_add_expr(base, 0-offset));
NetESelect*ss = new NetESelect(net, base_adjusted, wid); NetESelect*ss = new NetESelect(net, base_adjusted, wid);
ss->set_line(*this); ss->set_line(*this);
if (debug_elaborate) { if (debug_elaborate) {
cerr << get_line() << ": debug: Elaborate part " cerr << get_line() << ": debug: Elaborate part "
<< "select base="<< *base << ", wid="<< wid << endl; << "select base="<< *base_adjusted << ", wid="<< wid << endl;
} }
return ss; return ss;
@ -1612,6 +1633,9 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope,
/* /*
* $Log: elab_expr.cc,v $ * $Log: elab_expr.cc,v $
* Revision 1.124 2007/04/01 05:28:26 steve
* Get offsets into indexed part selects correct.
*
* Revision 1.123 2007/03/26 19:23:13 steve * Revision 1.123 2007/03/26 19:23:13 steve
* Handle part select of array words. * Handle part select of array words.
* *