⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cif.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: CIF.java * Input/output tool: CIF input * Original C CIF Parser (front end) by Robert W. Hon, Schlumberger Palo Alto Research * and its interface to C Electric (back end) by Robert Winstanley, University of Calgary. * 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.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.technology.Layer;import com.sun.electric.technology.Technology;import com.sun.electric.tool.io.IOTool;import java.awt.Point;import java.awt.Rectangle;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.IOException;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;/** * This class reads files in CIF files. */public class CIF extends Input{	/** max depth of minmax stack */		private static final int MAXMMSTACK = 50;	/** max value that can add extra digit */private static final int BIGSIGNED = ((0X7FFFFFFF-9)/10);	//	specific syntax errors	private static final int NOERROR    = 100;	private static final int NUMTOOBIG  = 101;	private static final int NOUNSIGNED = 102;	private static final int NOSIGNED   = 103;	private static final int NOSEMI     = 104;	private static final int NOPATH     = 105;	private static final int BADTRANS   = 106;	private static final int BADUSER    = 107;	private static final int BADCOMMAND = 108;	private static final int INTERNAL   = 109;	private static final int BADDEF     = 110;	private static final int NOLAYER    = 111;	private static final int BADCOMMENT = 112;	private static final int BADAXIS    = 113;	private static final int NESTDEF    = 114;	private static final int NESTDD     = 115;	private static final int NODEFSTART = 116;	private static final int NESTEND    = 117;	private static final int NOSPACE    = 118;	private static final int NONAME     = 119;	// enumerated types for cif 2.0 parser//	private static final int SEMANTICERROR = 0;	private static final int SYNTAXERROR   = 1;	private static final int WIRECOM       = 2;	private static final int BOXCOM        = 3;	private static final int POLYCOM       = 4;	private static final int FLASHCOM      = 5;	private static final int DEFSTART      = 6;	private static final int DEFEND        = 7;	private static final int DELETEDEF     = 8;	private static final int LAYER         = 9;	private static final int CALLCOM       = 10;	private static final int COMMENT       = 11;	private static final int NULLCOMMAND   = 12;	private static final int USERS         = 13;	private static final int END           = 14;	private static final int ENDFILE       = 15;	private static final int SYMNAME       = 16;	private static final int INSTNAME      = 17;	private static final int GEONAME       = 18;	private static final int LABELCOM      = 19;	// types for FrontTransformLists	static class FrontTransformType {}	private FrontTransformType MIRROR = new FrontTransformType();	private FrontTransformType TRANSLATE = new FrontTransformType();	private FrontTransformType ROTATE = new FrontTransformType();	// error codes for reporting errors	private static final int FATALINTERNAL = 0;	private static final int FATALSYNTAX   = 1;	private static final int FATALSEMANTIC = 2;	private static final int FATALOUTPUT   = 3;	private static final int ADVISORY      = 4;//	private static final int OTHER         = 5;			/* OTHER must be last */	private static final int TIDENT     = 0;	private static final int TROTATE    = 1;	private static final int TTRANSLATE = 2;	private static final int TMIRROR    = 4;	// values for BackCIFList->identity	private static final int CSTART =   0;	private static final int CEND =     1;//	private static final int CWIRE =    2;//	private static final int CFLASH =   3;	private static final int CBOX =     4;	private static final int CPOLY =    5;//	private static final int CCOMMAND = 6;	private static final int CGNAME =   7;	private static final int CLABEL =   8;	private static final int CCALL =    9;	static class BackCIFCell	{		/** cell index given in the define statement */	int  cIndex;		/** bounding box of cell */						int  l, r, t, b;		/** the address of the cif cell */				Cell addr;	};	static class BackCIFList	{		/** specifies the nature of the entry */	int         identity;		/** will point to member's structure */		Object      member;		/** next entry in list */					BackCIFList next;	};	static class BackCIFStart	{		/** cell index */							int    cIndex;		/** cell name */							String name;		/** bounding box of cell */					int    l, r, t, b;	};	static class BackCIFBox	{		/** the corresponding layer number */		Layer lay;		/** dimensions of box */					int   length, width;		/** center point of box */					int   cenX, cenY;		/** box direction */						int   xRot, yRot;	};	static class BackCIFPoly	{		/** the corresponding layer number */		Layer  lay;		/** list of points */						int [] x, y;		/** number of points in list */				int    lim;	};	static class BackCIFGeomName	{		/** the corresponding layer number */		Layer  lay;	};	static class BackCIFLabel	{		/** location of label */					int    x, y;		/** the label */							String label;	};	static class BackCIFCall	{		/** index of cell called */					int              cIndex;		/** name of cell called */					String           name;		/** list of transformations */				BackCIFTransform list;	};	// values for the transformation type	/** mirror in x */	private static final int MIRX  = 1;	/** mirror in y */	private static final int MIRY  = 2;	/** translation */	private static final int TRANS = 3;	/** rotation */		private static final int ROT   = 4;	static class BackCIFTransform	{		/** type of transformation */				int              type;		/** not required for the mirror types */	int              x, y;		/** next element in list */					BackCIFTransform next;	};	static class FrontTransformEntry	{		FrontTransformType kind;		boolean            xCoord;		int                xt, yt;		int                xRot, yRot;	};	/** data types for transformation package */	static class FrontMatrix	{		double a11, a12, a21, a22, a31, a32, a33;		FrontMatrix prev, next;		int type;		boolean multiplied;	};	/** bounding box */	static class FrontBBox	{		int l, r, b, t;	};	static class FrontSymbol	{		/** symbol number for this entry */					int symNumber;		boolean expanded;		boolean defined;		boolean dumped;		/** bb as if this symbol were called by itself */	FrontBBox bounds;		/** flag for rebuilding bounding box */				boolean boundsValid;		/** name of this symbol */							String name;		/** number of calls made by this symbol */			int numCalls;		/** pointer to linked list of objects */			FrontObjBase guts;		FrontSymbol(int num)		{			bounds = new FrontBBox();			symNumber = num;			expanded = false;			defined = false;			dumped = false;			numCalls = 0;			boundsValid = false;			name = null;			guts = null;		}	};	static class FrontLinkedPoint	{		Point pValue;		FrontLinkedPoint pNext;	};	static class FrontPath	{		FrontLinkedPoint pFirst, pLast;		int pLength;		FrontPath()		{			pFirst = null;			pLast = null;			pLength = 0;		}	};	static class FrontLinkedTransform	{		FrontTransformEntry tValue;		FrontLinkedTransform tNext;	};	static class FrontTransformList	{		FrontLinkedTransform tFirst, tLast;		int tLength;		FrontTransformList()		{			tFirst = null;			tLast = null;			tLength = 0;		}	};	/** items in item tree */	static class FrontItem	{		/** links for tree */					FrontItem same;		/** pointer into symbol structure */	FrontObjBase   what;	};	/** hack structure for referencing first fields of any object */	static class FrontObjBase	{		/** bounding box */				FrontBBox bb;		/** for ll */					FrontObjBase  next;		/** layer for this object */	Layer layer;		FrontObjBase()		{			bb = new FrontBBox();		}	};	/** symbol call object */	static class FrontCall extends FrontObjBase	{		/** rest is noncritical */				int symNumber;		FrontSymbol unID;		FrontMatrix matrix;		/** trans list for this call */			FrontTransformList transList;	};	static class FrontGeomName extends FrontObjBase	{	};	static class FrontLabel extends FrontObjBase	{		String name;		Point pos;	};	static class FrontBox extends FrontObjBase	{		int length, width;		Point center;		int xRot, yRot;	};	static class FrontManBox extends FrontObjBase	{	};	static class FrontFlash extends FrontObjBase	{		Point center;		int diameter;	};	static class FrontPoly extends FrontObjBase	{		/** array of points in path */			Point [] points;	};	static class FrontWire extends FrontObjBase	{		/** width of wire */					int width;		/** array of points in wire */			Point [] points;	};	/** current transformation */			private BackCIFTransform currentCTrans;	/** head of the list */					private BackCIFList      currentFrontList = null;	/** current location in list */			private BackCIFList      currentFrontElement;	/** head of item list */				private FrontItem        currentItemList;	/** A/B from DS */						private double           cellScaleFactor;	/** current symbol being defined */		private FrontSymbol      currentFrontSymbol;	/** place to save layer during def */	private Layer            backupLayer;	/** symbol has been named */			private boolean          symbolNamed;	/** flag for error encountered */		private boolean          errorFound;	/** what it was */						private int              errorType;	/** definition in progress flag */		private boolean          isInCellDefinition;	/** end command flag */					private boolean          endIsSeen;	/** number of chars in buffer */		private int              charactersRead;	/** flag to reset buffer */				private boolean          resetInputBuffer;	/** number of "fatal" errors */			private int              numFatalErrors;	/** null layer errors encountered */	private boolean          numNullLayerErrors;	/** ignore statements until DF */		private boolean          ignoreStatements;	/** 91 pending */						private boolean          namePending;	/** end command flag */					private boolean          endCommandFound;	/** current layer */					private Layer            currentLayer;	/** symbol table */						private HashMap<Integer,FrontSymbol> symbolTable;	/** the top of stack */					private FrontMatrix      matrixStackTop;	/** lookahead character */				private int              nextInputCharacter;	/** # statements since 91 com */		private boolean          statementsSince91;	/** min/max stack pointer */			private int              minMaxStackPtr;	/** min/max stack: left edge */			private int []           minMaxStackLeft;	/** min/max stack: right edge */		private int []           minMaxStackRight;	/** min/max stack: bottom edge */		private int []           minMaxStackBottom;	/** min/max stack: top edge */			private int []           minMaxStackTop;	/** map from cell numbers to cells */	private HashMap<Integer,BackCIFCell> cifCellMap;	/** the current cell */					private BackCIFCell      currentBackCell;	/** current technology for layers */	private Technology       curTech;	/** map from layer names to layers */	private HashMap<String,Layer> cifLayerNames;	/** set of unknown layers */			private HashSet<String>  unknownLayerNames;	/** address of cell being defined */	private Cell             cellBeingBuilt;	/** name of the current cell */			private String           currentNodeProtoName;	/** the line being read */				private StringBuffer     inputBuffer;	/**	 * 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)	{        setProgressNote("Reading CIF file");        // initialize all lists and the searching routines		cifCellMap = new HashMap<Integer,BackCIFCell>();		if (initFind()) return null;		// parse the cif and create a listing		if (interpret()) return null;		// instantiate the cif as nodes        setProgressNote("Storing CIF in database...");		if (listToNodes(lib)) return null;		// clean up		doneInterpreter();		return lib;	}	private boolean listToNodes(Library lib)	{		cellBeingBuilt = null;		for(currentFrontElement = currentFrontList; currentFrontElement != null; currentFrontElement = currentFrontElement.next)		{			if (currentFrontElement.identity == CSTART)			{				cellBeingBuilt = nodesStart(lib);				if (cellBeingBuilt == null) return true;				continue;			}			if (currentFrontElement.identity == CEND)			{//				lib.setCurCell(cellBeingBuilt);		// THIS TAKES WAY TOO LONG				cellBeingBuilt = null;				continue;			}			if (cellBeingBuilt == null)			{				// circuitry found at the top level: create a fake cell for it				cellBeingBuilt = lib.findNodeProto("TOP_LEVEL_UNNAMED{lay}");				if (cellBeingBuilt == null)				{					cellBeingBuilt = Cell.newInstance(lib, "TOP_LEVEL_UNNAMED{lay}");					if (cellBeingBuilt == null) break;					currentBackCell = makeBackCIFCell(9999);				}				currentBackCell.addr = cellBeingBuilt;			}			if (currentFrontElement.identity == CBOX)			{				if (nodesBox()) return true;			} else if (currentFrontElement.identity == CPOLY)			{				if (nodesPoly()) return true;			} else if (currentFrontElement.identity == CCALL)			{				if (nodesCall()) return true;			}		}		return false;	}	private Cell nodesStart(Library lib)	{		BackCIFStart cs = (BackCIFStart)currentFrontElement.member;		BackCIFCell cifCell = makeBackCIFCell(cs.cIndex);		cifCell.l = cs.l;   cifCell.r = cs.r;		cifCell.b = cs.b;   cifCell.t = cs.t;		currentNodeProtoName = cs.name;		// remove illegal characters		StringBuffer properName = new StringBuffer();		for(int i=0; i<currentNodeProtoName.length(); i++)		{			char chr = currentNodeProtoName.charAt(i);			if (Character.isWhitespace(chr) || chr == ':' || chr == ';')			{				chr = 'X';			}			properName.append(chr);		}		currentNodeProtoName = properName.toString();		cifCell.addr = Cell.newInstance(lib, currentNodeProtoName + "{lay}");		if (cifCell.addr == null)		{			System.out.println("Cannot create the cell " + currentNodeProtoName);			return null;		}		return cifCell.addr;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -