Skip to content

Commit 91c025c

Browse files
authored
Merge pull request #639 from diffblue/continuous_assignment_to_variable_systemverilog2.sv
Verilog: fix for continuous assignments to state variables
2 parents 77937fe + 272e412 commit 91c025c

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
continuous_assignment_to_variable_systemverilog2.sv
3+
--bound 1
4+
^\[main\.cover1\] cover 1: PROVED$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module main(input clk);
2+
3+
bit state = 0;
4+
5+
always_ff @(posedge clk)
6+
state = 1;
7+
8+
logic data;
9+
10+
// continuous assignment to variable
11+
assign data = state;
12+
13+
cover1: cover property (@(posedge clk) (1));
14+
15+
endmodule

src/verilog/verilog_synthesis.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,23 +2389,40 @@ void verilog_synthesist::synth_force_rec(
23892389
}
23902390

23912391
// get symbol
2392-
23932392
const symbolt &symbol=assignment_symbol(lhs);
23942393

2394+
// turn into combinational assignment
23952395
assignmentt &assignment=assignments[symbol.name];
23962396

23972397
if(assignment.type==event_guardt::NONE)
2398+
{
23982399
assignment.type=event_guardt::COMBINATIONAL;
2399-
else if(assignment.type!=event_guardt::COMBINATIONAL)
2400+
}
2401+
else if(assignment.type == event_guardt::CLOCK)
24002402
{
24012403
throw errort().with_location(lhs.source_location())
2402-
<< "variable is clocked";
2404+
<< "variable " << symbol.display_name() << " is clocked";
2405+
}
2406+
else if(assignment.type == event_guardt::COMBINATIONAL)
2407+
{
2408+
// leave as is
24032409
}
2410+
else
2411+
DATA_INVARIANT(false, "unexpected assignment type");
24042412

2405-
auto rhs_synth = synth_expr(rhs, symbol_statet::CURRENT);
2413+
auto rhs_synth = synth_expr(rhs, symbol_statet::CURRENT);
24062414

2407-
equal_exprt equality(lhs, rhs_synth);
2408-
invars.push_back(equality);
2415+
// If it's a variable, synth_assignments will
2416+
// generate the constraint.
2417+
if(symbol.is_state_var)
2418+
{
2419+
assignment.next.value = rhs_synth;
2420+
}
2421+
else
2422+
{
2423+
equal_exprt equality(lhs, rhs_synth);
2424+
invars.push_back(equality);
2425+
}
24092426
}
24102427

24112428
/*******************************************************************\
@@ -3642,7 +3659,7 @@ void verilog_synthesist::synth_assignments(transt &trans)
36423659
}
36433660
}
36443661
}
3645-
3662+
36463663
for(const auto & it : new_wires)
36473664
{
36483665
symbolt &symbol=symbol_table_lookup(it);
@@ -3725,7 +3742,7 @@ exprt verilog_synthesist::current_value(
37253742
{
37263743
return symbol_expr(symbol, CURRENT);
37273744
}
3728-
else
3745+
else if(construct == constructt::INITIAL)
37293746
{
37303747
// Initial state computation, i.e., this is a value _before_ the
37313748
// initial state -- make it non-deterministic
@@ -3734,6 +3751,10 @@ exprt verilog_synthesist::current_value(
37343751
result.set("initial_value", true);
37353752
return result;
37363753
}
3754+
else
3755+
{
3756+
DATA_INVARIANT(false, "unexpected assignment construct");
3757+
}
37373758
}
37383759
}
37393760

0 commit comments

Comments
 (0)