Skip to content

Commit

Permalink
Add support for '*_name attributes of generate block label. Fixes n…
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Jan 8, 2025
1 parent b305c37 commit 0b329dd
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
- `vhpi_assert` now behaves the same as VHDL `assert` for the purposes
of determining the simulation exit code and early termination (#1060).
- The `'driving_value` attribute now works correctly with record types.
- Added basic support for `'instance_name`, `'path_name` and `'simple_name`
attributes of generate block labels (from @NikLeberg) (#1125).
- Several other minor bugs were resolved (#1038, #1057, #1067).

## Version 1.14.2 - 2024-11-23
Expand Down
4 changes: 4 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ class_t class_of(tree_t t)
case T_CONCURRENT:
case T_ELAB:
case T_PSL:
case T_FOR_GENERATE:
case T_IF_GENERATE:
case T_CASE_GENERATE:
return C_LABEL;
case T_COMPONENT:
return C_COMPONENT;
Expand Down Expand Up @@ -1990,6 +1993,7 @@ type_t get_type_or_null(tree_t t)
case T_GROUP:
case T_FOR_GENERATE:
case T_IF_GENERATE:
case T_CASE_GENERATE:
case T_USE:
case T_CONTEXT:
case T_PSL:
Expand Down
3 changes: 3 additions & 0 deletions src/lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,9 @@ static vcode_reg_t lower_name_attr(lower_unit_t *lu, tree_t decl,
case T_ARCH:
case T_PROT_DECL:
case T_PROT_BODY:
case T_FOR_GENERATE:
case T_IF_GENERATE:
case T_CASE_GENERATE:
tb_append(tb, ':');
break;

Expand Down
14 changes: 11 additions & 3 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11163,12 +11163,14 @@ static tree_t p_for_generate_statement(ident_t label)

consume(tFOR);

push_scope(nametab);
scope_set_prefix(nametab, label);

tree_t g = tree_new(T_FOR_GENERATE);
tree_set_ident(g, label);

if (label != NULL)
insert_name(nametab, g, NULL);

push_scope(nametab);
scope_set_prefix(nametab, label);
scope_set_container(nametab, g);

p_parameter_specification(g, T_GENERIC_DECL);
Expand Down Expand Up @@ -11207,6 +11209,9 @@ static tree_t p_if_generate_statement(ident_t label)
tree_t g = tree_new(T_IF_GENERATE);
tree_set_ident(g, label);

if (label != NULL)
insert_name(nametab, g, NULL);

ident_t alt_label = NULL;
if (peek() == tID && peek_nth(2) == tCOLON) {
require_std(STD_08, "alternative labels");
Expand Down Expand Up @@ -11342,6 +11347,9 @@ static tree_t p_case_generate_statement(ident_t label)
tree_t g = tree_new(T_CASE_GENERATE);
tree_set_ident(g, label);

if (label != NULL)
insert_name(nametab, g, NULL);

tree_t value = p_expression();
tree_set_value(g, value);

Expand Down
17 changes: 9 additions & 8 deletions src/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -4417,14 +4417,15 @@ static bool sem_is_named_entity(tree_t t)
tree_t decl = tree_ref(t);

switch (tree_kind(decl)) {
case T_SIGNAL_DECL: case T_VAR_DECL: case T_PORT_DECL:
case T_ALIAS: case T_ENTITY: case T_ARCH:
case T_PACKAGE: case T_PACK_BODY: case T_BLOCK:
case T_FILE_DECL: case T_CONST_DECL: case T_FUNC_DECL:
case T_FUNC_BODY: case T_PROC_DECL: case T_PROC_BODY:
case T_PROCESS: case T_GENERIC_DECL: case T_PARAM_DECL:
case T_INSTANCE: case T_PROT_DECL: case T_PROT_BODY:
case T_TYPE_DECL: case T_SUBTYPE_DECL:
case T_SIGNAL_DECL: case T_VAR_DECL: case T_PORT_DECL:
case T_ALIAS: case T_ENTITY: case T_ARCH:
case T_PACKAGE: case T_PACK_BODY: case T_BLOCK:
case T_FILE_DECL: case T_CONST_DECL: case T_FUNC_DECL:
case T_FUNC_BODY: case T_PROC_DECL: case T_PROC_BODY:
case T_PROCESS: case T_GENERIC_DECL: case T_PARAM_DECL:
case T_INSTANCE: case T_PROT_DECL: case T_PROT_BODY:
case T_TYPE_DECL: case T_SUBTYPE_DECL: case T_FOR_GENERATE:
case T_IF_GENERATE: case T_CASE_GENERATE:
return true;
case T_IMPLICIT_SIGNAL:
return tree_subkind(decl) == IMPLICIT_GUARD; // See LRM 93 section 4.3
Expand Down
70 changes: 70 additions & 0 deletions test/regress/issue1125.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
ENTITY issue1125 IS END ENTITY;

ARCHITECTURE arch OF issue1125 IS
BEGIN

gen_if : IF true GENERATE
ASSERT gen_if'simple_name = "gen_if";
ASSERT gen_if'path_name = ":issue1125:gen_if:";
END GENERATE;

-- *_name attributes in if generate with alternative labels not supported:
-- f : FOR i IN 0 TO 2 GENERATE
-- gen_if : IF gen_if_0 : i = 0 GENERATE
-- ASSERT gen_if'simple_name = "gen_if";
-- ASSERT gen_if'path_name = ":issue1125:f(0):gen_if:";
--
-- ASSERT gen_if_0'simple_name = "gen_if_0";
-- ASSERT gen_if_0'path_name = ":issue1125:f(0):gen_if_0:";
--
-- ELSIF gen_if_1 : i = 1 GENERATE
-- ASSERT gen_if'simple_name = "gen_if";
-- ASSERT gen_if'path_name = ":issue1125:f(1):gen_if:";
--
-- ASSERT gen_if_1'simple_name = "gen_if_1";
-- ASSERT gen_if_1'path_name = ":issue1125:f(1):gen_if_1:";
--
-- ELSE GENERATE
-- ASSERT gen_if'simple_name = "gen_if";
-- ASSERT gen_if'path_name = ":issue1125:f(2):gen_if:";
-- END GENERATE;
--
-- ASSERT gen_if'simple_name = "gen_if";
-- ASSERT gen_if'path_name = ":issue1125:f(" & INTEGER'image(i) & "):gen_if:";
-- END GENERATE;

ASSERT gen_if'simple_name = "gen_if";
-- Error, currently resolves to ":issue1125:"
-- ASSERT gen_if'path_name = ":issue1125:gen_if:";

gen_for : FOR i IN 0 TO 1 GENERATE
ASSERT gen_for'simple_name = "gen_for";
ASSERT gen_for'path_name = ":issue1125:gen_for(" & INTEGER'image(i) & "):";
END GENERATE;

ASSERT gen_for'simple_name = "gen_for";
-- Error, currently resolves to ":issue1125:"
-- ASSERT gen_for'path_name = ":issue1125:gen_for:";

gen_case : CASE true GENERATE
WHEN true =>
ASSERT gen_case'simple_name = "gen_case";
ASSERT gen_case'path_name = ":issue1125:gen_case:";
WHEN false =>
END GENERATE;

ASSERT gen_case'simple_name = "gen_case";
-- Error, currently resolves to ":issue1125:"
-- ASSERT gen_case'path_name = ":issue1125:gen_case:";

-- *_name attributes in case generate with alternative labels not supported:
-- gen_case : CASE true GENERATE
-- WHEN gen_case_true : true =>
-- ASSERT gen_case'simple_name = "gen_case";
-- ASSERT gen_case'path_name = ":issue1125:gen_case:";
--
-- ASSERT gen_case_true'simple_name = "gen_case_true";
-- ASSERT gen_case_true'path_name = ":issue1125:gen_case_true:";
-- WHEN false =>
-- END GENERATE;
END ARCHITECTURE;
6 changes: 3 additions & 3 deletions test/regress/issue430.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ architecture MODEL of CHANNEL_PLAYER is
read_val(signals.AR.ADDR(ADDR_WIDTH-1 downto 0));
end procedure;
begin
CHANNEL_M: if (CHANNEL = CHANNEL_M) generate
gCHANNEL_M: if (CHANNEL = CHANNEL_M) generate
PROCESS_M: process
begin
FINISH <= '1';
wait;
end process;
end generate;
CHANNEL_A:if (CHANNEL = CHANNEL_AW or CHANNEL = CHANNEL_AR) generate
gCHANNEL_A:if (CHANNEL = CHANNEL_AW or CHANNEL = CHANNEL_AR) generate
PROCESS_A: process
procedure execute_output is
begin
Expand All @@ -125,7 +125,7 @@ begin
wait;
end process;
end generate;
CHANNEL_D:if (CHANNEL = CHANNEL_DW or CHANNEL = CHANNEL_DR) generate
gCHANNEL_D:if (CHANNEL = CHANNEL_DW or CHANNEL = CHANNEL_DR) generate
PROCESS_D: process
procedure execute_output is
begin
Expand Down
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,3 +1091,4 @@ conv18 normal
ename17 fail,gold,2008
cmdline13 shell
issue1117 normal,psl,2008
issue1125 normal,2008

0 comments on commit 0b329dd

Please sign in to comment.