Skip to content

Commit 47d438a

Browse files
committed
systemverilog-plugin: add support for multiple variables declared in anonymous enum var
Signed-off-by: Kamil Rakoczy <[email protected]>
1 parent a08c529 commit 47d438a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

systemverilog-plugin/UhdmAst.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,17 @@ void UhdmAst::process_enum_typespec()
24862486
const auto *enum_object = (const UHDM::enum_typespec *)handle->object;
24872487
const auto *typespec = enum_object->Base_typespec();
24882488

2489+
if (current_node->str.empty()) {
2490+
// anonymous typespec, check if not already created
2491+
if (shared.anonymous_enums.find(enum_object) != shared.anonymous_enums.end()) {
2492+
// we already created typedef for this.
2493+
delete current_node;
2494+
current_node = new AST::AstNode(AST::AST_WIRETYPE);
2495+
current_node->str = shared.anonymous_enums[enum_object];
2496+
return;
2497+
}
2498+
}
2499+
24892500
if (typespec && typespec->UhdmType() == UHDM::uhdmlogic_typespec) {
24902501
// If it's a logic_typespec, try to reduce expressions inside of it.
24912502
// The `reduceExpr` function needs the whole context of the enum typespec
@@ -2574,6 +2585,17 @@ void UhdmAst::process_enum_typespec()
25742585
if (range) {
25752586
delete range;
25762587
}
2588+
if (current_node->str.empty()) {
2589+
// anonymous typespec
2590+
std::string typedef_name = "$systemverilog_plugin$anonymous_enum" + std::to_string(shared.next_anonymous_enum_typedef_id());
2591+
current_node->str = typedef_name;
2592+
auto current_scope = find_ancestor({AST::AST_PACKAGE, AST::AST_MODULE, AST::AST_BLOCK, AST::AST_GENBLOCK});
2593+
uhdmast_assert(current_scope != nullptr);
2594+
move_type_to_new_typedef(current_scope, current_node);
2595+
current_node = new AST::AstNode(AST::AST_WIRETYPE);
2596+
current_node->str = typedef_name;
2597+
shared.anonymous_enums[enum_object] = typedef_name;
2598+
}
25772599
}
25782600

25792601
void UhdmAst::process_enum_const()

systemverilog-plugin/uhdmastshared.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class UhdmAstShared
2525
// Used for generating unique names for anonymous types used as parameters.
2626
unsigned anonymous_type_count = 0;
2727

28+
// Used to generate unique names for anonymous enum typedefs
29+
unsigned anonymous_enum_typedef_count = 0;
30+
2831
public:
2932
~UhdmAstShared()
3033
{
@@ -45,6 +48,9 @@ class UhdmAstShared
4548
// Generate the next anonymous type ID (starting with 0).
4649
unsigned next_anonymous_type_id() { return anonymous_type_count++; }
4750

51+
// Generate the next anonymous enum typedef ID (starting with 0).
52+
unsigned next_anonymous_enum_typedef_id() { return anonymous_enum_typedef_count++; }
53+
4854
// Flag that determines whether debug info should be printed
4955
bool debug_flag = false;
5056

@@ -81,8 +87,12 @@ class UhdmAstShared
8187
std::unordered_map<std::string, ::Yosys::AST::AstNode *> param_types;
8288

8389
::Yosys::AST::AstNode *current_top_node = nullptr;
90+
8491
// Set of non-synthesizable objects to skip in current design;
8592
std::set<const UHDM::BaseClass *> nonSynthesizableObjects;
93+
94+
// Map of anonymous enum types to generated typedefs
95+
std::unordered_map<const UHDM::enum_typespec *, std::string> anonymous_enums;
8696
};
8797

8898
} // namespace systemverilog_plugin

0 commit comments

Comments
 (0)