Skip to content

Commit 378864d

Browse files
committed
bound attributes: handle vhdl null ranges
1 parent 03033ab commit 378864d

File tree

5 files changed

+88
-25
lines changed

5 files changed

+88
-25
lines changed

frontends/verific/verific.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static const std::string verific_unescape(const char *value)
407407
}
408408
#endif
409409

410-
void VerificImporter::import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, DesignObj *obj, Netlist *nl)
410+
void VerificImporter::import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, DesignObj *obj, Netlist *nl, int wire_width_hint)
411411
{
412412
if (!obj)
413413
return;
@@ -436,7 +436,15 @@ void VerificImporter::import_attributes(dict<RTLIL::IdString, RTLIL::Const> &att
436436
if (nl->IsFromVhdl() && type_range->IsTypeScalar()) {
437437
const long long bottom_bound = type_range->GetScalarRangeLeftBound();
438438
const long long top_bound = type_range->GetScalarRangeRightBound();
439-
const unsigned bit_width = type_range->NumElements();
439+
int bit_width = type_range->LeftRangeBound()+1;
440+
if (bit_width <= 0) { // VHDL null range
441+
if (wire_width_hint >= 0)
442+
bit_width = wire_width_hint;
443+
else
444+
bit_width = 64; //fallback, currently largest integer width that verific will allow (in vhdl2019 mode)
445+
} else {
446+
if (wire_width_hint >= 0) log_assert(bit_width == wire_width_hint);
447+
}
440448
RTLIL::Const bottom_const(bottom_bound, bit_width);
441449
RTLIL::Const top_const(top_bound, bit_width);
442450
if (bottom_bound < 0 || top_bound < 0) {
@@ -1499,7 +1507,7 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma
14991507
log(" importing port %s.\n", port->Name());
15001508

15011509
RTLIL::Wire *wire = module->addWire(RTLIL::escape_id(port->Name()));
1502-
import_attributes(wire->attributes, port, nl);
1510+
import_attributes(wire->attributes, port, nl, 1);
15031511

15041512
wire->port_id = nl->IndexOf(port) + 1;
15051513

@@ -1527,11 +1535,11 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma
15271535
RTLIL::Wire *wire = module->addWire(RTLIL::escape_id(portbus->Name()), portbus->Size());
15281536
wire->start_offset = min(portbus->LeftIndex(), portbus->RightIndex());
15291537
wire->upto = portbus->IsUp();
1530-
import_attributes(wire->attributes, portbus, nl);
1538+
import_attributes(wire->attributes, portbus, nl, portbus->Size());
15311539
SetIter si ;
15321540
Port *port ;
15331541
FOREACH_PORT_OF_PORTBUS(portbus, si, port) {
1534-
import_attributes(wire->attributes, port->GetNet(), nl);
1542+
import_attributes(wire->attributes, port->GetNet(), nl, portbus->Size());
15351543
break;
15361544
}
15371545
bool portbus_input = portbus->GetDir() == DIR_INOUT || portbus->GetDir() == DIR_IN;
@@ -1693,7 +1701,7 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma
16931701
log(" importing net %s as %s.\n", net->Name(), log_id(wire_name));
16941702

16951703
RTLIL::Wire *wire = module->addWire(wire_name);
1696-
import_attributes(wire->attributes, net, nl);
1704+
import_attributes(wire->attributes, net, nl, 1);
16971705

16981706
net_map[net] = wire;
16991707
}
@@ -1722,10 +1730,10 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma
17221730
MapIter mibus;
17231731
FOREACH_NET_OF_NETBUS(netbus, mibus, net) {
17241732
if (net)
1725-
import_attributes(wire->attributes, net, nl);
1733+
import_attributes(wire->attributes, net, nl, netbus->Size());
17261734
break;
17271735
}
1728-
import_attributes(wire->attributes, netbus, nl);
1736+
import_attributes(wire->attributes, netbus, nl, netbus->Size());
17291737

17301738
RTLIL::Const initval = Const(State::Sx, GetSize(wire));
17311739
bool initval_valid = false;

frontends/verific/verific.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct VerificImporter
8181
RTLIL::SigBit net_map_at(Verific::Net *net);
8282

8383
RTLIL::IdString new_verific_id(Verific::DesignObj *obj);
84-
void import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, Verific::DesignObj *obj, Verific::Netlist *nl = nullptr);
84+
void import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, Verific::DesignObj *obj, Verific::Netlist *nl = nullptr, int wire_width_hint = -1);
8585

8686
RTLIL::SigBit netToSigBit(Verific::Net *net);
8787
RTLIL::SigSpec operatorInput(Verific::Instance *inst);

tests/verific/bounds.sv

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
1+
typedef enum {IDLE, RUN, STOP} state_t;
2+
3+
typedef struct {
4+
logic [7:0] field1;
5+
int field2;
6+
} my_struct_t;
7+
8+
// Submodule to handle the interface ports
9+
module submodule (
10+
my_ifc i_ifc,
11+
my_ifc o_ifc
12+
);
13+
// Connect the interface signals
14+
assign o_ifc.data = i_ifc.data;
15+
endmodule
16+
117
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;
18+
input i_a,
19+
output o_a,
20+
input [0:0] i_b,
21+
output [0:0] o_b,
22+
input [3:0] i_c,
23+
output [3:0] o_c,
24+
input logic i_d,
25+
output logic o_d,
26+
input bit [7:0] i_e,
27+
output bit [7:0] o_e,
28+
input int i_f,
29+
output int o_f,
30+
input state_t i_h,
31+
output state_t o_h,
32+
input my_struct_t i_i,
33+
output my_struct_t o_i
34+
);
35+
36+
assign o_a = i_a;
37+
assign o_b = i_b;
38+
assign o_c = i_c;
39+
assign o_d = i_d;
40+
assign o_e = i_e;
41+
assign o_f = i_f;
42+
assign o_h = i_h;
43+
assign o_i = i_i;
1344

