📄 techpool.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: TechPool.java * Written by: Dmitry Nadezhin, Sun Microsystems. * * Copyright (c) 2008 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.technology;import com.sun.electric.database.CellRevision;import com.sun.electric.database.ImmutableArcInst;import com.sun.electric.database.ImmutableNodeInst;import com.sun.electric.database.id.ArcProtoId;import com.sun.electric.database.id.IdManager;import com.sun.electric.database.id.IdReader;import com.sun.electric.database.id.IdWriter;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.text.ArrayIterator;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.technology.Technology.SizeCorrector;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import java.io.IOException;import java.util.AbstractMap;import java.util.AbstractSet;import java.util.ArrayList;import java.util.BitSet;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeSet;/** * A customized Map from TechId to Technolgy. * All TechIds must belong to same IdManager. */public class TechPool extends AbstractMap<TechId, Technology> {// public static final TechPool EMPTY = new TechPool(Collections.<Technology>emptySet()); public final IdManager idManager; private final Technology[] techs; private final EntrySet entrySet; private ArcProto[] univList; /** Generic technology */ private Generic generic; /** Artwork technology */ private Artwork artwork; /** Schematic technology */ private Schematics schematics; /** * Constructs empty TechPool * @param idManager pool's IdManager */ public TechPool(IdManager idManager) { this.idManager = idManager; techs = new Technology[0]; entrySet = new EntrySet(); assert size() == 0; univList = new ArcProto[0]; } /** * Constructs TechPool from Collection of technologies * All technologies must belong to the same IdManager * @param technologies Collection of technologies in the Pool */ public TechPool(Collection<Technology> technologies) { Iterator<Technology> it = technologies.iterator(); TechId techId = it.next().getId(); idManager = techId.idManager; int maxTechIndex = techId.techIndex; while (it.hasNext()) { techId = it.next().getId(); if (techId.idManager != idManager) { throw new IllegalArgumentException(); } maxTechIndex = Math.max(maxTechIndex, techId.techIndex); } techs = new Technology[maxTechIndex + 1]; for (Technology tech : technologies) { techId = tech.getId(); int techIndex = techId.techIndex; if (techs[techIndex] != null) { throw new IllegalArgumentException(); } techs[techIndex] = tech; if (tech instanceof Generic) { generic = (Generic) tech; } else if (tech instanceof Artwork) { artwork = (Artwork) tech; } else if (tech instanceof Schematics) { schematics = (Schematics) tech; } } entrySet = new EntrySet(); assert size() == technologies.size(); } /** * Returns restriction of this TechPool to specified subset of TechIds. * A candidate TechPool is a valid result, it is returned to save allocation. * @param techUsed contains techIndex of those TechIds which are in subset * @param candidatePool a candidate TechPool to save allocation * @return restriction of this TechPool to specified subset of TechIds */ public TechPool restrict(BitSet techUsed, TechPool candidatePool) { if (candidatePool != null && candidatePool.isRestriction(this, techUsed)) return candidatePool; return restrict(techUsed); } /** * Returns restriction of this TechPool to specified subset of TechIds * @param techUsed contains techIndex of those TechIds which are in subset * @return restriction of this TechPool to specified subset of TechIds */ public TechPool restrict(BitSet techUsed) { ArrayList<Technology> technologies = new ArrayList<Technology>(); for (Technology tech: values()) { if (techUsed.get(tech.getId().techIndex)) technologies.add(tech); } if (technologies.size() != techUsed.cardinality()) throw new IllegalArgumentException(); return technologies.isEmpty() ? new TechPool(idManager) : new TechPool(technologies); } private boolean isRestriction(TechPool superPool, BitSet techUsed) { if (techUsed.length() != techs.length) return false; if (techs.length > superPool.techs.length) return false; if (idManager != superPool.idManager) return false; for (int techIndex = 0; techIndex < techs.length; techIndex++) { Technology tech = superPool.techs[techIndex]; if (techUsed.get(techIndex)) { if (tech == null) return false; } else { tech = null; } if (techs[techIndex] != tech) return false; } return true; } /** * Returns new TechPool which differs from this TechPool by adding * new technology * @param tech Technology to add * @return TechPool which differs from this TechPool by adding technology */ public TechPool withTech(Technology tech) { TechId techId = tech.getId(); int techIndex = techId.techIndex; if (techIndex < techs.length && techs[techIndex] == tech) { return this; } if (techId.idManager != idManager) { throw new IllegalArgumentException(); } HashMap<TechId, Technology> newMap = new HashMap<TechId, Technology>(this); newMap.put(techId, tech); return new TechPool(newMap.values()); } /** * Get Technology by TechId * TechId must belong to same IdManager as TechPool * @param techId TechId to find * @return Technology by given TechId or null * @throws IllegalArgumentException if TechId is not from this IdManager */ public Technology getTech(TechId techId) { if (techId.idManager != idManager) { throw new IllegalArgumentException(); } int techIndex = techId.techIndex; return techIndex < techs.length ? techs[techIndex] : null; } /** * Get ArcProto by ArcProtoId * ArcProtoId must belong to same IdManager as TechPool * @param arcProtoId ArcProtoId to find * @return ArcProto by given ArcProtoId or null * @throws IllegalArgumentException if TechId is not from this IdManager */ public ArcProto getArcProto(ArcProtoId arcProtoId) { Technology tech = getTech(arcProtoId.techId); if (tech == null) return null; return tech.getArcProtoByChronIndex(arcProtoId.chronIndex); } /** * Get PrimitiveNode by PrimitiveNodeId * PrimitiveNodeId must belong to same IdManager as TechPool * @param primitiveNodeId PrimitiveNodeId to find * @return PrimitiveNode by given PrimitiveNodeId or null * @throws IllegalArgumentException if TechId is not from this IdManager */ public PrimitiveNode getPrimitiveNode(PrimitiveNodeId primitiveNodeId) { Technology tech = getTech(primitiveNodeId.techId); if (tech == null) return null; return tech.getPrimitiveNodeByChronIndex(primitiveNodeId.chronIndex); } /** * Get PrimitivePort by PrimitivePortId * PrimitivePortId must belong to same IdManager as TechPool * @param primitivePortId PrimitivePortId to find * @return PrimitivePort by given PrimitivePortId or null * @throws IllegalArgumentException if TechId is not from this IdManager */ public PrimitivePort getPrimitivePort(PrimitivePortId primitivePortId) { PrimitiveNode pn = getPrimitiveNode(primitivePortId.getParentId()); if (pn == null) return null; return pn.getPrimitivePortByChronIndex(primitivePortId.chronIndex); } public void correctSizesToDisk(List<CellRevision> cells, Version version, Map<Setting,Object> projectSettings, boolean isJelib, boolean keepExtendOverMin) { HashMap<TechId,SizeCorrector> sizeCorrectors = new HashMap<TechId,SizeCorrector>(); for (int i = 0; i < cells.size(); i++) { CellRevision cellRevision = cells.get(i); boolean needCorrection = false; for (TechId techId: cellRevision.getTechUsages()) { SizeCorrector sizeCorrector = sizeCorrectors.get(techId); if (sizeCorrector == null) { if (!sizeCorrectors.containsKey(techId)) { Technology tech = getTech(techId); sizeCorrector = tech.getSizeCorrector(version, projectSettings, isJelib, keepExtendOverMin); if (sizeCorrector.isIdentity()) sizeCorrector = null; sizeCorrectors.put(techId, sizeCorrector); } } if (sizeCorrector != null) needCorrection = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -