@@ -27,6 +27,34 @@ Author: Daniel Kroening, kroening@kroening.com
27
27
28
28
/* ******************************************************************\
29
29
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
+
30
58
Function: verilog_typecheckt::typecheck_port_connection
31
59
32
60
Inputs:
@@ -74,7 +102,10 @@ void verilog_typecheckt::typecheck_port_connection(
74
102
if (symbol.is_output )
75
103
check_lhs (op, A_CONTINUOUS);
76
104
else
77
- propagate_type (op, port.type ());
105
+ {
106
+ // This is an assignment to the input
107
+ assignment_conversion (op, port.type ());
108
+ }
78
109
}
79
110
}
80
111
@@ -239,7 +270,8 @@ void verilog_typecheckt::typecheck_builtin_port_connections(
239
270
convert_expr (connection);
240
271
}
241
272
242
- propagate_type (connection, type);
273
+ // like an assignment
274
+ assignment_conversion (connection, type);
243
275
}
244
276
}
245
277
@@ -427,7 +459,7 @@ void verilog_typecheckt::convert_decl(verilog_declt &decl)
427
459
{
428
460
auto &rhs = declarator.value ();
429
461
convert_expr (rhs);
430
- propagate_type (rhs, symbol.type );
462
+ assignment_conversion (rhs, symbol.type );
431
463
}
432
464
}
433
465
}
@@ -795,7 +827,7 @@ void verilog_typecheckt::convert_procedural_continuous_assign(
795
827
convert_expr (lhs);
796
828
convert_expr (rhs);
797
829
798
- propagate_type (rhs, lhs.type ());
830
+ assignment_conversion (rhs, lhs.type ());
799
831
800
832
check_lhs (lhs, A_PROCEDURAL_CONTINUOUS);
801
833
}
@@ -839,7 +871,7 @@ void verilog_typecheckt::convert_continuous_assign(
839
871
else
840
872
convert_expr (lhs);
841
873
842
- propagate_type (rhs, lhs.type ());
874
+ assignment_conversion (rhs, lhs.type ());
843
875
844
876
check_lhs (lhs, A_CONTINUOUS);
845
877
}
@@ -903,7 +935,7 @@ void verilog_typecheckt::convert_function_call_or_task_enable(
903
935
for (unsigned i=0 ; i<arguments.size (); i++)
904
936
{
905
937
convert_expr (arguments[i]);
906
- propagate_type (arguments[i], parameter_types[i].type ());
938
+ assignment_conversion (arguments[i], parameter_types[i].type ());
907
939
}
908
940
909
941
statement.function ().type () = symbol->type ;
@@ -983,7 +1015,8 @@ void verilog_typecheckt::convert_force(verilog_forcet &statement)
983
1015
984
1016
convert_expr (lhs);
985
1017
convert_expr (rhs);
986
- propagate_type (rhs, lhs.type ());
1018
+
1019
+ assignment_conversion (rhs, lhs.type ());
987
1020
// check_lhs(lhs, blocking?A_BLOCKING:A_NON_BLOCKING);
988
1021
}
989
1022
@@ -1014,7 +1047,7 @@ void verilog_typecheckt::convert_assign(
1014
1047
1015
1048
convert_expr (lhs);
1016
1049
convert_expr (rhs);
1017
- propagate_type (rhs, lhs.type ());
1050
+ assignment_conversion (rhs, lhs.type ());
1018
1051
check_lhs (lhs, blocking?A_BLOCKING:A_NON_BLOCKING);
1019
1052
}
1020
1053
@@ -1199,6 +1232,8 @@ void verilog_typecheckt::convert_case_values(
1199
1232
Forall_operands (it, values)
1200
1233
{
1201
1234
convert_expr (*it);
1235
+
1236
+ // This works like a relational operator, not like an assignment
1202
1237
typet t=max_type (it->type (), case_operand.type ());
1203
1238
propagate_type (*it, t);
1204
1239
}
0 commit comments