import byucc.jhdl.base.*;
import byucc.jhdl.Logic.*;
import byucc.jhdl.util.*;

import java.io.*;
import java.util.*;
import java.text.*;
/**
 * This class was written specifically for the LANL TMR counter tests.  
 * This class finds all of the nets in the counter design.  The nets
 * give us the names needed for XPower's *_xpwr.xml file net name format
 * as well as the wires needed to determine the transition counts needed
 * to determine each net's activity rate.  After grabbing all that info
 * a *.xml file is generated ready to input into XPower. 
 *
 * This class has also been adapted to allow for tesing of different
 * FPGA voltages and temperatures.
 *
 * @author Nathan Rollins
 * @version $Id$
 **/
public class powerTransitionNew extends Logic implements TestBench {

    /** Constructor for this testbench
     *  @param parent the hardwareSystem for the testbench
     */
    public powerTransitionNew(Node parent) {
	super(parent);
        
        clk = (clk3) ? wire(3, "clk") : wire(1, "clk");
        reset = (tmr) ? wire(3, "reset") : wire(1, "reset");
        switch (design) {
        case INCREMENTER:
            length = (usrlength) ? length : (clk3) ? INCR_LENGTH_3CLK : INCR_LENGTH;
            outwidth = length;
            break;            
        case XOR:
            length = (usrlength) ? length : XOR_LENGTH;
            outwidth = length / XOR_LEN;
            break;
        case COUNTER:
            length = (usrlength) ? length : CNT_LENGTH;
            outwidth = width;
            break;
        default:
            length = (usrlength) ? length : (clk3) ? INCR_LENGTH_3CLK : INCR_LENGTH;
            outwidth = length;
            break;
        }
        cnt1 = wire(outwidth, "cnt1");

        allCntVector acv = new allCntVector(this, clk, reset, cnt1, width, length,
                                            type, place, tmr, clk3);
    }

    /** This function takes the vector of Nets and returns a vector of Strings
     *  of the net names
     *  @param nets the vector of nets 
     *  @return a vector of net names as Strings
     */
    public static ArrayList createStringsFromNetVector(ArrayList nets) {
        int idxdash = -1;
        int idxgt = -1;
        int idxlt = -1;
        int idxslash = -1;
        Net mynet;
        String dash = "-";
        String gt = ">";
        String lt = "<";
        String newdash = "__";
        String newgt = "&gt;";
        String newlt = "&lt;";
        String netname, temp, temp2;
        String slash = "/";        
        ArrayList netStrings = new ArrayList();        

        for (int i = 0; i < nets.size(); i++) {
            mynet = (Net)nets.get(i);
            netname = mynet.getName()+mynet.getIndexString();
            temp = netname;

            // Any <x> strings have to be converted to: &lt;x&gt;
            idxlt = netname.indexOf(lt);
            if (idxlt > 0) 
                temp = netname.substring(0, idxlt)+newlt;
            idxgt = netname.indexOf(gt);
            if (idxgt > 0)
                temp += netname.substring(idxlt+1, idxgt)+newgt+netname.substring(idxgt+1);

            // Any '-' strings in the latter part of the name need to be
            // converted to '__'
            idxslash = temp.indexOf(slash);
            if (idxslash > 0) {
                idxdash = temp.indexOf(dash);
                if (idxdash > 0) {
                    temp2 = temp.substring(0, idxdash)+newdash+temp.substring(idxdash+1);
                    temp = temp2;
                }
            }
            netStrings.add(temp);
        }
        return netStrings;
    }

    /** This function is for debugging puprposes.  It outputs netnames
     *  along with transition counts for each net
     *  @param svect a ArrayList of Nets 
     *  @param fname the name of the file the vector will print to
     */
    public static void fprintNetTransitionCounts(ArrayList svect, String fname) 
        throws Exception {

        BufferedWriter fout;
        Net mynet;
        String ext = ".dat";
        String name;

        fout = new BufferedWriter(new FileWriter(fname+ext));
        
        for (int i = 0; i < svect.size(); i++) {
            mynet = (Net)svect.get(i);
            name = mynet.getName()+mynet.getIndexString();
            fout.write(name+"  "+mynet.getWire().getTransitionCount()+"\n");
        }
        fout.flush();
        fout.close();
    }

    /** This function creates the filename and directory name for the design.
     *  NOTE that this function is written specifically for Nathan Rollins'
     *  directory structure
     */
    public static void getDirFileName() {
        String tempfile = outfile;
        String tempdir = "";

        if (!nofile) {
            switch (design) {
            case (INCREMENTER):
                tempfile = tempfile+"_incr";
                tempdir = "simple";
                break;
                
            case (COUNTER):
                tempfile = tempfile+"_cnt";
                break;
            case (XOR):
                tempfile = tempfile+"_xor";
                tempdir = "simple";
                break;
            default:
                break;
            }
            if (tmr) {
                tempfile = tempfile+"tmr";
                tempdir += "tmr";
            }
            else {
                tempdir += "notmr";
            }
            
            if (clk3) {
                tempfile = tempfile+"3clk";
                tempdir += "3clk";
            }
            if (design == XOR) {
                tempdir += "2";
            }
            tempdir += "_"+width+"_"+length;
            if (p1)
                tempdir += "_pinsplaced";
            if (p2)
                tempdir += "_pinsplaced2";
            if (p3)
                tempdir += "_pinsplaced3";
            dirname = tempdir+"/";
            outfile = tempfile;
        }
    }

    /** This function finds the important nets in a given design and returns
     *  them in a vector.
     *  @param cell The top-level cell design
     *  @return a vector of Nets for the given cell
     */
    public static ArrayList getNetVector(Cell cell) {
        Cell mycell;
        Enumeration nets;
        int cnt = 0;
        int found = 0;
        Net mynet;
        NodeList cells = cell.getChildren();
        ArrayList uniquev = new ArrayList();
        Wire mywire;

        for(cells.init(); !cells.atEnd(); cells.next()) {
            cnt++;
            mycell = cells.getCell();            

            // get all the nets of the current cell
            nets = mycell.getFlatNetlist().getNets();

            // getting the nets puts 'cells.AtEnd()' to true for some reason
            // so we need to reposition the NodeList
            cells.init();
            for (int i = 0; i < cnt; i++)
                cells.next();

            // iterate through the nets
            while (nets.hasMoreElements()) {
                mynet = (Net)nets.nextElement();
                mywire = mynet.getWire();
                
                // filter out unimportant nets
                if (!(mywire.getSourceCell() instanceof byucc.jhdl.Xilinx.Virtex.buf) &&
                    !(mywire.getSourceCell() instanceof byucc.jhdl.Xilinx.Virtex.inv) &&
                    !(mywire.getSourceCell() instanceof byucc.jhdl.Xilinx.Virtex.ibufg) &&
                    !(mywire.getSourceCell() == null) &&
                    !(mywire.getTransitionCount() == 0)) {
                    uniquev.add(mynet);
                }
            }
        }
        return uniquev;
    }
    
    /** This function hacks the net names to make them acceptable to XPower.  This
     *  function is specific to the counter designs.
     *  @param names the net names as a vector of Strings
     *  @param nets the ArrayList of nets
     */
    public static void illegitimateFix(ArrayList names, ArrayList nets) {
        int idxcout = -1;
        int idxgt = -1;
        int idxlt = -1;
        int idxrm = -1;
        int num = -1;
        String carry = "carry";
        String cout = "cout";
        String gt = "&gt;";
        String lt = "&lt;";
        String incout = "incout";
        String newnameprename = "upCnt_muxcy_l";
        String newnamepre = "muxcy_l__";
        String newnamepre0 = "muxcy_l";
        String newnamepost = "/O";
        String netname, temp;  
        String ramvoter = "ramVoter";
        String slash = "/";

        for (int i = 0; i < names.size(); i++) { 
            netname = (String)names.get(i);

            // The TMR'ed version of the design has different stipulations
            if (tmr) {

                // Here we are changing occurances of 'carry' to 'muxcy_l__'
                // The indexing is a little different too.  The string '/0'
                // is also tacked on after the index
                idxcout = netname.indexOf(carry);
                if (idxcout > -1) {
                    temp = netname.substring(0, idxcout);
                    idxlt = netname.indexOf(lt);
                    if (idxlt > 0) {
                        idxgt = netname.indexOf(gt);
                        if (idxgt > 0) {
                            num = Integer.parseInt(netname.substring(idxlt+lt.length(), idxgt));
                            if (num == 0) {
                                
                                // if we are using the explicitly named designs
                                // we have to replace 'incout' with the muxcy_l's 
                                // given name.
                                if (name)
                                    temp += newnameprename+newnamepost;
                                else
                                    temp += newnamepre0+newnamepost;
                            }
                            else {

                                // if we are using the explicitly named designs
                                // we have to replace 'incout' with the muxcy_l's 
                                // given name.
                                if (name)
                                    temp += newnameprename+num+newnamepost;
                                else
                                    temp += newnamepre+num+newnamepost;
                            }
                        }
                    }
                    names.set(i, temp);
                }

                // This is a hack to get rid of some nets we don't need                
                idxrm = netname.indexOf(ramvoter, 0);
                if (idxrm > -1) {
                    names.remove(i);
                    nets.remove(i);
                    idxrm = -1;
                    i--;
                }
            }
            else {

                // Here we are changing occurances of 'cout' to 'muxcy_l__'
                // The indexing is a little different too.  The string '/0'
                // is also tacked on after the index
                idxcout = netname.indexOf(cout);
                if (idxcout > -1) {
                    temp = netname.substring(0, idxcout);
                    idxlt = netname.indexOf(lt);
                    if (idxlt > 0) {
                        idxgt = netname.indexOf(gt);
                        if (idxgt > 0) {
                            num = Integer.parseInt(netname.substring(idxlt+lt.length(), idxgt));
                            if (num == 1) {

                                // if we are using the explicitly named designs
                                // we have to replace 'cout' with the muxcy_l's 
                                // given name.
                                if (name)
                                    temp += newnameprename+newnamepost;
                                else
                                    temp += newnamepre0+newnamepost;                                    
                            }
                            else {
                                num--;

                                // if we are using the explicitly named designs
                                // we have to replace 'cout' with the muxcy_l's 
                                // given name.
                                if (name)
                                    temp += newnameprename+num+newnamepost;
                                else
                                    temp += newnamepre+num+newnamepost;
                            }
                        }
                    }
                    names.set(i, temp);
                }
            }
        }
    }

    /** This is the main function
     *  @param argv The array of input Strings from the command line
     */
    public static void main(String argv[]) throws Exception {

	HWSystem hw = new HWSystem();
        ArrayList uniquenets;
        ArrayList netnames;

        // parse the command line strings
        parseInput(argv);

	// You must enable transition counting on the HWSystem.
	hw.collectTransitionCountEnabled(true);

        // create the testbench
	powerTransitionNew td = new powerTransitionNew(hw);

        // cycle the design
	hw.cycle(cycles);

        topcell = td;

        // get the needed info from the desing to create the *.xml file
        // and then write out the *.xml file
        uniquenets = getNetVector(td);
        netnames = createStringsFromNetVector(uniquenets);
        illegitimateFix(netnames, uniquenets);                   
        getDirFileName();

        if (allfreq) {
            for (int i = 10; i < stopfreq; i += 10) {
                freq = i;                    
                printXML(outfile+"_"+i+"_"+vstring+tstring, uniquenets, netnames);
            }
        }
        else {
            printXML(outfile+"_"+freq+"_"+vstring+tstring, uniquenets, netnames);
        }
    
        if (nettransitions)
            fprintNetTransitionCounts(uniquenets, "nets");
    }

    /** This function takes a Vector and transforms it to a SortedVector
     *  @param vect the non-sorted vector
     *  @return a sorted version of the vector as a SortedVector type
     */
    public static SortedVector nonSortedToSortedVector(ArrayList vect) {
        SortedVector sv = new SortedVector();

        for (int i = 0; i < vect.size(); i++) {
            sv.addSortedElement(vect.get(i));
        }
        return sv;
    }
    
    /** This function parses the commandline input.
     *  @param argv the String array of inputs
     */
    public static void parseInput(String argv[]) {

        for (int i = 0; i < argv.length; i++) {
            if (argv[i].equals("-c") || argv[i].equals("-cycles")) {
                i++;
                cycles = Integer.parseInt(argv[i]);
            }
            else if (argv[i].equals("-rc") || argv[i].equals("-resultclk")) {
                i++;
                resultclk = Integer.parseInt(argv[i]);
            }
            else if (argv[i].equals("-incr"))
                design = INCREMENTER;
            else if (argv[i].equals("-counter"))
                design = COUNTER;
            else if (argv[i].equals("-xor"))
                design = XOR;
            else if (argv[i].equals("-hi") || argv[i].equals("-halfiteration"))
                halfiteration = false;
            else if (argv[i].equals("-h") || argv[i].equals("-help")) {
                System.out.println(usage);
                System.exit(0);                
            }
            else if (argv[i].equals("-of") || argv[i].equals("-outfile")) {
                i++;
                outfile = argv[i];
            }
            else if (argv[i].equals("-nt") || argv[i].equals("-nettransitions")) {
                nettransitions = true;
            }
            else if (argv[i].equals("-freq")) {
                i++;
                freq = Integer.parseInt(argv[i]);
            }                
            else if (argv[i].equals("-w") || argv[i].equals("-width")) {
                i++;
                width = Integer.parseInt(argv[i]);
            }
            else if (argv[i].equals("-l") || argv[i].equals("-length")) {
                i++;
                length = Integer.parseInt(argv[i]);
                usrlength = true;
            }
            else if (argv[i].equals("-tmr")) {
                tmr = true;
                type |= VOTE;
            }
            else if (argv[i].equals("-nf") || argv[i].equals("-nofile"))
                nofile = true;
            else if (argv[i].equals("-name"))
                name = true;
            else if (argv[i].equals("-p1")) {
                p1 = true;
                p2 = false;
                p3 = false;
                place = 1;
            }
            else if (argv[i].equals("-p2")) {
                p1 = false;
                p2 = true;
                p3 = false;
                tmr = true;
                place = 2;
                design = INCREMENTER;
            }
            else if (argv[i].equals("-p3")) {
                p1 = false;
                p2 = false;
                p3 = true;
                tmr = true;
                place = 3;
                design = INCREMENTER;
            }
            else if (argv[i].equals("-allfreq") || argv[i].equals("-af")) {
                i++;
                allfreq = true;
                stopfreq = Integer.parseInt(argv[i]);
            }
            else if (argv[i].equals("-3clk")) {
                clk3 = true;
                tmr = true;
                type |= VOTE;
            }
            else if (argv[i].equals("-temp")) {
                i++;
                temp = Double.parseDouble(argv[i]);
                tstring = temp+"C";
            }
            else if (argv[i].equals("-voltage") || argv[i].equals("-v")) {
                i++;
                voltage = Double.parseDouble(argv[i]);
                vstring = voltage+"V";
            }
            else {
                System.out.println(usage);
                System.exit(-1);
            }
        }
        type |= design;
    }
    

    /** This function is for debugging puprposes.  It outputs netnames
     *  along with transition counts for each net
     *  @param svect a ArrayList of Nets 
     */
    public static void printNetTransitionCounts(ArrayList svect) {
        Net mynet;

        for (int i = 0; i < svect.size(); i++) {
            mynet = (Net)svect.get(i);
            System.out.println(mynet.getName()+mynet.getIndexString()+"  "+
                               mynet.getWire().getTransitionCount());
        }
    }

    /** This function is for debugging purposes.  It simply prints out 
     *  the contents of a given ArrayList.
     *  @param svect the ArrayList whose contents we will print out
     */
    public static void printArrayList(ArrayList svect) {
        
        for (int i = 0; i < svect.size(); i++) {
            System.out.println(i+" "+svect.get(i));
        }
    }
    
    /** This function creates a *.xml file to be inputted to XPower.
     *  @param filename the String name for the *.xml file
     *  @param nets the sorted vector of nets of the design
     *  @param names the 'sorted' vector of names of the nets (note that the
     *               not necesarily be 'sorted' any longer since some of the
     *               net names will have been modified.  It is important
     *               however that they retain their relative position in the
     *               vector so that they correspond the the vector element at 
     *               the same position in the Nets vector.
     */
    public static void printXML(String filename, ArrayList nets, ArrayList names) 
        throws Exception {

        BufferedWriter fout;
        double dfreq = (double)freq; 
        double frac;
        Net mynet;
        String currdate = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date());
        String xmlext = "_xpwr.xml";
        
        fout = new BufferedWriter(new FileWriter(filename+xmlext));
            
        // Preamble for the heading of the *.xml file
        fout.write("<?xml version=\"1.0\"?>\n");
        fout.write("<!-- Generated by Nathan Rollins PowerTransition testbench-->\n");
        fout.write("<!DOCTYPE Power_Manager PUBLIC \"-//XILINX// DTD $XILINX/data/xml/Power/Power_Manager.dtd//EN\" \"\">\n");
        fout.write("<Power_Manager version=\"1.0\" date=\""+currdate+"\n");
        fout.write("\" creator=\"XPower\">\n");
        fout.write("<Power_Head ");
        fout.write("design=\""+directory+netlist+dirname+xp1+ncd+"\"");
        fout.write(" device=\"v1000fg680-6\" ");
        fout.write("constraints=\""+directory+netlist+dirname+xp1+pcf+"\"");
        fout.write(" settings=\""+directory+netlist+dirname+filename+xmlext);
        fout.write("\">\n");
        fout.write("  <Power_Environment voltage=\""+voltage+"\" ambient=\""+temp+"C\" airflow=\"0LFM\" thetaja=\"10C/W\"");
        fout.write(" battery=\"0mAh\" parttype=\"commercial\" glue=\"0C/W\" heatsink=\"0C/W\">\n");
        fout.write("    <Power_Voltage source=\"Vccint\" voltage=\""+voltage+"\" quiescent=\"10.225732\" startup=\"500.00\"/>\n");
        fout.write("    <Power_Voltage source=\"Vcco33\" voltage=\"3.30\" quiescent=\"2.000000\" startup=\"0.00\"/>\n");
        fout.write("  </Power_Environment>\n");
        fout.write("  <!-- Set the globals and defaults -->\n");
        fout.write("  <Power_Defaults>\n");
        fout.write("    <Power_Activity rate=\"100.0%\"/>\n");
        fout.write("    <Power_Activity freq=\""+dfreq+"Mhz\"/>\n");
        fout.write("    <Power_Load cap=\"0fF\"/>\n");
        fout.write("  </Power_Defaults>\n");
        fout.write("</Power_Head>\n");
        fout.write("<Power_Body>\n");
        fout.write("  <!-- Clocks -->\n");
        
        if (clk3) {
            fout.write(" <Power_Net name=\"clki&lt;0&gt;\">\n");
            fout.write("  <Power_Activity freq=\""+dfreq+"Mhz\" />\n");
            fout.write(" </Power_Net>\n");
            fout.write("  <!-- Nets -->\n");
            fout.write(" <Power_Net name=\"clk&lt;0&gt;\">\n");
            fout.write("  <Power_Activity freq=\""+dfreq+"Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }
        else {
            fout.write(" <Power_Net name=\"clkg\">\n");
            fout.write("  <Power_Activity freq=\""+dfreq+"Mhz\" />\n");
            fout.write(" </Power_Net>\n");
            fout.write("  <!-- Nets -->\n");
            fout.write(" <Power_Net name=\"clk\">\n");
            fout.write("  <Power_Activity freq=\""+dfreq+"Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }

        // ensure that the gnd wires are set to 0MHz
        if (tmr) {
            fout.write(" <Power_Net name=\"gnd&lt;0&gt;\">\n");
            fout.write("  <Power_Activity freq=\"0Mhz\" />\n");
            fout.write(" </Power_Net>\n");
            fout.write(" <Power_Net name=\"gnd&lt;1&gt;\">\n");
            fout.write("  <Power_Activity freq=\"0Mhz\" />\n");
            fout.write(" </Power_Net>\n");
            fout.write(" <Power_Net name=\"gnd&lt;2&gt;\">\n");
            fout.write("  <Power_Activity freq=\"0Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }
        else {
            fout.write(" <Power_Net name=\"gnd\">\n");
            fout.write("  <Power_Activity freq=\"0Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }

        if (design == COUNTER) {
            fout.write(" <Power_Net name=\"rst\">\n");
            fout.write("  <Power_Activity freq=\"0Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }
        // iterate through the nets and write a tag for each one
        for (int i = 0; i < nets.size(); i++) {
            mynet = (Net)nets.get(i);
            frac = (dfreq / 2) * ((double) mynet.getWire().getTransitionCount() / 
                             (double)iteration);
            fout.write(" <Power_Net name=\""+names.get(i)+"\">\n");
            //fout.write("  <Power_Activity freq=\""+frac+"Mhz\" src=\"Probability\" duty=\"0.500%\" />\n");
            fout.write("  <Power_Activity freq=\""+frac+"Mhz\" />\n");
            fout.write(" </Power_Net>\n");
        }
        fout.write("  <!-- External loads -->\n");
        fout.write("</Power_Body>\n");
        fout.write("</Power_Manager>\n");
        fout.flush();
        fout.close();
    }
    
    /** This function updates the clock stimulus on each clock iteration
     */
    public void clock() {
        
        // We may want results on every X clcok iterations (rather than every
        // clock iteration)
        if (iteration % resultclk == 0 && iteration > 0)
            getResults();
	putWires();

        // we may want to count each step as an iteration or a whole clock
        // cycle as an iteration
        if (halfiteration) {
            if (clktog == 0)
                iteration++;
        }
        else
            iteration++;                
    }

    /** This function reports results after a given number of clock cycles
     */
    public void getResults() {
        // currently empty, but a needed function when debugging
    }
    
    /** This function updates wire values on each clocking
     */
    public void putWires() {
	clktog = ~clktog;

        // update the design inputs
        clk.put(this, clktog);
        if (design == COUNTER)
            reset.put(this, 0);
    }

    /** This function sets the input wires and testbench variables 
     *  in the event of a design reset 
     */
    public void reset() {
        clk.put(this, 0);
        if (design == COUNTER)
            reset.put(this, 0);
	iteration = 0;
	transitions=0;
    }

    public static final boolean TMR = false;
    public static final int COUNTER = 4;
    public static final int CNT_LENGTH = 416;
    public static final int INCR_LENGTH = 72;
    public static final int INCR_LENGTH_3CLK = 69;
    public static final int INCREMENTER = 1;
    public static final int WIDTH = 8;
    public static final int VOTE = 8;
    public static final int XOR = 2;
    public static final int XOR_LEN = 16;
    public static final int XOR_LENGTH = 416;
    public static final String directory = "/net/fpga3/users/nhr2/LANL/REDUNDANT/TMR_tests/power/";
    public static final String netlist = "netlist_";
    public static final String ncd = ".ncd";
    public static final String pcf = ".pcf";
    public static final String xp1 = "xp1";

    public static boolean clk3 = false;
    public static boolean allfreq = false;
    public static boolean halfiteration = true;
    public static boolean name = false;
    public static boolean nettransitions = false;
    public static boolean nofile = false;
    public static boolean p1 = false;
    public static boolean p2 = false;
    public static boolean p3 = false;
    public static boolean tmr = TMR;
    public static boolean usrlength = false;
    public static PrintWriter sysout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Cell topcell;
    public static double temp = 25.0;
    public static double voltage = 2.5;
    public static int cycles = 5000;
    public static int design = INCREMENTER;
    public static int freq = 20;
    public static int iteration;
    public static int length = INCR_LENGTH;
    public static int outwidth = INCR_LENGTH;
    public static int place = 0;
    public static int stopfreq = 101;
    public static int resultclk = 100;
    public static int type = 0;
    public static int width = WIDTH;
    public static String dirname;
    public static String outfile = "xp1mine";
    public static String tstring = "";
    public static String vstring = "";
    public static String usage = "powerTransition Usage: java powerTransition [options]\n"+
        "OPTIONS:\n"+
        "\t[-3clk]\t\t\t - triplicated clocks\n"+
        "\t[-allfreq <stop_freq>]\t - create *.xml files for all frequencies \n"+
        "\t                      \t   up to stop_freq\n"+
        "\t[(-c || -cycles) <cycles>] - specify the number of cycles for the \n"+
        "\t                             simulator to run\n"+
        "\t[-counter]\t\t - run tests on the up/down counter design\n"+
        "\t[-freq <value>]\t\t - explicitly set the frequency value\n"+
        "\t[(-h || -help)]\t\t - print this message\n"+
        "\t[-incr]\t\t\t - run tests on the incrementer design (default)\n"+
        "\t[(-l || -length) <value>]\t - set the number of cascaded counters\n"+
        "\t[-name]\t\t\t - set the flag that uses designs with explicit \n"+
        "\t       \t\t\t   cell names\n"+
        "\t[-nt || -nettransitions] - reset that flag that determines \n"+
        "\t                           incrementation on each step or cycle\n"+
        "\t[(-of || -outfile) <filename>] - set the name of the output \n"+
        "\t                                 file to filename\n"+
        "\t[-p1 || -p2 || -p3]\t - run the tests on the placed designs\n"+
        "\t[(-rc || -resultclk) <cycle_value>] - specify the numver of iterations \n"+
        "\t                                      between result collection\n"+
        "\t[-temp <value>]\t\t - specify the device temparature (25.0C)\n"+
        "\t[-tmr]\t\t\t - run tests on TMR'ed design\n"+
        "\t[(-v || -voltage) <value>] - specify the device voltage (2.5V)\n"+
        "\t[(-w || -width) <value>] - specify the bitwidth of the counters\n"+
        "\t[-xor]\t\t\t - run tests on the xor'ed incrementers\n";
    
    public int clktog = 0;
    public int transitions=0;    
    public Wire clk, cnt1, reset;

}















