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

📄 simulation.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: Simulation.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.simulation;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.text.Pref;import com.sun.electric.database.text.Setting;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.EditWindow_;import com.sun.electric.database.variable.UserInterface;import com.sun.electric.database.variable.VarContext;import com.sun.electric.database.variable.Variable;import com.sun.electric.lib.LibFile;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.Tool;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.io.output.GenerateVHDL;import com.sun.electric.tool.io.output.Spice;import com.sun.electric.tool.io.output.Verilog;import com.sun.electric.tool.simulation.als.ALS;import com.sun.electric.tool.user.CompileVHDL;import com.sun.electric.tool.user.dialogs.EDialog;import com.sun.electric.tool.user.dialogs.OpenFile;import com.sun.electric.tool.user.menus.EMenu;import com.sun.electric.tool.user.ui.TextWindow;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import com.sun.electric.tool.user.waveform.Panel;import com.sun.electric.tool.user.waveform.WaveSignal;import com.sun.electric.tool.user.waveform.WaveformWindow;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.geom.Rectangle2D;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JRadioButton;import javax.swing.JTextField;/** * This is the Simulation Interface tool. */public class Simulation extends Tool{	/** the Simulation tool. */							private static Simulation tool = new Simulation();	/** key of Variable holding rise time. */			public static final Variable.Key RISE_DELAY_KEY = Variable.newKey("SIM_rise_delay");	/** key of Variable holding fall time. */			public static final Variable.Key FALL_DELAY_KEY = Variable.newKey("SIM_fall_delay");	/** key of Variable holding flag for weak nodes. */	public static final Variable.Key WEAK_NODE_KEY = Variable.newKey("SIM_weak_node");	/** key of Variable holding "M" factors. */			public static final Variable.Key M_FACTOR_KEY = Variable.newKey("ATTR_M");	/** constant for ALS simulation */					public static final int ALS_ENGINE = 0;	/** constant for IRSIM simulation */				public static final int IRSIM_ENGINE = 1;	private static boolean irsimChecked = false;	private static Class<?> irsimClass = null;	private static Method irsimSimulateMethod;	private static boolean fleetChecked = false;	private static Class<?> fleetClass = null;	private static EMenu fleetSimMenu = null;	/**	 * The constructor sets up the Simulation tool.	 */	private Simulation()	{		super("simulation");	}	/**	 * Method to initialize the Simulation tool.	 */	public void init()	{	}	/**	 * Method to retrieve the singleton associated with the Simulation tool.	 * @return the Simulation tool.	 */	public static Simulation getSimulationTool() { return tool; }	/****************************** CONTROL OF SIMULATION ENGINES ******************************/	private static final int CONVERT_TO_VHDL	  =  1;	private static final int COMPILE_VHDL_FOR_SIM =  4;	/**	 * Method to invoke a simulation engine.	 * @param engine the simulation engine to run.	 * @param forceDeck true to force simulation from a user-specified netlist file.	 * @param prevCell the previous cell being simulated (null for a new simulation).	 * @param prevEngine the previous simulation engine running (null for a new simulation).	 */	public static void startSimulation(int engine, boolean forceDeck, Cell prevCell, Engine prevEngine)	{		Cell cell = null;		VarContext context = null;		String fileName = null;		if (prevCell != null) cell = prevCell; else		{			UserInterface ui = Job.getUserInterface();			if (forceDeck)			{				fileName = OpenFile.chooseInputFile(FileType.IRSIM, "IRSIM deck to simulate");				if (fileName == null) return;				cell = ui.getCurrentCell();			} else			{				cell = ui.needCurrentCell();				if (cell == null) return;				EditWindow_ wnd = ui.getCurrentEditWindow_();				if (wnd != null) context = wnd.getVarContext();			}		}		switch (engine)		{			case ALS_ENGINE:				// see if the current cell needs to be compiled				Cell originalCell = cell;				int activities = 0;				if (cell.getView() != View.NETLISTALS)				{					if (cell.isSchematic() || cell.getView() == View.LAYOUT)					{						// current cell is Schematic.  See if there is a more recent netlist or VHDL						Cell vhdlCell = cell.otherView(View.VHDL);						if (vhdlCell != null && vhdlCell.getRevisionDate().after(cell.getRevisionDate())) cell = vhdlCell; else							activities |= CONVERT_TO_VHDL | COMPILE_VHDL_FOR_SIM;					}					if (cell.getView() == View.VHDL)					{						// current cell is VHDL.  See if there is a more recent netlist						Cell netListCell = cell.otherView(View.NETLISTQUISC);						if (netListCell != null && netListCell.getRevisionDate().after(cell.getRevisionDate())) cell = netListCell; else							activities |= COMPILE_VHDL_FOR_SIM;					}				}				// now schedule the simulation work				new DoALSActivity(cell, activities, originalCell, prevEngine);				break;			case IRSIM_ENGINE:				if (!hasIRSIM()) return;				runIRSIM(cell, context, fileName);				break;		}	}	/**	 * Class to do the next silicon-compilation activity in a new thread.	 */	private static class DoALSActivity extends Job	{		private Cell cell, originalCell;		private int activities;		private transient Engine prevEngine;		private List<Cell> textCellsToRedraw;		private DoALSActivity(Cell cell, int activities, Cell originalCell, Engine prevEngine)		{			super("ALS Simulation", tool, Job.Type.CHANGE, null, null, Job.Priority.USER);			this.cell = cell;			this.activities = activities;			this.originalCell = originalCell;			this.prevEngine = prevEngine;			startJob();		}		public boolean doIt() throws JobException		{			Library destLib = cell.getLibrary();			textCellsToRedraw = new ArrayList<Cell>();			fieldVariableChanged("textCellsToRedraw");			if ((activities&CONVERT_TO_VHDL) != 0)			{				// convert Schematic to VHDL				System.out.print("Generating VHDL from '" + cell + "' ...");				List<String> vhdlStrings = GenerateVHDL.convertCell(cell);				if (vhdlStrings == null)				{					throw new JobException("No VHDL produced");				}				String cellName = cell.getName() + "{vhdl}";				Cell vhdlCell = cell.getLibrary().findNodeProto(cellName);				if (vhdlCell == null)				{					vhdlCell = Cell.makeInstance(cell.getLibrary(), cellName);					if (vhdlCell == null) return false;				}				String [] array = new String[vhdlStrings.size()];				for(int i=0; i<vhdlStrings.size(); i++) array[i] = vhdlStrings.get(i);				vhdlCell.setTextViewContents(array);				textCellsToRedraw.add(vhdlCell);				System.out.println(" Done, created " + vhdlCell);				cell = vhdlCell;				fieldVariableChanged("cell");			}			if ((activities&COMPILE_VHDL_FOR_SIM) != 0)			{				// compile the VHDL to a netlist				System.out.print("Compiling VHDL in " + cell + " ...");				CompileVHDL c = new CompileVHDL(cell);				if (c.hasErrors())				{					throw new JobException("ERRORS during compilation, no netlist produced");				}				List<String> netlistStrings = c.getALSNetlist(destLib);				if (netlistStrings == null)				{					throw new JobException("No netlist produced");				}				// store the ALS netlist				String cellName = cell.getName() + "{net.als}";				Cell netlistCell = cell.getLibrary().findNodeProto(cellName);				if (netlistCell == null)				{					netlistCell = Cell.makeInstance(cell.getLibrary(), cellName);					if (netlistCell == null) return false;				}				String [] array = new String[netlistStrings.size()];				for(int i=0; i<netlistStrings.size(); i++) array[i] = netlistStrings.get(i);				netlistCell.setTextViewContents(array);				textCellsToRedraw.add(netlistCell);				System.out.println(" Done, created " + netlistCell);				cell = netlistCell;				fieldVariableChanged("cell");			}			return true;		}		public void terminateOK()		{			for(Cell cell : textCellsToRedraw) {				TextWindow.updateText(cell);			}			if (prevEngine != null)			{				ALS.restartSimulation(cell, originalCell, (ALS)prevEngine);			} else			{				ALS.simulateNetlist(cell, originalCell);			}		}	}	/**	 * Method to tell whether the IRSIM simulator is available.	 * IRSIM is packaged separately because it is from Stanford University.	 * This method dynamically figures out whether the IRSIM module is present by using reflection.	 * @return true if the IRSIM simulator is available.	 */	public static boolean hasIRSIM()	{		if (!irsimChecked)		{			irsimChecked = true;			// find the IRSIM class			try			{				irsimClass = Class.forName("com.sun.electric.plugins.irsim.Analyzer");			} catch (ClassNotFoundException e)			{				irsimClass = null;				return false;			}			// find the necessary methods on the IRSIM class			try			{				irsimSimulateMethod = irsimClass.getMethod("simulateCell", new Class[] {Cell.class, VarContext.class, String.class});			} catch (NoSuchMethodException e)			{				irsimClass = null;				return false;			}		}		// if already initialized, return		if (irsimClass == null) return false;	 	return true;	}	/**	 * Method to run the IRSIM simulator on a given cell, context or file.	 * Uses reflection to find the IRSIM simulator (if it exists).	 * @param cell the Cell to simulate.	 * @param context the context to the cell to simulate.	 * @param fileName the name of the file with the netlist.  If this is null, simulate the cell.	 * If this is not null, ignore the cell and simulate the file.	 */	public static void runIRSIM(Cell cell, VarContext context, String fileName)	{		try		{			irsimSimulateMethod.invoke(irsimClass, new Object[] {cell, context, fileName});			return;

⌨️ 快捷键说明

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