1
/* -*- tab-width: 4 -*-
3
* Electric(tm) VLSI Design System
5
* File: PartTypeTable.java
7
* Copyright (c) 2005 Sun Microsystems and Static Free Software
9
* Electric(tm) is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* Electric(tm) is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with Electric(tm); see the file COPYING. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
* Boston, Mass 02111-1307, USA.
24
package com.sun.electric.tool.ncc.netlist;
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.Iterator;
30
import com.sun.electric.tool.generator.layout.LayoutLib;
33
* Transistor and resistor types have long and short names. In Electric,
34
* schematic and layout primitive transistors have different names. NCC uses
35
* the long name to match types between the schematic and layout. Except for
36
* the basic NMOS and PMOS types, each schematic transistor contains an
37
* annotation specifying which layout transistor it matches.
38
* The short names are used internally for NCC print-outs because the long
39
* names are too verbose.
41
* Scalable transistors, in the layout, have a different long name than
42
* regular transistor but map to the same type as ordinary layout transistors.
44
public class PartTypeTable {
45
private int numTypes = 0;
46
private int log2NumTypes;
47
private ArrayList<PartType> types = new ArrayList<PartType>();
48
private HashMap<String,PartType> nameToType = new HashMap<String,PartType>();
49
/** Long type names are used only to identify transistors when NCC creates
51
private HashMap<String,PartType> longNameToType = new HashMap<String,PartType>();
52
private void add(String typeName, String longTypeName) {
53
PartType t = nameToType.get(typeName);
55
t = new PartType(numTypes++, typeName);
56
nameToType.put(typeName, t);
58
LayoutLib.error(longNameToType.containsKey(longTypeName),
59
"duplicate long type name");
60
longNameToType.put(longTypeName, t);
63
log2NumTypes = (int) Math.ceil( Math.log(numTypes)/Math.log(2) );
65
public PartTypeTable(String[][] typeNames) {
66
for (int i=0; i<typeNames.length; i++) {
67
add(typeNames[i][0], typeNames[i][1]);
70
public int log2NumTypes() {return log2NumTypes;}
71
public Iterator<PartType> iterator() {return types.iterator();}
72
public PartType get(String nm) {return nameToType.get(nm);}
73
public PartType getTypeFromLongName(String nm) {
74
return longNameToType.get(nm);