1445
endmodule

tests/verific/bounds.vhd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ entity test is
8383
end entity test;
8484

8585
architecture Behavioral of test is
86+
signal integer_with_range : INTEGER range -1 to 100;
8687
begin
8788
bit_out <= bit_in;
8889
bit_vector_out <= bit_vector_in;
@@ -103,4 +104,6 @@ begin
103104
integer_null_range_out <= integer_null_range_in;
104105
natural_out <= natural_in;
105106
positive_out <= positive_in;
107+
108+
integer_with_range <= 42;
106109
end architecture Behavioral;

tests/verific/bounds.ys

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ select -assert-count 1 w:integer_single_value_out a:bottom_bound=3'bs101 %i
9898
select -assert-count 1 w:integer_single_value_out a:top_bound=3'bs101 %i
9999

100100
# 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
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=1'bs0 %i
104+
select -assert-count 1 w:integer_null_range_out a:top_bound=1'bs1 %i
105105

106106
# natural: scalar type
107107
select -assert-count 1 w:natural_in a:bottom_bound=31'b0000000000000000000000000000000 %i
@@ -116,11 +116,11 @@ select -assert-count 1 w:positive_out a:bottom_bound=31'b00000000000000000000000
116116
select -assert-count 1 w:positive_out a:top_bound=31'b1111111111111111111111111111111 %i
117117

118118

119-
# integer size changed in VHDL 2019
120119
design -reset
121120
read -vhdl2019 bounds.vhd
122121
hierarchy -top test
123122

123+
## integer size changed in VHDL 2019
124124
# integer: scalar type
125125
select -assert-count 1 w:integer_in a:bottom_bound=64'b1000000000000000000000000000000000000000000000000000000000000000 %i
126126
select -assert-count 1 w:integer_in a:top_bound=64'b0111111111111111111111111111111111111111111111111111111111111111 %i
@@ -139,9 +139,30 @@ select -assert-count 1 w:positive_in a:top_bound=63'b111111111111111111111111111
139139
select -assert-count 1 w:positive_out a:bottom_bound=63'b000000000000000000000000000000000000000000000000000000000000001 %i
140140
select -assert-count 1 w:positive_out a:top_bound=63'b111111111111111111111111111111111111111111111111111111111111111 %i
141141

142+
## ranged integer sizes should be unaffected
143+
# integer with range: scalar type
144+
select -assert-count 1 w:integer_with_range_in a:bottom_bound=5'bs11011 %i
145+
select -assert-count 1 w:integer_with_range_in a:top_bound=5'bs01010 %i
146+
select -assert-count 1 w:integer_with_range_out a:bottom_bound=5'bs11010 %i
147+
select -assert-count 1 w:integer_with_range_out a:top_bound=5'bs01010 %i
148+
149+
# integer with single value range: scalar type
150+
select -assert-count 1 w:integer_single_value_in a:bottom_bound=3'bs101 %i
151+
select -assert-count 1 w:integer_single_value_in a:top_bound=3'bs101 %i
152+
select -assert-count 1 w:integer_single_value_out a:bottom_bound=3'bs101 %i
153+
select -assert-count 1 w:integer_single_value_out a:top_bound=3'bs101 %i
154+
155+
# integer with null range: scalar type
156+
select -assert-count 1 w:integer_null_range_in a:bottom_bound=4'bs0111 %i
157+
select -assert-count 1 w:integer_null_range_in a:top_bound=4'bs1111 %i
158+
select -assert-count 1 w:integer_null_range_out a:bottom_bound=1'bs0 %i
159+
select -assert-count 1 w:integer_null_range_out a:top_bound=1'bs1 %i
160+
161+
142162
design -reset
143163
read -sv bounds.sv
144164
hierarchy -top test
145165

166+
## bounds should not be generated for SV
146167
select -assert-count none a:bottom_bound
147168
select -assert-count none a:top_bound

0 commit comments

Comments
 (0)