@@ -1879,11 +1879,12 @@ exprt verilog_typecheck_exprt::convert_unary_expr(unary_exprt expr)
18791879 }
18801880 else if (expr.id () == ID_verilog_explicit_cast)
18811881 {
1882- // System Verilog has got type'(expr). This is an explicit
1882+ // SystemVerilog has got type'(expr). This is an explicit
18831883 // type cast.
1884- expr.type () = convert_type (expr.type ());
18851884 convert_expr (expr.op ());
1886- expr.id (ID_typecast);
1885+ auto new_type = convert_type (expr.type ());
1886+ return typecast_exprt{expr.op (), new_type}.with_source_location <exprt>(
1887+ expr);
18871888 }
18881889 else if (expr.id () == ID_verilog_implicit_typecast)
18891890 {
@@ -2247,6 +2248,31 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
22472248 return convert_hierarchical_identifier (
22482249 to_hierarchical_identifier_expr (std::move (expr)));
22492250 }
2251+ else if (expr.id () == ID_verilog_size_cast)
2252+ {
2253+ // SystemVerilog has got expr'(expr). This is an explicit
2254+ // type cast, to change the size (in bits) of the rhs to the
2255+ // number given as lhs.
2256+ convert_expr (expr.rhs ());
2257+ auto new_size = convert_integer_constant_expression (expr.lhs ());
2258+ auto new_size_int = numeric_cast_v<std::size_t >(new_size);
2259+ auto &op_type = expr.rhs ().type ();
2260+ if (op_type.id () == ID_signedbv)
2261+ {
2262+ return typecast_exprt{expr.rhs (), signedbv_typet{new_size_int}}
2263+ .with_source_location <exprt>(expr);
2264+ }
2265+ else if (op_type.id () == ID_unsignedbv)
2266+ {
2267+ return typecast_exprt{expr.rhs (), unsignedbv_typet{new_size_int}}
2268+ .with_source_location <exprt>(expr);
2269+ }
2270+ else
2271+ {
2272+ throw errort ().with_location (expr.source_location ())
2273+ << " cannot perform size cast on " << to_string (op_type);
2274+ }
2275+ }
22502276 else
22512277 {
22522278 // type is guessed for now
0 commit comments