📄 libraryfiles.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: LibraryFiles.java * * 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.IdMapper;import com.sun.electric.database.ImmutableNodeInst;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.EDatabase;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.id.*;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.Setting;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.text.Version;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.MutableTextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.lib.LibFile;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.PrimitivePort;import com.sun.electric.technology.TechPool;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.Listener;import com.sun.electric.tool.Tool;import com.sun.electric.tool.cvspm.CVS;import com.sun.electric.tool.cvspm.CVSLibrary;import com.sun.electric.tool.cvspm.Update;import com.sun.electric.tool.io.ELIBConstants;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.io.output.Verilog;import com.sun.electric.tool.io.output.CellModelPrefs;import com.sun.electric.tool.ncc.basic.NccCellAnnotations;import com.sun.electric.tool.user.ErrorLogger;import com.sun.electric.tool.user.CircuitChangeJobs;import com.sun.electric.tool.user.dialogs.OpenFile;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.File;import java.io.IOException;import java.net.URL;import java.util.ArrayList;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 Library files (ELIB or readable dump) format. */public abstract class LibraryFiles extends Input{ /** key of Varible holding true library of fake cell. */ public static final Variable.Key IO_TRUE_LIBRARY = Variable.newKey("IO_true_library"); /** key of Variable to denote a dummy cell or library */ public static final Variable.Key IO_DUMMY_OBJECT = Variable.newKey("IO_dummy_object"); /** Database where to load libraries */ final EDatabase database = EDatabase.serverDatabase(); /** IdManager where to create ids */ final IdManager idManager = database.getIdManager(); /** The Library being input. */ protected Library lib; /** true if the library is the main one being read. */ protected boolean topLevelLibrary; // the cell information /** The number of Cells in the file. */ protected int nodeProtoCount; /** A list of cells being read. */ protected Cell [] nodeProtoList; /** lambda value for each cell of the library */ protected double [] cellLambda; /** total number of cells in all read libraries */ protected static int totalCells; /** number of cells constructed so far. */ protected static int cellsConstructed; /** a List of scaled Cells that got created */ protected List<Cell> scaledCells; /** Number of errors in this LibraryFile */ protected int errorCount; /** the Electric version in the library file. */ protected Version version; /** true if old MOSIS CMOS technologies appear in the library */ protected boolean convertMosisCmosTechnologies; /** true to scale lambda by 20 */ protected boolean scaleLambdaBy20; /** true if rotation mirror bits are used */ protected boolean rotationMirrorBits; /** SizeCorrectors for used technologies */ protected HashMap<Technology,Technology.SizeCorrector> sizeCorrectors = new HashMap<Technology,Technology.SizeCorrector>(); /** font names obtained from FONT_ASSOCIATIONS */ private String [] fontNames; /** buffer for reading text descriptors and variable flags. */ MutableTextDescriptor mtd = new MutableTextDescriptor(); /** buffer for reading Variables. */ ArrayList<Variable> variablesBuf = new ArrayList<Variable>(); /** the path to the library being read. */ protected static String mainLibDirectory = null; /** collection of libraries and their input objects. */ private static List<LibraryFiles> libsBeingRead; /** collection of undefined Nodes/Technologies */ static Map<TechId, Set<PrimitiveNodeId>> undefinedTechsAndPrimitives; /** Project settings from library file. */ HashMap<Setting,Object> projectSettings = new HashMap<Setting,Object>(); protected static final boolean VERBOSE = false; protected static final double TINYDISTANCE = DBMath.getEpsilon()*2; static class NodeInstList { NodeInst [] theNode; NodeProto [] protoType; String [] name; TextDescriptor[] nameTextDescriptor; int [] lowX; int [] highX; int [] lowY; int [] highY; int [] anchorX; int [] anchorY; short [] rotation; int [] transpose; TextDescriptor[] protoTextDescriptor; int [] userBits; Variable[][] vars; NodeInstList(int nodeCount, boolean hasAnchor) { theNode = new NodeInst[nodeCount]; protoType = new NodeProto[nodeCount]; name = new String[nodeCount]; nameTextDescriptor = new TextDescriptor[nodeCount]; lowX = new int[nodeCount]; highX = new int[nodeCount]; lowY = new int[nodeCount]; highY = new int[nodeCount]; if (hasAnchor) { anchorX = new int[nodeCount]; anchorY = new int[nodeCount]; } rotation = new short[nodeCount]; transpose = new int[nodeCount]; protoTextDescriptor = new TextDescriptor[nodeCount]; userBits = new int[nodeCount]; vars = new Variable[nodeCount][]; } }; LibraryFiles() {} /** * Method to read a Library from disk. * This method is for reading full Electric libraries in ELIB, JELIB, and Readable Dump format. * This method doesn't read project settings contained in library file. * @param fileURL the URL to the disk file. * @param libName the name to give the library (null to derive it from the file path) * @param type the type of library file (ELIB, JELIB, etc.) * @param quick true to read the library without verbosity (used when reading a library internally). * @return the read Library, or null if an error occurred. */ public static Library readLibrary(URL fileURL, String libName, FileType type, boolean quick) { if (fileURL == null) return null; long startTime = System.currentTimeMillis(); errorLogger = ErrorLogger.newInstance("Library Read"); File f = new File(fileURL.getPath()); if (f != null && f.exists()) { LibDirs.readLibDirs(f.getParent()); } LibraryFiles.initializeLibraryInput(); Library lib = null; boolean formerQuiet = isChangeQuiet(); if (!formerQuiet) changesQuiet(true); try { // show progress if (!quick) startProgressDialog("library", fileURL.getFile()); Cell.setAllowCircularLibraryDependences(true); StringBuffer errmsg = new StringBuffer(); boolean exists = TextUtils.URLExists(fileURL, errmsg); if (!exists) { System.out.print(errmsg.toString()); // if doesn't have extension, assume DEFAULTLIB as extension String fileName = fileURL.toString(); if (fileName.indexOf(".") == -1) { fileURL = TextUtils.makeURLToFile(fileName+"."+type.getExtensions()[0]); System.out.print("Attempting to open " + fileURL+"\n"); errmsg.setLength(0); exists = TextUtils.URLExists(fileURL, errmsg); if (!exists && (type != FileType.DELIB)) { // Check if this is a DELIB fileURL = TextUtils.makeURLToFile(fileName+"."+FileType.DELIB.getExtensions()[0]); System.out.print("Attempting to open " + fileURL+"\n"); errmsg.setLength(0); exists = TextUtils.URLExists(fileURL, errmsg); if (exists) { // If it is a DELIB libName = null; // Get the library name from fileURL type = FileType.DELIB; // Set the type to DELIB } } if (!exists) System.out.print(errmsg.toString()); } } if (exists) { // get the library name if (libName == null) libName = TextUtils.getFileNameWithoutExtension(fileURL); lib = readALibrary(fileURL, null, libName, type); } if (LibraryFiles.VERBOSE) System.out.println("Done reading data for all libraries"); LibraryFiles.cleanupLibraryInput(); if (LibraryFiles.VERBOSE) System.out.println("Done instantiating data for all libraries"); } finally { if (!quick) stopProgressDialog(); Cell.setAllowCircularLibraryDependences(false); } if (!formerQuiet) changesQuiet(formerQuiet); if (lib != null && !quick) { long endTime = System.currentTimeMillis(); float finalTime = (endTime - startTime) / 1000F; System.out.println("Library " + fileURL.getFile() + " read, took " + finalTime + " seconds"); } // if CVS is enabled, get status of library if (CVS.isEnabled()) { Update.updateOpenLibraries(Update.UpdateEnum.STATUS); } errorLogger.termLogging(true); return lib; } /** * 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. * @param type the type of library file (ELIB, JELIB, etc.) * @return the read Library, or null if an error occurred. */ public static synchronized Map<Setting,Object> readProjectsSettingsFromLibrary(URL fileURL, FileType type) { if (fileURL == null) return null; long startTime = System.currentTimeMillis(); errorLogger = ErrorLogger.newInstance("Library Read Project Settings"); Library lib = null; StringBuffer errmsg = new StringBuffer(); boolean exists = TextUtils.URLExists(fileURL, errmsg); if (!exists) { System.out.print(errmsg.toString()); // if doesn't have extension, assume DEFAULTLIB as extension String fileName = fileURL.toString(); if (fileName.indexOf(".") == -1) { fileURL = TextUtils.makeURLToFile(fileName+"."+type.getExtensions()[0]); System.out.print("Attempting to open " + fileURL+"\n"); errmsg.setLength(0); exists = TextUtils.URLExists(fileURL, errmsg); if (!exists) { System.out.print(errmsg.toString()); return null; } } } // handle different file types if (type == FileType.JELIB || type == FileType.DELIB) { TechPool techPool = EDatabase.serverDatabase().getTechPool(); try { return JELIB.readProjectSettings(fileURL, type, techPool, errorLogger); } finally { errorLogger.termLogging(true); } } LibraryFiles in; if (type == FileType.ELIB) { in = new ELIB(); if (in.openBinaryInput(fileURL)) return null; } else if (type == FileType.READABLEDUMP) { in = new ReadableDump(); if (in.openTextInput(fileURL)) return null; } else { System.out.println("Unknown import type: " + type); return null; } // determine whether this is top-level in.topLevelLibrary = true; // read the library
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -