Skip to content

Commit c93d1e8

Browse files
authored
Merge pull request #917 from diffblue/verilog_associative_array
SystemVerilog: associative arrays
2 parents 845b340 + 542afcd commit c93d1e8

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
associative_array1.sv
33

4-
^EXIT=0$
4+
^no properties$
5+
^EXIT=10$
56
^SIGNAL=0$
67
--
78
--
8-
Parsing fails.

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
@@ -2055,6 +2055,24 @@ packed_dimension:
20552055
| unsized_dimension
20562056
;
20572057

2058+
associative_dimension:
2059+
'[' data_type ']'
2060+
{ init($$, ID_verilog_associative_array);
2061+
// for the element type
2062+
stack_type($$).add_subtype().make_nil();
2063+
}
2064+
| '[' '*' ']'
2065+
{ init($$, ID_verilog_associative_array);
2066+
// for the element type
2067+
stack_type($$).add_subtype().make_nil();
2068+
}
2069+
| "[*" ']'
2070+
{ init($$, ID_verilog_associative_array);
2071+
// for the element type
2072+
stack_type($$).add_subtype().make_nil();
2073+
}
2074+
;
2075+
20582076
unpacked_dimension:
20592077
'[' const_expression TOK_COLON const_expression ']'
20602078
{ init($$, ID_verilog_unpacked_array);
@@ -2073,6 +2091,7 @@ unpacked_dimension:
20732091
variable_dimension:
20742092
unsized_dimension
20752093
| unpacked_dimension
2094+
| associative_dimension
20762095
;
20772096

20782097
variable_dimension_brace:

src/verilog/verilog_elaborate_type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
210210
return rec;
211211
}
212212
}
213+
else if(src.id() == ID_verilog_associative_array)
214+
{
215+
// The subtype is the element type.
216+
auto tmp = to_type_with_subtype(src);
217+
tmp.subtype() = elaborate_type(tmp.subtype());
218+
return std::move(tmp);
219+
}
213220
else if(src.id() == ID_verilog_byte)
214221
{
215222
// two-valued type, signed

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)