Skip to content

Commit 7f7e517

Browse files
committed
SystemVerilog: associative arrays
1 parent 4b0c862 commit 7f7e517

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
@@ -2000,6 +2000,24 @@ packed_dimension:
20002000
| unsized_dimension
20012001
;
20022002

2003+
associative_dimension:
2004+
'[' data_type ']'
2005+
{ init($$, ID_verilog_associative_array);
2006+
// for the element type
2007+
stack_type($$).add_subtype().make_nil();
2008+
}
2009+
| '[' '*' ']'
2010+
{ init($$, ID_verilog_associative_array);
2011+
// for the element type
2012+
stack_type($$).add_subtype().make_nil();
2013+
}
2014+
| "[*" ']'
2015+
{ init($$, ID_verilog_associative_array);
2016+
// for the element type
2017+
stack_type($$).add_subtype().make_nil();
2018+
}
2019+
;
2020+
20032021
unpacked_dimension:
20042022
'[' const_expression TOK_COLON const_expression ']'
20052023
{ init($$, ID_verilog_unpacked_array);
@@ -2018,6 +2036,7 @@ unpacked_dimension:
20182036
variable_dimension:
20192037
unsized_dimension
20202038
| unpacked_dimension
2039+
| associative_dimension
20212040
;
20222041

20232042
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)