@@ -2474,6 +2474,17 @@ void UhdmAst::process_enum_typespec()
24742474 const auto *enum_object = (const UHDM::enum_typespec *)handle->object ;
24752475 const auto *typespec = enum_object->Base_typespec ();
24762476
2477+ if (current_node->str .empty ()) {
2478+ // anonymous typespec, check if not already created
2479+ if (const auto enum_iter = shared.anonymous_enums .find (enum_object); enum_iter != shared.anonymous_enums .end ()) {
2480+ // we already created typedef for this.
2481+ delete current_node;
2482+ current_node = make_node (AST::AST_WIRETYPE);
2483+ current_node->str = enum_iter->second ;
2484+ return ;
2485+ }
2486+ }
2487+
24772488 if (typespec && typespec->UhdmType () == UHDM::uhdmlogic_typespec) {
24782489 // If it's a logic_typespec, try to reduce expressions inside of it.
24792490 // The `reduceExpr` function needs the whole context of the enum typespec
@@ -2562,6 +2573,17 @@ void UhdmAst::process_enum_typespec()
25622573 if (range) {
25632574 delete range;
25642575 }
2576+ if (current_node->str .empty ()) {
2577+ // anonymous typespec
2578+ std::string typedef_name = " $systemverilog_plugin$anonymous_enum" + std::to_string (shared.next_anonymous_enum_typedef_id ());
2579+ current_node->str = typedef_name;
2580+ auto current_scope = find_ancestor ({AST::AST_PACKAGE, AST::AST_MODULE, AST::AST_BLOCK, AST::AST_GENBLOCK});
2581+ uhdmast_assert (current_scope != nullptr );
2582+ move_type_to_new_typedef (current_scope, current_node);
2583+ current_node = make_node (AST::AST_WIRETYPE);
2584+ current_node->str = typedef_name;
2585+ shared.anonymous_enums [enum_object] = std::move (typedef_name);
2586+ }
25652587}
25662588
25672589void UhdmAst::process_enum_const ()
0 commit comments