📄 fpga.java
字号:
LispTree ltType = null, ltName = null, ltPosition = null, ltRotation = null, ltAttribute = null; for(int i=0; i<lt.size(); i++) { if (lt.isLeaf(i)) continue; LispTree scanLT = lt.getBranch(i); if (scanLT.keyword.equalsIgnoreCase("type")) { if (ltType != null) { System.out.println("Multiple 'type' sections for a block (line " + lt.lineNumber + ")"); return true; } ltType = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("name")) { if (ltName != null) { System.out.println("Multiple 'name' sections for a block (line " + lt.lineNumber + ")"); return true; } ltName = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("position")) { if (ltPosition != null) { System.out.println("Multiple 'position' sections for a block (line " + lt.lineNumber + ")"); return true; } ltPosition = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("rotation")) { if (ltRotation != null) { System.out.println("Multiple 'rotation' sections for a block (line " + lt.lineNumber + ")"); return true; } ltRotation = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("attributes")) { if (ltAttribute != null) { System.out.println("Multiple 'attributes' sections for a block (line " + lt.lineNumber + ")"); return true; } ltAttribute = scanLT; continue; } } // validate if (ltType == null) { System.out.println("No 'type' specified for block instance (line " + lt.lineNumber + ")"); return true; } if (ltType.size() != 1 || ltType.isBranch(0)) { System.out.println("Need one atom in 'type' of block instance (line " + ltType.lineNumber + ")"); return true; } NodeProto np = findNodeProto(ltType.getLeaf(0)); if (np == null) np = cell.getLibrary().findNodeProto(ltType.getLeaf(0)); if (np == null) { System.out.println("Cannot find block type '" + ltType.getLeaf(0) + "' (line " + ltType.lineNumber + ")"); return true; } if (ltPosition == null) { System.out.println("No 'position' specified for block instance (line " + lt.lineNumber + ")"); return true; } if (ltPosition.size() != 2 || ltPosition.isBranch(0) || ltPosition.isBranch(1)) { System.out.println("Need two atoms in 'position' of block instance (line " + ltPosition.lineNumber + ")"); return true; } int rotation = 0; if (ltRotation != null) { if (ltRotation.size() != 1 || ltRotation.isBranch(0)) { System.out.println("Need one atom in 'rotation' of block instance (line " + ltRotation.lineNumber + ")"); return true; } rotation = TextUtils.atoi(ltRotation.getLeaf(0)) * 10; } // name the instance if one is given String nodeName = null; if (ltName != null) { if (ltName.size() != 1 || ltName.isBranch(0)) { System.out.println("Need one atom in 'name' of block instance (line " + ltName.lineNumber + ")"); return true; } nodeName = ltName.getLeaf(0); } // place the instance double posX = TextUtils.atof(ltPosition.getLeaf(0)); double posY = TextUtils.atof(ltPosition.getLeaf(1)); double wid = np.getDefWidth(); double hei = np.getDefHeight(); if (np instanceof PrimitiveNode) { posX += wid/2; posY += hei/2; } Point2D ctr = new Point2D.Double(posX, posY); Orientation orient = Orientation.fromAngle(rotation); NodeInst ni = NodeInst.makeInstance(np, ctr, wid, hei, cell, orient, nodeName, 0); if (ni == null) return true; // add any attributes if (ltAttribute != null) { for(int i=0; i<ltAttribute.size(); i++) { if (ltAttribute.isLeaf(i)) continue; LispTree scanLT = ltAttribute.getBranch(i); if (scanLT.size() != 1 || scanLT.isBranch(0)) { System.out.println("Attribute '" + scanLT.keyword+ "' attribute should take a single atomic parameter (line " + lt.lineNumber + ")"); return true; } ni.newVar(scanLT.keyword, scanLT.getLeaf(0)); } } return false; } /** * Method to add a port to block "cell" from the tree in "lt". * Tree has "(port...)" structure. Returns true on error. */ private boolean makeBlockPort(Cell cell, LispTree lt) { LispTree ltName = null, ltPosition = null; for(int j=0; j<lt.size(); j++) { if (lt.isLeaf(j)) continue; LispTree scanLT = lt.getBranch(j); if (scanLT.keyword.equalsIgnoreCase("name")) { ltName = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("position")) { ltPosition = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("direction")) { continue; } } // make the port if (ltName == null) { System.out.println("Port has no name (line " + lt.lineNumber + ")"); return true; } if (ltName.size() != 1 || ltName.isBranch(0)) { System.out.println("Port name must be a single atom (line " + ltName.lineNumber + ")"); } if (ltPosition == null) { System.out.println("Port has no position (line " + lt.lineNumber + ")"); return true; } if (ltPosition.size() != 2 || ltPosition.isBranch(0) || ltPosition.isBranch(1)) { System.out.println("Port position must be two atoms (line " + ltPosition.lineNumber + ")"); } // create the structure double posX = TextUtils.atof(ltPosition.getLeaf(0)); double posY = TextUtils.atof(ltPosition.getLeaf(1)); NodeInst ni = NodeInst.makeInstance(wirePinNode, new Point2D.Double(posX, posY), 0, 0, cell); if (ni == null) { System.out.println("Error creating pin for port '" + ltName.getLeaf(0) + "' (line " + lt.lineNumber + ")"); return true; } PortInst pi = ni.getOnlyPortInst(); Export e = Export.newInstance(cell, pi, ltName.getLeaf(0)); if (e == null) { System.out.println("Error creating port '" + ltName.getLeaf(0) + "' (line " + lt.lineNumber + ")"); return true; } return false; } /** * Method to place a repeater in cell "cell" from the LISPTREE in "lt". * Tree has "(repeater...)" structure. Returns true on error. */ private boolean makeBlockRepeater(Cell cell, LispTree lt) { LispTree ltName = null, ltPortA = null, ltPortB = null; for(int j=0; j<lt.size(); j++) { if (lt.isLeaf(j)) continue; LispTree scanLT = lt.getBranch(j); if (scanLT.keyword.equalsIgnoreCase("name")) { ltName = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("porta")) { ltPortA = scanLT; continue; } if (scanLT.keyword.equalsIgnoreCase("portb")) { ltPortB = scanLT; continue; } } // make the repeater if (ltPortA == null) { System.out.println("Repeater has no 'porta' (line " + lt.lineNumber + ")"); return true; } if (ltPortA.size() != 2 || ltPortA.isBranch(0) || ltPortA.isBranch(1)) { System.out.println("Repeater 'porta' position must be two atoms (line " + ltPortA.lineNumber + ")"); } if (ltPortB == null) { System.out.println("Repeater has no 'portb' (line " + lt.lineNumber + ")"); return true; } if (ltPortB.size() != 2 || ltPortB.isBranch(0) || ltPortB.isBranch(1)) { System.out.println("Repeater 'portb' position must be two atoms (line " + ltPortB.lineNumber + ")"); } // name the repeater if one is given String name = null; if (ltName != null) { if (ltName.size() != 1 || ltName.isBranch(0)) { System.out.println("Need one atom in 'name' of block repeater (line " + ltName.lineNumber + ")"); return true; } name = ltName.getLeaf(0); } // create the repeater double portAX = TextUtils.atof(ltPortA.getLeaf(0)); double portAY = TextUtils.atof(ltPortA.getLeaf(1)); double portBX = TextUtils.atof(ltPortB.getLeaf(0)); double portBY = TextUtils.atof(ltPortB.getLeaf(1)); int angle = GenMath.figureAngle(new Point2D.Double(portAX, portAY), new Point2D.Double(portBX, portBY)); Point2D ctr = new Point2D.Double((portAX + portBX) / 2, (portAY + portBY) / 2); Orientation orient = Orientation.fromAngle(angle); NodeInst ni = NodeInst.makeInstance(repeaterNode, ctr, 10,3, cell, orient, name, 0); if (ni == null) { System.out.println("Error creating repeater (line " + lt.lineNumber + ")"); return true; } return false; } /** * Method to extract block net information from the LISPTREE in "lt". * Tree has "(net...)" structure. Returns true on error. */ private boolean makeBlockNet(Cell cell, LispTree lt) { // find the net name for(int j=0; j<lt.size(); j++) { if (lt.isLeaf(j)) continue; LispTree scanLT = lt.getBranch(j); if (scanLT.keyword.equalsIgnoreCase("name")) { if (scanLT.size() != 1 || scanLT.isBranch(0)) { System.out.println("Net name must be a single atom (line " + scanLT.lineNumber + ")"); return true; } continue; } } // scan for segment objects for(int j=0; j<lt.size(); j++) { if (lt.isLeaf(j)) continue; LispTree scanLT = lt.getBranch(j); if (scanLT.keyword.equalsIgnoreCase("segment")) { int pos = 0; NodeInst [] nis = new NodeInst[2]; PortProto [] pps = new PortProto[2]; for(int i=0; i<2; i++) { // get end of arc if (scanLT.size() < pos+1) { System.out.println("Incomplete block net segment (line " + scanLT.lineNumber + ")"); return true; } if (scanLT.isBranch(pos)) { System.out.println("Must have atoms in block net segment (line " + scanLT.lineNumber + ")"); return true; } if (scanLT.getLeaf(pos).equalsIgnoreCase("component")) { if (scanLT.size() < pos+3) { System.out.println("Incomplete block net segment (line " + scanLT.lineNumber + ")"); return true; } if (scanLT.isBranch(pos+1) || scanLT.isBranch(pos+2)) { System.out.println("Must have atoms in block net segment (line " + scanLT.lineNumber + ")"); return true; } // find component and port NodeInst niFound = null; String name = scanLT.getLeaf(pos+1); for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.getName().equalsIgnoreCase(name)) { niFound = ni; break; } } if (niFound == null) { System.out.println("Cannot find component '" + scanLT.getLeaf(pos+1) + "' in block net segment (line " + scanLT.lineNumber + ")"); return true; } nis[i] = niFound; pps[i] = niFound.getProto().findPortProto(scanLT.getLeaf(pos+2)); if (pps[i] == null) { System.out.println("Cannot find port '" + scanLT.getLeaf(pos+2) + "' on component '" + scanLT.getLeaf(pos+1) + "' in block net segment (line " + scanLT.lineNumber + ")"); return true; } pos += 3; } else if (scanLT.getLeaf(pos).equalsIgnoreCase("coord")) { if (scanLT.size() < pos+3) { System.out.println("Incomplete block net segment (line " + scanLT.lineNumber + ")"); return true; } if (scanLT.isBranch(pos+1) || scanLT.isBranch(pos+2)) { System.out.println("Must have atoms in block net segment (line " + scanLT.lineNumber + ")"); return true; } double x = TextUtils.atof(scanLT.getLeaf(pos+1)); double y = TextUtils.atof(scanLT.getLeaf(pos+2)); Rectangle2D search = new Rectangle2D.Double(x, y, 0, 0); // find pin at this point NodeInst niFound = null; for(Iterator<RTBounds> it = cell.searchIterator(search); it.hasNext(); ) { RTBounds geom = it.next(); if (!(geom instanceof NodeInst)) continue; NodeInst ni = (NodeInst)geom; if (ni.getProto() != wirePinNode) continue; if (ni.getTrueCenterX() == x && ni.getTrueCenterY() == y) { niFound = ni; break; } } if (niFound == null) { niFound = NodeInst.makeInstance(wirePinNode, new Point2D.Double(x, y), 0, 0, cell); if (niFound == null) { System.out.println("Cannot create pin for block net segment (line " + scanLT.lineNumber + ")"); return true; } } nis[i] = niFound; pps[i] = niFound.getProto().getPort(0); pos += 3; } else if (scanLT.getLeaf(pos).equalsIgnoreCase("port")) { if (scanLT.size() < pos+2) { System.out.println("Incomplete block net segment (line " + scanLT.lineNumber + ")"); return true; } if (scanLT.isBranch(pos+1)) { System.out.println("Must have atoms in block net segment (line " + scanLT.lineNumber + ")"); return true; } // find port Export pp = cell.findExport(scanLT.getLeaf(pos+1)); if (pp == null) { System.out.printl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -