WIP: introduced expanded net name

This commit is contained in:
Matthias Koefferlein 2018-12-27 10:43:25 +01:00
parent 639b0026d3
commit 8b2902c31b
6 changed files with 37 additions and 12 deletions

View File

@ -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<size_t>::max () / 2) {
// avoid printing huge ID numbers for internal cluster IDs
return "$I" + tl::to_string ((std::numeric_limits<size_t>::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;

View File

@ -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
*

View File

@ -236,6 +236,10 @@ Class<db::Net> 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 "

View File

@ -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<size_t>::max () / 2) {
return "$I" + tl::to_string ((std::numeric_limits<size_t>::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)

View File

@ -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<size_t>::max () - 2);
EXPECT_EQ (n2.expanded_name (), "$I3");
n.clear ();
EXPECT_EQ (n.name (), "");

View File

@ -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