Skip to content

Commit b8bf283

Browse files
committed
SystemVerilog: chandle data type
This adds 1800 2017 6.14 chandle.
1 parent 2733cf9 commit b8bf283

15 files changed

+170
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Verilog: fix for nor/nand/xnor primitive gates
77
* SystemVerilog: $bitstoreal/$bitstoshortreal, $realtobits/$shortrealtobits
88
* SystemVerilog: $itor, $rtoi
9+
* SystemVerilog: chandle
910

1011
# EBMC 5.4
1112

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
chandle1.sv
3+
--bound 0
4+
^\[main\.p0\] always main\.some_handle == null: PROVED up to bound 0$
5+
^\[main\.p1\] always 56'h6368616E646C65 == 56'h6368616E646C65: PROVED up to bound 0$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module main;
2+
3+
// IEEE 1800-2017 6.14
4+
chandle some_handle = null;
5+
6+
p0: assert final (some_handle == null);
7+
p1: assert final ($typename(some_handle) == "chandle");
8+
9+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ IREP_ID_ONE(verilog_value_range)
104104
IREP_ID_ONE(verilog_void)
105105
IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)
106106
IREP_ID_ONE(verilog_streaming_concatenation_right_to_left)
107-
IREP_ID_ONE(chandle)
107+
IREP_ID_ONE(verilog_chandle)
108+
IREP_ID_ONE(verilog_null)
108109
IREP_ID_ONE(event)
109110
IREP_ID_ONE(reg)
110111
IREP_ID_ONE(macromodule)

src/verilog/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SRC = aval_bval_encoding.cpp \
2626
verilog_typecheck_base.cpp \
2727
verilog_typecheck_expr.cpp \
2828
verilog_typecheck_sva.cpp \
29+
verilog_types.cpp \
2930
verilog_y.tab.cpp \
3031
vtype.cpp
3132

src/verilog/expr2verilog.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,15 @@ expr2verilogt::resultt expr2verilogt::convert_constant(
12081208
ieee_float.from_expr(tmp);
12091209
return {precedence, ieee_float.to_ansi_c_string()};
12101210
}
1211+
else if(type.id() == ID_verilog_chandle)
1212+
{
1213+
if(src.get_value() == ID_NULL)
1214+
{
1215+
dest = "null";
1216+
}
1217+
else
1218+
return convert_norep(src, precedence);
1219+
}
12111220
else
12121221
return convert_norep(src, precedence);
12131222

@@ -1978,6 +1987,8 @@ std::string expr2verilogt::convert(const typet &type)
19781987

19791988
return dest;
19801989
}
1990+
else if(type.id() == ID_verilog_chandle)
1991+
return "chandle";
19811992
else if(type.id() == ID_verilog_genvar)
19821993
return "genvar";
19831994
else if(type.id()==ID_integer)
@@ -1988,6 +1999,8 @@ std::string expr2verilogt::convert(const typet &type)
19881999
return "real";
19892000
else if(type.id()==ID_verilog_realtime)
19902001
return "realtime";
2002+
else if(type.id() == ID_verilog_null)
2003+
return "null";
19912004
else if(type.id() == ID_verilog_enum)
19922005
{
19932006
return "enum";

src/verilog/parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ data_type:
14771477
| TOK_STRING
14781478
{ init($$, ID_string); }
14791479
| TOK_CHANDLE
1480-
{ init($$, ID_chandle); }
1480+
{ init($$, ID_verilog_chandle); }
14811481
| TOK_VIRTUAL interface_opt interface_identifier
14821482
{ init($$, "virtual_interface"); }
14831483
| /*scope_opt*/ type_identifier packed_dimension_brace
@@ -4039,7 +4039,7 @@ primary: primary_literal
40394039
| cast
40404040
| assignment_pattern_expression
40414041
| streaming_concatenation
4042-
| TOK_NULL { init($$, ID_NULL); }
4042+
| TOK_NULL { init($$, ID_verilog_null); }
40434043
| TOK_THIS { init($$, ID_this); }
40444044
;
40454045

src/verilog/verilog_elaborate_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
383383
{
384384
return src;
385385
}
386+
else if(src.id() == ID_verilog_chandle)
387+
{
388+
return src;
389+
}
386390
else
387391
{
388392
throw errort().with_location(source_location)

src/verilog/verilog_lowering.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include "aval_bval_encoding.h"
1919
#include "verilog_bits.h"
2020
#include "verilog_expr.h"
21+
#include "verilog_types.h"
2122

2223
/// Lowers
2324
/// * the three Verilog real types to floatbv;
@@ -41,6 +42,10 @@ typet verilog_lowering(typet type)
4142
{
4243
return lower_to_aval_bval(type);
4344
}
45+
else if(type.id() == ID_verilog_chandle)
46+
{
47+
return to_verilog_chandle_type(type).encoding();
48+
}
4449
else
4550
return type;
4651
}
@@ -338,9 +343,26 @@ exprt verilog_lowering(exprt expr)
338343
// no need to change value
339344
expr.type() = verilog_lowering(expr.type());
340345
}
346+
else if(expr.type().id() == ID_verilog_chandle)
347+
{
348+
// this is 'null'
349+
return to_verilog_chandle_type(expr.type()).null_expr();
350+
}
341351

342352
return expr;
343353
}
354+
else if(expr.id() == ID_symbol)
355+
{
356+
auto &symbol_expr = to_symbol_expr(expr);
357+
if(expr.type().id() == ID_verilog_chandle)
358+
{
359+
auto &chandle_type = to_verilog_chandle_type(expr.type());
360+
return symbol_exprt{
361+
symbol_expr.get_identifier(), chandle_type.encoding()};
362+
}
363+
else
364+
return expr;
365+
}
344366
else if(expr.id() == ID_concatenation)
345367
{
346368
if(

src/verilog/verilog_synthesis.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3346,7 +3346,14 @@ void verilog_synthesist::synth_assignments(
33463346
if(!symbol.is_state_var)
33473347
post_process_wire(symbol.name, new_value);
33483348

3349-
equal_exprt equality_expr{symbol_expr(symbol, curr_or_next), new_value};
3349+
auto lhs = symbol_expr(symbol, curr_or_next);
3350+
3351+
if(lhs.type() != new_value.type())
3352+
throw errort() << lhs.pretty() << "\nVS\n" << new_value.pretty();
3353+
DATA_INVARIANT(
3354+
lhs.type() == new_value.type(), "synth_assignments type consistency");
3355+
3356+
equal_exprt equality_expr{std::move(lhs), new_value};
33503357

33513358
constraints.add_to_operands(std::move(equality_expr));
33523359
}

0 commit comments

Comments
 (0)