Skip to content

Commit c336ac9

Browse files
Blebowskinickg
authored andcommitted
src, test: emit coverage instance scope for case-generate and if-generate.
1 parent 6205ea7 commit c336ac9

File tree

13 files changed

+203
-5
lines changed

13 files changed

+203
-5
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Fixed a crash when an entity uses VHDL-2019 enhanced type generics and
66
sub-elements of a port with a generic array type are associated
77
individually (#1201).
8+
- `generate` statements now create separate hierarchy in the code
9+
coverage report
810
- Several other minor bugs were resolved (#1202).
911

1012
## Version 1.16.1 - 2025-05-12

nvc.1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,29 @@ to
11501150
.Bd -literal -offset indent
11511151
fold TB_TOP_LIB.TB_TOP.DUT.I_CPU_DATAPATH.I_INSTR_CACHE UNIT_TEST_LIB.CACHE_UNIT_TEST.DUT
11521152
.Ed
1153+
.Ss Code coverage limitations
1154+
When part of the design hierarchy is formed by an if-generate-else or
1155+
case-generate statement, the hierarchical path of implicit block
1156+
statements for each of the if-else branches or case choices is identical
1157+
unless the user provides an alternative label for each branch or choice.
1158+
For example:
1159+
.Bd -literal -offset indent
1160+
my_gen : case (op_kind) generate
1161+
when op_add => x <= a + b;
1162+
when op_sub => x <= a - b;
1163+
end generate my_gen;
1164+
.Ed
1165+
.Pp
1166+
Both assignment statements have a hierarchical path that ends with
1167+
.Ql .MY_GEN._P0._SO
1168+
and will not be considered distinct when merging.
1169+
To avoid this give each case branch a unique label:
1170+
.Bd -literal -offset indent
1171+
my_gen : case (op_kind) generate
1172+
when branch1: op_add => x <= a + b;
1173+
when branch2: op_sub => x <= a - b;
1174+
end generate my_gen;
1175+
.Ed
11531176
.Ss Additional Information
11541177
In coverage specification file and Exclude file
11551178
.Ql <ENTITY_NAME>

src/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ bool is_concurrent_block(tree_t t)
695695
case T_BLOCK:
696696
case T_IF_GENERATE:
697697
case T_FOR_GENERATE:
698+
case T_CASE_GENERATE:
698699
return true;
699700
default:
700701
return false;

src/cov/cov-data.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,7 @@ cover_scope_t *cover_create_instance(cover_data_t *data, cover_scope_t *parent,
993993
parent->name = parent->hier = lib_name(lib_work());
994994
}
995995

996-
// TODO: do not emit scopes for components
997-
assert(tree_kind(unit) == T_ARCH);
996+
assert(is_concurrent_block(unit));
998997
assert(tree_kind(block) == T_BLOCK);
999998

1000999
cover_scope_t *s = xcalloc(sizeof(cover_scope_t));

src/lower.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13131,7 +13131,7 @@ lower_unit_t *lower_instance(unit_registry_t *ur, lower_unit_t *parent,
1313113131
lu->cscope = cover_create_instance(cover, parent->parent->cscope,
1313213132
parent->container, unit);
1313313133
}
13134-
else if (tree_kind(unit) == T_ARCH)
13134+
else if (is_concurrent_block(unit))
1313513135
lu->cscope = cover_create_instance(cover, parent->cscope, block, unit);
1313613136
else
1313713137
lu->cscope = cover_create_scope(cover, parent->cscope, block, NULL);

src/simp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,9 @@ static tree_t simp_if_generate(tree_t t)
13221322
else {
13231323
tree_t b = tree_new(T_BLOCK);
13241324
tree_set_loc(b, tree_loc(t));
1325-
if (tree_has_ident(t))
1325+
if (tree_has_ident(c))
1326+
tree_set_ident(b, tree_ident(c));
1327+
else if (tree_has_ident(t))
13261328
tree_set_ident(b, tree_ident(t));
13271329

13281330
const int ndecls = tree_decls(c);

test/regress/cover27.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set -xe
2+
3+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=0 --cover=statement --cover-file=cover27_a.ncdb cover27 -r
4+
nvc --cover-export --format=xml -o cover27_a.xml cover27_a.ncdb
5+
sed -i -e "s/[^ ]*regress//g" cover27_a.xml
6+
7+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=1 --cover=statement --cover-file=cover27_b.ncdb cover27 -r
8+
nvc --cover-export --format=xml -o cover27_b.xml cover27_b.ncdb
9+
sed -i -e "s/[^ ]*regress//g" cover27_b.xml
10+
11+
nvc --cover-merge cover27*.ncdb --output=merged.covdb
12+
nvc --cover-report --output=html merged.covdb 2>&1 | tee out.txt
13+
14+
diff -u $TESTDIR/regress/gold/cover27.txt out.txt
15+
diff -u $TESTDIR/regress/gold/cover27_a.xml cover27_a.xml
16+
diff -u $TESTDIR/regress/gold/cover27_b.xml cover27_b.xml

test/regress/cover27.vhd

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
4+
entity cover27 is
5+
generic (
6+
G_PAR : integer
7+
);
8+
end entity;
9+
10+
architecture test of cover27 is
11+
12+
signal a,b,c,d,e,f : std_logic;
13+
signal vec : std_logic_vector(3 downto 0);
14+
15+
begin
16+
17+
G_IF_GEN : if (G_PAR = 0) generate
18+
a <= '0';
19+
elsif G_IF_GEN_1: (G_PAR = 1) generate
20+
b <= '0';
21+
end generate;
22+
23+
T_FOR_GEN : for i in 0 to 3 generate
24+
vec(i) <= a when (i = 0) else
25+
b when (i = 1) else
26+
c when (i = 2) else
27+
d;
28+
end generate;
29+
30+
G_CASE_GEN : case (G_PAR) generate
31+
when G_CASE_0: 0 => c <= '1';
32+
when G_CASE_1: 1 => d <= '0';
33+
end generate;
34+
35+
end architecture;

test/regress/gold/cover27.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
** Note: Code coverage report folder: html.
2+
** Note: Code coverage report contains: covered, uncovered, excluded coverage details.
3+
** Note: code coverage results for: WORK.COVER27
4+
** Note: statement: 100.0 % (8/8)
5+
** Note: branch: N.A.
6+
** Note: toggle: N.A.
7+
** Note: expression: N.A.
8+
** Note: FSM state: N.A.
9+
** Note: functional: N.A.

test/regress/gold/cover27_a.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" /cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="G_IF_GEN" block_name="G_IF_GEN" line="17">
5+
<scope name="_P0" line="18">
6+
<scope name="_S0">
7+
<statement hier="WORK.COVER27.G_IF_GEN._P0._S0" data="1"/>
8+
</scope>
9+
</scope>
10+
</scope>
11+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
12+
<scope name="_P0" line="24">
13+
<scope name="_S0">
14+
<scope name="_S0">
15+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="2"/>
16+
</scope>
17+
</scope>
18+
</scope>
19+
</scope>
20+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
21+
<scope name="_P0" line="24">
22+
<scope name="_S0">
23+
<scope name="_S0" line="25">
24+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="2"/>
25+
</scope>
26+
</scope>
27+
</scope>
28+
</scope>
29+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
30+
<scope name="_P0" line="24">
31+
<scope name="_S0">
32+
<scope name="_S0" line="26">
33+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="2"/>
34+
</scope>
35+
</scope>
36+
</scope>
37+
</scope>
38+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
39+
<scope name="_P0" line="24">
40+
<scope name="_S0">
41+
<scope name="_S0" line="27">
42+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="2"/>
43+
</scope>
44+
</scope>
45+
</scope>
46+
</scope>
47+
<scope name="G_CASE_0" block_name="G_CASE_0" line="31">
48+
<scope name="_P0">
49+
<scope name="_S0">
50+
<statement hier="WORK.COVER27.G_CASE_0._P0._S0" data="1"/>
51+
</scope>
52+
</scope>
53+
</scope>
54+
</scope>
55+
</scope>

test/regress/gold/cover27_b.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" /cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="G_IF_GEN_1" block_name="G_IF_GEN_1" line="17">
5+
<scope name="_P0" line="20">
6+
<scope name="_S0">
7+
<statement hier="WORK.COVER27.G_IF_GEN_1._P0._S0" data="1"/>
8+
</scope>
9+
</scope>
10+
</scope>
11+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
12+
<scope name="_P0" line="24">
13+
<scope name="_S0">
14+
<scope name="_S0">
15+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="2"/>
16+
</scope>
17+
</scope>
18+
</scope>
19+
</scope>
20+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
21+
<scope name="_P0" line="24">
22+
<scope name="_S0">
23+
<scope name="_S0" line="25">
24+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="2"/>
25+
</scope>
26+
</scope>
27+
</scope>
28+
</scope>
29+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
30+
<scope name="_P0" line="24">
31+
<scope name="_S0">
32+
<scope name="_S0" line="26">
33+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="2"/>
34+
</scope>
35+
</scope>
36+
</scope>
37+
</scope>
38+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
39+
<scope name="_P0" line="24">
40+
<scope name="_S0">
41+
<scope name="_S0" line="27">
42+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="2"/>
43+
</scope>
44+
</scope>
45+
</scope>
46+
</scope>
47+
<scope name="G_CASE_1" block_name="G_CASE_1" line="32">
48+
<scope name="_P0">
49+
<scope name="_S0">
50+
<statement hier="WORK.COVER27.G_CASE_1._P0._S0" data="1"/>
51+
</scope>
52+
</scope>
53+
</scope>
54+
</scope>
55+
</scope>

test/regress/gold/issue906.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<toggle hier="WORK.ISSUE906.Y(3).BIN_0_TO_1" data="1"/>
1818
<toggle hier="WORK.ISSUE906.Y(3).BIN_1_TO_0" data="0"/>
1919
</scope>
20-
<scope name="B" line="11">
20+
<scope name="B" block_name="B" line="11">
2121
<scope name="P" line="12">
2222
</scope>
2323
<scope name="Q" line="13">

test/regress/testlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,3 +1116,4 @@ issue1185 normal,2008
11161116
issue1186 normal,2008
11171117
issue1177 normal
11181118
issue1192 normal,vhpi
1119+
cover27 shell

0 commit comments

Comments
 (0)