Skip to content

Commit f8c7c21

Browse files
committed
Verilog: use zero_extend_exprt
This replaces two typecasts by zero_extend_exprt.
1 parent 1a93509 commit f8c7c21

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/verilog/verilog_typecheck_expr.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -2097,23 +2097,14 @@ Function: zero_extend
20972097

20982098
static exprt zero_extend(const exprt &expr, const typet &type)
20992099
{
2100-
auto old_width = expr.type().id() == ID_bool ? 1
2101-
: expr.type().id() == ID_integer
2102-
? 32
2103-
: to_bitvector_type(expr.type()).get_width();
2104-
2105-
// first make unsigned
2106-
typet tmp_type;
2107-
2108-
if(type.id() == ID_unsignedbv)
2109-
tmp_type = unsignedbv_typet{old_width};
2110-
else if(type.id() == ID_verilog_unsignedbv)
2111-
tmp_type = verilog_unsignedbv_typet{old_width};
2112-
else
2113-
PRECONDITION(false);
2100+
exprt result = expr;
2101+
2102+
if(expr.type().id() == ID_bool)
2103+
result = typecast_exprt{expr, unsignedbv_typet{1}};
2104+
else if(expr.type().id() == ID_integer)
2105+
result = typecast_exprt{expr, unsignedbv_typet{32}};
21142106

2115-
return typecast_exprt::conditional_cast(
2116-
typecast_exprt::conditional_cast(expr, tmp_type), type);
2107+
return zero_extend_exprt{std::move(result), type};
21172108
}
21182109

21192110
/*******************************************************************\

0 commit comments

Comments
 (0)