Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemVerilog: associative arrays #917

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hw_cbmc_irep_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ IREP_ID_ONE(inst)
IREP_ID_ONE(Verilog)
IREP_ID_ONE(verilog_array_range)
IREP_ID_ONE(verilog_assignment_pattern)
IREP_ID_ONE(verilog_associative_array)
IREP_ID_ONE(verilog_declarations)
IREP_ID_ONE(verilog_lifetime)
IREP_ID_ONE(verilog_logical_equality)
Expand Down
19 changes: 19 additions & 0 deletions src/verilog/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,24 @@ packed_dimension:
| unsized_dimension
;

associative_dimension:
'[' data_type ']'
{ init($$, ID_verilog_associative_array);
// for the element type
stack_type($$).add_subtype().make_nil();
}
| '[' '*' ']'
{ init($$, ID_verilog_associative_array);
// for the element type
stack_type($$).add_subtype().make_nil();
}
| "[*" ']'
{ init($$, ID_verilog_associative_array);
// for the element type
stack_type($$).add_subtype().make_nil();
}
;

unpacked_dimension:
'[' const_expression TOK_COLON const_expression ']'
{ init($$, ID_verilog_unpacked_array);
Expand All @@ -2018,6 +2036,7 @@ unpacked_dimension:
variable_dimension:
unsized_dimension
| unpacked_dimension
| associative_dimension
;

variable_dimension_brace:
Expand Down
7 changes: 7 additions & 0 deletions src/verilog/verilog_elaborate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
return rec;
}
}
else if(src.id() == ID_verilog_associative_array)
{
// The subtype is the element type.
auto tmp = to_type_with_subtype(src);
tmp.subtype() = elaborate_type(tmp.subtype());
return std::move(tmp);
}
else if(src.id() == ID_verilog_byte)
{
// two-valued type, signed
Expand Down
10 changes: 8 additions & 2 deletions src/verilog/verilog_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ typet verilog_declaratort::merged_type(const typet &declaration_type) const
typet result = type();
typet *p = &result;

while(p->id() == ID_verilog_unpacked_array)
while(p->id() == ID_verilog_unpacked_array ||
p->id() == ID_verilog_associative_array)
{
p = &to_type_with_subtype(*p).subtype();
}

DATA_INVARIANT(
p->is_nil(),
"merged_type only works on unpacked arrays and associative arrays");

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

return result;
Expand Down
Loading