File tree Expand file tree Collapse file tree 11 files changed +113
-3
lines changed
regression/verilog/data-types Expand file tree Collapse file tree 11 files changed +113
-3
lines changed Original file line number Diff line number Diff line change
1
+ CORE
2
+ chandle1.sv
3
+ --bound 0
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ --
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -97,7 +97,8 @@ IREP_ID_ONE(verilog_property_declaration)
97
97
IREP_ID_ONE (verilog_value_range )
98
98
IREP_ID_ONE (verilog_streaming_concatenation_left_to_right )
99
99
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 )
101
102
IREP_ID_ONE (event )
102
103
IREP_ID_ONE (reg )
103
104
IREP_ID_ONE (macromodule )
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ SRC = aval_bval_encoding.cpp \
25
25
verilog_typecheck_base.cpp \
26
26
verilog_typecheck_expr.cpp \
27
27
verilog_typecheck_sva.cpp \
28
+ verilog_types.cpp \
28
29
verilog_y.tab.cpp \
29
30
vtype.cpp
30
31
Original file line number Diff line number Diff line change @@ -1878,6 +1878,8 @@ std::string expr2verilogt::convert(const typet &type)
1878
1878
1879
1879
return dest;
1880
1880
}
1881
+ else if (type.id () == ID_verilog_chandle)
1882
+ return " chandle" ;
1881
1883
else if (type.id () == ID_verilog_genvar)
1882
1884
return " genvar" ;
1883
1885
else if (type.id ()==ID_integer)
@@ -1888,6 +1890,8 @@ std::string expr2verilogt::convert(const typet &type)
1888
1890
return " real" ;
1889
1891
else if (type.id ()==ID_verilog_realtime)
1890
1892
return " realtime" ;
1893
+ else if (type.id () == ID_verilog_null)
1894
+ return " null" ;
1891
1895
else if (type.id () == ID_verilog_enum)
1892
1896
{
1893
1897
return " enum" ;
Original file line number Diff line number Diff line change @@ -1453,7 +1453,7 @@ data_type:
1453
1453
| TOK_STRING
1454
1454
{ init ($$, ID_string); }
1455
1455
| TOK_CHANDLE
1456
- { init ($$, ID_chandle ); }
1456
+ { init ($$, ID_verilog_chandle ); }
1457
1457
| TOK_VIRTUAL interface_opt interface_identifier
1458
1458
{ init ($$, " virtual_interface" ); }
1459
1459
| /* scope_opt*/ type_identifier packed_dimension_brace
@@ -3955,7 +3955,7 @@ primary: primary_literal
3955
3955
| cast
3956
3956
| assignment_pattern_expression
3957
3957
| streaming_concatenation
3958
- | TOK_NULL { init ($$, ID_NULL ); }
3958
+ | TOK_NULL { init ($$, ID_verilog_null ); }
3959
3959
| TOK_THIS { init ($$, ID_this); }
3960
3960
;
3961
3961
Original file line number Diff line number Diff line change @@ -333,6 +333,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
333
333
{
334
334
return src;
335
335
}
336
+ else if (src.id () == ID_verilog_chandle)
337
+ {
338
+ return src;
339
+ }
336
340
else
337
341
{
338
342
throw errort ().with_location (source_location)
Original file line number Diff line number Diff line change 15
15
#include " aval_bval_encoding.h"
16
16
#include " verilog_bits.h"
17
17
#include " verilog_expr.h"
18
+ #include " verilog_types.h"
18
19
19
20
exprt extract (
20
21
const exprt &src,
@@ -157,9 +158,24 @@ exprt verilog_lowering(exprt expr)
157
158
{
158
159
return lower_to_aval_bval (to_constant_expr (expr));
159
160
}
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
+ }
160
166
161
167
return expr;
162
168
}
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
+ }
163
179
else if (expr.id () == ID_concatenation)
164
180
{
165
181
if (
Original file line number Diff line number Diff line change @@ -1004,6 +1004,11 @@ exprt verilog_typecheck_exprt::convert_nullary_expr(nullary_exprt expr)
1004
1004
throw errort ().with_location (expr.source_location ())
1005
1005
<< " 'this' outside of method" ;
1006
1006
}
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
+ }
1007
1012
else
1008
1013
{
1009
1014
throw errort ().with_location (expr.source_location ())
@@ -2027,6 +2032,17 @@ void verilog_typecheck_exprt::implicit_typecast(
2027
2032
return ;
2028
2033
}
2029
2034
}
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
+ }
2030
2046
2031
2047
throw errort ().with_location (expr.source_location ())
2032
2048
<< " failed to convert `" << to_string (src_type) << " ' to `"
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -544,4 +544,41 @@ inline verilog_union_typet &to_verilog_union_type(typet &type)
544
544
return static_cast <verilog_union_typet &>(type);
545
545
}
546
546
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
+
547
584
#endif
You can’t perform that action at this time.
0 commit comments