Skip to content

Commit

Permalink
Handle indexed defparams.
Browse files Browse the repository at this point in the history
The l-value of a defparam assignment is a hierarchical name that may
include array selects to select scopes from module arrays. Therefore
it makes no sense to store parsed defparams in a map. Instead, they
should go into an ordered list. This also maked more sense because later
defparams *may* have the same name as a previous defparam, and will
override the previous defparam. So replace the map of parsed defparams
with a list of parsed defparams.

Also, as soon as the defparam expression is elaborated, the list entry
is no longer needed, so delete it. Save memory.
  • Loading branch information
steveicarus committed Jun 28, 2008
1 parent da2c4b0 commit 1ef7994
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 30 deletions.
6 changes: 4 additions & 2 deletions Module.h
Expand Up @@ -22,6 +22,7 @@

# include <list>
# include <map>
# include <utility>
# include "svector.h"
# include "StringHeap.h"
# include "HName.h"
Expand Down Expand Up @@ -118,7 +119,8 @@ class Module : public PScope, public LineInfo {
new parameters within the module, but may be used to set
values within this module (when instantiated) or in other
instantiated modules. */
map<pform_name_t,PExpr*>defparms;
typedef pair<pform_name_t,PExpr*> named_expr_t;
list<named_expr_t>defparms;

/* Parameters may be overridden at instantiation time;
the overrides do not contain explicit parameter names,
Expand Down Expand Up @@ -169,7 +171,7 @@ class Module : public PScope, public LineInfo {
bool elaborate(Design*, NetScope*scope) const;

typedef map<perm_string,NetExpr*> replace_t;
bool elaborate_scope(Design*, NetScope*scope, const replace_t&rep) const;
bool elaborate_scope(Design*, NetScope*scope, const replace_t&rep);

bool elaborate_sig(Design*, NetScope*scope) const;

Expand Down
14 changes: 7 additions & 7 deletions elab_scope.cc
Expand Up @@ -182,7 +182,7 @@ static void elaborate_scope_funcs(Design*des, NetScope*scope,
}

bool Module::elaborate_scope(Design*des, NetScope*scope,
const replace_t&replacements) const
const replace_t&replacements)
{
if (debug_scopes) {
cerr << get_fileline() << ": debug: Elaborate scope "
Expand All @@ -201,8 +201,6 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
// place of the elaborated expression.

typedef map<perm_string,param_expr_t>::const_iterator mparm_it_t;
typedef map<pform_name_t,PExpr*>::const_iterator pform_parm_it_t;


// This loop scans the parameters in the module, and creates
// stub parameter entries in the scope for the parameter name.
Expand Down Expand Up @@ -286,15 +284,17 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
// here because the parameter receiving the assignment may be
// in a scope not discovered by this pass.

for (pform_parm_it_t cur = defparms.begin()
; cur != defparms.end() ; cur ++ ) {
while (! defparms.empty()) {
Module::named_expr_t cur = defparms.front();
defparms.pop_front();

PExpr*ex = (*cur).second;
PExpr*ex = cur.second;
assert(ex);

NetExpr*val = ex->elaborate_pexpr(des, scope);
delete ex;
if (val == 0) continue;
scope->defparams.push_back(make_pair(cur->first, val));
scope->defparams.push_back(make_pair(cur.first, val));
}

// Evaluate the attributes. Evaluate them in the scope of the
Expand Down
2 changes: 0 additions & 2 deletions net_design.cc
Expand Up @@ -240,8 +240,6 @@ void NetScope::run_defparams(Design*des)
is the current scope. */
NetScope*targ_scope = des->find_scope(this, eval_path);
if (targ_scope == 0) {
cerr << val->get_fileline() << ": warning: scope of " <<
path << "." << perm_name << " not found." << endl;

// Push the defparam onto a list for retry
// later. It is possible for the scope lookup to
Expand Down
2 changes: 1 addition & 1 deletion pform.cc
Expand Up @@ -1760,7 +1760,7 @@ void pform_set_specparam(perm_string name, PExpr*expr)
void pform_set_defparam(const pform_name_t&name, PExpr*expr)
{
assert(expr);
pform_cur_module->defparms[name] = expr;
pform_cur_module->defparms.push_back(make_pair(name,expr));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion pform_dump.cc
Expand Up @@ -991,7 +991,6 @@ void Module::dump(ostream&out) const
}

typedef map<perm_string,param_expr_t>::const_iterator parm_iter_t;
typedef map<pform_name_t,PExpr*>::const_iterator parm_hiter_t;
for (parm_iter_t cur = parameters.begin()
; cur != parameters.end() ; cur ++) {
out << " parameter " << (*cur).second.type << " ";
Expand Down Expand Up @@ -1068,6 +1067,7 @@ void Module::dump(ostream&out) const
<< *(*cur).second << ";" << endl;
}

typedef list<Module::named_expr_t>::const_iterator parm_hiter_t;
for (parm_hiter_t cur = defparms.begin()
; cur != defparms.end() ; cur ++) {
out << " defparam " << (*cur).first << " = ";
Expand Down
13 changes: 1 addition & 12 deletions pform_types.cc
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 Stephen Williams (steve@icarus.com)
* Copyright (c) 2007-2008 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -16,17 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: pform_types.cc,v 1.1 2007/05/24 04:07:12 steve Exp $"
#endif


# include "pform_types.h"

bool operator < (const name_component_t&lef, const name_component_t&rig)
{
if (lef.name < rig.name)
return true;

return false;
}
6 changes: 1 addition & 5 deletions pform_types.h
@@ -1,7 +1,7 @@
#ifndef __pform_types_H
#define __pform_types_H
/*
* Copyright (c) 2007 Stephen Williams (steve@icarus.com)
* Copyright (c) 2007-2008 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand All @@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: pform_types.h,v 1.2 2007/06/04 02:19:07 steve Exp $"
#endif

// This for the perm_string type.
# include "StringHeap.h"
Expand Down Expand Up @@ -50,7 +47,6 @@ struct name_component_t {
std::list<index_component_t>index;
};

extern bool operator < (const name_component_t&lef, const name_component_t&rig);

/*
* The pform_name_t is the general form for a hierarchical
Expand Down

0 comments on commit 1ef7994

Please sign in to comment.