Skip to content

Commit 876ca77

Browse files
authored
Merge pull request #1291 from diffblue/verilog_null_conversion
Verilog: retain type of `null`
2 parents 6038d22 + fd38ee3 commit 876ca77

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/verilog/expr2verilog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,10 @@ expr2verilogt::convert_constant(const constant_exprt &src)
13481348
else
13491349
return convert_norep(src);
13501350
}
1351+
else if(type.id() == ID_verilog_null)
1352+
{
1353+
dest = "null";
1354+
}
13511355
else
13521356
return convert_norep(src);
13531357

src/verilog/verilog_lowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ exprt verilog_lowering_cast(typecast_exprt expr)
251251
auto &src_type = expr.op().type();
252252
auto &dest_type = expr.type();
253253

254+
if(src_type.id() == ID_verilog_null && dest_type.id() == ID_verilog_chandle)
255+
{
256+
return to_verilog_chandle_type(dest_type).null_expr();
257+
}
258+
259+
if(src_type.id() == ID_verilog_null && dest_type.id() == ID_verilog_event)
260+
{
261+
return to_verilog_event_type(dest_type).null_expr();
262+
}
263+
254264
// float to int
255265
if(
256266
(src_type.id() == ID_verilog_real ||

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,11 +2313,8 @@ void verilog_typecheck_exprt::implicit_typecast(
23132313
dest_type.id() == ID_verilog_class_type ||
23142314
dest_type.id() == ID_verilog_event)
23152315
{
2316-
if(expr.id() == ID_constant)
2317-
{
2318-
expr.type() = dest_type;
2319-
return;
2320-
}
2316+
expr = typecast_exprt{expr, dest_type};
2317+
return;
23212318
}
23222319
}
23232320

0 commit comments

Comments
 (0)