From 8b2902c31bd1efd052d88ddfd3b7bf3f5351792a Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 27 Dec 2018 10:43:25 +0100 Subject: [PATCH] WIP: introduced expanded net name --- src/db/db/dbNetlist.cc | 14 ++++++++++++++ src/db/db/dbNetlist.h | 8 ++++++++ src/db/db/gsiDeclDbNetlist.cc | 4 ++++ src/db/unit_tests/dbNetlistDeviceExtractorTests.cc | 13 +------------ src/db/unit_tests/dbNetlistTests.cc | 5 +++++ testdata/ruby/dbNetlist.rb | 5 +++++ 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/db/db/dbNetlist.cc b/src/db/db/dbNetlist.cc index ec2a987bd..bf5de8610 100644 --- a/src/db/db/dbNetlist.cc +++ b/src/db/db/dbNetlist.cc @@ -415,6 +415,20 @@ void Net::set_name (const std::string &name) m_name = name; } +std::string Net::expanded_name () const +{ + if (name ().empty ()) { + if (cluster_id () > std::numeric_limits::max () / 2) { + // avoid printing huge ID numbers for internal cluster IDs + return "$I" + tl::to_string ((std::numeric_limits::max () - cluster_id ()) + 1); + } else { + return "$" + tl::to_string (cluster_id ()); + } + } else { + return name (); + } +} + void Net::set_cluster_id (size_t ci) { m_cluster_id = ci; diff --git a/src/db/db/dbNetlist.h b/src/db/db/dbNetlist.h index 09652cb08..cf44b1c84 100644 --- a/src/db/db/dbNetlist.h +++ b/src/db/db/dbNetlist.h @@ -352,6 +352,14 @@ public: return m_name; } + /** + * @brief Gets the expanded name + * + * The "expanded name" is a non-empty name for the net. It uses the + * cluster ID if no name is set. + */ + std::string expanded_name () const; + /** * @brief Sets the cluster ID of this net * diff --git a/src/db/db/gsiDeclDbNetlist.cc b/src/db/db/gsiDeclDbNetlist.cc index e210eccb2..32abccf50 100644 --- a/src/db/db/gsiDeclDbNetlist.cc +++ b/src/db/db/gsiDeclDbNetlist.cc @@ -236,6 +236,10 @@ Class decl_dbNet ("db", "Net", "@brief Gets the name of the net.\n" "See \\name= for details about the name." ) + + gsi::method ("expanded_name", &db::Net::expanded_name, + "@brief Gets the expanded name of the net.\n" + "The expanded name takes the name of the net. If the name is empty, the cluster ID will be used to build a name. " + ) + gsi::method ("cluster_id=", &db::Net::set_cluster_id, gsi::arg ("id"), "@brief Sets the cluster ID of the net.\n" "The cluster ID connects the net with a layout cluster. It is set when " diff --git a/src/db/unit_tests/dbNetlistDeviceExtractorTests.cc b/src/db/unit_tests/dbNetlistDeviceExtractorTests.cc index 97c648649..71bdba71f 100644 --- a/src/db/unit_tests/dbNetlistDeviceExtractorTests.cc +++ b/src/db/unit_tests/dbNetlistDeviceExtractorTests.cc @@ -405,20 +405,9 @@ private: hier_clusters_type m_net_clusters; }; -// @@@ TODO: move this somewhere else static std::string net_name (const db::Net *net) { - if (! net) { - return "(null)"; - } else if (net->name ().empty ()) { - if (net->cluster_id () > std::numeric_limits::max () / 2) { - return "$I" + tl::to_string ((std::numeric_limits::max () - net->cluster_id ()) + 1); - } else { - return "$" + tl::to_string (net->cluster_id ()); - } - } else { - return net->name (); - } + return net ? net->expanded_name () : "(null)"; } static std::string device_name (const db::Device &device) diff --git a/src/db/unit_tests/dbNetlistTests.cc b/src/db/unit_tests/dbNetlistTests.cc index 138e4dd41..e1df6d1df 100644 --- a/src/db/unit_tests/dbNetlistTests.cc +++ b/src/db/unit_tests/dbNetlistTests.cc @@ -547,6 +547,11 @@ TEST(6_Net) n2 = n; EXPECT_EQ (n2.name (), "n"); EXPECT_EQ (int (n2.cluster_id ()), 17); + EXPECT_EQ (n2.expanded_name (), "n"); + n2.set_name (""); + EXPECT_EQ (n2.expanded_name (), "$17"); + n2.set_cluster_id (std::numeric_limits::max () - 2); + EXPECT_EQ (n2.expanded_name (), "$I3"); n.clear (); EXPECT_EQ (n.name (), ""); diff --git a/testdata/ruby/dbNetlist.rb b/testdata/ruby/dbNetlist.rb index bcd6314bc..eeead78df 100644 --- a/testdata/ruby/dbNetlist.rb +++ b/testdata/ruby/dbNetlist.rb @@ -342,9 +342,14 @@ class DBNetlist_TestClass < TestBase net.name = "NET" assert_equal(net.name, "NET") + assert_equal(net.expanded_name, "NET") net.cluster_id = 42 assert_equal(net.cluster_id, 42) + assert_equal(net.expanded_name, "NET") + + net.name = "" + assert_equal(net.expanded_name, "$42") end