Use elab_and_eval to evaluate genvar expressions.

This commit is contained in:
steve 2006-04-12 05:05:03 +00:00
parent 6a74a090f0
commit fc5cf55400
2 changed files with 33 additions and 9 deletions

View File

@ -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.102 2006/02/02 02:43:57 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.103 2006/04/12 05:05:03 steve Exp $"
#endif
# include "config.h"
@ -637,6 +637,18 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
return tmp;
}
// Hmm... maybe this is a genvar? This is only possible while
// processing generate blocks, but then the genvar_tmp will be
// set in the scope.
if (path_.component_count() == 1
&& scope->genvar_tmp.str()
&& strcmp(path_.peek_name(0), scope->genvar_tmp) == 0) {
verinum val (scope->genvar_tmp_val);
NetEConst*tmp = new NetEConst(val);
tmp->set_line(*this);
return tmp;
}
// Finally, if this is a scope name, then return that. Look
// first to see if this is a name of a local scope. Failing
// that, search globally for a hierarchical name.
@ -1345,6 +1357,9 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
* Revision 1.103 2006/04/12 05:05:03 steve
* Use elab_and_eval to evaluate genvar expressions.
*
* Revision 1.102 2006/02/02 02:43:57 steve
* Allow part selects of memory words in l-values.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: elab_scope.cc,v 1.39 2006/04/10 00:37:42 steve Exp $"
#ident "$Id: elab_scope.cc,v 1.40 2006/04/12 05:05:03 steve Exp $"
#endif
# include "config.h"
@ -342,9 +342,10 @@ bool PGenerate::generate_scope_loop_(Design*des, NetScope*container)
container->genvar_tmp = loop_index;
container->genvar_tmp_val = 0;
verinum*test = loop_test->eval_const(des, container);
NetExpr*test_ex = elab_and_eval(des, container, loop_test);
NetEConst*test = dynamic_cast<NetEConst*>(test_ex);
assert(test);
while (test->as_long()) {
while (test->value().as_long()) {
// The actual name of the scope includes the genvar so
// that each instance has a unique name in the
@ -378,19 +379,24 @@ bool PGenerate::generate_scope_loop_(Design*des, NetScope*container)
scope_list_.push_back(scope);
// Calculate the step for the loop variable.
verinum*step = loop_step->eval_const(des, container);
NetExpr*step_ex = elab_and_eval(des, container, loop_step);
NetEConst*step = dynamic_cast<NetEConst*>(step_ex);
assert(step);
if (debug_elaborate)
cerr << get_line() << ": debug: genvar step from "
<< genvar << " to " << step->as_long() << endl;
<< genvar << " to " << step->value().as_long() << endl;
genvar = step->as_long();
genvar = step->value().as_long();
container->genvar_tmp_val = genvar;
delete step;
delete test;
test = loop_test->eval_const(des, container);
delete test_ex;
test_ex = elab_and_eval(des, container, loop_test);
test = dynamic_cast<NetEConst*>(test_ex);
assert(test);
}
// Clear the genvar_tmp field in the scope to reflect that the
// genvar is no longer value for evaluating expressions.
container->genvar_tmp = perm_string();
return true;
@ -742,6 +748,9 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const
/*
* $Log: elab_scope.cc,v $
* Revision 1.40 2006/04/12 05:05:03 steve
* Use elab_and_eval to evaluate genvar expressions.
*
* Revision 1.39 2006/04/10 00:37:42 steve
* Add support for generate loops w/ wires and gates.
*