Fix repeated use of disabled const functions.

If constant functions are exited by a return/disable, fix
the leaked "disable" flag that causes blocks in the next
try at the function to not work.

There are also a lot of debug messages added to help find
this and similar problems.
This commit is contained in:
Stephen Williams 2013-06-02 16:56:46 -07:00
parent bcaa6accec
commit af304fea65
2 changed files with 72 additions and 12 deletions

View File

@ -964,6 +964,10 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
vector<netrange_t> plist, nlist;
/* If they exist get the port definition MSB and LSB */
if (port_set_ && !port_.empty()) {
if (debug_elaborate) {
cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Evaluate ranges for port " << basename() << endl;
}
bad_range |= evaluate_ranges(des, scope, plist, port_);
nlist = plist;
/* An implicit port can have a range so note that here. */
@ -974,10 +978,20 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
/* If they exist get the net/etc. definition MSB and LSB */
if (net_set_ && !net_.empty() && !bad_range) {
nlist.clear();
if (debug_elaborate) {
cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Evaluate ranges for net " << basename() << endl;
}
bad_range |= evaluate_ranges(des, scope, nlist, net_);
}
assert(net_set_ || net_.empty());
if (debug_elaborate) {
cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Calculated ranges for " << basename()
<< ". Now check for consistency." << endl;
}
/* If we find errors here, then give up on this signal. */
if (bad_range)
return 0;

View File

@ -60,7 +60,7 @@ NetExpr* NetFuncDef::evaluate_function(const LineInfo&loc, const std::vector<Net
map<perm_string,LocalVar>context_map;
if (debug_eval_tree) {
cerr << loc.get_fileline() << ": debug: "
cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: "
<< "Evaluate function " << scope_->basename() << endl;
}
@ -78,7 +78,7 @@ NetExpr* NetFuncDef::evaluate_function(const LineInfo&loc, const std::vector<Net
input_var.value = fix_assign_value(ports_[idx], args[idx]);
if (debug_eval_tree) {
cerr << loc.get_fileline() << ": debug: "
cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: "
<< " input " << aname << " = " << *args[idx] << endl;
}
}
@ -123,9 +123,32 @@ NetExpr* NetFuncDef::evaluate_function(const LineInfo&loc, const std::vector<Net
}
}
if (disable) {
if (debug_eval_tree)
cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: "
<< "disable of " << scope_path(disable)
<< " trapped in function " << scope_path(scope_)
<< "." << endl;
ivl_assert(loc, disable==scope_);
disable = 0;
}
// Done.
if (flag)
if (flag) {
if (debug_eval_tree) {
cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: "
<< "Evalutated to ";
if (res) cerr << *res;
else cerr << "<nil>";
cerr << endl;
}
return res;
}
if (debug_eval_tree) {
cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: "
<< "Evaluation failed." << endl;
}
delete res;
return 0;
@ -256,9 +279,8 @@ bool NetAssign::eval_func_lval_(const LineInfo&loc,
delete old_lval;
if (debug_eval_tree) {
cerr << get_fileline() << ": debug: "
<< "NetAssign::evaluate_function: " << lval->name()
<< " = " << *rval_result << endl;
cerr << get_fileline() << ": NetAssign::evaluate_function: "
<< lval->name() << " = " << *rval_result << endl;
}
if (ptr->second.nwords > 0)
@ -326,6 +348,11 @@ bool NetBlock::evaluate_function(const LineInfo&loc,
if (disable == subscope_) disable = 0;
if (debug_eval_tree) {
cerr << get_fileline() << ": NetBlock::evaluate_function: "
<< "flag=" << (flag?"true":"false") << endl;
}
return flag;
}
@ -448,8 +475,13 @@ bool NetCondit::evaluate_function(const LineInfo&loc,
map<perm_string,LocalVar>&context_map) const
{
NetExpr*cond = expr_->evaluate_function(loc, context_map);
if (cond == 0)
if (cond == 0) {
if (debug_eval_tree) {
cerr << get_fileline() << ": NetCondit::evaluate_function: "
<< "Unable to evaluate condition (" << *expr_ <<")" << endl;
}
return false;
}
NetEConst*cond_const = dynamic_cast<NetEConst*> (cond);
ivl_assert(loc, cond_const);
@ -457,18 +489,32 @@ bool NetCondit::evaluate_function(const LineInfo&loc,
long val = cond_const->value().as_long();
delete cond;
bool flag;
if (val)
// The condition is true, so evaluate the if clause
return (if_ == 0) || if_->evaluate_function(loc, context_map);
flag = (if_ == 0) || if_->evaluate_function(loc, context_map);
else
// The condition is false, so evaluate the else clause
return (else_ == 0) || else_->evaluate_function(loc, context_map);
flag = (else_ == 0) || else_->evaluate_function(loc, context_map);
if (debug_eval_tree) {
cerr << get_fileline() << ": NetCondit::evaluate_function: "
<< "Finished, flag=" << (flag?"true":"false") << endl;
}
return flag;
}
bool NetDisable::evaluate_function(const LineInfo&,
map<perm_string,LocalVar>&) const
{
disable = target_;
if (debug_eval_tree) {
cerr << get_fileline() << ": NetDisable::evaluate_function: "
<< "disable " << scope_path(disable) << endl;
}
return true;
}
@ -541,7 +587,7 @@ bool NetWhile::evaluate_function(const LineInfo&loc,
bool flag = true;
if (debug_eval_tree) {
cerr << get_fileline() << ": debug: NetWhile::evaluate_function: "
cerr << get_fileline() << ": NetWhile::evaluate_function: "
<< "Start loop" << endl;
}
@ -572,8 +618,8 @@ bool NetWhile::evaluate_function(const LineInfo&loc,
}
if (debug_eval_tree) {
cerr << get_fileline() << ": debug: NetWhile::evaluate_function: "
<< "Done loop" << endl;
cerr << get_fileline() << ": NetWhile::evaluate_function: "
<< "Done loop, flag=" << (flag?"true":"false") << endl;
}
return flag;