From f5abb2d63e074dd4b96a6ac38c27932982c20522 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Mon, 28 Oct 2024 19:39:24 +0000 Subject: [PATCH] odb/cdl: Handle top-level pins wired to nets of different name ATM the code seem to assume that for each top level pin, the net name is equal to the pin name. That's not always the case and this produces an incorect netlist. To solve that, during pin name enumeration when creating the subckt line, we create a mapping from "net name" -> "pin name" for each pin connected to a net of a different name. Then when outputting the connections between sub blocks, we use the pin name instead of the DB net name. Signed-off-by: Sylvain Munaut --- src/odb/src/cdl/cdl.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/odb/src/cdl/cdl.cpp b/src/odb/src/cdl/cdl.cpp index 1e3d2f597fd..d0773e7a5ae 100644 --- a/src/odb/src/cdl/cdl.cpp +++ b/src/odb/src/cdl/cdl.cpp @@ -89,6 +89,7 @@ std::string getUnconnectedNet(dbBlock* block, int& unconnectedNets) std::string getNetName(dbBlock* block, dbInst* inst, dbMTerm* mterm, + std::map &net2pin, int& unconnectedNets) { if (mterm == nullptr) { @@ -105,7 +106,14 @@ std::string getNetName(dbBlock* block, return getUnconnectedNet(block, unconnectedNets); } - return net->getName(); + std::string net_name = net->getName(); + + auto pin_name_match = net2pin.find(net_name); + if (pin_name_match != net2pin.end()) { + return pin_name_match->second; + } + + return net_name; } // Look for .subckt lines and record the terminal order for module to @@ -189,6 +197,7 @@ bool cdl::writeCdl(utl::Logger* logger, } int unconnectedNets = 0; utl::FileHandler fileHandler(outFileName); + std::map net2pin; FILE* f = fileHandler.getFile(); if (f == nullptr) { @@ -204,6 +213,10 @@ bool cdl::writeCdl(utl::Logger* logger, std::string line = ".SUBCKT " + block->getName(); for (auto&& pin : block->getBTerms()) { line += " " + pin->getName(); + auto net = pin->getNet(); + if ((net != nullptr) && (net->getName() != pin->getName())) { + net2pin.emplace(net->getName(), pin->getName()); + } } writeLine(f, line); @@ -231,7 +244,7 @@ bool cdl::writeCdl(utl::Logger* logger, } } else { for (auto&& mterm : it->second) { - line += " " + getNetName(block, inst, mterm, unconnectedNets); + line += " " + getNetName(block, inst, mterm, net2pin, unconnectedNets); } }