📄 topology.java
字号:
for(int k=cas.low; k<=cas.high; k++) { CellSignal cs = cas.signals[k-cas.low]; cs.name = getSafeNetName(cas.name + "[" + k + "]", false); } } } } Collections.sort(cni.cellAggregateSignals, new SortAggregateNetsByName(isSeparateInputAndOutput())); } else { // just get safe net names for all cell signals for (CellSignal cs : cni.cellSignalsSorted) { cs.name = getSafeNetName(cs.name, false); } } return cni; } private void setBusDirectionality(Network [] nets, String [] netNames, CellNetInfo cni) { boolean upDir = false, downDir = false; int last = 0; int width = nets.length; for(int i=0; i<width; i++) { Network subNet = nets[i]; if (subNet == null) continue; String netName = netNames[i]; int index = -1; int charPos = 0; for(;;) { charPos = netName.indexOf('[', charPos); if (charPos < 0) break; charPos++; if (!TextUtils.isDigit(netName.charAt(charPos))) continue; index = TextUtils.atoi(netName.substring(charPos)); break; } if (index < 0) break; if (i != 0) { if (index < last) downDir = true; else if (index > last) upDir = true; } last = index; } if (upDir && downDir) return; if (!upDir && !downDir) return; // valid direction found: set it on all entries of the bus for(int i=0; i<width; i++) { Network subNet = nets[i]; CellSignal cs = cni.cellSignals.get(subNet); cs.descending = downDir; } } /** * Method to return the character position in network name "name" that is the start of indexing. * If there is no indexing ("clock"), this will point to the end of the string. * If there is simple indexing ("dog[12]"), this will point to the "[". * If the index is nonnumeric ("dog[cat]"), this will point to the end of the string. * If there are multiple indices, ("dog[12][45]") this will point to the last "[" (unless it is nonnumeric). */ protected static String unIndexedName(String name) { int len = name.length(); if (len == 0) return name; if (name.charAt(len-1) != ']') return name; int i = len - 2; for( ; i > 0; i--) { char theChr = name.charAt(i); if (theChr == '[') break; if (theChr == ':' || theChr == ',') continue; if (!TextUtils.isDigit(theChr)) break; } if (name.charAt(i) != '[') return name; return name.substring(0, i); } private static class SortNetsByName implements Comparator<CellSignal> { private boolean separateInputAndOutput, aggregateNamesSupported; SortNetsByName(boolean separateInputAndOutput, boolean aggregateNamesSupported) { this.separateInputAndOutput = separateInputAndOutput; this.aggregateNamesSupported = aggregateNamesSupported; } public int compare(CellSignal cs1, CellSignal cs2) { if ((aggregateNamesSupported || separateInputAndOutput) && (cs1.pp == null) != (cs2.pp == null)) { // one is exported and the other isn't...sort accordingly return cs1.pp == null ? 1 : -1; } if (cs1.pp != null && cs2.pp != null) { if (separateInputAndOutput) { // both are exported: sort by characteristics (if different) PortCharacteristic ch1 = cs1.pp.getCharacteristic(); PortCharacteristic ch2 = cs2.pp.getCharacteristic(); if (ch1 != ch2) return ch1.getOrder() - ch2.getOrder(); } } if (aggregateNamesSupported && cs1.descending != cs2.descending) { // one is descending and the other isn't...sort accordingly return cs1.descending ? 1 : -1; } if (aggregateNamesSupported) return TextUtils.STRING_NUMBER_ORDER.compare(cs1.name, cs2.name); // Sort by simple string comparison, otherwise it is impossible // to stitch this together with netlists from other tools return cs1.name.compareTo(cs2.name); } } private static class SortAggregateNetsByName implements Comparator<CellAggregateSignal> { private boolean separateInputAndOutput; SortAggregateNetsByName(boolean separateInputAndOutput) { this.separateInputAndOutput = separateInputAndOutput; } public int compare(CellAggregateSignal cs1, CellAggregateSignal cs2) { if ((separateInputAndOutput) && (cs1.pp == null) != (cs2.pp == null)) { // one is exported and the other isn't...sort accordingly return cs1.pp == null ? 1 : -1; } if (cs1.pp != null && cs2.pp != null) { if (separateInputAndOutput) { // both are exported: sort by characteristics (if different) PortCharacteristic ch1 = cs1.pp.getCharacteristic(); PortCharacteristic ch2 = cs2.pp.getCharacteristic(); if (ch1 != ch2) return ch1.getOrder() - ch2.getOrder(); } } // Sort by simple string comparison, otherwise it is impossible // to stitch this together with netlists from other tools return cs1.name.compareTo(cs2.name); } } /** * Method to create a parameterized name for node instance "ni". * If the node is not parameterized, returns zero. * If it returns a name, that name must be deallocated when done. */ protected String parameterizedName(Nodable no, VarContext context) { Cell cell = (Cell)no.getProto(); String uniqueCellName = getUniqueCellName(cell); if (canParameterizeNames() && no.isCellInstance()) { // if there are parameters, append them to this name Map<Variable.Key,Variable> paramValues = new HashMap<Variable.Key,Variable>(); for(Iterator<Variable> it = no.getDefinedParameters(); it.hasNext(); ) { Variable var = it.next(); paramValues.put(var.getKey(), var); } for(Variable.Key key : paramValues.keySet()) { Variable var = no.getParameter(key); String eval = var.describe(context, no.getNodeInst()); if (eval == null) continue; uniqueCellName += "-" + eval.toString(); } } // if it is over the length limit, truncate it int limit = maxNameLength(); if (limit > 0 && uniqueCellName.length() > limit) { int ckSum = 0; for(int i=0; i<uniqueCellName.length(); i++) ckSum += uniqueCellName.charAt(i); ckSum = (ckSum % 9999); uniqueCellName = uniqueCellName.substring(0, limit-10) + "-TRUNC"+ckSum; } // make it safe return getSafeCellName(uniqueCellName); } /** * Method to return the name of cell "c", given that it may be ambiguously used in multiple * libraries. */ protected String getUniqueCellName(Cell cell) { Cell contents = cell.contentsView(); if (contents != null) cell = contents; String name = cellNameMap.get(cell); return name; } private static class NameMapGenerator extends HierarchyEnumerator.Visitor { private Map<Cell,String> cellNameMap; private Map<String,List<Cell>> cellNameMapReverse; private boolean alwaysUseLibName; private Topology topology; private Cell topCell; public NameMapGenerator(boolean alwaysUseLibName, Topology topology) { cellNameMap = new HashMap<Cell,String>(); cellNameMapReverse = new HashMap<String,List<Cell>>(); this.alwaysUseLibName = alwaysUseLibName; this.topology = topology; topCell = null; } public boolean enterCell(HierarchyEnumerator.CellInfo info) { Cell cell = info.getCell(); if (topCell == null) topCell = cell; if (cellNameMap.containsKey(cell)) return false; // add name for this cell String name = getDefaultName(cell); cellNameMap.put(cell, name); getConflictList(name).add(cell); //System.out.println("Mapped "+cell.describe(false) + " --> " + name); return true; } private List<Cell> getConflictList(String cellname) { String properCellName = topology.isCaseSensitive() ? cellname : cellname.toLowerCase(); List<Cell> conflictList = cellNameMapReverse.get(properCellName); if (conflictList == null) { conflictList = new ArrayList<Cell>(); cellNameMapReverse.put(properCellName, conflictList); } return conflictList; } public void exitCell(HierarchyEnumerator.CellInfo info) { Cell cell = info.getCell(); if (cell == topCell) { // resolve conflicts resolveConflicts();// if (!alwaysUseLibName)// resolveConflicts(1);// resolveConflicts(2);// resolveConflicts(3); } } public boolean visitNodeInst(Nodable no, HierarchyEnumerator.CellInfo info) { if (!no.isCellInstance()) return false; VarContext context = info.getContext(); Cell cell = (Cell)no.getProto(); Cell schcell = cell.contentsView(); if (schcell == null) schcell = cell; if (cell.isSchematic() && topology.enumerateLayoutView(schcell)) { Cell layCell = null; for (Iterator<Cell> it = cell.getCellGroup().getCells(); it.hasNext(); ) { Cell c = it.next(); if (c.getView() == View.LAYOUT) { layCell = c; break; } } if (layCell != null) { String name = getDefaultName(schcell); cellNameMap.put(schcell, name); getConflictList(name).add(schcell); //System.out.println("Mapped "+schcell.describe(false) + " --> " + name); HierarchyEnumerator.enumerateCell(layCell, context, this); return false; } } else { // special case for cells with only icons schcell = cell.contentsView(); if (cell.isIcon() && schcell == null && !cellNameMap.containsKey(cell)) { String name = getDefaultName(cell); cellNameMap.put(cell, name); getConflictList(name).add(cell); return false; } } return true; } private String getDefaultName(Cell cell) { if (alwaysUseLibName && !SCLibraryGen.isStandardCell(cell)) return cell.getLibrary().getName() + "__" + cell.getName(); return cell.getName(); } private void resolveConflicts() { List<List<Cell>> conflictLists = new ArrayList<List<Cell>>(); for (List<Cell> conflictList : cellNameMapReverse.values()) { if (conflictList.size() <= 1) continue; // no conflict conflictLists.add(conflictList); } for (List<Cell> conflictList : conflictLists) { // see if cells in the same library have a case conflict if (!topology.isCaseSensitive()) { for(int i=0; i<conflictList.size()-1; i++) { Cell cellI = conflictList.get(i); String cellIName = cellNameMap.get(cellI); for(int j=i+1; j<conflictList.size(); j++) { Cell cellJ = conflictList.get(j); if (cellI.getLibrary() != cellJ.getLibrary()) continue; String cellJName = cellNameMap.get(cellJ); if (cellIName.equalsIgnoreCase(cellJName) && !cellIName.equals(cellJName)) { // two cells with same name, just case differences for(int append=1; append<1000; append++) { String newTestName = cellJName.toLowerCase() + "_" + append; if (cellNameMapReverse.get(newTestName) != null) continue; cellNameMap.put(cellJ, newTestName); getConflictList(newTestName).add(cellJ); conflictList.remove(j); j--; break; } } } } if (conflictList.size() <= 1) continue; } // if not using library names, resolve conflicts by using them if (!alwaysUseLibName) { for(int i=0; i<conflictList.size(); i++) { Cell cell = conflictList.get(i); String cellName = cellNameMap.get(cell); String newTestName = cell.getLibrary().getName() + "__" + cellName; if (cellNameMapReverse.get(newTestName) != null) continue; cellNameMap.put(cell, newTestName); getConflictList(newTestName).add(cell); conflictList.remove(i); i--; } if (conflictList.size() <= 1) continue; } // still conflicts: try adding view abbreviations for(int i=0; i<conflictList.size(); i++) { Cell cell = conflictList.get(i); String cellName = cellNameMap.get(cell); String newTestName = cell.getLibrary().getName() + "__" + cellName + "__" + cell.getView().getAbbreviation(); if (cellNameMapReverse.get(newTestName) != null) continue; cellNameMap.put(cell, newTestName); getConflictList(newTestName).add(cell); conflictList.remove(i); i--; } if (conflictList.size() <= 1) continue; // must be an error Cell cell = conflictList.get(0); System.out.print("Error: Unable to make unique cell name for "+cell.describe(false)+ ", it conflicts with:"); for (int i=1; i<conflictList.size(); i++) System.out.print(" "+conflictList.get(i).describe(false)); System.out.println(); } }// private void resolveConflicts(int whichPass) {// List<List<Cell>> conflictLists = new ArrayList<List<Cell>>();// for (List<Cell> conflictList : cellNameMapReverse.values()) {// if (conflictList.size() <= 1) continue; // no conflict// conflictLists.add(conflictList);// }// for (List<Cell> conflictList : conflictLists) {// // on pass 1, only cell names. If any conflicts, prepend libname// if (whichPass == 1) {// // replace name with lib + name// for (Cell cell : conflictList) {// String name = cell.getLibrary().getName() + "__" + cell.getName();// cellNameMap.put(cell, name);// getConflictList(name).add(cell);// }// conflictList.clear();// }// if (whichPass == 2) {// // lib + name conflicts, append view// for (Cell cell : conflictList) {// String name = cell.getLibrary().getName() + "__" + cell.getName() + "__" + cell.getView().getAbbreviation();// cellNameMap.put(cell, name);// getConflictList(name).add(cell);// }// conflictList.clear();// }// if (whichPass == 3) {// // must be an error// Cell cell = conflictList.get(0);// System.out.print("Error: Unable to make unique cell name for "+cell.describe(false)+// ", it conflicts with: ");// for (int i=1; i<conflictList.size(); i++) {// System.out.print(conflictList.get(i).describe(false)+" ");// }// System.out.println();// }// }// } } /** * determine whether any cells have name clashes in other libraries */ private Map<Cell,String> makeCellNameMap(Cell cell) { NameMapGenerator gen = new NameMapGenerator(isLibraryNameAlwaysAddedToCellName(), this); HierarchyEnumerator.enumerateCell(cell, VarContext.globalContext, gen); return gen.cellNameMap; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -