Skip to content

Commit 866207f

Browse files
committed
Verilog: grammar for tagged unions
This adds the grammar for tagged union types and tagged union expressions. The type checker errors these as unsupported.
1 parent 9867c06 commit 866207f

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
tagged_union1.sv
3+
4+
^file .* line 9: no support for tagged unions$
5+
^EXIT=2$
6+
^SIGNAL=0$
7+
--
8+
--
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
typedef union tagged {
3+
void Invalid;
4+
int Valid;
5+
} VInt;
6+
7+
VInt v;
8+
9+
initial v = tagged Invalid;
10+
11+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ IREP_ID_ONE(verilog_past)
140140
IREP_ID_ONE(verilog_property_declaration)
141141
IREP_ID_ONE(verilog_sequence_declaration)
142142
IREP_ID_ONE(verilog_sequence)
143+
IREP_ID_ONE(verilog_tagged_union)
143144
IREP_ID_ONE(verilog_value_range)
144145
IREP_ID_ONE(verilog_void)
145146
IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)

src/verilog/parser.y

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,7 @@ unsized_dimension: '[' ']'
21612161
struct_union:
21622162
TOK_STRUCT { init($$, ID_struct); }
21632163
| TOK_UNION { init($$, ID_union); }
2164+
| TOK_UNION TOK_TAGGED { init($$, ID_union); }
21642165
;
21652166

21662167
// System Verilog standard 1800-2017
@@ -4341,6 +4342,12 @@ expression:
43414342
| TOK_QSTRING
43424343
{ init($$, ID_constant); stack_expr($$).type()=typet(ID_string); addswap($$, ID_value, $1); }
43434344
| inside_expression
4345+
| tagged_union_expression
4346+
;
4347+
4348+
tagged_union_expression:
4349+
TOK_TAGGED member_identifier
4350+
{ init($$, ID_verilog_tagged_union); mto($$, $2); }
43444351
;
43454352

43464353
inside_expression:

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,11 @@ exprt verilog_typecheck_exprt::convert_unary_expr(unary_exprt expr)
28192819
// assignment patterns, 1800 2017 10.9
28202820
convert_expr(expr.op());
28212821
}
2822+
else if(expr.id() == ID_verilog_tagged_union)
2823+
{
2824+
throw errort{}.with_location(expr.source_location())
2825+
<< "no support for tagged unions";
2826+
}
28222827
else
28232828
{
28242829
throw errort() << "no conversion for unary expression " << expr.id();

0 commit comments

Comments
 (0)