Skip to content

Commit 20645b2

Browse files
committed
SystemVerilog: event data type
This adds 1800-2017 6.17 event.
1 parent cb19887 commit 20645b2

15 files changed

+130
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
event1.sv
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module main;
2+
3+
// IEEE 1800-2017 6.17
4+
event done;
5+
event empty = null;
6+
7+
task trigger_done;
8+
-> done;
9+
endtask
10+
11+
task wait_until_done;
12+
@ done;
13+
endtask
14+
15+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)
106106
IREP_ID_ONE(verilog_streaming_concatenation_right_to_left)
107107
IREP_ID_ONE(verilog_chandle)
108108
IREP_ID_ONE(verilog_null)
109-
IREP_ID_ONE(event)
109+
IREP_ID_ONE(verilog_event)
110+
IREP_ID_ONE(verilog_event_trigger)
110111
IREP_ID_ONE(reg)
111112
IREP_ID_ONE(macromodule)
112113
IREP_ID_ONE(output_register)

src/verilog/expr2verilog.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ 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)
1211+
else if(type.id() == ID_verilog_chandle || type.id() == ID_verilog_event)
12121212
{
12131213
if(src.get_value() == ID_NULL)
12141214
{
@@ -1989,6 +1989,8 @@ std::string expr2verilogt::convert(const typet &type)
19891989
}
19901990
else if(type.id() == ID_verilog_chandle)
19911991
return "chandle";
1992+
else if(type.id() == ID_verilog_event)
1993+
return "event";
19921994
else if(type.id() == ID_verilog_genvar)
19931995
return "genvar";
19941996
else if(type.id()==ID_integer)

src/verilog/parser.y

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ data_type:
14821482
$$ = $2; }
14831483
// | class_type
14841484
| TOK_EVENT
1485-
{ init($$, ID_event); }
1485+
{ init($$, ID_verilog_event); }
14861486
/*
14871487
| ps_covergroup_identifier
14881488
*/
@@ -3382,7 +3382,7 @@ event_control:
33823382

33833383
ored_event_expression:
33843384
event_expression
3385-
{ init($$, ID_event); mto($$, $1); }
3385+
{ init($$, ID_verilog_event); mto($$, $1); }
33863386
| ored_event_expression TOK_OR event_expression
33873387
{ $$=$1; mto($$, $3); }
33883388
| ored_event_expression ',' event_expression
@@ -3857,6 +3857,7 @@ function_subroutine_call: subroutine_call
38573857
;
38583858

38593859
event_trigger: TOK_MINUSGREATER hierarchical_event_identifier ';'
3860+
{ init($$, ID_verilog_event_trigger); mto($$, $2); }
38603861
;
38613862

38623863
// System Verilog standard 1800-2017

src/verilog/verilog_elaborate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ void verilog_typecheckt::collect_symbols(const verilog_statementt &statement)
751751
else if(statement.id() == ID_wait)
752752
{
753753
}
754+
else if(statement.id() == ID_verilog_event_trigger)
755+
{
756+
}
754757
else
755758
DATA_INVARIANT(false, "unexpected statement: " + statement.id_string());
756759
}

src/verilog/verilog_elaborate_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
256256
result.set(ID_C_identifier, enum_type.identifier());
257257
return result.with_source_location(source_location);
258258
}
259+
else if(src.id() == ID_verilog_event)
260+
{
261+
return src;
262+
}
259263
else if(src.id() == ID_verilog_packed_array)
260264
{
261265
return convert_packed_array_type(to_type_with_subtype(src));

src/verilog/verilog_lowering.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ exprt verilog_lowering(exprt expr)
189189
// this is 'null'
190190
return to_verilog_chandle_type(expr.type()).null_expr();
191191
}
192+
else if(expr.type().id() == ID_verilog_event)
193+
{
194+
// this is 'null'
195+
return to_verilog_event_type(expr.type()).null_expr();
196+
}
192197

193198
return expr;
194199
}
@@ -201,6 +206,11 @@ exprt verilog_lowering(exprt expr)
201206
return symbol_exprt{
202207
symbol_expr.get_identifier(), chandle_type.encoding()};
203208
}
209+
else if(expr.type().id() == ID_verilog_event)
210+
{
211+
auto &event_type = to_verilog_event_type(expr.type());
212+
return symbol_exprt{symbol_expr.get_identifier(), event_type.encoding()};
213+
}
204214
else
205215
return expr;
206216
}
@@ -441,6 +451,8 @@ typet verilog_lowering(typet type)
441451
return lower_to_aval_bval(type);
442452
else if(type.id() == ID_verilog_chandle)
443453
return to_verilog_chandle_type(type).encoding();
454+
else if(type.id() == ID_verilog_event)
455+
return to_verilog_event_type(type).encoding();
444456
else
445457
return type;
446458
}

