Skip to content

Commit 10f9fc4

Browse files
authored
Merge pull request #1279 from diffblue/assignment_conversion
Verilog: assignment conversion
2 parents 878a1c1 + 18504a4 commit 10f9fc4

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

regression/verilog/SVA/sequence_repetition1.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module main(input clk);
44

55
// 0 1 2 3 4 ...
66
always_ff @(posedge clk)
7-
x<=x+1;
7+
x<=x+8'd1;
88

99
// 0 0 1 1 2 2 3 3 ...
10-
wire [7:0] half_x = x/2;
10+
wire [7:0] half_x = x/8'd2;
1111

1212
// should pass
1313
initial p0: assert property (half_x==0[*2]);

regression/verilog/SVA/sequence_repetition2.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module main(input clk);
44

55
// 0 1 2 3 4 ...
66
always_ff @(posedge clk)
7-
x<=x+1;
7+
x<=x+8'd1;
88

99
// 0 0 1 1 2 2 3 3 ...
10-
wire [7:0] half_x = x/2;
10+
wire [7:0] half_x = x/8'd2;
1111

1212
// should pass
1313
initial p0: assert property (x==0[*]);

regression/verilog/SVA/sequence_repetition3.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module main(input clk);
44

55
// 0 1 2 3 4 ...
66
always_ff @(posedge clk)
7-
x<=x+1;
7+
x<=x+8'd1;
88

99
// 0 0 1 1 2 2 3 3 ...
10-
wire [7:0] half_x = x/2;
10+
wire [7:0] half_x = x/8'd2;
1111

1212
// should pass
1313
initial p0: assert property (x==0[*1] #=# x==1[*1]);

regression/verilog/modules/ports2.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE broken-smt-backend
22
ports2.v
33
--module main --bound 1
44
^EXIT=0$

src/verilog/verilog_typecheck.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ Author: Daniel Kroening, kroening@kroening.com
2727

2828
/*******************************************************************\
2929
30+
Function: verilog_typecheckt::assignment_conversion
31+
32+
Inputs:
33+
34+
Outputs:
35+
36+
Purpose:
37+
38+
\*******************************************************************/
39+
40+
void verilog_typecheckt::assignment_conversion(
41+
exprt &rhs,
42+
const typet &lhs_type)
43+
{
44+
// Implements 1800-2017 10.7
45+
// If the RHS is smaller than the LHS:
46+
// * if the RHS is unsigned, it is zero-padded
47+
// * if the RHS is signed, it is sign-extended
48+
// If the RHS is larger than the LHS, it is truncated.
49+
50+
// This matches our typecast, but differs from the steps taken
51+
// when evaluating binary expressions (11.8.2), where sign
52+
// extension only happens when the propagated type is signed.
53+
implicit_typecast(rhs, lhs_type);
54+
}
55+
56+
/*******************************************************************\
57+
3058
Function: verilog_typecheckt::typecheck_port_connection
3159
3260
Inputs:
@@ -74,7 +102,10 @@ void verilog_typecheckt::typecheck_port_connection(
74102
if(symbol.is_output)
75103
check_lhs(op, A_CONTINUOUS);
76104
else
77-
propagate_type(op, port.type());
105+
{
106+
// This is an assignment to the input
107+
assignment_conversion(op, port.type());
108+
}
78109
}
79110
}
80111

@@ -239,7 +270,8 @@ void verilog_typecheckt::typecheck_builtin_port_connections(
239270
convert_expr(connection);
240271
}
241272

242-
propagate_type(connection, type);
273+
// like an assignment
274+
assignment_conversion(connection, type);
243275
}
244276
}
245277

@@ -427,7 +459,7 @@ void verilog_typecheckt::convert_decl(verilog_declt &decl)
427459
{
428460
auto &rhs = declarator.value();
429461
convert_expr(rhs);
430-
propagate_type(rhs, symbol.type);
462+
assignment_conversion(rhs, symbol.type);
431463
}
432464
}
433465
}
@@ -795,7 +827,7 @@ void verilog_typecheckt::convert_procedural_continuous_assign(
795827
convert_expr(lhs);
796828
convert_expr(rhs);
797829

798-
propagate_type(rhs, lhs.type());
830+
assignment_conversion(rhs, lhs.type());
799831

800832
check_lhs(lhs, A_PROCEDURAL_CONTINUOUS);
801833
}
@@ -839,7 +871,7 @@ void verilog_typecheckt::convert_continuous_assign(
839871
else
840872
convert_expr(lhs);
841873

842-
propagate_type(rhs, lhs.type());
874+
assignment_conversion(rhs, lhs.type());
843875

844876
check_lhs(lhs, A_CONTINUOUS);
845877
}
@@ -903,7 +935,7 @@ void verilog_typecheckt::convert_function_call_or_task_enable(
903935
for(unsigned i=0; i<arguments.size(); i++)
904936
{
905937
convert_expr(arguments[i]);
906-
propagate_type(arguments[i], parameter_types[i].type());
938+
assignment_conversion(arguments[i], parameter_types[i].type());
907939
}
908940

909941
statement.function().type() = symbol->type;
@@ -983,7 +1015,8 @@ void verilog_typecheckt::convert_force(verilog_forcet &statement)
9831015

9841016
convert_expr(lhs);
9851017
convert_expr(rhs);
986-
propagate_type(rhs, lhs.type());
1018+
1019+
assignment_conversion(rhs, lhs.type());
9871020
//check_lhs(lhs, blocking?A_BLOCKING:A_NON_BLOCKING);
9881021
}
9891022

@@ -1014,7 +1047,7 @@ void verilog_typecheckt::convert_assign(
10141047

10151048
convert_expr(lhs);
10161049
convert_expr(rhs);
1017-
propagate_type(rhs, lhs.type());
1050+
assignment_conversion(rhs, lhs.type());
10181051
check_lhs(lhs, blocking?A_BLOCKING:A_NON_BLOCKING);
10191052
}
10201053

@@ -1199,6 +1232,8 @@ void verilog_typecheckt::convert_case_values(
11991232
Forall_operands(it, values)
12001233
{
12011234
convert_expr(*it);
1235+
1236+
// This works like a relational operator, not like an assignment
12021237
typet t=max_type(it->type(), case_operand.type());
12031238
propagate_type(*it, t);
12041239
}

src/verilog/verilog_typecheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class verilog_typecheckt:
168168
void convert_assert_assume_cover(verilog_assert_assume_cover_statementt &);
169169
void convert_assume(verilog_assume_statementt &);
170170

171+
void assignment_conversion(exprt &rhs, const typet &lhs_type);
172+
171173
// module items
172174
void convert_decl(class verilog_declt &);
173175
void convert_function_or_task(class verilog_function_or_task_declt &);

0 commit comments

Comments
 (0)