@@ -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
25792601void UhdmAst::process_enum_const ()
0 commit comments