📄 netcell.java
字号:
numConnectedDrawns = numDrawns; for (int i = 0, numNodes = cell.getNumNodes(); i < numNodes; i++) { NodeInst ni = cell.getNode(i); NodeProto np = ni.getProto(); if (ni.isIconOfParent() || np.getFunction() == PrimitiveNode.Function.ART && np != Generic.tech().simProbeNode || np == Artwork.tech().pinNode || np == Generic.tech().invisiblePinNode) { continue; } int numPortInsts = np.getNumPorts(); for (int j = 0; j < numPortInsts; j++) { PortInst pi = ni.getPortInst(j); int piOffset = getPortInstOffset(pi); if (drawns[piOffset] >= 0) continue; if (pi.getPortProto() instanceof PrimitivePort && ((PrimitivePort)pi.getPortProto()).isIsolated()) continue; addToDrawn(pi); numDrawns++; } } stack = null; // showDrawns();// System.out.println(cell + " has " + cell.getNumPorts() + " ports, " + cell.getNumNodes() + " nodes, " +// cell.getNumArcs() + " arcs, " + (arcsOffset - cell.getNumPorts()) + " portinsts, " + netMap.length + "(" + piDrawns + ") drawns"); } void showDrawns() { java.io.PrintWriter out; String filePath = "tttt"; try { out = new java.io.PrintWriter(new java.io.BufferedWriter(new java.io.FileWriter(filePath, true))); } catch (java.io.IOException e) { System.out.println("Error opening " + filePath); return; } out.println("Drawns " + cell); int numPorts = cell.getNumPorts(); for (int drawn = 0; drawn < numDrawns; drawn++) { for (int i = 0; i < drawns.length; i++) { if (drawns[i] != drawn) continue; if (i < numPorts) { out.println(drawn + ": " + cell.getPort(i)); } else if (i >= arcsOffset) { out.println(drawn + ": " + cell.getArc(i - arcsOffset)); } else { int k = 1; for (; k < cell.getNumNodes() && ni_pi[k] <= i; k++) ; k--; NodeInst ni = cell.getNode(k); PortInst pi = ni.getPortInst(i - ni_pi[k]); out.println(drawn + ": " + pi); } } } out.close(); } void initNetnames() { for (GenMath.MutableInteger nn: netNames.values()) { nn.setValue(-1); } netNameCount = 0; for (Iterator<Export> it = cell.getExports(); it.hasNext();) { Export e = it.next(); addNetNames(e.getNameKey(), e, null); } exportedNetNameCount = netNameCount; for (Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); if (ai.getProto().getFunction() == ArcProto.Function.NONELEC) continue; if (ai.getNameKey().isBus() && ai.getProto() != busArc) { String msg = "Network: " + cell + " has bus name <"+ai.getNameKey()+"> on arc that is not a bus"; System.out.println(msg); networkManager.pushHighlight(ai); networkManager.logError(msg, NetworkTool.errorSortNetworks); } if (ai.isUsernamed()) addNetNames(ai.getNameKey(), null, ai); } for (Iterator<Map.Entry<Name,GenMath.MutableInteger>> it = netNames.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Name,GenMath.MutableInteger> e = it.next(); Name name = e.getKey(); int index = e.getValue().intValue(); if (index < 0) it.remove(); else if (NetworkTool.debug) System.out.println("NetName "+name+" "+index); } assert netNameCount == netNames.size(); } void addNetNames(Name name, Export e, ArcInst ai) { if (name.isBus()) System.out.println("Network: Layout " + cell + " has bus port/arc " + name); addNetName(name, e, ai); } void addNetName(Name name, Export e, ArcInst ai) { GenMath.MutableInteger nn = netNames.get(name); if (nn == null) { nn = new GenMath.MutableInteger(-1); netNames.put(name, nn); } if (nn.intValue() < 0) nn.setValue(netNameCount++); } private void internalConnections(int[] netMapF, int[] netMapP, int[] netMapA) { for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext();) { NodeInst ni = it.next(); int nodeOffset = ni_pi[ni.getNodeIndex()]; if (!ni.isCellInstance()) { PrimitiveNode.Function fun = ni.getFunction(); if (fun == PrimitiveNode.Function.RESIST) { Netlist.connectMap(netMapP, drawns[nodeOffset], drawns[nodeOffset + 1]); Netlist.connectMap(netMapA, drawns[nodeOffset], drawns[nodeOffset + 1]); } else if (fun.isPolyOrWellResistor()) { Netlist.connectMap(netMapA, drawns[nodeOffset], drawns[nodeOffset + 1]); } continue; } NetCell netCell = networkManager.getNetCell((Cell)ni.getProto()); if (netCell instanceof NetSchem) continue; int[] eqF = netCell.equivPortsN; int[] eqP = netCell.equivPortsP; int[] eqA = netCell.equivPortsA; for (int i = 0; i < eqF.length; i++) { if (eqF[i] != i) Netlist.connectMap(netMapF, drawns[nodeOffset + i], drawns[nodeOffset + eqF[i]]); if (eqP[i] != i) Netlist.connectMap(netMapP, drawns[nodeOffset + i], drawns[nodeOffset + eqP[i]]); if (eqA[i] != i) Netlist.connectMap(netMapA, drawns[nodeOffset + i], drawns[nodeOffset + eqA[i]]); } } } final int getPortInstOffset(PortInst pi) { return ni_pi[pi.getNodeInst().getNodeIndex()] + pi.getPortProto().getPortIndex(); } int getPortOffset(int portIndex, int busIndex) { return busIndex == 0 ? portIndex : -1; } NetSchem getSchem() { return null; } private void buildNetworkList(int[] netMapN) { netlistN = new NetlistImpl(this, numExportedDrawns, netMapN); int[] netNameToNetIndex = new int[netNames.size()]; Arrays.fill(netNameToNetIndex, -1); int numPorts = cell.getNumPorts(); for (int i = 0; i < numPorts; i++) { Export e = cell.getPort(i); int drawn = drawns[i]; setNetName(netNameToNetIndex, drawn, e.getNameKey(), true); netlistN.setEquivPortIndexByNetIndex(i, netlistN.getNetIndex(e, 0)); } int numArcs = cell.getNumArcs(), arcIndex = 0; for (Iterator<ArcInst> it = cell.getArcs(); arcIndex < numArcs; arcIndex++) { ArcInst ai = it.next(); if (!ai.isUsernamed()) continue; int drawn = drawns[arcsOffset + arcIndex]; if (drawn < 0) continue; setNetName(netNameToNetIndex, drawn, ai.getNameKey(), false); } arcIndex = 0; for (Iterator<ArcInst> it = cell.getArcs(); arcIndex < numArcs; arcIndex++) { ArcInst ai = it.next(); int drawn = drawns[arcsOffset + arcIndex]; if (drawn < 0) continue; int netIndexN = netlistN.getNetIndexByMap(drawn); if (netlistN.hasNames(netIndexN)) continue; netlistN.addTempName(netIndexN, ai.getName()); } for (int i = 0; i < cell.getNumNodes(); i++) { NodeInst ni = cell.getNode(i); for (int j = 0; j < ni.getProto().getNumPorts(); j++) { int drawn = drawns[ni_pi[i] + j]; if (drawn < 0) continue; int netIndexN = netlistN.getNetIndexByMap(drawn); if (netlistN.hasNames(netIndexN)) continue; netlistN.addTempName(netIndexN, ni.getName() + PORT_SEPARATOR + ni.getProto().getPort(j).getName()); } } // check names and equivPortIndexByNetIndex map for (int i = 0, numNetworks = netlistN.getNumNetworks(); i < numNetworks; i++) { assert netlistN.hasNames(i); assert netlistN.isExported(i) == (i < netlistN.getNumExternalNetworks()); if (netlistN.isExported(i)) { int equivPortIndex = netlistN.getEquivPortIndexByNetIndex(i); assert equivPortIndex >= 0 && equivPortIndex < numPorts; } } /* // debug info System.out.println("BuildNetworkList "+this); int i = 0; for (Iterator<Network> nit = getNetworks(); nit.hasNext(); ) { Network network = nit.next(); String s = ""; for (Iterator<String> sit = network.getNames(); sit.hasNext(); ) { String n = sit.next(); s += "/"+ n; } for (Iterator<PortInst> pit = network.getPorts(); pit.hasNext(); ) { PortInst pi = pit.next(); s += "|"+pi.getNodeInst().getProto()+"&"+pi.getPortProto().getName(); } System.out.println(" "+i+" "+s); i++; } */ } private void setNetName(int[] netNamesToNetIndex, int drawn, Name name, boolean exported) { int netIndexN = netlistN.getNetIndexByMap(drawn); assert netIndexN >= 0; GenMath.MutableInteger nn = netNames.get(name); if (netNamesToNetIndex[nn.intValue()] >= 0) { if (netNamesToNetIndex[nn.intValue()] == netIndexN) return; String msg = "Network: Layout " + cell + " has nets with same name " + name; System.out.println(msg); // because this should be an infrequent event that the user will fix, let's // put all the work here for (int i = 0, numPorts = cell.getNumPorts(); i < numPorts; i++) { Export e = cell.getPort(i); if (e.getName().equals(name.toString())) networkManager.pushHighlight(cell.getPort(i)); } for (Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); if (!ai.isUsernamed()) continue; if (ai.getName().equals(name.toString())) networkManager.pushHighlight(ai); } networkManager.logError(msg, NetworkTool.errorSortNetworks); } else netNamesToNetIndex[nn.intValue()] = netIndexN; netlistN.addUserName(netIndexN, name, exported); } /** * Update map of equivalent ports newEquivPort. */ private boolean updateInterface() { boolean changed = false; int numPorts = cell.getNumPorts(); if (equivPortsN == null || equivPortsN.length != numPorts) { changed = true; equivPortsN = new int[numPorts]; equivPortsP = new int[numPorts]; equivPortsA = new int[numPorts]; } int[] netToPortN = new int[numPorts]; int[] netToPortP = new int[numPorts]; int[] netToPortA = new int[numPorts]; Arrays.fill(netToPortN, -1); Arrays.fill(netToPortP, -1); Arrays.fill(netToPortA, -1); for (int i = 0; i < numPorts; i++) { int netN = netlistN.netMap[drawns[i]]; if (netToPortN[netN] < 0) netToPortN[netN] = i; if (equivPortsN[i] != netToPortN[netN]) { changed = true; equivPortsN[i] = netToPortN[netN]; } int netP = netlistP.netMap[drawns[i]]; if (netToPortP[netP] < 0) netToPortP[netP] = i; if (equivPortsP[i] != netToPortP[netP]) { changed = true; equivPortsP[i] = netToPortP[netP]; } int netA = netlistA.netMap[drawns[i]]; if (netToPortA[netA] < 0) netToPortA[netA] = i; if (equivPortsA[i] != netToPortA[netA]) { changed = true; equivPortsA[i] = netToPortA[netA]; } } return changed; }// /**// * Show map of equivalent ports newEquivPort.// */// private void showEquivPorts()// {// System.out.println("Equivalent ports of "+cell);// String s = "\t";// Export[] ports = new Export[cell.getNumPorts()];// int i = 0;// for (Iterator<Export> it = cell.getExports(); it.hasNext(); i++)// ports[i] = it.next();// for (i = 0; i < equivPorts.length; i++)// {// Export pi = ports[i];// if (equivPorts[i] != i) continue;// boolean found = false;// for (int j = i+1; j < equivPorts.length; j++)// {// if (equivPorts[i] != equivPorts[j]) continue;// Export pj = ports[j];// if (!found) s = s+" ( "+pi.getName();// found = true;// s = s+" "+pj.getName();// }// if (found)// s = s+")";// else// s = s+" "+pi.getName();// }// System.out.println(s);// } void redoNetworks() { if ((flags & VALID) != 0) return; // redo descendents for (Iterator<CellUsage> it = cell.getUsagesIn(); it.hasNext();) { CellUsage u = it.next(); Cell subCell = u.getProto(); if (subCell.isIconOf(cell)) continue; NetCell netCell = networkManager.getNetCell(subCell); if ((netCell.flags & VALID) == 0) netCell.redoNetworks(); } // redo implementation NetSchem schem = getSchem(); if (schem != null && schem != this) schem.redoNetworks(); if ((flags & LOCALVALID) != 0) { flags |= VALID; return; } // Mark this netcell changed modCount++; // clear errors for cell networkManager.startErrorLogging(cell); try { makeDrawns(); // Gather port and arc names initNetnames(); if (redoNetworks1()) setInvalid(false, true); } finally { networkManager.finishErrorLogging(); } flags |= (LOCALVALID|VALID); } boolean redoNetworks1() { /* Set index of NodeInsts */// HashMap/*<Cell,Netlist>*/ subNetlists = new HashMap/*<Cell,Netlist>*/();// for (Iterator<Nodable> it = getNodables(); it.hasNext(); ) {// Nodable no = it.next();// if (!no.isCellInstance()) continue;// Cell subCell = (Cell)no.getProto();// subNetlists.put(subCell, networkManager.getNetlist(subCell, false));// } int[] netMapN = Netlist.initMap(numDrawns); int[] netMapP = netMapN.clone(); int[] netMapA = netMapN.clone(); internalConnections(netMapN, netMapP, netMapA); buildNetworkList(netMapN); netlistP = new NetlistShorted(netlistN, Netlist.ShortResistors.PARASITIC, netMapP); netlistA = new NetlistShorted(netlistN, Netlist.ShortResistors.ALL, netMapA); return updateInterface(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -