Simplify parameter handling in the elaborated netlist.

A NetScope object currently has two lists of parameters, 'parameters'
and 'localparams'. However, user-declared localparams are stored in
the 'parameters' list, and 'localparams' is only used for adding
genvar values to the parameter list. There seems no good reason to
maintain separate lists, as the lists are merged before being passed
to the target DLL. This is most likely a hang-over from older code.
This commit is contained in:
Martin Whitaker 2012-05-07 13:01:12 +01:00 committed by Stephen Williams
parent 5cbdac2a46
commit 509ec1dcb1
5 changed files with 32 additions and 62 deletions

View File

@ -1191,12 +1191,6 @@ void NetScope::dump(ostream&o) const
o << ";" << endl;
}
for (pp = localparams.begin()
; pp != localparams.end() ; ++ pp ) {
o << " localparam " << (*pp).first << " = " <<
*(*pp).second.val << ";" << endl;
}
}
/* Dump the saved defparam assignments here. */

View File

@ -730,7 +730,7 @@ bool PGenerate::generate_scope_loop_(Design*des, NetScope*container)
genvar_verinum);
// The file and line information should really come
// from the genvar statement, not the for loop.
scope->set_localparam(loop_index, gp, *this);
scope->set_parameter(loop_index, gp, *this);
if (debug_scopes)
cerr << get_fileline() << ": debug: "
<< "Create implicit localparam "

View File

@ -114,6 +114,11 @@ void NetScope::set_line(perm_string file, perm_string def_file,
def_lineno_ = def_lineno;
}
/*
* This is the full-featured version of set_parameter. It is used for
* adding parameter, localparam, and specparam declarations to the
* parameter list.
*/
void NetScope::set_parameter(perm_string key, bool is_annotatable,
PExpr*val, ivl_variable_type_t type__,
PExpr*msb, PExpr*lsb, bool signed_flag,
@ -138,6 +143,28 @@ void NetScope::set_parameter(perm_string key, bool is_annotatable,
ivl_assert(file_line, type__ != IVL_VT_NO_TYPE);
}
/*
* This is a simplified version of set_parameter, for use when the
* parameter value is already known. It is currently only used to
* add a genvar to the parameter list.
*/
void NetScope::set_parameter(perm_string key, NetExpr*val,
const LineInfo&file_line)
{
param_expr_t&ref = parameters[key];
ref.is_annotatable = false;
ref.msb_expr = 0;
ref.lsb_expr = 0;
ref.val_expr = 0;
ref.val_scope = this;
ref.type = IVL_VT_BOOL;
ref.msb = 0;
ref.lsb = 0;
ref.signed_flag = false;
ref.val = val;
ref.set_line(file_line);
}
bool NetScope::auto_name(const char*prefix, char pad, const char* suffix)
{
// Find the current reference to myself in the parent scope.
@ -202,29 +229,6 @@ bool NetScope::make_parameter_unannotatable(perm_string key)
return flag;
}
/*
* This is not really complete (msb, lsb, sign). It is currently only
* used to add a genvar to the local parameter list.
*/
NetExpr* NetScope::set_localparam(perm_string key, NetExpr*val,
const LineInfo&file_line)
{
param_expr_t&ref = localparams[key];
NetExpr* res = ref.val;
ref.is_annotatable = false;
ref.msb_expr = 0;
ref.lsb_expr = 0;
ref.val_expr = 0;
ref.val_scope = this;
ref.type = IVL_VT_BOOL;
ref.msb = 0;
ref.lsb = 0;
ref.signed_flag = false;
ref.val = val;
ref.set_line(file_line);
return res;
}
/*
* NOTE: This method takes a const char* as a key to lookup a
* parameter, because we don't save that pointer. However, due to the
@ -257,16 +261,6 @@ const NetExpr* NetScope::get_parameter(Design*des,
return idx->second.val;
}
idx = localparams.find(key);
if (idx != localparams.end()) {
if (idx->second.val_expr)
evaluate_parameter_(des, idx);
msb = idx->second.msb;
lsb = idx->second.lsb;
return idx->second.val;
}
map<perm_string,NetEConstEnum*>::const_iterator eidx;
eidx = enum_names_.find(key);
@ -286,9 +280,6 @@ NetScope::param_ref_t NetScope::find_parameter(perm_string key)
idx = parameters.find(key);
if (idx != parameters.end()) return idx;
idx = localparams.find(perm_string::literal(key));
if (idx != localparams.end()) return idx;
// To get here the parameter must already exist, so we should
// never get here.
assert(0);

View File

@ -762,8 +762,7 @@ class NetScope : public Attrib {
/* Parameters exist within a scope, and these methods allow
one to manipulate the set. In these cases, the name is the
*simple* name of the parameter, the hierarchy is implicit in
the scope. The return value from set_parameter is the
previous expression, if there was one. */
the scope. */
struct range_t;
void set_parameter(perm_string name, bool is_annotatable,
@ -771,8 +770,8 @@ class NetScope : public Attrib {
PExpr*msb, PExpr*lsb, bool signed_flag,
NetScope::range_t*range_list,
const LineInfo&file_line);
NetExpr* set_localparam(perm_string name, NetExpr*val,
const LineInfo&file_line);
void set_parameter(perm_string name, NetExpr*val,
const LineInfo&file_line);
const NetExpr*get_parameter(Design*des,
const char* name,
@ -986,7 +985,6 @@ class NetScope : public Attrib {
NetExpr*val;
};
map<perm_string,param_expr_t>parameters;
map<perm_string,param_expr_t>localparams;
typedef map<perm_string,param_expr_t>::iterator param_ref_t;

View File

@ -461,7 +461,7 @@ ivl_parameter_t dll_target::scope_find_param(ivl_scope_t scope,
*/
void dll_target::make_scope_parameters(ivl_scope_t scop, const NetScope*net)
{
scop->nparam_ = net->parameters.size() + net->localparams.size();
scop->nparam_ = net->parameters.size();
if (scop->nparam_ == 0) {
scop->param_ = 0;
return;
@ -481,19 +481,6 @@ void dll_target::make_scope_parameters(ivl_scope_t scop, const NetScope*net)
cur_par->scope = scop;
FILE_NAME(cur_par, &((*cur_pit).second));
NetExpr*etmp = (*cur_pit).second.val;
make_scope_param_expr(cur_par, etmp);
idx += 1;
}
for (pit_t cur_pit = net->localparams.begin()
; cur_pit != net->localparams.end() ; ++ cur_pit ) {
assert(idx < scop->nparam_);
ivl_parameter_t cur_par = scop->param_ + idx;
cur_par->basename = (*cur_pit).first;
cur_par->scope = scop;
FILE_NAME(cur_par, &((*cur_pit).second));
NetExpr*etmp = (*cur_pit).second.val;
make_scope_param_expr(cur_par, etmp);
idx += 1;