@@ -786,6 +786,21 @@ ObjectId dbNetwork::id(const Instance* instance) const
786786 return staToDb (instance)->getId ();
787787}
788788
789+ std::string dbNetwork::stripParentPrefix (const std::string& name)
790+ {
791+ size_t pos = name.length ();
792+ while ((pos = name.rfind (' /' , pos)) != std::string::npos) {
793+ if (pos > 0 && name[pos - 1 ] == ' \\ ' ) {
794+ // Escaped slash inside a Verilog escaped identifier; not a
795+ // hierarchy separator. Keep searching to the left.
796+ pos--;
797+ } else {
798+ return name.substr (pos + 1 );
799+ }
800+ }
801+ return name;
802+ }
803+
789804std::string dbNetwork::name (const Port* port) const
790805{
791806 if (isConcretePort (port)) {
@@ -808,10 +823,7 @@ std::string dbNetwork::name(const Port* port) const
808823 }
809824
810825 if (hasHierarchy ()) {
811- size_t last_idx = name.find_last_of (' /' );
812- if (last_idx != std::string::npos) {
813- name = name.substr (last_idx + 1 );
814- }
826+ name = stripParentPrefix (name);
815827 }
816828 return name;
817829}
@@ -855,21 +867,7 @@ std::string dbNetwork::name(const Instance* instance) const
855867 }
856868
857869 if (hasHierarchy ()) {
858- size_t last_idx = std::string::npos;
859- size_t pos = name.length ();
860- while ((pos = name.rfind (' /' , pos)) != std::string::npos) {
861- if (pos > 0 && name[pos - 1 ] == ' \\ ' ) {
862- // This is an escaped slash, so we should ignore it and continue
863- // searching.
864- pos--;
865- } else {
866- last_idx = pos;
867- break ;
868- }
869- }
870- if (last_idx != std::string::npos) {
871- name = name.substr (last_idx + 1 );
872- }
870+ name = stripParentPrefix (name);
873871 }
874872 return name;
875873}
0 commit comments