From 0c2255beeec620ede3d840461f404264261557d4 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Thu, 12 Aug 2021 15:50:25 -0700 Subject: [PATCH] groupBusPorts callback for endedness Signed-off-by: James Cherry --- include/sta/ConcreteLibrary.hh | 3 ++- include/sta/ConcreteNetwork.hh | 3 ++- include/sta/Network.hh | 3 ++- network/ConcreteLibrary.cc | 27 ++++++++++++++++++--------- network/ConcreteNetwork.cc | 5 +++-- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/sta/ConcreteLibrary.hh b/include/sta/ConcreteLibrary.hh index 1ba2878a..5f12bd0c 100644 --- a/include/sta/ConcreteLibrary.hh +++ b/include/sta/ConcreteLibrary.hh @@ -117,7 +117,8 @@ public: ConcretePortSeq *members); // Group previously defined bus bit ports together. void groupBusPorts(const char bus_brkt_left, - const char bus_brkt_right); + const char bus_brkt_right, + std::function port_big_endian_pred); size_t portCount() const; void setName(const char *name); void addPort(ConcretePort *port); diff --git a/include/sta/ConcreteNetwork.hh b/include/sta/ConcreteNetwork.hh index 7b418772..f6eda0a7 100644 --- a/include/sta/ConcreteNetwork.hh +++ b/include/sta/ConcreteNetwork.hh @@ -176,7 +176,8 @@ public: const char *name, int from_index, int to_index); - virtual void groupBusPorts(Cell *cell); + virtual void groupBusPorts(Cell *cell, + std::function port_is_big_endian); virtual Port *makeBundlePort(Cell *cell, const char *name, PortSeq *members); diff --git a/include/sta/Network.hh b/include/sta/Network.hh index eab973ad..0f2fb048 100644 --- a/include/sta/Network.hh +++ b/include/sta/Network.hh @@ -548,7 +548,8 @@ public: const char *name, int from_index, int to_index) = 0; - virtual void groupBusPorts(Cell *cell) = 0; + virtual void groupBusPorts(Cell *cell, + std::function port_is_big_endian) = 0; virtual Port *makeBundlePort(Cell *cell, const char *name, PortSeq *members) = 0; diff --git a/network/ConcreteLibrary.cc b/network/ConcreteLibrary.cc index 776908a5..093eed4a 100644 --- a/network/ConcreteLibrary.cc +++ b/network/ConcreteLibrary.cc @@ -375,7 +375,8 @@ typedef Map BusPortMap; void ConcreteCell::groupBusPorts(const char bus_brkt_left, - const char bus_brkt_right) + const char bus_brkt_right, + std::function port_is_big_endian) { const char bus_brkts_left[2]{bus_brkt_left, '\0'}; const char bus_brkts_right[2]{bus_brkt_right, '\0'}; @@ -395,12 +396,8 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left, if (bus_name) { if (!port->isBusBit()) { BusPort *bus_port = port_map.findKey(bus_name); - if (bus_port) { - // Treat it as [max:min]/[from:to], ie downto. - bus_port->setFrom(std::max(index, bus_port->from())); - bus_port->setTo(std::min(index, bus_port->to())); + if (bus_port) stringDelete(bus_name); - } else { bus_port = new BusPort(bus_name, index, port->direction()); port_map[bus_name] = bus_port; @@ -419,6 +416,7 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left, while (bus_iter.hasNext()) { BusPort *bus_port = bus_iter.next(); const char *bus_name = bus_port->name(); + bool is_big_endian = port_is_big_endian(bus_name); ConcretePortSeq *members = bus_port->members(); sort(members, [&](ConcretePort *port1, ConcretePort *port2) { @@ -430,10 +428,21 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left, parseBusName(port2->name(), bus_brkts_left, bus_brkts_right, escape_, bus_name, index2); stringDelete(bus_name); - return index1 > index2; + return is_big_endian ? index1 > index2 : index1 < index2; }); - ConcretePort *port = makeBusPort(bus_name, bus_port->from(), - bus_port->to(), members); + + char *bus_name1; + int from_index, to_index; + parseBusName((*members)[0]->name(), + bus_brkts_left, bus_brkts_right, escape_, + bus_name1, from_index); + stringDelete(bus_name1); + parseBusName((*members)[members->size() - 1]->name(), + bus_brkts_left, bus_brkts_right, escape_, + bus_name1, to_index); + stringDelete(bus_name1); + + ConcretePort *port = makeBusPort(bus_name, from_index, to_index, members); port->setDirection(bus_port->direction()); delete bus_port; diff --git a/network/ConcreteNetwork.cc b/network/ConcreteNetwork.cc index 7b066eee..e163353d 100644 --- a/network/ConcreteNetwork.cc +++ b/network/ConcreteNetwork.cc @@ -638,12 +638,13 @@ ConcreteNetwork::makeBusPort(Cell *cell, } void -ConcreteNetwork::groupBusPorts(Cell *cell) +ConcreteNetwork::groupBusPorts(Cell *cell, + std::function port_is_big_endian) { Library *lib = library(cell); ConcreteLibrary *clib = reinterpret_cast(lib); ConcreteCell *ccell = reinterpret_cast(cell); - ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight()); + ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight(), port_is_big_endian); } Port *