Skip to content

Commit 65e652e

Browse files
committed
SystemVerilog: chandle data type
This adds 1800 2017 6.14 chandle.
1 parent 6c6f411 commit 65e652e

15 files changed

+168
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Verilog: fix for primitive gates with more than two inputs
55
* Verilog: Support $past when using AIG-based engines
66
* Verilog: fix for nor/nand/xnor primitive gates
7+
* SystemVerilog: chandle
78

89
# EBMC 5.4
910

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
@@ -103,7 +103,8 @@ IREP_ID_ONE(verilog_value_range)
103103
IREP_ID_ONE(verilog_void)
104104
IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)
105105
IREP_ID_ONE(verilog_streaming_concatenation_right_to_left)
106-
IREP_ID_ONE(chandle)
106+
IREP_ID_ONE(verilog_chandle)
107+
IREP_ID_ONE(verilog_null)
107108
IREP_ID_ONE(event)
108109
IREP_ID_ONE(reg)
109110
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
@@ -1473,7 +1473,7 @@ data_type:
14731473
| TOK_STRING
14741474
{ init($$, ID_string); }
14751475
| TOK_CHANDLE
1476-
{ init($$, ID_chandle); }
1476+
{ init($$, ID_verilog_chandle); }
14771477
| TOK_VIRTUAL interface_opt interface_identifier
14781478
{ init($$, "virtual_interface"); }
14791479
| /*scope_opt*/ type_identifier packed_dimension_brace
@@ -4018,7 +4018,7 @@ primary: primary_literal
40184018
| cast
40194019
| assignment_pattern_expression
40204020
| streaming_concatenation
4021-
| TOK_NULL { init($$, ID_NULL); }
4021+
| TOK_NULL { init($$, ID_verilog_null); }
40224022
| TOK_THIS { init($$, ID_this); }
40234023
;
40244024

src/verilog/verilog_elaborate_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
337337
{
338338
return src;
339339
}
340+
else if(src.id() == ID_verilog_chandle)
341+
{
342+
return src;
343+
}
340344
else
341345
{
342346
throw errort().with_location(source_location)

src/verilog/verilog_lowering.cpp

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

2122
/// If applicable, lower the three Verilog real types to floatbv.
2223
typet lower_verilog_real_types(typet type)
@@ -183,9 +184,26 @@ exprt verilog_lowering(exprt expr)
183184
// no need to change value
184185
expr.type() = lower_verilog_real_types(expr.type());
185186
}
187+
else if(expr.type().id() == ID_verilog_chandle)
188+
{
189+
// this is 'null'
190+
return to_verilog_chandle_type(expr.type()).null_expr();
191+
}
186192

187193
return expr;
188194
}
195+
else if(expr.id() == ID_symbol)
196+
{
197+
auto &symbol_expr = to_symbol_expr(expr);
198+
if(expr.type().id() == ID_verilog_chandle)
199+
{
200+
auto &chandle_type = to_verilog_chandle_type(expr.type());
201+
return symbol_exprt{
202+
symbol_expr.get_identifier(), chandle_type.encoding()};
203+
}
204+
else
205+
return expr;
206+
}
189207
else if(expr.id() == ID_concatenation)
190208
{
191209
if(
@@ -421,6 +439,8 @@ typet verilog_lowering(typet type)
421439
{
422440
if(type.id() == ID_verilog_signedbv || type.id() == ID_verilog_unsignedbv)
423441
return lower_to_aval_bval(type);
442+
else if(type.id() == ID_verilog_chandle)
443+
return to_verilog_chandle_type(type).encoding();
424444
else
425445
return type;
426446
}

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)