📄 edifequiv.java
字号:
} /** * Create a new EDIF equivalence object. This contains equivalence information between * Electric cells/prims and Exteranal EDIF cells/prims. The equivalence information is * read from a configuration file. The file has the format: * <pre> * C Lib Cell View rotation { porta(x,y), ... } ExternalLib ExternalCell ExternalView { porta(x,y), ... } * P Tech NodeName Function rotation { porta(x,y), ... } ExternalLib ExternalCell ExternalView { porta(x,y), ... } * F FigureGroup ExternalFigureGroup * V VariableName ExternalVariableName [appendToElectricOutput] * # comment * </pre> * 'C' is for Cell, and 'P' is for Primitive. The left hand size specifies the Electric cell/node, * while the right hand side specifies the External tool's cell/node. The list of ports must be the * same in length, and specify the x,y coordinate of the port. This coordinate is on the prototype of * the node, or also when the node is default size at 0,0. Note that Electric port locations should * be locations after the node has been rotated, if rot is not 0. Rotation should be in tenth-degrees. * * For 'F', an association between internal FigureGroup names and external names is declared. * For 'V', an association between internal Variable names and external names is declared. You * can also specify a string to be append to all matching Variable values. */ public EDIFEquiv() { equivsByNodeProto = new HashMap<Object,NodeEquivalence>(); equivsByExternal = new HashMap<Object,NodeEquivalence>(); exportByVariable = new HashMap<String,VariableEquivalence>(); exportFromVariable = new HashMap<String,VariableEquivalence>(); exportByFigureGroup = new HashMap<String,FigureGroupEquivalence>(); exportFromFigureGroup = new HashMap<String,FigureGroupEquivalence>(); exportByGlobal = new HashMap<String,GlobalEquivalence>(); exportFromGlobal = new HashMap<String,GlobalEquivalence>(); String file = IOTool.getEDIFConfigurationFile(); if (file.length() == 0) { System.out.println("No EDIF configuration information being used"); return; } File fd = new File(file); if (!fd.exists()) { System.out.println("Error: EDIF configuration file not found: "+fd.getAbsolutePath()); return; } System.out.println("Using EDIF configuration file: "+fd.getAbsolutePath()); try { FileReader reader = new FileReader(fd); BufferedReader bufReader = new BufferedReader(reader); String line = ""; int lineno = 1; while ((line = bufReader.readLine()) != null) { readLine(line, lineno); lineno++; } } catch (IOException e) { System.out.println("Error reading EDIF config file ("+fd.getAbsolutePath()+"): "+e.getMessage()); return; } } private static final Pattern portsPat = Pattern.compile("(.+?)\\{(.+?)\\}(.+?)\\{(.+?)\\}"); /** * Read one line of the configuration file. See Constructor for file format. * @param line * @param lineno * @return false on error */ private boolean readLine(String line, int lineno) { line = line.trim(); if (line.equals("")) return true; if (line.startsWith("#")) return true; // special case for Variable equivalences if (line.startsWith("V")) { String [] parts = line.split("\\s+"); String append = ""; double scale = TextUtils.atof(parts[3]); if (parts.length == 5) append = parts[4]; VariableEquivalence ve = new VariableEquivalence(parts[1], parts[2], scale, append); exportByVariable.put(parts[1], ve); exportFromVariable.put(parts[2], ve); return true; } // special case for FigureGroup equivalences if (line.startsWith("F")) { String [] parts = line.split("\\s+"); FigureGroupEquivalence fge = new FigureGroupEquivalence(parts[1], parts[2]); exportByFigureGroup.put(parts[1], fge); exportFromFigureGroup.put(parts[2], fge); return true; } // special case for Global equivalences if (line.startsWith("G")) { String [] parts = line.split("\\s+"); GlobalEquivalence ge = new GlobalEquivalence(parts[1], parts[2]); exportByGlobal.put(parts[1], ge); exportFromGlobal.put(parts[2], ge); return true; } // grab port parts Matcher mat = portsPat.matcher(line); if (!mat.find()) { System.out.println("Wrong number of curly brackets for ports on line "+lineno); return false; } String elec = mat.group(1).trim(); String elec_ports = mat.group(2).trim(); String ext = mat.group(3).trim(); String ext_ports = mat.group(4).trim(); String [] parts; // internal definition NodeProto np = null; PrimitiveNode.Function func = null; PortCharacteristic portType = null; int rot = 0; parts = elec.split("\\s+"); if (parts.length < 1) { System.out.println("No Electric arguments on line "+lineno); return false; } boolean keyE = parts[0].equalsIgnoreCase("E") ? true : false; boolean keyP = parts[0].equalsIgnoreCase("P") ? true : false; boolean keyC = parts[0].equalsIgnoreCase("C") ? true : false; if (keyP && parts.length != 5) { System.out.println("Wrong number of arguments for Electric Primitive, expected 'P tech node func rot' on line "+lineno); return false; } if (keyE && parts.length != 6) { System.out.println("Wrong number of arguments for Electric Primitive, expected 'E tech node func rot porttype' on line "+lineno); return false; } if (keyC && parts.length != 5) { System.out.println("Wrong number of arguments for Electric cell, expected 'C lib cell view rot' on line "+lineno); return false; } if (keyP || keyE) { // primitive node np = null; Technology tech = Technology.findTechnology(parts[1]); if (tech == null) { System.out.println("Could not find Technology " + parts[1] + " on line " + lineno); return false; } np = tech.findNodeProto(parts[2]); if (np == null) { System.out.println("Could not find " + parts[2] + " in technology " + parts[1] + " on line " + lineno); return false; } for (PrimitiveNode.Function function : PrimitiveNode.Function.getFunctions()) { if (parts[3].equals(function.getName()) || parts[3].equals(function.getShortName()) || parts[3].equals(function.getConstantName())) { func = function; break; } } if (func == null) { System.out.println("Could not find Function " + parts[3] + " on line " + lineno); return false; } try { rot = Integer.parseInt(parts[4]); } catch (NumberFormatException e) { System.out.println("Rotation " + parts[4] + " is not an integer on line " + lineno); } if (keyE) { // get port type portType = PortCharacteristic.findCharacteristic(parts[5]); if (portType == null) { System.out.println("Unable to find Export type " + parts[5] + " on line " + lineno); return false; } } } else if (keyC) { // cell Library lib = Library.findLibrary(parts[1]); if (lib == null) { System.out.println("Could not find Library " + parts[1] + " on line " + lineno); return false; } np = lib.findNodeProto(parts[2]+"{"+parts[3]+"}"); if (np == null) { System.out.println("Could not find Cell " + parts[2] + ", view " + parts[3] + " in library " + parts[1] + " on line " + lineno); return false; } func = PrimitiveNode.Function.UNKNOWN; try { rot = Integer.parseInt(parts[4]); } catch (NumberFormatException e) { System.out.println("Rotation " + parts[4] + " is not an integer on line " + lineno); } } else { System.out.println("Unrecognized key " + parts[0] + ", expected 'P', 'C', or 'E' on line " + lineno); return false; } // external definition String extlib, extname, extview; parts = ext.split("\\s+"); if (parts.length != 3) { System.out.println("Wrong number of arguments for external lib, expected 'lib name view' on line "+lineno); return false; } extlib = parts[0]; extname = parts[1]; extview = parts[2]; // port equivalences List<Port> elecPorts = parsePortsList(elec_ports, lineno); List<Port> extPorts = parsePortsList(ext_ports, lineno); if (elecPorts.size() != extPorts.size()) { System.out.println("Port lists are not the same size on line "+lineno); return false; } addNodeEquiv(np, func, portType, rot, extlib, extname, extview, elecPorts, extPorts); return true; } /** * String should be of the format (ignore spaces): * a(x,y), b(x,y), ... z(x,y) * @param portsList * @return a list of Port objects */ private List<Port> parsePortsList(String portsList, int lineno) { // split by commas not contained in () boolean opened = false; List<Port> ports = new ArrayList<Port>(); int i = 0, last = 0; for (i=0; i<portsList.length(); i++) { char c = portsList.charAt(i); if (c == '(') { if (opened == true) { System.out.println("Unmatched open parenthesis in ports list on line "+lineno); return ports; } opened = true; continue; } if (c == ')') { if (opened == false) { System.out.println("Unmatched close parenthesis in ports list on line "+lineno); return ports; } opened = false; continue; } if (c == ',') { if (opened == true) // ignore commands in coords (x,y) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -