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

📄 verilogdata.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.sun.electric.tool.io.input.verilog;import com.sun.electric.database.prototype.PortCharacteristic;import com.sun.electric.database.text.TextUtils;import com.sun.electric.tool.Job;import java.util.*;import java.io.Serializable;/** * User: gg151869 * Date: Jan 19, 2007 */public class VerilogData implements Serializable{    String name;    private Map<String, VerilogModule> modules = new HashMap<String, VerilogModule>();    VerilogData(String name)    {        this.name = name;    }    public String getName() {return name;}    VerilogModule addModule(String name, boolean primitive)    {        VerilogModule module = new VerilogModule(name, primitive);        modules.put(name, module);        return module;    }    /**     * Compare class for VerilogModule     */    private static VerilogModuleSort compareVerilogModules = new VerilogModuleSort();    private static class VerilogModuleSort implements Comparator<VerilogModule>    {        public int compare(VerilogModule a1, VerilogModule a2)        {            int cmp = TextUtils.STRING_NUMBER_ORDER.compare(a1.getName(), a2.getName());            return cmp;//            return (a1.getName().compareTo(a2.getName()));        }    }    /**     * Function to return a collection of modules defined.     * The collection is sorted by name.     * @return Collection of VerilogModule objects     */    public Collection<VerilogModule> getModules()    {        List<VerilogModule> list = new ArrayList<VerilogModule>(modules.size());        list.addAll(modules.values());        Collections.sort(list, compareVerilogModules);        return list;    }    /**     * Function to return VerilogModule object for a given name     * @param name name of the module     * @return VerilogModule object     */    VerilogModule getModule(String name) {return modules.get(name);}    /**     * Function to write in standard output the modules in Verilog format     */    void write()    {        for (VerilogModule module : modules.values())        {            module.write();        }    }    void simplifyWires()    {        for (VerilogModule module : modules.values())        {            module.simplifyWires();        }    }    /********************** AUXILIAR CLASSES *************************************/    /**     * Covers supplies     */    abstract static class VerilogConnection implements Serializable    {        protected String name;        int start;        int end;        VerilogConnection(String name)        {            this.name = name;        }        /**         * Method to control if busses are converted into single pins or treated as bus in Electric.         * For now, busses are converted into single pins. More memory is used though.         * @return the list of pin names.         * @param fullOyster         */        abstract List<String> getPinNames(boolean fullOyster);        PortCharacteristic getPortType() {return null; } // not valid        String getName() {return name;}        /**         * Function to know if a wire represents a wire         * @return true if wire is a bus         */        boolean isBusConnection()        {            return (start != end);        }        String getConnectionName()        {            if (start != -1) // it could be a bus or simple wire            {                if (isBusConnection())                    return name + "[" + start + ":" + end + "]";                else                    return name + "[" + start + "]";            }            else // simple wire                return name;        }    }    /**     * Compare class for VerilogModule     */    private static VerilogPortSort compareVerilogPorts = new VerilogPortSort();    private static class VerilogPortSort implements Comparator<VerilogPort>    {        public int compare(VerilogPort a1, VerilogPort a2)        {            int cmp = TextUtils.STRING_NUMBER_ORDER.compare(a1.name, a2.name);            return cmp;//            return (a1.name.compareTo(a2.name));        }    }    /**     * This class covers input/output/inout     */    public class VerilogPort extends VerilogConnection    {        PortCharacteristic type;        VerilogPort(String name, PortCharacteristic type)        {            super(name);            this.type = type;            start = end = -1;        }        PortCharacteristic getPortType() {return type; } // not valid        void setBusInformation(String s)        {            int pos = s.indexOf(":");            start = Integer.parseInt(s.substring(1, pos)); // first number            end = Integer.parseInt(s.substring(pos+1, s.length()-1)); // second number        }        public List<String> getPinNames(boolean fullOyster)        {            List<String> list = new ArrayList<String>();            if (fullOyster && isBusConnection())            {                extractPinNames(start, end, name, list);            } else            {                list.add(name);            }            return list;        }        void write()        {            String typeName = "";            if (type == PortCharacteristic.BIDIR) typeName = "inout";            else if (type == PortCharacteristic.IN) typeName = "input";            else if (type == PortCharacteristic.OUT) typeName = "output";            else if (type == PortCharacteristic.GND) typeName = "supply0";            else if (type == PortCharacteristic.PWR) typeName = "supply1";            System.out.println("\t" + typeName + " " + ((isBusConnection())?"["+start+":"+end+"]":"") + " " + name + ";");        }    }    /**     * This class covers wires. To avoid confusion, VerilogExport is not used for this type.     */    public static class VerilogWire extends VerilogConnection    {        public VerilogWire(String name, String busPins)        {            super(name);            this.name = name;            if (busPins == null)            {                int index = name.indexOf("[");                if (index != -1)                {                    this.name = name.substring(0, index);                    index = Integer.parseInt(name.substring(index+1, name.length()-1));                }                this.start = this.end = index;            }            else            {                int index2 = busPins.indexOf(":");                assert(index2 != -1);                start = Integer.parseInt(busPins.substring(1, index2)); // assuming 0 contains "["                end = Integer.parseInt(busPins.substring(index2+1, busPins.length()-1));            }        }        List<String> getPinNames(boolean fullOyster)        {            List<String> list = new ArrayList<String>();            if (fullOyster && isBusConnection())            {                extractPinNames(start, end, name, list);            } else            {                list.add(name);            }            return list;        }        void write()        {            System.out.println("\twire " + ((start != end)?("["+start+":"+end+"["):"") + " " + name + ";");        }    }    private static void extractPinNames(int start, int end, String root, List<String> l)    {        if (start > end)        {            for (int i = start; i >= end; i--)            {                String thisName = root+"["+i+"]";                l.add(thisName);            }        }        else        {            for (int i = start; i <= end; i++)            {                String thisName = root+"["+i+"]";                l.add(thisName);            }        }    }    public class VerilogPortInst implements Serializable    {        String name;        VerilogPort port;        VerilogPortInst(String name, VerilogPort port)        {            this.name = name;            this.port = port;        }        List<String> getPortNames()        {            List<String> list = new ArrayList<String>();             // It is unknown how many pins are coming in the stream            if (name.contains("{"))            {                StringTokenizer parse = new StringTokenizer(name, "\t{,}", false); // extracting pins                while (parse.hasMoreTokens())                {                    String name = parse.nextToken();                    name = name.replaceAll(" ", "");                    list.add(name);                    if (Job.getDebug())                        assert(!name.contains(":")); // this case not handled yet!//                    else//                        System.out.println("This case not handled yet in getPortNames");                }            }            else                list.add(name);            // Now to really extract every individual pin            List<String> l = new ArrayList<String>(list.size());            for (String s : list)            {                int pos = s.indexOf(":");                if (pos != -1)                {                    int index1 = s.indexOf("[");                    int index2 = s.indexOf("]");                    String root = s.substring(0, index1);                    int start = Integer.parseInt(s.substring(index1+1, pos)); // first number                    int end = Integer.parseInt(s.substring(pos+1, index2)); // second number                    extractPinNames(start, end, root, l);                }                else                    l.add(s);            }            // sort list            return l;        }    }    /**     * Compare class for VerilogInstance     */    private static VerilogInstanceSort compareVerilogInstances = new VerilogInstanceSort();    private static class VerilogInstanceSort implements Comparator<VerilogInstance>    {        public int compare(VerilogInstance a1, VerilogInstance a2)        {            int cmp = TextUtils.STRING_NUMBER_ORDER.compare(a1.getName(), a2.getName());            return cmp;//            return (a1.getName().compareTo(a2.getName()));        }    }

⌨️ 快捷键说明

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