📄 als.java
字号:
vectPtr2.type = 'N'; vectPtr2.ptr = nodeHead; vectPtr2.state = new Integer(Stimuli.parseLevel(com)); vectPtr2.strength = strength; vectPtr2.priority = 1; vectPtr2.time = TextUtils.atof(parts[1]); vectPtr2.right = null; clokHead.inList.add(vectPtr2); } } if (command.equals("SET")) { if (parts.length < 6) { System.out.println("Error: SET stimuli line has only " + parts.length + " fields: " + s1); continue; } String nodeName = parts[1]; Node nodeHead = findNode(nodeName); if (nodeHead == null) { System.out.println("ERROR: Unable to find node " + nodeName); continue; } Link setHead = new Link(); setHead.type = 'N'; setHead.ptr = nodeHead; setHead.state = new Integer(Stimuli.parseLevel(parts[2])); setHead.strength = Stimuli.indexToStrength(TextUtils.atoi(parts[3])); setHead.priority = 2; setHead.time = TextUtils.atof(parts[5]); setHead.right = null; insertSetList(setHead); if (nodeHead.sig != null) nodeHead.sig.addControlPoint(setHead.time); } } } /** * Method to processe the string specified by the calling argument * and fragments it into a series of smaller character strings, each of which * is terminated by a null character. Returns true on error. * * Calling Arguments: * line = pointer to the character string to be fragmented */ private String [] fragmentCommand(String line) { List<String> fragments = new ArrayList<String>(); line = line.trim(); for(int i=0; i<line.length(); i++) { int spacePos = line.indexOf(' ', i); if (spacePos < 0) spacePos = line.length(); int equalPos = line.indexOf('=', i); if (equalPos < 0) equalPos = line.length(); int atPos = line.indexOf('@', i); if (atPos < 0) atPos = line.length(); int pos = Math.min(Math.min(spacePos, equalPos), atPos); if (pos < 0) { fragments.add(line.substring(i)); break; } fragments.add(line.substring(i, pos)); i = pos; } String [] parts = new String[fragments.size()]; for(int i=0; i<fragments.size(); i++) parts[i] = fragments.get(i); return parts; } /** * Method to return a pointer to a structure in the cross reference * table. The calling argument string contains information detailing the path * name to the desired level in the cross reference table. * * Calling Argument: * sp = pointer to char string containing path name to level in xref table */ Connect findLevel(String sp) { Connect cellPtr = cellRoot; if (sp.startsWith(".")) sp = sp.substring(1); while (sp.length() > 0) { String part = sp; sp = ""; int dotPos = part.indexOf('.'); if (dotPos >= 0) { sp = part.substring(dotPos+1); part = part.substring(0, dotPos); } for( ; ; cellPtr = cellPtr.next) { if (cellPtr == null) return null; if (part.equals(cellPtr.instName)) { if (sp.length() > 0) cellPtr = cellPtr.child; break; } } } return cellPtr; } /** * Method to compose a character string which indicates the node name * for the nodePtr specified in the calling argument. * * Calling Arguments: * nodeHead = pointer to desired node in database * sp = pointer to char string where complete name is to be saved */ String computeNodeName(Node nodeHead) { Connect cellHead = nodeHead.cellPtr; String sp = computePathName(cellHead); for(ALSExport exHead : cellHead.exList) { if (nodeHead == exHead.nodePtr) { sp += "." + exHead.nodeName; return sp; } } return ""; } /** * Method to compose a character string which indicates the path name * to the level of hierarchy specified in the calling argument. * * Calling Arguments: * cellHead = pointer to desired level of hierarchy * sp = pointer to char string where path name is to be saved */ String computePathName(Connect cellHead) { StringBuffer infstr = new StringBuffer(); for ( ; cellHead != null; cellHead = cellHead.parent) infstr.append("." + cellHead.instName); return infstr.toString(); } /** * Method to return a pointer to the calling routine which indicates * the address of the node entry in the database. The calling argument string * contains information detailing the path name to the desired node. * * Calling Argument: * sp = pointer to char string containing path name to node */ private Node findNode(String sp) { if (sp.startsWith("$N")) { int i = TextUtils.atoi(sp.substring(2)); for(Node nodeHead : nodeList) { if (nodeHead.num == i) return nodeHead; } return null; } int dotPos = sp.lastIndexOf('.'); String s2 = sp; Connect cellPtr = findLevel(an.getStimuli().getCell().getName().toUpperCase()); if (dotPos >= 0) { s2 = sp.substring(dotPos+1); cellPtr = findLevel(sp.substring(0, dotPos)); } if (cellPtr == null) cellPtr = cellRoot; for(ALSExport exHead : cellPtr.exList) { if (exHead.nodeName.equals(s2)) return exHead.nodePtr; } return null; } /********************************** PARSING NETLISTS **********************************/ /** * Method to read a netlist description of the logic network * to be analysed in other procedures. Returns true on error. */ private boolean readNetDesc(Cell cell) { netlistStrings = cell.getTextViewContents(); if (netlistStrings == null) { System.out.println("No netlist information found in " + cell); return true; } netlistStringPoint = 0; System.out.println("Simulating netlist in " + cell); instPtr[0] = -1; iPtr = 0; for(;;) { String s1 = getAString(); if (s1 == null) break; if (s1.equals("GATE") || s1.equals("FUNCTION") || s1.equals("MODEL")) { if (parseStructHeader(s1.charAt(0))) return true; continue; } System.out.println("ERROR: String '" + s1 + "' invalid (expecting gate, function, or model)"); return true; } return false; } /** * Method to parse the input text used to describe the header for * a top level structure (gate, function, model). The structure name and * argument list (exported node names) are entered into the database. Returns * nonzero on error. * @param flag char representing the type of structure to be parsed */ private boolean parseStructHeader(char flag) { String s1 = getAName(); if (s1 == null) { System.out.println("Structure declaration: EOF unexpectedly found"); return true; } for(Model modPtr1 : modelList) { if (modPtr1.name.equals(s1)) { System.out.println("ERROR: Structure " + s1 + " already defined"); return true; } } modPtr2 = new Model(s1, flag); modPtr2.fanOut = 1; modelList.add(modPtr2); s1 = getAString(); if (s1 == null) { System.out.println("Structure declaration: EOF unexpectedly found"); return true; } if (!s1.startsWith("(")) { System.out.println("Structure declaration: Expecting to find '(' in place of string '" + s1 + "'"); return true; } for(;;) { s1 = getAName(); if (s1 == null) { System.out.println("Structure declaration: EOF unexpectedly found"); return true; } if (s1.startsWith(")")) break; for(ALSExport exPtr1 : modPtr2.exList) { if (exPtr1.nodeName.equals(s1)) { System.out.println("Node " + s1 + " specified more than once in argument list"); return true; } } exPtr2 = new ALSExport(); exPtr2.nodeName = s1; exPtr2.nodePtr = null; modPtr2.exList.add(exPtr2); } switch (flag) { case 'G': if (parseGate()) return true; return false; case 'F': if (parseFunction()) return true; return false; case 'M': if (parseModel()) return true; return false; } System.out.println("Error in parser: invalid structure type"); return true; } /** * Method to parse the text used to describe a gate entity. * The user specifies truth table entries, loading factors, and timing parameters * in this region of the netlist. Returns true on error. */ private boolean parseGate() { // init delay transition name delay = "XX"; deltaDef = linearDef = expDef = randomDef = absDef = 0; Object last = modPtr2; Row rowPtr2 = null; for(;;) { String s1 = getAString(); if (s1 == null || s1.equals("GATE") || s1.equals("FUNCTION") || s1.equals("MODEL")) { --iPtr; break; } if (s1.equals("I")) { rowPtr2 = new Row(); rowPtr2.inList = new ArrayList<Object>(); rowPtr2.outList = new ArrayList<Object>(); rowPtr2.delta = deltaDef; rowPtr2.linear = linearDef; rowPtr2.exp = expDef; rowPtr2.random = randomDef; rowPtr2.abs = absDef; rowPtr2.delay = delay; delay = "XX"; rowPtr2.next = null; if (last instanceof Row) ((Row)last).next = rowPtr2; else ((Model)last).ptr = rowPtr2; last = rowPtr2; ioPtr1 = rowPtr2.inList; if (parseNode()) return true; continue; } if (s1.equals("O")) { ioPtr1 = rowPtr2.outList; if (parseNode()) return true; continue; } if (s1.equals("T")) { if (parseTiming()) return true; continue; } if (s1.equals("D")) { if (parseDelay()) return true; continue; } if (s1.equals("FANOUT")) { if (parseFanOut()) return true; continue; } if (s1.equals("LOAD")) { if (parseLoad()) return true; continue; } if (s1.equals("PRIORITY")) { Integer jj = getAnInt(); if (jj == null) { System.out.println("Priority declaration: EOF unexpectedly found"); return true; } modPtr2.priority = jj.intValue(); continue; } if (s1.equals("SET")) { ioPtr1 = modPtr2.setList; if (parseNode()) return true; continue; } System.out.println("ERROR: String '" + s1 + "' invalid gate syntax"); return true; } return false; } /** * Method to create an entry in the database for one of the nodes * that belong to a row entry or set state entry. Returns true on error. */ private boolean parseNode() { for(;;) { String s1 = getAName(); if (s1 == null || s1.equals("GATE") || s1.equals("FUNCTION") || s1.equals("MODEL") || s1.equals("I") || s1.equals("O") || s1.equals("T") || s1.equals("FANOUT") || s1.equals("LOAD") || s1.equals("PRIORITY") || s1.equals("SET")) { --iPtr; break; } ioPtr2 = new IO(); ioPtr2.nodePtr = s1; ioPtr2.strength = Stimuli.GATE_STRENGTH; ioPtr1.add(ioPtr2); s1 = getAString(); if (s1 == null) { System.out.println("Node declaration: EOF unexpectedly found"); return true; } switch (s1.charAt(0)) { case '=': case '!': case '>': case '<': case '+': case '-': case '*': case '/': case '%': break; default: System.out.println("Gate declaration: Invalid Operator '" + s1 + "'"); return true; } ioPtr2.operatr = s1.charAt(0); s1 = getAString(); if (s1 == null) { System.out.println("Node declaration: EOF unexpectedly found"); return true; } if (s1.equals("L") || s1.equals("X") || s1.equals("H")) { ioPtr2.operand = new Integer(Stimuli.parseLevel(s1)); } else { --iPtr; if (s1.charAt(0) == '+' || s1.charAt(0) == '-' || TextUtils.isDigit(s1.charAt(0))) { Integer jj = getAnInt(); if (jj == null) { System.out.println("Node declaration: EOF unexpectedly found"); return true; } ioPtr2.operand = jj; } else { s1 = getAName(); if (s1 == null) { System.out.println("Node declaration: EOF unexpectedly found"); return true; } ioPtr2.operand = s1; ioPtr2.operatr += 128; } } s1 = getAString(); if (s1 == null || !s1.startsWith("@")) { --iPtr; continue; } Integer jj = getAnInt(); if (jj == null) { System.out.println("Node declaration: EOF unexpectedly found"); return true; } ioPtr2.strength = Stimuli.indexToStrength(jj.intValue()); } return false; } /** * Method to insert timing values into the appropriate places in * the database. Returns true on error. */ private boolean parseTiming() { deltaDef = linearDef = expDef = randomDef = absDef = 0; for(;;) { String s1 = getAString(); if (s1 == null) { System.out.println("Timing declaration: EOF unexpectedly found"); return true; } String s2 = getAString(); if (s2 == null) { System.out.println("Timing declaration: EOF unexpectedly found"); return true; } if (!s2.startsWith("=")) { System.out.println("Timing declaration: Invalid Operator '" + s2 + "' (expecting '=')"); return true; } Double value = getADouble(); if (value == null) { System.out.println("Timing declaration: EOF unexpectedly found"); return true; } switch (s1.charAt(0)) { case 'A': absDef = value.doubleValue(); break; case 'D': deltaDef = value.doubleValue(); break; case 'E': expDef = value.doubleValue(); break; case 'L': linearDef = value.doubleValue(); break; case 'R': randomDef = value.doubleValue(); if (value.doubleValue() > 0.0) modPtr2.priority = 2; break; default: System.out.println("Invalid timing mode '" + s1 + "'"); return true; } s1 = getAString(); if (s1 == null || !s1.startsWith("+"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -