Fix for pr3557493.

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.
This commit is contained in:
Martin Whitaker 2012-08-16 00:07:50 +01:00 committed by Cary R
parent 83fff3adf7
commit 1f152aa838
4 changed files with 28 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#ifndef __PGenerate_H
#define __PGenerate_H
/*
* Copyright (c) 2006-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 2006-2010,2012 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
@ -80,6 +80,10 @@ 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*);
@ -87,9 +91,6 @@ class PGenerate : public LineInfo, public LexicalScope {
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;

View File

@ -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.

View File

@ -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));
}
/*

View File

@ -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);