@@ -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+
3058Function: 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 }
0 commit comments