groupBusPorts callback for endedness

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2021-08-12 15:50:25 -07:00
parent 598842f4a7
commit 0c2255beee
5 changed files with 27 additions and 14 deletions

View File

@ -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<bool(const char*)> port_big_endian_pred);
size_t portCount() const;
void setName(const char *name);
void addPort(ConcretePort *port);

View File

@ -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<bool(const char*)> port_is_big_endian);
virtual Port *makeBundlePort(Cell *cell,
const char *name,
PortSeq *members);

View File

@ -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<bool(const char*)> port_is_big_endian) = 0;
virtual Port *makeBundlePort(Cell *cell,
const char *name,
PortSeq *members) = 0;

View File

@ -375,7 +375,8 @@ typedef Map<const char*, BusPort*, CharPtrLess> BusPortMap;
void
ConcreteCell::groupBusPorts(const char bus_brkt_left,
const char bus_brkt_right)
const char bus_brkt_right,
std::function<bool(const char*)> 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;

View File

@ -638,12 +638,13 @@ ConcreteNetwork::makeBusPort(Cell *cell,
}
void
ConcreteNetwork::groupBusPorts(Cell *cell)
ConcreteNetwork::groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_is_big_endian)
{
Library *lib = library(cell);
ConcreteLibrary *clib = reinterpret_cast<ConcreteLibrary*>(lib);
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight());
ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight(), port_is_big_endian);
}
Port *