src/verilog/verilog_synthesis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,10 @@ void verilog_synthesist::synth_statement(
31853185
}
31863186
else if(statement.id() == ID_verilog_label_statement)
31873187
synth_statement(to_verilog_label_statement(statement).statement());
3188+
else if(statement.id() == ID_verilog_event_trigger)
3189+
{
3190+
// not synthesized
3191+
}
31883192
else
31893193
{
31903194
throw errort().with_location(statement.source_location())
@@ -3348,8 +3352,6 @@ void verilog_synthesist::synth_assignments(
33483352

33493353
auto lhs = symbol_expr(symbol, curr_or_next);
33503354

3351-
if(lhs.type() != new_value.type())
3352-
throw errort() << lhs.pretty() << "\nVS\n" << new_value.pretty();
33533355
DATA_INVARIANT(
33543356
lhs.type() == new_value.type(), "synth_assignments type consistency");
33553357

src/verilog/verilog_typecheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,10 @@ void verilog_typecheckt::convert_statement(
16131613
else if(statement.id() == ID_wait)
16141614
{
16151615
}
1616+
else if(statement.id() == ID_verilog_event_trigger)
1617+
{
1618+
convert_expr(to_unary_expr(statement).op());
1619+
}
16161620
else
16171621
{
16181622
throw errort().with_location(statement.source_location())

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ exprt verilog_typecheck_exprt::convert_expr_rec(exprt expr)
275275
{
276276
// variable number of operands
277277

278-
if(expr.id()==ID_event)
278+
if(expr.id() == ID_verilog_event)
279279
{
280280
expr.type()=bool_typet();
281281

@@ -739,6 +739,10 @@ exprt verilog_typecheck_exprt::typename_string(const exprt &expr)
739739
{
740740
s = "chandle";
741741
}
742+
else if(type.id() == ID_verilog_event)
743+
{
744+
s = "event";
745+
}
742746
else
743747
s = "?";
744748

@@ -1943,7 +1947,9 @@ void verilog_typecheck_exprt::implicit_typecast(
19431947
}
19441948
else if(src_type.id() == ID_verilog_null)
19451949
{
1946-
if(dest_type.id() == ID_verilog_chandle)
1950+
if(
1951+
dest_type.id() == ID_verilog_chandle ||
1952+
dest_type.id() == ID_verilog_event)
19471953
{
19481954
if(expr.id() == ID_constant)
19491955
{
@@ -2210,6 +2216,12 @@ typet verilog_typecheck_exprt::max_type(
22102216
if(vt0.is_chandle() || vt1.is_null())
22112217
return t0;
22122218

2219+
if(vt0.is_null() || vt1.is_event())
2220+
return t1;
2221+
2222+
if(vt0.is_event() || vt1.is_null())
2223+
return t0;
2224+
22132225
if(vt0.is_other() || vt1.is_other())
22142226
return static_cast<const typet &>(get_nil_irep());
22152227

src/verilog/verilog_types.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ constant_exprt verilog_chandle_typet::null_expr() const
1414
{
1515
return encoding().all_zeros_expr();
1616
}
17+
18+
constant_exprt verilog_event_typet::null_expr() const
19+
{
20+
return encoding().all_zeros_expr();
21+
}

src/verilog/verilog_types.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,41 @@ inline verilog_chandle_typet &to_verilog_chandle_type(typet &type)
581581
return static_cast<verilog_chandle_typet &>(type);
582582
}
583583

584+
/// The SystemVerilog event type
585+
class verilog_event_typet : public typet
586+
{
587+
public:
588+
verilog_event_typet() : typet(ID_verilog_event)
589+
{
590+
}
591+
592+
constant_exprt null_expr() const;
593+
594+
bv_typet encoding() const
595+
{
596+
return bv_typet{32};
597+
}
598+
};
599+
600+
/// \brief Cast a typet to a \ref verilog_event_typet
601+
///
602+
/// This is an unchecked conversion. \a type must be known to be \ref
603+
/// verilog_event_typet. Will fail with a precondition violation if type
604+
/// doesn't match.
605+
///
606+
/// \param type: Source type.
607+
/// \return Object of type \ref verilog_event_typet
608+
inline const verilog_event_typet &to_verilog_event_type(const typet &type)
609+
{
610+
PRECONDITION(type.id() == ID_verilog_event);
611+
return static_cast<const verilog_event_typet &>(type);
612+
}
613+
614+
/// \copydoc to_event_type(const typet &)
615+
inline verilog_event_typet &to_verilog_event_type(typet &type)
616+
{
617+
PRECONDITION(type.id() == ID_verilog_event);
618+
return static_cast<verilog_event_typet &>(type);
619+
}
620+
584621
#endif

src/verilog/vtype.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ vtypet::vtypet(const typet &type)
7878
vtype = CHANDLE;
7979
width = 32;
8080
}
81+
else if(type.id() == ID_verilog_event)
82+
{
83+
vtype = EVENT;
84+
width = 32;
85+
}
8186
else
8287
{
8388
width=0;
@@ -122,16 +127,18 @@ std::ostream &operator << (std::ostream &out, const vtypet &vtype)
122127
case vtypet::VERILOG_REAL:
123128
return out << "real";
124129

130+
case vtypet::NULL_TYPE:
131+
return out << "null";
132+
125133
case vtypet::CHANDLE:
126134
return out << "chandle";
127135

128-
case vtypet::NULL_TYPE:
129-
return out << "null";
136+
case vtypet::EVENT:
137+
return out << "event";
130138

131139
case vtypet::UNKNOWN:
132140
case vtypet::OTHER:
133141
default:
134142
return out << "?";
135143
}
136144
}
137-

src/verilog/vtype.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ class vtypet
3131
{
3232
return vtype == VERILOG_REAL;
3333
}
34+
bool is_null() const
35+
{
36+
return vtype == NULL_TYPE;
37+
}
3438
bool is_chandle() const
3539
{
3640
return vtype == CHANDLE;
3741
}
38-
bool is_null() const
42+
inline bool is_event() const
3943
{
40-
return vtype == NULL_TYPE;
44+
return vtype == EVENT;
4145
}
4246
inline bool is_other() const { return vtype==OTHER; }
4347

@@ -52,8 +56,9 @@ class vtypet
5256
VERILOG_SIGNED,
5357
VERILOG_UNSIGNED,
5458
VERILOG_REAL,
55-
CHANDLE,
5659
NULL_TYPE,
60+
CHANDLE,
61+
EVENT,
5762
OTHER
5863
} _vtypet;
5964
_vtypet vtype;

0 commit comments

Comments
 (0)