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

📄 elib.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: ELIB.java * Input/output tool: ELIB Library input * Written by Steven M. Rubin, Sun Microsystems. * * Copyright (c) 2003 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.ImmutableArcInst;import com.sun.electric.database.ImmutableExport;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.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.id.ArcProtoId;import com.sun.electric.database.id.CellId;import com.sun.electric.database.id.ExportId;import com.sun.electric.database.id.IdManager;import com.sun.electric.database.id.LibId;import com.sun.electric.database.id.NodeProtoId;import com.sun.electric.database.id.PrimitiveNodeId;import com.sun.electric.database.id.PrimitivePortId;import com.sun.electric.database.id.TechId;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.text.Version;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.CodeExpression;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.PrimitiveNode;import com.sun.electric.technology.PrimitivePort;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.Tool;import com.sun.electric.tool.io.ELIBConstants;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.ncc.basic.TransitiveRelation;import com.sun.electric.tool.user.ErrorLogger;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.IOException;import java.io.ObjectInputStream;import java.io.Serializable;import java.net.URL;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.TreeSet;/** * This class reads files in binary (.elib) format. */public class ELIB extends LibraryFiles{	public static class Header implements Comparable, Serializable	{		/** current header */		static final Header DEFAULT = new Header(ELIBConstants.MAGIC13, ByteOrder.BIG_ENDIAN, 4, 2, 1);		/** the magic number in the library file */							private final int magic;		// characteristics of the file		/** byte order on disk */											private transient ByteOrder byteOrder;		/** true if BIG_ENDIAN byte order on disk */						private final boolean bytesSwapped;		/** the size of a "big" integer on disk (4 or more bytes) */		private final int sizeOfBig;		/** the size of a "small" integer on disk (2 or more bytes) */		private final int sizeOfSmall;		/** the size of a character on disk (1 or 2 bytes) */				private final int sizeOfChar;		/** string description */											private final String s;		Header(int magic, ByteOrder byteOrder, int sizeOfBig, int sizeOfSmall, int sizeOfChar)		{			this.magic = magic;			this.byteOrder = byteOrder;			this.bytesSwapped = (byteOrder == ByteOrder.BIG_ENDIAN);			this.sizeOfBig = sizeOfBig;			this.sizeOfSmall = sizeOfSmall;			this.sizeOfChar = sizeOfChar;			int magicNum = ELIBConstants.MAGIC1 + 2 - magic;			String s = "MAGIC" + (magicNum/2);			if (magicNum%2 != 0) s += "?";			if (byteOrder != ByteOrder.BIG_ENDIAN) s += "L";			if (sizeOfBig != 4) s += "I" + sizeOfBig;			if (sizeOfSmall != 2) s += "S" + sizeOfSmall;			if (sizeOfChar != 1) s += "C" + sizeOfChar;			this.s = s;		}		private void readObject(ObjectInputStream s)			throws IOException, ClassNotFoundException		{			s.defaultReadObject();			byteOrder = bytesSwapped ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;		}		/**		 * Returns a hash code for this <code>Header</code>.		 * @return  a hash code value for this Header.		 */        @Override		public int hashCode() {			return s.hashCode();		}		/**		 * Compares this Header object to the specified object.  The result is		 * <code>true</code> if and only if the argument is not		 * <code>null</code> and is an <code>Header</code> object that		 * contains the same <code>version</code>, <code>view</code> and case-insensitive <code>name</code> as this Header.		 *		 * @param   obj   the object to compare with.		 * @return  <code>true</code> if the objects are the same;		 *          <code>false</code> otherwise.		 */        @Override		public boolean equals(Object obj) {			if (obj instanceof Header) {				Header h = (Header)obj;				return s.equals(h.s);			}			return false;		}		/**		 * Compares two <code>Header</code> objects.		 * @param   o   the object to be compared.		 * @return	the result of comparision.		 */		public int compareTo(Object o) {			Header h = (Header)o;			return TextUtils.STRING_NUMBER_ORDER.compare(s, h.s);		}		/**		 * Returns string description of this Header.		 * @return the string description of this Header.		 */        @Override		public String toString()		{			return s;		}	}	// ------------------------- private data ----------------------------	/** header of the file */												private Header header;	// statistics about the file	/** the number of integers on disk that got clipped during input */		private int clippedIntegers;	// the tool information	/** the number of tools in the file */									private int toolCount;	/** the number of tools in older files */								private int toolBCount;	/** list of all tools in the library */									private Tool [] toolList;	/** list of all tool-related errors in the library */					private String [] toolError;	/** list of all tool variables */                                       private Variable [][] toolVars;    /** the library userbits */                                             private int libUserBits;	/** the library variables */                                            private Variable[] libVars;	// the technology information	/** the number of technologies in the file */							private int techCount;	/** list of all TechIds in the library */                               private TechId [] techIdList;	/** list of all Technologies in the library */							private Technology [] techList;	/** list of all technology-related errors in the library */				private String [] techError;	/** list of all technology variables in the library */                  private Variable [][] techVars;    /** list of technology lambda values in the library */                  private int [] techLambda;	/** scale factors for each technology in the library */					private HashMap<Technology,Double> techScale = new HashMap<Technology,Double>();	/** the number of ArcProtos in the file */								private int arcProtoCount;	/** list of all ArcProtoIds in the library */							private ArcProtoId [] arcProtoIdList;	/** list of all ArcProtos in the library */								private ArcProto [] arcProtoList;	/** list of all ArcProto-related errors in the library */				private String [] arcProtoError;	/** the number of primitive NodeProtos in the file */					private int primNodeProtoCount;	/** list of all PrimitiveNodeIds in the library */					    private PrimitiveNodeId [] primitiveNodeIdList;	/** list of all Primitive NodeProtos in the library */					private PrimitiveNode [] primNodeProtoList;	/** list of the primitive-NodeProto-related errors in the library */	private boolean [] primNodeProtoError;	/** list of the original primitive NodeProtos in the library */			private String [] primNodeProtoOrig;	/** list of all NodeProto technologies in the library */				private int [] primNodeProtoTech;	/** the number of primitive PortProtos in the file */					private int primPortProtoCount;	/** list of all PrimitivePortIds in the library */                      private PrimitivePortId [] primitivePortIdList;	/** list of all Primitive PortProtos in the library */					private PrimitivePort [] primPortProtoList;	/** list of all Primitive-PortProto-related errors in the library */	private String [] primPortProtoError;	// the cell information	/** the number of Cells in the file */									private int cellCount;	/** list of all former cells in the library */							private FakeCell [] fakeCellList;    /** list of Cell full names in the library */                           private String [] cellProtoName;    /** list of Cell creation dates in the library */                       private int [] cellCreationDate;    /** list of Cell revision dates in the library */                       private int [] cellRevisionDate;    /** list of Cell user bits in the library */                            private int [] cellUserBits;    /** list of Cell variables in the library */                            private Variable [][] cellVars;    /** list of Cell low X coordinates in the library */                    private int [] cellLowX;    /** list of Cell high X coordinates in the library */                   private int [] cellHighX;    /** list of Cell low Y coordinates in the library */                    private int [] cellLowY;    /** list of Cell high Y coordinates in the library */                   private int [] cellHighY;    /** list of Cell library paths in the library */                        private String [] cellLibraryPath;	/** list of number of NodeInsts in each Cell of the library */			private int [] nodeCounts;	/** index of first NodeInst in each cell of the library */				private int [] firstNodeIndex;	/** list of number of ArcInsts in each Cell of the library */			private int [] arcCounts;	/** index of first ArcInst in each cell of the library */				private int [] firstArcIndex;	/** list of all Exports in each Cell of the library */					private int [] portCounts;	/** index of first Export in each cell of the library */				private int [] firstPortIndex;	/** X center each cell of the library */								private int [] cellXOff;	/** Y center each cell of the library */								private int [] cellYOff;    /** a next cell index in the same next group of the library */          private int [] cellNextInCellGroup;	/** true if this x-lib cell ref is satisfied */							private boolean [] xLibRefSatisfied;	/** mapping view indices to views */									private HashMap<Integer,View> viewMapping;	// the NodeInsts in the library	/** the number of NodeInsts in the library */							private int nodeCount;	/** All data for NodeInsts in each Cell. */								private LibraryFiles.NodeInstList nodeInstList;    /** List of prototypes of the NodeInsts in the library */               private int [] nodeTypeList;	// the ArcInsts in the library	/** the number of ArcInsts in the library */							private int arcCount;	/** list of all ArcInsts in the library */								private ArcInst [] arcList;	/** list of the prototype of the ArcInsts in the library */				private int [] arcTypeList;	/** list of the Names of the ArcInsts in the library */					private String [] arcNameList;	/** list of the name descriptors of the ArcInsts in the library */		private TextDescriptor[] arcNameDescriptorList;	/** list of the width of the ArcInsts in the library */					private int [] arcWidthList;	/** list of the head X of the ArcInsts in the library */				private int [] arcHeadXPosList;	/** list of the head Y of the ArcInsts in the library */				private int [] arcHeadYPosList;	/** list of the head node of the ArcInsts in the library */				private int [] arcHeadNodeList;	/** list of the head port of the ArcInsts in the library */				private int [] arcHeadPortList;	/** list of the tail X of the ArcInsts in the library */				private int [] arcTailXPosList;	/** list of the tail Y of the ArcInsts in the library */				private int [] arcTailYPosList;	/** list of the tail node of the ArcInsts in the library */				private int [] arcTailNodeList;	/** list of the tail port of the ArcInsts in the library */				private int [] arcTailPortList;	/** list of the user flags on the ArcInsts in the library */			private int [] arcUserBits;	/** list of the variables on the ArcInsts in the library */             private Variable [][] arcVariables;	// the Exports in the library	/** the number of Exports in the library */								private int exportCount;	/** counter for Exports in the library */								private int exportIndex;	/** list of all Exports in the library */								private Object [] exportList;	/** list of NodeInsts that are origins of Exports in the library */		private int [] exportSubNodeList;	/** list of PortProtos that are origins of Exports in the library */	private int [] exportSubPortList;	/** list of Export names in the library */								private String [] exportNameList;    /** list of Export name descriptors in the library */                   private TextDescriptor[] exportNameDescriptors;	/** list of Export userbits in the library */							private int [] exportUserbits;    /** list of variables on Exports in the library */                      private Variable [][] exportVariables;	// the geometric information (only used for old format files)	/** the number of Geometrics in the file */								private int geomCount;	/** list of all Geometric types in the library */						private boolean [] geomType;	/** list of all Geometric up-pointers in the library */					private int [] geomMoreUp;	// the variable information    /** variable names possibly in the library */                           private String varNames[];    /** variable keys possibly in the library */                            private Variable.Key[] varKeys;	/** true to convert all text descriptor values */						private boolean convertTextDescriptors;	/** true to require text descriptor values */							private boolean alwaysTextDescriptors; 	/**	 * This class is used to convert old "facet" style Libraries to pure Cell Libraries.	 */	private static class FakeCell	{		String cellName;		NodeProto firstInCell;	}	ELIB() {}	// ----------------------- public methods -------------------------------	/**	 * Method to read a Library from disk.	 * This method is for reading full Electric libraries in ELIB, JELIB, and Readable Dump format.	 * @param fileURL the URL to the disk file.	 * @return the read Library, or null if an error occurred.	 */	public static synchronized Header readLibraryHeader(URL fileURL, ErrorLogger errorLogger)	{		try {			ELIB in = new ELIB();			if (in.openBinaryInput(fileURL)) return null;			Header header = in.readHeader();			// read the library			in.closeInput();			return header;        } catch (Exception e)		{            errorLogger.logError("Error " + e + " on " + fileURL, -1);        }		return null;    }	/**	 * Method to read a Library from disk.	 * This method is for reading full Electric libraries in ELIB, JELIB, and Readable Dump format.	 * @param fileURL the URL to the disk file.	 * @return the read Library, or null if an error occurred.	 */	public static synchronized boolean readStatistics(URL fileURL, ErrorLogger errorLogger, LibraryStatistics.FileContents fc)	{		try {			ELIB in = new ELIB();			if (in.openBinaryInput(fileURL)) return true;			boolean error = in.readTheLibrary(true, fc);			// read the library			in.closeInput();			return error;        } catch (Exception e)		{            errorLogger.logError("Error " + e + " on " + fileURL, -1);            e.printStackTrace();        }		return true;    }    @Override    protected boolean readProjectSettings() {

⌨️ 快捷键说明

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