Skip to content

Commit a87374e

Browse files
committed
SystemVerilog: chandle data type
This adds 1800 2017 6.14 chandle.
1 parent 8642dd3 commit a87374e

File tree

11 files changed

+113
-3
lines changed

11 files changed

+113
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
chandle1.sv
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
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+
assert final (!some_handle);
7+
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
@@ -97,7 +97,8 @@ IREP_ID_ONE(verilog_property_declaration)
9797
IREP_ID_ONE(verilog_value_range)
9898
IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)
9999
IREP_ID_ONE(verilog_streaming_concatenation_right_to_left)
100-
IREP_ID_ONE(chandle)
100+
IREP_ID_ONE(verilog_chandle)
101+
IREP_ID_ONE(verilog_null)
101102
IREP_ID_ONE(event)
102103
IREP_ID_ONE(reg)
103104
IREP_ID_ONE(macromodule)

src/verilog/Makefile

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

src/verilog/expr2verilog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,8 @@ std::string expr2verilogt::convert(const typet &type)
18781878

18791879
return dest;
18801880
}
1881+
else if(type.id() == ID_verilog_chandle)
1882+
return "chandle";
18811883
else if(type.id() == ID_verilog_genvar)
18821884
return "genvar";
18831885
else if(type.id()==ID_integer)
@@ -1888,6 +1890,8 @@ std::string expr2verilogt::convert(const typet &type)
18881890
return "real";
18891891
else if(type.id()==ID_verilog_realtime)
18901892
return "realtime";
1893+
else if(type.id() == ID_verilog_null)
1894+
return "null";
18911895
else if(type.id() == ID_verilog_enum)
18921896
{
18931897
return "enum";

src/verilog/parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ data_type:
14531453
| TOK_STRING
14541454
{ init($$, ID_string); }
14551455
| TOK_CHANDLE
1456-
{ init($$, ID_chandle); }
1456+
{ init($$, ID_verilog_chandle); }
14571457
| TOK_VIRTUAL interface_opt interface_identifier
14581458
{ init($$, "virtual_interface"); }
14591459
| /*scope_opt*/ type_identifier packed_dimension_brace
@@ -3955,7 +3955,7 @@ primary: primary_literal
39553955
| cast
39563956
| assignment_pattern_expression
39573957
| streaming_concatenation
3958-
| TOK_NULL { init($$, ID_NULL); }
3958+
| TOK_NULL { init($$, ID_verilog_null); }
39593959
| TOK_THIS { init($$, ID_this); }
39603960
;
39613961

src/verilog/verilog_elaborate_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
333333
{
334334
return src;
335335
}
336+
else if(src.id() == ID_verilog_chandle)
337+
{
338+
return src;
339+
}
336340
else
337341
{
338342
throw errort().with_location(source_location)

src/verilog/verilog_lowering.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include "aval_bval_encoding.h"
1616
#include "verilog_bits.h"
1717
#include "verilog_expr.h"
18+
#include "verilog_types.h"
1819

1920
exprt extract(
2021
const exprt &src,
@@ -157,9 +158,24 @@ exprt verilog_lowering(exprt expr)
157158
{
158159
return lower_to_aval_bval(to_constant_expr(expr));
159160
}
161+
else if(expr.type().id() == ID_verilog_chandle)
162+
{
163+
// this is 'null'
164+
return to_verilog_chandle_type(expr.type()).null_expr();
165+
}
160166

161167
return expr;
162168
}
169+
else if(expr.id() == ID_symbol)
170+
{
171+
auto &symbol_expr = to_symbol_expr(expr);
172+
if(expr.type().id() == ID_verilog_chandle)
173+
{
174+
return symbol_exprt{symbol_expr.get_identifier(), unsignedbv_typet{32}};
175+
}
176+
else
177+
return expr;
178+
}
163179
else if(expr.id() == ID_concatenation)
164180
{
165181
if(

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,11 @@ exprt verilog_typecheck_exprt::convert_nullary_expr(nullary_exprt expr)
10041004
throw errort().with_location(expr.source_location())
10051005
<< "'this' outside of method";
10061006
}
1007+
else if(expr.id() == ID_verilog_null)
1008+
{
1009+
return constant_exprt{ID_NULL, typet{ID_verilog_null}}.with_source_location(
1010+
expr.source_location());
1011+
}
10071012
else
10081013
{
10091014
throw errort().with_location(expr.source_location())
@@ -2027,6 +2032,17 @@ void verilog_typecheck_exprt::implicit_typecast(
20272032
return;
20282033
}
20292034
}
2035+
else if(src_type.id() == ID_verilog_null)
2036+
{
2037+
if(dest_type.id() == ID_verilog_chandle)
2038+
{
2039+
if(expr.id() == ID_constant)
2040+
{
2041+
expr.type() = dest_type;
2042+
return;
2043+
}
2044+
}
2045+
}
20302046

20312047
throw errort().with_location(expr.source_location())
20322048
<< "failed to convert `" << to_string(src_type) << "' to `"

src/verilog/verilog_types.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*******************************************************************\
2+
3+
Module: Verilog Types
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "verilog_types.h"
10+
11+
#include <util/std_expr.h>
12+
13+
constant_exprt verilog_chandle_typet::null_expr() const
14+
{
15+
return encoding().all_zeros_expr();
16+
}

src/verilog/verilog_types.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,41 @@ inline verilog_union_typet &to_verilog_union_type(typet &type)
544544
return static_cast<verilog_union_typet &>(type);
545545
}
546546

547+
/// a pointer type
548+
class verilog_chandle_typet : public typet
549+
{
550+
public:
551+
inline verilog_chandle_typet() : typet(ID_verilog_chandle)
552+
{
553+
}
554+
555+
bv_typet encoding() const
556+
{
557+
return bv_typet{32};
558+
}
559+
560+
constant_exprt null_expr() const;
561+
};
562+
563+
/// \brief Cast a typet to a \ref verilog_chandle_typet
564+
///
565+
/// This is an unchecked conversion. \a type must be known to be \ref
566+
/// verilog_chandle_typet. Will fail with a precondition violation if type
567+
/// doesn't match.
568+
///
569+
/// \param type: Source type.
570+
/// \return Object of type \ref verilog_chandle_typet
571+
inline const verilog_chandle_typet &to_verilog_chandle_type(const typet &type)
572+
{
573+
PRECONDITION(type.id() == ID_verilog_chandle);
574+
return static_cast<const verilog_chandle_typet &>(type);
575+
}
576+
577+
/// \copydoc to_chandle_type(const typet &)
578+
inline verilog_chandle_typet &to_verilog_chandle_type(typet &type)
579+
{
580+
PRECONDITION(type.id() == ID_verilog_chandle);
581+
return static_cast<verilog_chandle_typet &>(type);
582+
}
583+
547584
#endif

0 commit comments

Comments
 (0)