📄 jelib.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: JELIB.java * Input/output tool: JELIB Library output * Written 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.output;import com.sun.electric.database.CellBackup;import com.sun.electric.database.CellRevision;import com.sun.electric.database.ImmutableArcInst;import com.sun.electric.database.ImmutableCell;import com.sun.electric.database.ImmutableElectricObject;import com.sun.electric.database.ImmutableExport;import com.sun.electric.database.ImmutableIconInst;import com.sun.electric.database.ImmutableNodeInst;import com.sun.electric.database.LibraryBackup;import com.sun.electric.database.Snapshot;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.hierarchy.Cell;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.CellUsage;import com.sun.electric.database.id.ExportId;import com.sun.electric.database.id.LibId;import com.sun.electric.database.id.NodeProtoId;import com.sun.electric.database.id.PortProtoId;import com.sun.electric.database.id.PrimitiveNodeId;import com.sun.electric.database.id.TechId;import com.sun.electric.database.text.CellName;import com.sun.electric.database.text.Name;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.variable.CodeExpression;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.Technology;import com.sun.electric.tool.Tool;import java.net.URL;import java.util.ArrayList;import java.util.Collection;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;import java.util.TreeMap;/** * Class to write a library to disk in new Electric-Library format. */public class JELIB extends Output { private boolean oldRevision; private Version version; /** Project settings. */ private HashMap<Setting,Object> projectSettings = new HashMap<Setting,Object>();// private Map<LibId,URL> libFiles; JELIB() { } /** * Method to write a Library in Electric Library (.jelib) format. * @param snapshot snapshot of the Library * @param libId Id of the Library to be written. * @param libFiles new locations of lib files * @param oldRevision true to write library in format prior to "8.04l". * @return true on error. */ protected boolean writeLib(Snapshot snapshot, LibId libId, Map<LibId,URL> libFiles, boolean oldRevision) { this.oldRevision = oldRevision; version = oldRevision ? Version.parseVersion("8.03") : Version.getVersion();// this.libFiles = libFiles; writeTheLibrary(snapshot, libId); return false; } /** * Method to write the .jelib file. * @param snapshot snapshot of the Library * @param libId Id of the Library to be written. */ private void writeTheLibrary(Snapshot snapshot, LibId libId) { // gather all referenced objects// this.snapshot = snapshot; LibraryBackup libBackup = snapshot.getLib(libId); HashSet<CellId> usedCells = new HashSet<CellId>(); TreeMap<CellName,CellRevision> sortedCells = new TreeMap<CellName,CellRevision>(); for (CellBackup cellBackup: snapshot.cellBackups) { if (cellBackup == null) continue; CellRevision cellRevision = cellBackup.cellRevision; if (cellRevision.d.getLibId() != libId) continue; CellId cellId = cellRevision.d.cellId; sortedCells.put(cellId.cellName, cellRevision); int[] instCounts = cellRevision.getInstCounts(); for (int i = 0; i < instCounts.length; i++) { int instCount = instCounts[i]; if (instCount == 0) continue; CellUsage u = cellId.getUsageIn(i); usedCells.add(u.protoId); } } HashSet<LibId> usedLibs = new HashSet<LibId>(); for (CellId cellId: usedCells) usedLibs.add(cellId.libId); // write header information (library, version) printWriter.println("# header information:"); printWriter.print("H" + convertString(libBackup.d.libId.libName) + "|" + version); printlnVars(libBackup.d); // write view information boolean viewHeaderPrinted = false; HashSet<View> usedViews = new HashSet<View>(); for (CellBackup cellBackup: snapshot.cellBackups) { if (cellBackup == null) continue; CellRevision cellRevision = cellBackup.cellRevision; if (cellRevision.d.getLibId() != libId && !usedCells.contains(cellRevision.d.cellId)) continue; usedViews.add(cellRevision.d.cellId.cellName.getView()); } for(Iterator<View> it = View.getViews(); it.hasNext(); ) { View view = it.next(); if (!usedViews.contains(view)) continue; if (!viewHeaderPrinted) { printWriter.println(); printWriter.println("# Views:"); viewHeaderPrinted = true; } printWriter.println("V" + convertString(view.getFullName()) + "|" + convertString(view.getAbbreviation())); } // write external library information writeExternalLibraryInfo(libId, usedLibs); // write tool information boolean toolHeaderPrinted = false; for(Iterator<Tool> it = Tool.getTools(); it.hasNext(); ) { Tool tool = it.next(); Collection<Setting> settings = tool.getDiskSettings(); if (settings.size() == 0) continue; if (!toolHeaderPrinted) { printWriter.println(); printWriter.println("# Tools:"); toolHeaderPrinted = true; } printWriter.print("O" + convertString(tool.getName())); printlnSettings(settings); } // write technology information boolean technologyHeaderPrinted = false; for (Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); Collection<Setting> settings = tech.getDiskSettings(); if (settings.size() == 0) continue; if (!technologyHeaderPrinted) { printWriter.println(); printWriter.println("# Technologies:"); technologyHeaderPrinted = true; } printWriter.print("T" + convertString(tech.getTechName())); printlnSettings(settings); } // write cells ArrayList<CellRevision> sortedCellsList = new ArrayList<CellRevision>(sortedCells.values()); snapshot.techPool.correctSizesToDisk(sortedCellsList, version, projectSettings, true, false); for (CellRevision cellRevision: sortedCellsList) { writeCell(cellRevision); //printWriter.println(); }// printWriter.println(); } /** * Method to write a cell to the output file * @param cellRevision the cell to write */ void writeCell(CellRevision cellRevision) { ImmutableCell d = cellRevision.d; LibId libId = d.getLibId(); // write the Cell name printWriter.println(); printWriter.println("# Cell " + d.cellId.cellName); printWriter.print("C" + convertString(d.cellId.cellName.toString())); if (!oldRevision) { printWriter.print("|"); String cellGroupName = d.groupName.getName(); if (!cellGroupName.equals(d.cellId.cellName.getName())) printWriter.print(convertString(cellGroupName)); } printWriter.print("|" + convertString(d.techId.techName)); printWriter.print("|" + d.creationDate); printWriter.print("|" + d.revisionDate); StringBuilder cellBits = new StringBuilder(); if ((d.flags & Cell.INCELLLIBRARY) != 0) cellBits.append("C"); if ((d.flags & Cell.WANTNEXPAND) != 0 || d.cellId.isIcon()) cellBits.append("E"); if ((d.flags & Cell.NPILOCKED) != 0) cellBits.append("I"); if ((d.flags & Cell.NPLOCKED) != 0) cellBits.append("L"); if ((d.flags & Cell.TECEDITCELL) != 0) cellBits.append("T"); printWriter.print("|" + cellBits.toString()); printlnVars(d); ArrayList<String> nodeNames = new ArrayList<String>(); // write the nodes in this cell (sorted by node name) Name prevNodeName = null; int duplicate = 0; for (ImmutableNodeInst n: cellRevision.nodes) { NodeProtoId np = n.protoId; if (np instanceof CellId) { CellId subCellId = (CellId)np; String subCellName = subCellId.libId == libId ? subCellId.cellName.toString() : subCellId.toString(); printWriter.print("I" + convertString(subCellName)); } else { PrimitiveNodeId primId = (PrimitiveNodeId)np; if (d.techId == primId.techId) printWriter.print("N" + convertString(primId.name)); else printWriter.print("N" + convertString(primId.fullName)); } String diskNodeName; if (n.name != prevNodeName) { prevNodeName = n.name; duplicate = 0; diskNodeName = convertString(n.name.toString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -