📄 edif.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: EDIF.java * Input/output tool: EDIF 2.0.0 input * Original EDIF reader by Glen Lawson. * Translated into Java by Steven M. Rubin, Sun Microsystems. * * Copyright (c) 2004 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.io.input;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.geometry.GenMath.MutableInteger;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.Nodable;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.prototype.PortCharacteristic;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Connection;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.topology.RTBounds;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.Layer;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.io.IOTool;import com.sun.electric.tool.io.output.EDIFEquiv;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ViewChanges;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.IOException;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;/** * This class reads files in EDIF files. * <BR> * Notes: * I have tried EDIF files from CADENCE and VALID only. * Does not fully support portbundles * Multiple ports of the same name are named port_x (x is 1 to n duplicate) * Keywords such as ARRAY have unnamed parameters, ie (array (name..) 5 6) * this is handled in the processInteger function called by getKeyword, * this is a hack to fix this problem, a real table driven parser should be used. * Use circle arcs instead of splines. * Support text justifications and text height * Better NAME/RENAME/STRINGDISPLAY/ANNOTATE text handling. * ANSI prototypes * Changed arcs to simple polygons plus ARC attribute * Can read NETLIST views */public class EDIF extends Input{ private static final double INCH = 10; private static final int SHEETWIDTH = 44; // was 32 private static final int SHEETHEIGHT = 20; // name table for layers private static class NameEntry { /** the original MASK layer */ private String original; /** the replacement layer */ private String replace; /** the basic electric node */ private NodeProto node; /** default text height */ private int textHeight; /** default justification */ private TextDescriptor.Position justification; /** layer is visible */ private boolean visible; }; // Edif viewtypes ... private static class ViewType { private String name; ViewType(String name) { this.name = name; } public String toString() { return "VIEWTYPE "+name; } } private static final ViewType VNULL = new ViewType("Null"); private static final ViewType VBEHAVIOR = new ViewType("Behavior"); private static final ViewType VDOCUMENT = new ViewType("Document"); private static final ViewType VGRAPHIC = new ViewType("Graphic"); private static final ViewType VLOGICMODEL = new ViewType("LogicModel"); private static final ViewType VMASKLAYOUT = new ViewType("MaskLayout"); private static final ViewType VNETLIST = new ViewType("Netlist"); private static final ViewType VPCBLAYOUT = new ViewType("PCBLayout"); private static final ViewType VSCHEMATIC = new ViewType("Schematic"); private static final ViewType VSTRANGER = new ViewType("Stranger"); private static final ViewType VSYMBOLIC = new ViewType("Symbolic"); private static final ViewType VSYMBOL = new ViewType("Symbol"); /* not a real EDIF view, but electric has one */ // Edif geometry types ... private static class GeometryType {} private static final GeometryType GUNKNOWN = new GeometryType();// private static final GeometryType GRECTANGLE = new GeometryType();// private static final GeometryType GPOLYGON = new GeometryType();// private static final GeometryType GSHAPE = new GeometryType();// private static final GeometryType GOPENSHAPE = new GeometryType();// private static final GeometryType GTEXT = new GeometryType();// private static final GeometryType GPATH = new GeometryType(); private static final GeometryType GINSTANCE = new GeometryType();// private static final GeometryType GCIRCLE = new GeometryType();// private static final GeometryType GARC = new GeometryType(); private static final GeometryType GPIN = new GeometryType(); private static final GeometryType GNET = new GeometryType(); private static final GeometryType GBUS = new GeometryType(); // 8 standard orientations private static final Orientation OR0 = Orientation.fromC(0, false); private static final Orientation OR90 = Orientation.fromC(900, false); private static final Orientation OR180 = Orientation.fromC(1800, false); private static final Orientation OR270 = Orientation.fromC(2700, false); private static final Orientation OMX = Orientation.fromC(2700, true); private static final Orientation OMY = Orientation.fromC(900, true); private static final Orientation OMYR90 = Orientation.fromC(0, true); private static final Orientation OMXR90 = Orientation.fromC(1800, true); private static class EDIFPort { private String name; private String reference; private PortCharacteristic direction; private EDIFPort next; }; private static class VendorType {} private static final VendorType EVUNKNOWN = new VendorType(); private static final VendorType EVCADENCE = new VendorType(); private static final VendorType EVVIEWLOGIC = new VendorType(); private static class EDIFProperty { private String name; private Object val; private EDIFProperty next; } // view information ... /** the schematic page number */ private int pageNumber; /** indicates we are in a NETLIST view */ private ViewType activeView; /** the current vendor type */ private VendorType curVendor; // parser variables ... /** the current parser state */ private EDIFKEY curKeyword; /** the read buffer */ private String inputBuffer; /** the position within the buffer */ private int inputBufferPos; /** no update flag */ private boolean ignoreBlock; /** no update flag */ private boolean ignoreHigherBlock; /** load status */ private int errorCount, warningCount; // electric context data ... /** the new library */ private Library curLibrary; /** the active technology */ private Technology curTechnology; /** the current active cell */ private Cell curCell; /** the current page in cell */ private int curCellPage; /** the parameter position in cell */ private int curCellParameterOff; /** the current active instance */ private NodeInst curNode; /** the current active arc */ private ArcInst curArc; /** the current figure group node */ private NodeProto curFigureGroup; /** the cellRef type */ private NodeProto cellRefProto; /** the cellRef tech bits if primitive */ private int cellRefProtoTechBits; /** the cellRef addt'l rotation (in degrees) */ private int cellRefProtoRotation; /** the cellRef offset when mapped */ private double cellRefOffsetX, cellRefOffsetY; /** the current port proto */ private PortProto curPort; /** the current portList */ private List<Network> curPortlist; /** the last portList */ private List<Network> lastPortlist; // general geometry information ... /** the current geometry type */ private GeometryType curGeometryType; /** the list of points */ private List<Point2D> curPoints; /** the orientation of the structure */ private Orientation curOrientation; /** port direction */ private PortCharacteristic curDirection; // geometric path constructors ... /** the width of the path */ private int pathWidth; /** extend path end flag */ private boolean extendEnd; // array variables ... /** set if truely an array */ private boolean isArray; /** the bounds of the array */ private int arrayXVal, arrayYVal; /** offsets in x and y for X increment */ private double deltaPointXX, deltaPointXY; /** offsets in x and y for Y increment */ private double deltaPointYX, deltaPointYY; /** which offset flag */ private boolean deltaPointsSet; /** the element of the array */ private int memberXVal, memberYVal; // text variables ... /** Text string */ private String textString; /** the current default text height */ private int textHeight; /** the current text justificaton */ private TextDescriptor.Position textJustification; /** is stringdisplay visible */ private boolean textVisible; /** origin x and y */ private List<Point2D> saveTextPoints; /** the height of text */ private int saveTextHeight; /** justification of the text */ private TextDescriptor.Position saveTextJustification; // technology data ... /** scaling value */ private double inputScale; // current name and rename of EDIF objects ... /** the current cell name */ private String cellReference; /** the current cell name (original) */ private String cellName; /** the current port name */ private String portReference; /** the current port name (original) */ private String portName; /** the current instance name */ private String instanceReference; /** the current instance name (original) */ private String instanceName; /** the current bundle name */ private String bundleReference; /** the current bundle name (original) */ private String bundleName; /** the current net name */ private String netReference; /** the current net name (original) */ private String netName; /** the current property name */ private String propertyReference; /** the current viewRef name */ private String viewRef; /** the current cellRef name */ private String cellRef; /** the current libraryRef name */ private String libraryRef; /** property value */ private Object propertyValue; /** the name of the object */ private String objectName; /** the original name of the object */ private String originalName; /** cells that have been built so far */ private Set<Cell> builtCells; // layer or figure information ... /** the current name mapping table */ private List<NameEntry> nameEntryList; /** the current name table entry */ private NameEntry curNameEntry; /** cell name lookup (from rename) */ private Map<String,NameEntry> cellTable; // port data for port exporting /** active port list */ private EDIFPort portsListHead; // property data for all objects /** active property list */ private EDIFProperty propertiesListHead; // view NETLIST layout /** current sheet position */ private int sheetXPos, sheetYPos; /** stack of keywords at this point */ private EDIFKEY [] keyStack = new EDIFKEY[1000]; /** depth of keyword stack */ private int keyStackDepth; /** Edif equivs for primitives */ private EDIFEquiv equivs; /** List of ports in net -> joined list */ private List<PortInst> netPortRefs; /** mapping of renamed objects */ private Map<String,String> renamedObjects; /** list of offpage nodes in the cell */ private List<NodeInst> offpageNodes; /** list of nodes that were equived */ private Map<String,EDIFEquiv.NodeEquivalence> mappedNodes; /** mapping of named arcs in each cell */ private Map<Cell,Map<String,List<ArcInst>>> namedArcs = new HashMap<Cell,Map<String,List<ArcInst>>>(); /** export names needed on current net */ private Set<String> exportsOnNet; /** arcs placed on current net */ private List<ArcInst> arcsOnNet; // some standard artwork primitivies private PortProto defaultPort; private PortProto defaultIconPort; private PortProto defaultBusPort; private PortProto defaultInput; private PortProto defaultOutput; /** all keywords for parsing */ private static Map<String,EDIFKEY> edifKeys = new HashMap<String,EDIFKEY>(); /**************************************** MAIN CONTROL ****************************************/ /** * Method to import a library from disk. * @param lib the library to fill * @return the created library (null on error). */ protected Library importALibrary(Library lib) { // setup keyword prerequisites KARRAY.stateArray = new EDIFKEY [] {KINSTANCE, KPORT, KNET}; KAUTHOR.stateArray = new EDIFKEY [] {KWRITTEN}; KBOUNDINGBOX.stateArray = new EDIFKEY [] {KSYMBOL, KCONTENTS}; KCELL.stateArray = new EDIFKEY [] {KEXTERNAL, KLIBRARY}; KCELLREF.stateArray = new EDIFKEY [] {KDESIGN, KVIEWREF, KINSTANCE}; KCELLTYPE.stateArray = new EDIFKEY [] {KCELL}; KCONTENTS.stateArray = new EDIFKEY [] {KVIEW}; KDESIGN.stateArray = new EDIFKEY [] {KEDIF}; KDIRECTION.stateArray = new EDIFKEY [] {KPORT}; KEDIF.stateArray = new EDIFKEY [] {KINIT}; KEDIFLEVEL.stateArray = new EDIFKEY [] {KEDIF, KEXTERNAL, KLIBRARY}; KEXTERNAL.stateArray = new EDIFKEY [] {KEDIF}; KINSTANCE.stateArray = new EDIFKEY [] {KCONTENTS, KPAGE, KPORTIMPLEMENTATION, KCOMMENTGRAPHICS}; KINSTANCEREF.stateArray = new EDIFKEY [] {KINSTANCEREF, KPORTREF}; KINTERFACE.stateArray = new EDIFKEY [] {KVIEW}; KJOINED.stateArray = new EDIFKEY [] {KINTERFACE, KNET}; KEDIFKEYMAP.stateArray = new EDIFKEY [] {KEDIF}; KLIBRARYREF.stateArray = new EDIFKEY [] {KCELLREF}; KLISTOFNETS.stateArray = new EDIFKEY [] {KNETBUNDLE}; KNET.stateArray = new EDIFKEY [] {KCONTENTS, KPAGE, KLISTOFNETS}; KNETBUNDLE.stateArray = new EDIFKEY [] {KCONTENTS, KPAGE}; KNUMBERDEFINITION.stateArray = new EDIFKEY [] {KTECHNOLOGY}; KPORT.stateArray = new EDIFKEY [] {KINTERFACE, KLISTOFPORTS}; KSCALE.stateArray = new EDIFKEY [] {KNUMBERDEFINITION}; KSTATUS.stateArray = new EDIFKEY [] {KCELL, KDESIGN, KEDIF, KEXTERNAL, KLIBRARY, KVIEW}; KSYMBOL.stateArray = new EDIFKEY [] {KINTERFACE}; KTECHNOLOGY.stateArray = new EDIFKEY [] {KEXTERNAL, KLIBRARY}; KTIMESTAMP.stateArray = new EDIFKEY [] {KWRITTEN}; KUNIT.stateArray = new EDIFKEY [] {KPROPERTY, KSCALE}; KVIEW.stateArray = new EDIFKEY [] {KPROPERTY, KCELL}; KVIEWREF.stateArray = new EDIFKEY [] {KINSTANCE, KINSTANCEREF, KPORTREF}; KVIEWTYPE.stateArray = new EDIFKEY [] {KVIEW}; KWRITTEN.stateArray = new EDIFKEY [] {KSTATUS}; // inits propertyValue = null; curPoints = new ArrayList<Point2D>(); saveTextPoints = new ArrayList<Point2D>(); // parser inits curKeyword = KINIT; inputBuffer = ""; inputBufferPos = 0; errorCount = warningCount = 0; ignoreBlock = ignoreHigherBlock = false; curVendor = EVUNKNOWN; builtCells = new HashSet<Cell>(); // general inits inputScale = IOTool.getEDIFInputScale(); curLibrary = lib; curTechnology = Schematics.tech(); cellTable = new HashMap<String,NameEntry>(); portsListHead = null; propertiesListHead = null; // active database inits curCell = null; curCellPage = 0; curCellParameterOff = 0; curNode = null; curArc = null; curPort = null; curFigureGroup = null; cellRefProto = null; // name inits cellReference = ""; portReference = ""; instanceReference = ""; bundleReference = ""; netReference = ""; propertyReference = ""; // geometry inits nameEntryList = new ArrayList<NameEntry>(); curNameEntry = null; freePointList(); // text inits textHeight = 0; textJustification = TextDescriptor.Position.DOWNRIGHT; textVisible = true; freeSavedPointList(); sheetXPos = -1; sheetYPos = -1; keyStackDepth = 0; defaultPort = Schematics.tech().wirePinNode.findPortProto("wire"); defaultIconPort = Schematics.tech().wirePinNode.getPort(0); defaultBusPort = Schematics.tech().busPinNode.findPortProto("bus"); defaultInput = Schematics.tech().offpageNode.findPortProto("y"); defaultOutput = Schematics.tech().offpageNode.findPortProto("a"); equivs = new EDIFEquiv(); netPortRefs = new ArrayList<PortInst>(); renamedObjects = new HashMap<String,String>(); // parse the file try { loadEDIF(); } catch (IOException e) { System.out.println("line " + lineReader.getLineNumber() + ": " + e.getMessage()); return null; } if (errorCount != 0 || warningCount != 0) System.out.println("A total of " + errorCount + " errors, and " + warningCount + " warnings encountered during load"); if (curLibrary != null && Job.getUserInterface().getCurrentCell(curLibrary) == null && curLibrary.getCells().hasNext()) Job.getUserInterface().setCurrentCell(curLibrary, curLibrary.getCells().next());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -