Skip to content

Commit

Permalink
Fix for pr3557493.
Browse files Browse the repository at this point in the history
defparam assignments found inside a generate block were being stored
in the enclosing module scope. They should be stored in the generate
block scope.

Also removed the genvar list from the PGenerate class, as this is
already declared in the base LexicalScope class.
  • Loading branch information
martinwhitaker authored and caryr committed Aug 22, 2012
1 parent 83fff3a commit 1f152aa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions PGenerate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __PGenerate_H
#define __PGenerate_H
/*
* Copyright (c) 2006-2010 Stephen Williams ([email protected])
* Copyright (c) 2006-2010,2012 Stephen Williams ([email protected])
*
* 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 Down Expand Up @@ -80,16 +80,17 @@ class PGenerate : public LineInfo, public LexicalScope {
// test value.
std::valarray<PExpr*> item_test;

// defparam assignments found in this scope.
typedef pair<pform_name_t,PExpr*> named_expr_t;
list<named_expr_t>defparms;

list<PGate*> gates;
void add_gate(PGate*);

// Tasks instantiated within this scheme.
map<perm_string,PTask*> tasks;
map<perm_string,PFunction*>funcs;

// genvars declared within this scheme.
map<perm_string,LineInfo*> genvars;

// Generate schemes can contain further generate schemes.
list<PGenerate*> generate_schemes;
// PGenerate*parent;
Expand Down
9 changes: 9 additions & 0 deletions elab_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,15 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)
// module have been done.
collect_scope_localparams_(des, scope, localparams);

// Run through the defparams for this scope and save the result
// in a table for later final override.

typedef list<PGenerate::named_expr_t>::const_iterator defparms_iter_t;
for (defparms_iter_t cur = defparms.begin()
; cur != defparms.end() ; ++ cur ) {
scope->defparams.push_back(make_pair(cur->first, cur->second));
}

// Scan the generated scope for nested generate schemes,
// and *generate* new scopes, which is slightly different
// from simple elaboration.
Expand Down
5 changes: 4 additions & 1 deletion pform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,10 @@ void pform_set_specparam(const struct vlltype&loc, perm_string name,
void pform_set_defparam(const pform_name_t&name, PExpr*expr)
{
assert(expr);
pform_cur_module.front()->defparms.push_back(make_pair(name,expr));
if (pform_cur_generate)
pform_cur_generate->defparms.push_back(make_pair(name,expr));
else
pform_cur_module.front()->defparms.push_back(make_pair(name,expr));
}

/*
Expand Down
10 changes: 10 additions & 0 deletions pform_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,16 @@ void PGenerate::dump(ostream&out, unsigned indent) const

dump_localparams_(out, indent+2);

typedef list<PGenerate::named_expr_t>::const_iterator parm_hiter_t;
for (parm_hiter_t cur = defparms.begin()
; cur != defparms.end() ; ++ cur ) {
out << setw(indent+2) << "" << "defparam " << (*cur).first << " = ";
if ((*cur).second)
out << *(*cur).second << ";" << endl;
else
out << "/* ERROR */;" << endl;
}

dump_events_(out, indent+2);

dump_wires_(out, indent+2);
Expand Down

0 comments on commit 1f152aa

Please sign in to comment.