Skip to content

Commit 03033ab

Browse files
committed
add more tests for bounds attributes, fix attributes appearing in verilog
1 parent e91e95f commit 03033ab

File tree

4 files changed

+258
-15
lines changed

4 files changed

+258
-15
lines changed

frontends/verific/verific.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ void VerificImporter::import_attributes(dict<RTLIL::IdString, RTLIL::Const> &att
433433
auto type_range = nl->GetTypeRange(obj->Name());
434434
if (!type_range)
435435
return;
436-
if (type_range->IsTypeScalar()) {
436+
if (nl->IsFromVhdl() && type_range->IsTypeScalar()) {
437437
const long long bottom_bound = type_range->GetScalarRangeLeftBound();
438438
const long long top_bound = type_range->GetScalarRangeRightBound();
439439
const unsigned bit_width = type_range->NumElements();

tests/verific/bounds.sv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module test (
2+
input ia,
3+
output oa,
4+
input [0:0] ib,
5+
output [0:0] ob,
6+
input [3:0] ic,
7+
output [3:0] oc
8+
);
9+
10+
assign oa = ia;
11+
assign ob = ib;
12+
assign oc = ic;
13+
14+
endmodule

tests/verific/bounds.vhd

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,105 @@ library IEEE;
22
use IEEE.STD_LOGIC_1164.ALL;
33
use IEEE.NUMERIC_STD.ALL;
44

5-
entity work is
5+
entity test is
66
Port (
7-
a : in INTEGER range -5 to 10;
8-
b : out INTEGER range -6 to 11
7+
-- BIT type
8+
bit_in : in BIT;
9+
bit_out : out BIT;
10+
11+
-- BIT_VECTOR type
12+
bit_vector_in : in BIT_VECTOR(3 downto 0);
13+
bit_vector_out : out BIT_VECTOR(3 downto 0);
14+
15+
-- BIT_VECTOR type with to index
16+
bit_vector_in_to : in BIT_VECTOR(0 to 3);
17+
bit_vector_out_to : out BIT_VECTOR(0 to 3);
18+
19+
-- STD_ULOGIC type
20+
std_ulogic_in : in STD_ULOGIC;
21+
std_ulogic_out : out STD_ULOGIC;
22+
23+
-- STD_ULOGIC_VECTOR type
24+
std_ulogic_vector_in : in STD_ULOGIC_VECTOR(3 downto 0);
25+
std_ulogic_vector_out : out STD_ULOGIC_VECTOR(3 downto 0);
26+
27+
-- STD_ULOGIC_VECTOR type with to index
28+
std_ulogic_vector_in_to : in STD_ULOGIC_VECTOR(0 to 3);
29+
std_ulogic_vector_out_to : out STD_ULOGIC_VECTOR(0 to 3);
30+
31+
-- STD_LOGIC type
32+
std_logic_in : in STD_LOGIC;
33+
std_logic_out : out STD_LOGIC;
34+
35+
-- STD_LOGIC_VECTOR type
36+
std_logic_vector_in : in STD_LOGIC_VECTOR(3 downto 0);
37+
std_logic_vector_out : out STD_LOGIC_VECTOR(3 downto 0);
38+
39+
-- STD_LOGIC_VECTOR type with to index
40+
std_logic_vector_in_to : in STD_LOGIC_VECTOR(0 to 3);
41+
std_logic_vector_out_to : out STD_LOGIC_VECTOR(0 to 3);
42+
43+
-- SIGNED type
44+
signed_in : in SIGNED(3 downto 0);
45+
signed_out : out SIGNED(3 downto 0);
46+
47+
-- SIGNED type with to index
48+
signed_in_to : in SIGNED(0 to 3);
49+
signed_out_to : out SIGNED(0 to 3);
50+
51+
-- UNSIGNED type
52+
unsigned_in : in UNSIGNED(3 downto 0);
53+
unsigned_out : out UNSIGNED(3 downto 0);
54+
55+
-- UNSIGNED type with to index
56+
unsigned_in_to : in UNSIGNED(0 to 3);
57+
unsigned_out_to : out UNSIGNED(0 to 3);
58+
59+
-- INTEGER type without range
60+
integer_in : in INTEGER;
61+
integer_out : out INTEGER;
62+
63+
-- INTEGER type with range
64+
integer_with_range_in : in INTEGER range -5 to 10;
65+
integer_with_range_out : out INTEGER range -6 to 10;
66+
67+
-- INTEGER type with single value range
68+
integer_single_value_in : in INTEGER range 5 to 5;
69+
integer_single_value_out : out INTEGER range 5 to 5;
70+
71+
-- INTEGER type with null range
72+
integer_null_range_in : in INTEGER range 7 to -1;
73+
integer_null_range_out : out INTEGER range 0 to -1;
74+
75+
-- NATURAL type
76+
natural_in : in NATURAL;
77+
natural_out : out NATURAL;
78+
79+
-- POSITIVE type
80+
positive_in : in POSITIVE;
81+
positive_out : out POSITIVE
982
);
10-
end entity work;
83+
end entity test;
1184

12-
architecture Behavioral of work is
85+
architecture Behavioral of test is
1386
begin
14-
process(a)
15-
begin
16-
b <= a;
17-
end process;
87+
bit_out <= bit_in;
88+
bit_vector_out <= bit_vector_in;
89+
bit_vector_out_to <= bit_vector_in_to;
90+
std_ulogic_out <= std_ulogic_in;
91+
std_ulogic_vector_out <= std_ulogic_vector_in;
92+
std_ulogic_vector_out_to <= std_ulogic_vector_in_to;
93+
std_logic_out <= std_logic_in;
94+
std_logic_vector_out <= std_logic_vector_in;
95+
std_logic_vector_out_to <= std_logic_vector_in_to;
96+
signed_out <= signed_in;
97+
signed_out_to <= signed_in_to;
98+
unsigned_out <= unsigned_in;
99+
unsigned_out_to <= unsigned_in_to;
100+
integer_with_range_out <= integer_with_range_in;
101+
integer_out <= integer_in;
102+
integer_single_value_out <= integer_single_value_in;
103+
integer_null_range_out <= integer_null_range_in;
104+
natural_out <= natural_in;
105+
positive_out <= positive_in;
18106
end architecture Behavioral;

tests/verific/bounds.ys

Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,147 @@
11
read -vhdl bounds.vhd
2-
verific -import work
3-
select -assert-count 1 a:bottom_bound=5'bs11011
4-
select -assert-count 1 a:top_bound=5'bs01010
5-
select -assert-count 1 a:bottom_bound=5'bs11010
6-
select -assert-count 1 a:top_bound=5'bs01011
2+
hierarchy -top test
3+
4+
# bit: not a scalar type
5+
select -assert-count 0 w:bit_in a:bottom_bound %i
6+
select -assert-count 0 w:bit_in a:top_bound %i
7+
select -assert-count 0 w:bit_out a:bottom_bound %i
8+
select -assert-count 0 w:bit_out a:top_bound %i
9+
10+
# bit_vector: not a scalar type
11+
select -assert-count 0 w:bit_vector_in a:bottom_bound %i
12+
select -assert-count 0 w:bit_vector_in a:top_bound %i
13+
select -assert-count 0 w:bit_vector_out a:bottom_bound %i
14+
select -assert-count 0 w:bit_vector_out a:top_bound %i
15+
16+
# bit_vector with to index: not a scalar type
17+
select -assert-count 0 w:bit_vector_in_to a:bottom_bound %i
18+
select -assert-count 0 w:bit_vector_in_to a:top_bound %i
19+
select -assert-count 0 w:bit_vector_out_to a:bottom_bound %i
20+
select -assert-count 0 w:bit_vector_out_to a:top_bound %i
21+
22+
# std_ulogic: not a scalar type
23+
select -assert-count 0 w:std_ulogic_in a:bottom_bound %i
24+
select -assert-count 0 w:std_ulogic_in a:top_bound %i
25+
select -assert-count 0 w:std_ulogic_out a:bottom_bound %i
26+
select -assert-count 0 w:std_ulogic_out a:top_bound %i
27+
28+
# std_ulogic_vector: not a scalar type
29+
select -assert-count 0 w:std_ulogic_vector_in a:bottom_bound %i
30+
select -assert-count 0 w:std_ulogic_vector_in a:top_bound %i
31+
select -assert-count 0 w:std_ulogic_vector_out a:bottom_bound %i
32+
select -assert-count 0 w:std_ulogic_vector_out a:top_bound %i
33+
34+
# std_ulogic_vector with to index: not a scalar type
35+
select -assert-count 0 w:std_ulogic_vector_in_to a:bottom_bound %i
36+
select -assert-count 0 w:std_ulogic_vector_in_to a:top_bound %i
37+
select -assert-count 0 w:std_ulogic_vector_out_to a:bottom_bound %i
38+
select -assert-count 0 w:std_ulogic_vector_out_to a:top_bound %i
39+
40+
# std_logic: not a scalar type
41+
select -assert-count 0 w:std_logic_in a:bottom_bound %i
42+
select -assert-count 0 w:std_logic_in a:top_bound %i
43+
select -assert-count 0 w:std_logic_out a:bottom_bound %i
44+
select -assert-count 0 w:std_logic_out a:top_bound %i
45+
46+
# std_logic_vector: not a scalar type
47+
select -assert-count 0 w:std_logic_vector_in a:bottom_bound %i
48+
select -assert-count 0 w:std_logic_vector_in a:top_bound %i
49+
select -assert-count 0 w:std_logic_vector_out a:bottom_bound %i
50+
select -assert-count 0 w:std_logic_vector_out a:top_bound %i
51+
52+
# std_logic_vector with to index: not a scalar type
53+
select -assert-count 0 w:std_logic_vector_in_to a:bottom_bound %i
54+
select -assert-count 0 w:std_logic_vector_in_to a:top_bound %i
55+
select -assert-count 0 w:std_logic_vector_out_to a:bottom_bound %i
56+
select -assert-count 0 w:std_logic_vector_out_to a:top_bound %i
57+
58+
# signed: not a scalar type
59+
select -assert-count 0 w:signed_in a:bottom_bound %i
60+
select -assert-count 0 w:signed_in a:top_bound %i
61+
select -assert-count 0 w:signed_out a:bottom_bound %i
62+
select -assert-count 0 w:signed_out a:top_bound %i
63+
64+
# signed with to index: not a scalar type
65+
select -assert-count 0 w:signed_in_to a:bottom_bound %i
66+
select -assert-count 0 w:signed_in_to a:top_bound %i
67+
select -assert-count 0 w:signed_out_to a:bottom_bound %i
68+
select -assert-count 0 w:signed_out_to a:top_bound %i
69+
70+
# unsigned: not a scalar type
71+
select -assert-count 0 w:unsigned_in a:bottom_bound %i
72+
select -assert-count 0 w:unsigned_in a:top_bound %i
73+
select -assert-count 0 w:unsigned_out a:bottom_bound %i
74+
select -assert-count 0 w:unsigned_out a:top_bound %i
75+
76+
# unsigned with to index: not a scalar type
77+
select -assert-count 0 w:unsigned_in_to a:bottom_bound %i
78+
select -assert-count 0 w:unsigned_in_to a:top_bound %i
79+
select -assert-count 0 w:unsigned_out_to a:bottom_bound %i
80+
select -assert-count 0 w:unsigned_out_to a:top_bound %i
81+
82+
# integer: scalar type
83+
select -assert-count 1 w:integer_in a:bottom_bound=32'b10000000000000000000000000000000 %i
84+
select -assert-count 1 w:integer_in a:top_bound=32'b01111111111111111111111111111111 %i
85+
select -assert-count 1 w:integer_out a:bottom_bound=32'b10000000000000000000000000000000 %i
86+
select -assert-count 1 w:integer_out a:top_bound=32'b01111111111111111111111111111111 %i
87+
88+
# integer with range: scalar type
89+
select -assert-count 1 w:integer_with_range_in a:bottom_bound=5'bs11011 %i
90+
select -assert-count 1 w:integer_with_range_in a:top_bound=5'bs01010 %i
91+
select -assert-count 1 w:integer_with_range_out a:bottom_bound=5'bs11010 %i
92+
select -assert-count 1 w:integer_with_range_out a:top_bound=5'bs01010 %i
93+
94+
# integer with single value range: scalar type
95+
select -assert-count 1 w:integer_single_value_in a:bottom_bound=3'bs101 %i
96+
select -assert-count 1 w:integer_single_value_in a:top_bound=3'bs101 %i
97+
select -assert-count 1 w:integer_single_value_out a:bottom_bound=3'bs101 %i
98+
select -assert-count 1 w:integer_single_value_out a:top_bound=3'bs101 %i
99+
100+
# integer with null range: scalar type
101+
# select -assert-count 1 w:integer_null_range_in a:bottom_bound=4'bs0111 %i
102+
# select -assert-count 1 w:integer_null_range_in a:top_bound=4'bs1111 %i
103+
select -assert-count 1 w:integer_null_range_out a:bottom_bound=2'bs00 %i
104+
select -assert-count 1 w:integer_null_range_out a:top_bound=2'bs11 %i
105+
106+
# natural: scalar type
107+
select -assert-count 1 w:natural_in a:bottom_bound=31'b0000000000000000000000000000000 %i
108+
select -assert-count 1 w:natural_in a:top_bound=31'b1111111111111111111111111111111 %i
109+
select -assert-count 1 w:natural_out a:bottom_bound=31'b0000000000000000000000000000000 %i
110+
select -assert-count 1 w:natural_out a:top_bound=31'b1111111111111111111111111111111 %i
111+
112+
# positive: scalar type
113+
select -assert-count 1 w:positive_in a:bottom_bound=31'b0000000000000000000000000000001 %i
114+
select -assert-count 1 w:positive_in a:top_bound=31'b1111111111111111111111111111111 %i
115+
select -assert-count 1 w:positive_out a:bottom_bound=31'b0000000000000000000000000000001 %i
116+
select -assert-count 1 w:positive_out a:top_bound=31'b1111111111111111111111111111111 %i
117+
118+
119+
# integer size changed in VHDL 2019
120+
design -reset
121+
read -vhdl2019 bounds.vhd
122+
hierarchy -top test
123+
124+
# integer: scalar type
125+
select -assert-count 1 w:integer_in a:bottom_bound=64'b1000000000000000000000000000000000000000000000000000000000000000 %i
126+
select -assert-count 1 w:integer_in a:top_bound=64'b0111111111111111111111111111111111111111111111111111111111111111 %i
127+
select -assert-count 1 w:integer_out a:bottom_bound=64'b1000000000000000000000000000000000000000000000000000000000000000 %i
128+
select -assert-count 1 w:integer_out a:top_bound=64'b0111111111111111111111111111111111111111111111111111111111111111 %i
129+
130+
# natural: scalar type
131+
select -assert-count 1 w:natural_in a:bottom_bound=63'b000000000000000000000000000000000000000000000000000000000000000 %i
132+
select -assert-count 1 w:natural_in a:top_bound=63'b111111111111111111111111111111111111111111111111111111111111111 %i
133+
select -assert-count 1 w:natural_out a:bottom_bound=63'b000000000000000000000000000000000000000000000000000000000000000 %i
134+
select -assert-count 1 w:natural_out a:top_bound=63'b111111111111111111111111111111111111111111111111111111111111111 %i
135+
136+
# positive: scalar type
137+
select -assert-count 1 w:positive_in a:bottom_bound=63'b000000000000000000000000000000000000000000000000000000000000001 %i
138+
select -assert-count 1 w:positive_in a:top_bound=63'b111111111111111111111111111111111111111111111111111111111111111 %i
139+
select -assert-count 1 w:positive_out a:bottom_bound=63'b000000000000000000000000000000000000000000000000000000000000001 %i
140+
select -assert-count 1 w:positive_out a:top_bound=63'b111111111111111111111111111111111111111111111111111111111111111 %i
141+
142+
design -reset
143+
read -sv bounds.sv
144+
hierarchy -top test
145+
146+
select -assert-count none a:bottom_bound
147+
select -assert-count none a:top_bound

0 commit comments

Comments
 (0)