📄 letool.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: LETool.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. * * Created on November 17, 2003, 10:16 AM */package com.sun.electric.tool.logicaleffort;import com.sun.electric.database.hierarchy.*;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.prototype.NodeProto;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.topology.NodeInst;import com.sun.electric.database.variable.EvalJavaBsh;import com.sun.electric.database.variable.VarContext;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.Tool;import com.sun.electric.tool.generator.sclibrary.SCLibraryGen;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.simulation.Simulation;import java.util.*;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * This is the Logical Effort Tool. It doesn't actually do * any work itself, but acts as a public API for all of the * logical effort tool functionality. * * @author gainsley */public class LETool extends Tool { /** The Logical Effort tool */ private static LETool tool = new LETool(); private static final boolean DEBUG = false; /** Creates a new instance of LETool */ private LETool() { super("logeffort"); } /** * Method to retrieve the singleton associated with the LETool tool. * @return the LETool tool. */ public static LETool getLETool() { return tool; } /** Initialize tool - add calls to Bean Shell Evaluator */ public void init() { EvalJavaBsh.evalJavaBsh.setVariable("LE", tool); } // =========================== Java Parameter Evaluation ====================== /** * Grabs a logical effort calculated size from the instance. * @return the size. * @throws VarContext.EvalException in case of evaluation exception */ public Object getdrive() throws VarContext.EvalException { return getdrive(null, Double.MIN_VALUE); } /** * Grabs a logical effort calculated size from the instance. * @param defaultValue if a value cannot be found, and this value is not Double.MIN_VALUE, * then use this value. * @return the size. * @throws VarContext.EvalException in case of evaluation exception */ public Object getdrive(double defaultValue) throws VarContext.EvalException { return getdrive(null, defaultValue); } /** * Grabs a logical effort calculated size from the instance. * @param varName for SCOT results, multiple values are stored for the same instance, * so they are encoded into the value of the variable as a string array of * varName = value. * @param defaultValue if a value cannot be found, and this value is not Double.MIN_VALUE, * then use this value. * @return the size. * @throws VarContext.EvalException in case of evaluation exception */ public Object getdrive(String varName, double defaultValue) throws VarContext.EvalException { // info should be the node on which there is the variable with the getDrive() call Object info = EvalJavaBsh.evalJavaBsh.getCurrentInfo(); if (!(info instanceof Nodable)) { if (defaultValue != Double.MIN_VALUE) return new Double(defaultValue); throw new VarContext.EvalException("getdrive(): Not enough hierarchy"); } VarContext context = EvalJavaBsh.evalJavaBsh.getCurrentContext(); if (context == null) throw new VarContext.EvalException("getdrive(): null VarContext"); Nodable ni = (Nodable)info; // Try to find drive strength // if Nodeinst, get different sizes if arrayed Object val = null; if ( (ni instanceof NodeInst) && (ni.getNameKey().busWidth() > 1)) { Name name = ni.getNameKey(); ArrayList<Object> sizes = new ArrayList<Object>(); for (int i=0; i<name.busWidth(); i++) { Nodable no = Netlist.getNodableFor((NodeInst)ni, i); Variable var = getLEDRIVE(ni, context.push(no)); Object size = null; if (defaultValue != Double.MIN_VALUE) size = new Double(defaultValue); if (var != null) size = var.getObject(); if (varName != null && (size instanceof String)) { size = getSCOTValue(var, varName); } sizes.add(size); } if (sizes.size() > 5) { Object [] objs = new Object[3]; objs[0] = sizes.get(0); objs[1] = (Object)"..."; objs[2] = sizes.get(sizes.size()-1); val = objs; } else { val = sizes.toArray(); } } else { Variable var = getLEDRIVE(ni, context.push(ni)); if (var == null) { // none found, try to find drive strength using old format from C-Electric var = getLEDRIVE_old(ni, context); } if (var == null && defaultValue != Double.MIN_VALUE) { // return default value return new Double(defaultValue); } if (var == null) throw new VarContext.EvalException("getdrive(): no size"); val = var.getObject(); if (varName != null && (val instanceof String)) { val = getSCOTValue(var, varName); } } if (val == null) throw new VarContext.EvalException("getdrive(): size null"); return val; } /** * Grab a paramter 'parName' from a nodeInst 'nodeName' in a sub cell. * @param nodeName name of the nodeInst * @param parName name of parameter to evaluate * @return the parameter. */ public Object subdrive(String nodeName, String parName) throws VarContext.EvalException { // info should be the node on which there is the variable with the subDrive() call Object info = EvalJavaBsh.evalJavaBsh.getCurrentInfo(); if (!(info instanceof Nodable)) throw new VarContext.EvalException("subdrive(): Not enough hierarchy information"); Nodable no = (Nodable)info; // this inst has LE.subdrive(...) on it if (no == null) throw new VarContext.EvalException("subdrive(): Not enough hierarchy"); if (no instanceof NodeInst) { // networks have not been evaluated, calling no.getProto() // is going to give us icon cell, not equivalent schematic cell // We need to re-evaluate networks to get equivalent schematic cell NodeInst ni = (NodeInst)no; Cell parent = no.getParent(); // Cell in which inst which has LE.subdrive is if (parent == null) throw new VarContext.EvalException("subdrive(): null parent"); int arrayIndex = 0; // just use first index no = Netlist.getNodableFor(ni, arrayIndex); if (no == null) throw new VarContext.EvalException("subdrive(): can't get equivalent schematic"); } VarContext context = EvalJavaBsh.evalJavaBsh.getCurrentContext(); // get current context if (context == null) throw new VarContext.EvalException("subdrive(): null context"); NodeProto np = no.getProto(); // get contents of instance if (np == null) throw new VarContext.EvalException("subdrive(): null nodeProto"); if (!no.isCellInstance()) throw new VarContext.EvalException("subdrive(): NodeProto not a Cell"); Cell cell = (Cell)np; NodeInst ni = cell.findNode(nodeName); // find nodeinst that has variable on it if (ni == null) { // try converting to JElectric default name ni = cell.findNode(convertToJElectricDefaultName(nodeName)); if (ni == null) throw new VarContext.EvalException("subdrive(): no nodeInst named "+nodeName); } Variable var = ni.getParameterOrVariable(parName); // find variable on nodeinst //if (var == null) return "subdrive(): no variable of name "+parName.replaceFirst("ATTR_", ""); if (var == null) throw new VarContext.EvalException(parName.replaceFirst("ATTR_", "")+" not found"); return context.push(no).evalVarRecurse(var, ni); // evaluate variable and return it } /** * Attempt to get old style LEDRIVE off of <CODE>no</CODE> based * on the VarContext <CODE>context</CODE>. * Attemps to compensate for the situation when the user * had added extra hierarchy to the top of the hierarchy. * It cannot compensate for the user has less hierarchy than * is required to create the correct Variable name. * @param no nodable on which LEDRIVE_ var exists * @param context context of <CODE>no</CODE> * @return a variable if found, null otherwise */ private Variable getLEDRIVE_old(Nodable no, VarContext context) { String drive = makeDriveStrOLDRecurse(context); Variable var = null; while (!drive.equals("")) { if (DEBUG) System.out.println(" Looking for: LEDRIVE_"+drive+";0;S"); Variable.Key key = Variable.findKey("LEDRIVE_"+drive+";0;S"); var = (key != null ? no.getVar(key) : null); if (var != null) return var; // look for var int i = drive.indexOf(';'); if (i == -1) break; drive = drive.substring(i+1); // remove top level of hierarchy } // didn't find it: try converting new default names to old default style names // look for it at current level if (DEBUG) System.out.println(" Looking for: LEDRIVE_0;S"); var = no.getVar(Variable.newKey("LEDRIVE_0;S")); if (var != null) return var; // look for var return null; } /** * Attempt to get LEDRIVE off of <CODE>no</CODE> based * on the VarContext <CODE>context</CODE>. * @param no the nodable for which we want the size * @param context the context * @return a variable if found, null otherwise */ private Variable getLEDRIVE(Nodable no, VarContext context) { // try the top level cell way Variable var = null; var = getLEDRIVEtop(no, context); // try the old way (on leaf cells) if none found if (var == null) var = getLEDRIVEleaf(no, context); return var; } private Variable getLEDRIVEtop(Nodable no, VarContext context) { String drive = context.getInstPath("."); Nodable topno = no; while (context != VarContext.globalContext) { topno = context.getNodable(); context = context.pop(); } Cell parent = topno.getParent(); Variable.Key key = Variable.findKey("LEDRIVE_"+drive); if (key == null) return null; Variable var = parent.getVar(key); return var; } private Object getSCOTValue(Variable var, String varName) { if (var == null || varName == null) return null; Object val = var.getObject(); if (!(val instanceof String)) return null; String vals = (String)val; String []valsparts = vals.split("/"); for (String s : valsparts) { s = s.trim(); if (s.startsWith(varName)) { String [] parts = s.split("="); if (parts.length != 2) return null; return parts[1].trim(); } } return null; } /** * Attempt to get LEDRIVE off of <CODE>no</CODE> based * on the VarContext <CODE>context</CODE>. * Attemps to compensate for the situation when the user * had added extra hierarchy to the top of the hierarchy. * It cannot compensate for the user has less hierarchy than * is required to create the correct Variable name. * @param no nodable on which LEDRIVE_ var exists
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -