Fix naming of unnamed generate blocks (issue #528)
The IEEE standard specifies that the numbering of generate blocks
restarts at 1 in each new scope, and that the 'else' part of an 'if'
construct is part of the same constuct, so has the same number.
(cherry picked from commit ceb2581368)
This commit is contained in:
parent
19dc81a242
commit
2f75fe4053
8
PScope.h
8
PScope.h
|
|
@ -55,7 +55,8 @@ class LexicalScope {
|
|||
public:
|
||||
enum lifetime_t { INHERITED, STATIC, AUTOMATIC };
|
||||
|
||||
explicit LexicalScope(LexicalScope*parent) : default_lifetime(INHERITED), parent_(parent) { }
|
||||
explicit LexicalScope(LexicalScope*parent)
|
||||
: default_lifetime(INHERITED), generate_counter(0), parent_(parent) { }
|
||||
// A virtual destructor is so that dynamic_cast can work.
|
||||
virtual ~LexicalScope() { }
|
||||
|
||||
|
|
@ -139,6 +140,11 @@ class LexicalScope {
|
|||
// Enumeration sets.
|
||||
std::set<enum_type_t*> enum_sets;
|
||||
|
||||
// A count of the generate constructs in this scope. This is
|
||||
// used to automatically name unnamed generate blocks, as
|
||||
// specified in the LRM.
|
||||
unsigned generate_counter;
|
||||
|
||||
LexicalScope* parent_scope() const { return parent_; }
|
||||
|
||||
virtual bool var_init_needs_explicit_lifetime() const;
|
||||
|
|
|
|||
28
pform.cc
28
pform.cc
|
|
@ -341,10 +341,6 @@ bool pform_library_flag = false;
|
|||
*/
|
||||
static unsigned scope_unnamed_block_with_decl = 1;
|
||||
|
||||
/* increment this for generate schemes within a module, and set it
|
||||
to zero when a new module starts. */
|
||||
static unsigned scope_generate_counter = 1;
|
||||
|
||||
/* This tracks the current generate scheme being processed. This is
|
||||
always within a module. */
|
||||
static PGenerate*pform_cur_generate = 0;
|
||||
|
|
@ -1354,10 +1350,6 @@ void pform_startmodule(const struct vlltype&loc, const char*name,
|
|||
|
||||
lexical_scope = cur_module;
|
||||
|
||||
/* The generate scheme numbering starts with *1*, not
|
||||
zero. That's just the way it is, thanks to the standard. */
|
||||
scope_generate_counter = 1;
|
||||
|
||||
pform_bind_attributes(cur_module->attributes, attr);
|
||||
}
|
||||
|
||||
|
|
@ -1491,7 +1483,7 @@ void pform_genvars(const struct vlltype&li, list<perm_string>*names)
|
|||
delete names;
|
||||
}
|
||||
|
||||
static void detect_directly_nested_generate()
|
||||
static unsigned detect_directly_nested_generate()
|
||||
{
|
||||
if (pform_cur_generate && pform_generate_single_item)
|
||||
switch (pform_cur_generate->scheme_type) {
|
||||
|
|
@ -1501,10 +1493,12 @@ static void detect_directly_nested_generate()
|
|||
// fallthrough
|
||||
case PGenerate::GS_ELSE:
|
||||
pform_cur_generate->directly_nested = true;
|
||||
break;
|
||||
return pform_cur_generate->id_number;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ++lexical_scope->generate_counter;
|
||||
}
|
||||
|
||||
void pform_start_generate_for(const struct vlltype&li,
|
||||
|
|
@ -1513,7 +1507,7 @@ void pform_start_generate_for(const struct vlltype&li,
|
|||
PExpr*test,
|
||||
char*ident2, PExpr*next)
|
||||
{
|
||||
PGenerate*gen = new PGenerate(lexical_scope, scope_generate_counter++);
|
||||
PGenerate*gen = new PGenerate(lexical_scope, ++lexical_scope->generate_counter);
|
||||
lexical_scope = gen;
|
||||
|
||||
FILE_NAME(gen, li);
|
||||
|
|
@ -1534,9 +1528,9 @@ void pform_start_generate_for(const struct vlltype&li,
|
|||
|
||||
void pform_start_generate_if(const struct vlltype&li, PExpr*test)
|
||||
{
|
||||
detect_directly_nested_generate();
|
||||
unsigned id_number = detect_directly_nested_generate();
|
||||
|
||||
PGenerate*gen = new PGenerate(lexical_scope, scope_generate_counter++);
|
||||
PGenerate*gen = new PGenerate(lexical_scope, id_number);
|
||||
lexical_scope = gen;
|
||||
|
||||
FILE_NAME(gen, li);
|
||||
|
|
@ -1560,7 +1554,7 @@ void pform_start_generate_else(const struct vlltype&li)
|
|||
PGenerate*cur = pform_cur_generate;
|
||||
pform_endgenerate(false);
|
||||
|
||||
PGenerate*gen = new PGenerate(lexical_scope, scope_generate_counter++);
|
||||
PGenerate*gen = new PGenerate(lexical_scope, cur->id_number);
|
||||
lexical_scope = gen;
|
||||
|
||||
FILE_NAME(gen, li);
|
||||
|
|
@ -1580,9 +1574,9 @@ void pform_start_generate_else(const struct vlltype&li)
|
|||
*/
|
||||
void pform_start_generate_case(const struct vlltype&li, PExpr*expr)
|
||||
{
|
||||
detect_directly_nested_generate();
|
||||
unsigned id_number = detect_directly_nested_generate();
|
||||
|
||||
PGenerate*gen = new PGenerate(lexical_scope, scope_generate_counter++);
|
||||
PGenerate*gen = new PGenerate(lexical_scope, id_number);
|
||||
lexical_scope = gen;
|
||||
|
||||
FILE_NAME(gen, li);
|
||||
|
|
@ -1603,7 +1597,7 @@ void pform_start_generate_case(const struct vlltype&li, PExpr*expr)
|
|||
*/
|
||||
void pform_start_generate_nblock(const struct vlltype&li, char*name)
|
||||
{
|
||||
PGenerate*gen = new PGenerate(lexical_scope, scope_generate_counter++);
|
||||
PGenerate*gen = new PGenerate(lexical_scope, ++lexical_scope->generate_counter);
|
||||
lexical_scope = gen;
|
||||
|
||||
FILE_NAME(gen, li);
|
||||
|
|
|
|||
Loading…
Reference in New Issue