Skip to content

Commit 3d4b5d4

Browse files
authored
Merge pull request #636 from diffblue/synth-indexed-part-select
Verilog: Synthesis for indexed part select
2 parents 4dee118 + 86a6be6 commit 3d4b5d4

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
indexed-part-select4.sv
33
--bound 0
44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
Synthesis-time constant folding for the index does not work.

src/verilog/verilog_synthesis.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -1060,20 +1060,24 @@ void verilog_synthesist::assignment_rec(
10601060
const exprt &lhs_index = part_select.index();
10611061
const exprt &lhs_width = part_select.width();
10621062

1063-
mp_integer index, width;
1063+
auto index_opt = synthesis_constant(lhs_index);
10641064

1065-
if(to_integer_non_constant(lhs_index, index))
1065+
if(!index_opt.has_value())
10661066
{
10671067
throw errort().with_location(lhs_index.source_location())
10681068
<< "failed to convert part select index";
10691069
}
10701070

1071-
if(to_integer_non_constant(lhs_width, width))
1071+
auto width_opt = synthesis_constant(lhs_width);
1072+
1073+
if(!width_opt.has_value())
10721074
{
10731075
throw errort().with_location(lhs_width.source_location())
10741076
<< "failed to convert part select width";
10751077
}
10761078

1079+
mp_integer index = *index_opt, width = *width_opt;
1080+
10771081
// turn
10781082
// a[i]=e
10791083
// into
@@ -1325,14 +1329,16 @@ void verilog_synthesist::assignment_member_rec(
13251329
const exprt &lhs_index = part_select.index();
13261330
const exprt &lhs_width = part_select.width();
13271331

1328-
mp_integer index, width;
1332+
auto index_opt = synthesis_constant(lhs_index);
13291333

1330-
if(to_integer_non_constant(lhs_index, index))
1334+
if(!index_opt.has_value())
13311335
{
13321336
throw errort().with_location(lhs_index.source_location())
13331337
<< "failed to convert part select index";
13341338
}
13351339

1340+
mp_integer index = index_opt.value(), width;
1341+
13361342
if(to_integer_non_constant(lhs_width, width))
13371343
{
13381344
throw errort().with_location(lhs_width.source_location())

0 commit comments

Comments
 (0)