Skip to content

Commit

Permalink
Nested generate regions are illegal
Browse files Browse the repository at this point in the history
  • Loading branch information
caryr committed Dec 29, 2024
1 parent d484cb6 commit 788a94b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions ivtest/gold/br_gh1117.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ivltests/br_gh1117.v:10: error: generate/endgenerate regions cannot nest.
25 changes: 25 additions & 0 deletions ivtest/ivltests/br_gh1117.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module top;
wire x, y, z;
reg in;
genvar i;

generate
for (i=0; i<1; i=i+1) begin
assign x = in;
end
generate // This should be an error
for (i=0; i<1; i=i+1) begin
assign y = in;
end
endgenerate
endgenerate

generate // This is ok
for (i=0; i<1; i=i+1) begin
assign z = in;
end
endgenerate

initial $display("Failed: should be a compile error!");

endmodule
1 change: 1 addition & 0 deletions ivtest/regress-vlg.list
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ br_gh788 normal,-gno-io-range-error,-Wno-anachronisms ivltests gold=br_gh788.go
br_gh793 normal ivltests
br_gh827 normal ivltests gold=br_gh827.gold
br_gh889 normal,-gspecify ivltests gold=br_gh889.gold
br_gh1117 CE ivltests gold=br_gh1117.gold
br_gh1175a CE ivltests gold=br_gh1175a.gold
br_gh1175b CE ivltests gold=br_gh1175b.gold
br_gh1175c CE ivltests gold=br_gh1175c.gold
Expand Down
20 changes: 11 additions & 9 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern void lex_end_table();
static data_type_t* param_data_type = 0;
static bool param_is_local = false;
static bool param_is_type = false;
static bool in_gen_region = false;
static std::list<pform_range_t>* specparam_active_range = 0;

/* Port declaration lists use this structure for context. */
Expand Down Expand Up @@ -74,6 +75,15 @@ static stack<PBlock*> current_block_stack;
specified. */
static LexicalScope::lifetime_t var_lifetime;

static void check_in_gen_region(const struct vlltype &loc)
{
if (in_gen_region) {
cerr << loc << ": error: generate/endgenerate regions cannot nest." << endl;
error_count += 1;
}
in_gen_region = true;
}

static pform_name_t* pform_create_this(void)
{
name_component_t name (perm_string::literal(THIS_TOKEN));
Expand Down Expand Up @@ -5208,15 +5218,7 @@ module_item
generate/endgenerate regions do not nest. Generate schemes nest,
but generate regions do not. */

| K_generate generate_item_list_opt K_endgenerate
{ // Test for bad nesting. I understand it, but it is illegal.
if (pform_parent_generate()) {
cerr << @1 << ": error: Generate/endgenerate regions cannot nest." << endl;
cerr << @1 << ": : Try removing optional generate/endgenerate keywords," << endl;
cerr << @1 << ": : or move them to surround the parent generate scheme." << endl;
error_count += 1;
}
}
| K_generate { check_in_gen_region(@1); } generate_item_list_opt K_endgenerate { in_gen_region = false; }

| K_genvar list_of_identifiers ';'
{ pform_genvars(@1, $2); }
Expand Down

0 comments on commit 788a94b

Please sign in to comment.