Skip to content

Commit 6997a06

Browse files
committed
SystemVerilog: associative arrays
1 parent e3fe283 commit 6997a06

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ IREP_ID_ONE(inst)
7878
IREP_ID_ONE(Verilog)
7979
IREP_ID_ONE(verilog_array_range)
8080
IREP_ID_ONE(verilog_assignment_pattern)
81+
IREP_ID_ONE(verilog_associative_array)
8182
IREP_ID_ONE(verilog_declarations)
8283
IREP_ID_ONE(verilog_lifetime)
8384
IREP_ID_ONE(verilog_logical_equality)

src/verilog/parser.y

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,24 @@ packed_dimension:
19791979
| unsized_dimension
19801980
;
19811981

1982+
associative_dimension:
1983+
'[' data_type ']'
1984+
{ init($$, ID_verilog_associative_array);
1985+
// for the element type
1986+
stack_type($$).add_subtype().make_nil();
1987+
}
1988+
| '[' '*' ']'
1989+
{ init($$, ID_verilog_associative_array);
1990+
// for the element type
1991+
stack_type($$).add_subtype().make_nil();
1992+
}
1993+
| "[*" ']'
1994+
{ init($$, ID_verilog_associative_array);
1995+
// for the element type
1996+
stack_type($$).add_subtype().make_nil();
1997+
}
1998+
;
1999+
19822000
unpacked_dimension:
19832001
'[' const_expression TOK_COLON const_expression ']'
19842002
{ init($$, ID_verilog_unpacked_array);
@@ -1997,6 +2015,7 @@ unpacked_dimension:
19972015
variable_dimension:
19982016
unsized_dimension
19992017
| unpacked_dimension
2018+
| associative_dimension
20002019
;
20012020

20022021
variable_dimension_brace:

src/verilog/verilog_elaborate_type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
177177
// one bit, unsigned
178178
return unsignedbv_typet{1}.with_source_location(source_location);
179179
}
180+
else if(src.id() == ID_verilog_associative_array)
181+
{
182+
// The subtype is the element type.
183+
auto tmp = to_type_with_subtype(src);
184+
tmp.subtype() = elaborate_type(tmp.subtype());
185+
return std::move(tmp);
186+
}
180187
else if(src.id() == ID_verilog_byte)
181188
{
182189
return signedbv_typet{8}.with_source_location(source_location);

src/verilog/verilog_expr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ typet verilog_declaratort::merged_type(const typet &declaration_type) const
3333
typet result = type();
3434
typet *p = &result;
3535

36-
while(p->id() == ID_verilog_unpacked_array)
36+
while(p->id() == ID_verilog_unpacked_array ||
37+
p->id() == ID_verilog_associative_array)
38+
{
3739
p = &to_type_with_subtype(*p).subtype();
40+
}
41+
42+
DATA_INVARIANT(
43+
p->is_nil(),
44+
"merged_type only works on unpacked arrays and associative arrays");
3845

39-
DATA_INVARIANT(p->is_nil(), "merged_type only works on unpacked arrays");
4046
*p = declaration_type;
4147

4248
return result;

0 commit comments

Comments
 (0)