Esempio n. 1
0
    static PinList MakeList (int length)
    {
	PinList l = null;
	for (int i = 0; i < length; ++i)
	    l = new PinList (l);
	return l;
    }
Esempio n. 2
0
 /// <summary>
 /// Constructor for the TestBenchWriter class
 /// </summary>
 /// <param name="filePath">String containing the file path
 /// where the testbench should be saved</param>
 /// <param name="mod">Module containing the circuit that the testbench will be generated for</param>
 public TestBenchWriter(String filePath, Module mod)
 {
     //Class assignments
     this.filePath   = filePath;
     this.inputs     = new PinList(mod.inputPins);
     this.outputs    = new PinList(mod.outputPins);
     this.moduleName = mod.moduleName;
 }
Esempio n. 3
0
        private List <String> gateOrder;//gateorder keeps track of the order in which gates were added.

        /// <summary>
        /// Constructor for the module class
        /// </summary>
        /// <param name="modulename">A string holding the name of a circuit</param>
        public Module(string modulename)
        {
            this.modulename = modulename;
            this.inputs     = new PinList();
            this.outputs    = new PinList();
            this.wires      = new PinList();
            this.gateData   = new Dictionary <string, Gate>();
            this.gateOrder  = new List <string>();
        }
Esempio n. 4
0
    public static void Main()
    {
        PinList list = MakeList(1 << 24);

        Console.WriteLine("long list constructed");
        Benchmark(list, 10);
        GC.Collect(1);
        Benchmark(list, 100);
    }
Esempio n. 5
0
    static void AssignReferences (PinList l, Pinned[] objs)
    {
	int i = 0;
	int n = objs.Length;
	while (l != null)
	{
	    l.reference = objs [i++ % n];
	    l = l.next;
	}
    }
    static PinList MakeList(int length)
    {
        PinList l = null;

        for (int i = 0; i < length; ++i)
        {
            l = new PinList(l);
        }
        return(l);
    }
    static void AssignReferences(PinList l, Pinned[] objs)
    {
        int i = 0;
        int n = objs.Length;

        while (l != null)
        {
            l.reference = objs [i++ % n];
            l           = l.next;
        }
    }
Esempio n. 8
0
        /// <summary>
        /// Method returns number inputs/outputs found by the circuit recognizer
        /// </summary>
        /// <param name="circ">List of superwires from the circuitrec object</param>
        /// <returns>Int containing the total number of circuit inputs and outputs</returns>
        public int numCol(CircuitRec.CircuitRec circ)
        {
            //Convert the superwires to a list of input/output pins
            PinList pins = new PinList(MeshToPins(circ.Meshes));

            //removes the clock variable from the list of inputs/outputs
            pins.clk_rm();

            //returns the number of remaining inputs/outputs
            return(pins.Count);
        }
Esempio n. 9
0
 private bool ComparePinLists(PinList <TranslatedMaterialGraph.NodeInfo> list1,
                              PinList <TranslatedMaterialGraph.NodeInfo> list2)
 {
     if (list1.Count != list2.Count)
     {
         return(false);
     }
     foreach (var compareRes in list1.Zip(list2, (a, b) => CompareConnectedPins(a, b)))
     {
         if (!compareRes)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 10
0
        /// <summary>
        /// Writes the verilog code that runs the actual tests
        /// </summary>
        /// <param name="dir">String containing directory path of where the circuit should
        /// be saved</param>
        /// <param name="tv_count">Int containing the width of required test vectors</param>
        private void test(String dir, int tv_count)
        {
            //Sets the file writer to append mode
            FileStream fs = new FileStream(dir + "\\test.v", FileMode.Append, FileAccess.Write);
            TextWriter tw = new StreamWriter(fs);

            PinList tempInputs = new PinList();

            inputs.clk_rm();
            tempInputs.AddRange(inputs.Pins);

            foreach (Pin dataout in outputs.Pins)
            {
                if (dataout.bussize > 1)
                {
                    tw.Write("\t\t\tif (" + dataout.PinName + "[" + (dataout.bussize - 1) + ":0] !==" +
                             dataout + "Expected[" + (dataout.bussize - 1) + ":0])begin\n");
                    tw.Write("\t\t\t\t$display(\"Error:\");\n");
                }
                else
                {
                    tw.Write("\t\t\tif (" + dataout.PinName + "!==" +
                             dataout.PinName + "Expected" + ")begin\n");
                    tw.Write("\t\t\t\t$display(\"Error:\");\n");
                }
                //Lists all of the inputs
                foreach (Pin datain in tempInputs.Pins)
                {
                    tw.Write("\t\t\t\t$fdisplay(ch, \"" + datain.PinName + "=%b\", " + datain.PinName + ");\n");
                }

                tw.Write("\t\t\t\t$fdisplay(ch, \"Expected: " + dataout.PinName + "=%b (%b expected)\",\n" +
                         "\t\t\t\t\t\t" + dataout.PinName + ", " + dataout.PinName + "Expected);\n");
                tw.Write("\t\t\t\terrors = errors + 1;\n\t\t\tend\n\n");
            }

            tw.Write("\t\t\tvectornum=vectornum + 1;\n");
            tw.Write("\t\t\tif( testvectors[vectornum]===" + tv_count + "'bx)begin\n" +
                     "\t\t\t\t$display(\"%d tests completed with %d errors\",\n" +
                     "\t\t\t\t\t\tvectornum, errors);\n" +
                     "\t\t\t\t$fclose(error);\n" +
                     "\t\t\t\t$finish;\n\t\t\tend\n\t\tend\n\nendmodule");

            //Closes the textwriter and the filestream
            tw.Close();
            fs.Close();
        }
Esempio n. 11
0
 public void CreatePins(PinPointList points)
 {
     if (points != null)
     {
         pins = new PinList();
         foreach (var p in points)
         {
             pins.Add(new Pin()
             {
                 Id        = Guid.NewGuid(),
                 OffsetX   = p.X * 96.0 / 2.54,
                 OffsetY   = p.Y * 96.0 / 2.54,
                 Alignment = p.Alignment
             });
         }
     }
 }
Esempio n. 12
0
        private int GetPinsAndLinksHash(PinList <TranslatedMaterialGraph.NodeInfo> pins)
        {
            var hashCode = -1248223815;

            foreach (var pin in pins)
            {
                hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(pin.Id);

                hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(pin.Type);

                foreach (var link in pin.Links.OrderBy(_ => RuntimeHelpers.GetHashCode(_)))
                {
                    hashCode = hashCode * -1521134295 + RuntimeHelpers.GetHashCode(link.From);
                }
            }

            return(hashCode);
        }
 static Pinned Work(PinList list, Pinned[] objs, int i)
 {
     if (i >= objs.Length)
     {
         for (int j = 0; j < 10; ++j)
         {
             MakeList(list_size >> 5);
             AssignReferences(list, objs);
         }
         return(null);
     }
     else
     {
         Pinned obj = new Pinned();
         objs [i] = obj;
         Pinned dummy = Work(list, objs, i + 1);
         return(obj != dummy ? obj : dummy); // to keep obj alive
     }
 }
Esempio n. 14
0
    static Pinned Work (PinList list, Pinned[] objs, int i)
    {
	if (i >= objs.Length)
	{
	    for (int j = 0; j < 10; ++j)
	    {
		MakeList (1 << 19);
		AssignReferences (list, objs);
	    }
	    return null;
	}
	else
	{
	    Pinned obj = new Pinned ();
	    objs [i] = obj;
	    Pinned dummy = Work (list, objs, i + 1);
	    return obj != dummy ? obj : dummy; // to keep obj alive
	}
    }
    public static void Main()
    {
        list_size = 1 << 15;
        TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 5));

        for (int it1 = 1; it1 <= 10; it1++, list_size <<= 1)
        {
            PinList list = MakeList(list_size);
            Console.WriteLine("long list constructed {0}", it1);
            for (int it2 = 0; it2 < 5; it2++)
            {
                Benchmark(list, 10 * it1);
                GC.Collect(1);

                if (!timeout.HaveTimeLeft)
                {
                    return;
                }
            }
        }
    }
Esempio n. 16
0
    PinList (PinList n)
    {
	next = n;
    }
Esempio n. 17
0
 public void Clear()
 {
     PinList.Clear();
 }
Esempio n. 18
0
 public async Task ClearAndReload()
 {
     await PinList.ClearAndReload();
 }
Esempio n. 19
0
    static void Benchmark (PinList list, int n)
    {
	Pinned[] objs = new Pinned [n];
	Work (list, objs, 0);
    }
Esempio n. 20
0
        /// <summary>
        /// Writes the initialization code for reading in the test vectors
        /// </summary>
        /// <param name="dir">String containing directory path of where the circuit should
        /// be saved</param>
        private void initTest(String dir)
        {
            //Sets the file writer to append mode
            FileStream fs = new FileStream(dir + "\\test.v", FileMode.Append, FileAccess.Write);
            TextWriter tw = new StreamWriter(fs);

            int i;

            PinList tempInputs = new PinList();

            tempInputs.AddRange(inputs.Pins);

            Pin clkVar = tempInputs.clk_var();

            tempInputs.clk_rm(clkVar);

            tw.Write("\n\t);\n\n");
            tw.Write("\talways\n\t\tbegin\n\t\t\t" +
                     clkVar.PinName + "=1; #5; " + clkVar.PinName + "=0; #5;\n\t\tend\n");
            tw.Write("\n\tinitial\n\t\tbegin\n" +
                     "\t\t\terror = $fopen(\"error.log\");\n" +
                     "\t\t\tif(error==0) $stop(2);\n" +
                     "\t\t\tch = error|1;\n" +
                     "\t\t\t$readmemb(\"testVect.tv\", testvectors);\n" +
                     "\t\t\tvectornum=0; errors=0;\n\t\tend\n");
            tw.Write("\n\talways @ (posedge " + clkVar.PinName + ")\n\t\tbegin\n" +
                     "\t\t\t#1; {");

            i = 0;

            //Writes out the inputs for testvector assignment
            foreach (Pin datain in tempInputs.Pins)
            {
                if (datain.bussize > 1)
                {
                    if (i == 0)
                    {
                        tw.Write(datain.PinName + "[" +
                                 (datain.bussize - 1) + ":0]");
                    }
                    else
                    {
                        tw.Write(", " + datain.PinName + "[" +
                                 (datain.bussize - 1) + ":0]");
                    }
                }

                else
                {
                    if (i == 0)
                    {
                        tw.Write(datain.PinName);
                    }
                    else
                    {
                        tw.Write(", " + datain.PinName);
                    }
                }
                i++;
            }

            //Writes out the expected outputs for testvector assignment
            foreach (Pin dataout in outputs.Pins)
            {
                if (dataout.bussize > 1)
                {
                    tw.Write(", " + dataout.PinName + "Expected[" +
                             (dataout.bussize - 1) + ":0]");
                }
                else
                {
                    tw.Write(", " + dataout.PinName + "Expected");
                }
            }

            tw.Write("}=\n\t\t\ttestvectors[vectornum];\n\t\tend\n");

            tw.Write("\n\talways @ (negedge " + clkVar.PinName + ")\n\t\tbegin\n");

            tw.Close();
            fs.Close();
        }
Esempio n. 21
0
        /// <summary>
        /// Writes the testbench code that instantiates the module and writes out the
        /// inputs and outputs
        /// </summary>
        /// <param name="dir">String containing directory path of where the circuit should
        /// be saved</param>
        /// <returns>int containing the required width of the testvectors</returns>
        private int instantiate(String dir)
        {
            //Sets the file writer to append mode
            FileStream fs = new FileStream(dir + "\\test.v", FileMode.Append, FileAccess.Write);
            TextWriter tw = new StreamWriter(fs);

            //puts the inputs into a temp value so that once the clock is removed, it doesn't
            //remove it from the class object
            PinList tempInputs = new PinList();

            tempInputs.AddRange(inputs.Pins);

            tw.Write("module test; \n\n\t//inputs\n");

            int i = 0;

            //Gets the name of the clock variable
            Pin clkVar = tempInputs.clk_var();

            //Console.WriteLine(clkVar);
            //Removes the clock variable from the inputs and insizes
            tempInputs.clk_rm(clkVar);

            tw.Write("\treg " + clkVar.PinName + ";\n");

            //Writes out the module inputs
            foreach (Pin datain in tempInputs.Pins)
            {
                if (datain.bussize > 1)
                {
                    tw.Write("\treg [");
                    tw.Write(datain.bussize - 1);
                    tw.Write(":0] " + datain.PinName + ";\n");
                }
                else
                {
                    tw.Write("\treg " + datain.PinName + ";\n");
                }
            }

            tw.Write("\n\t//expected results\n");

            //Writes the expected module outputs
            foreach (Pin dataout in outputs.Pins)
            {
                if (dataout.bussize > 1)
                {
                    tw.Write("\treg [");
                    tw.Write(dataout.bussize - 1);
                    tw.Write(":0] " + dataout.PinName + "Expected;\n");
                }
                else
                {
                    tw.Write("\treg " + dataout.PinName + "Expected;\n");
                }
            }

            tw.Write("\n\t//outputs\n");

            //Writes the module outputs
            foreach (Pin dataout in outputs.Pins)
            {
                if (dataout.bussize > 1)
                {
                    tw.Write("\twire [");
                    tw.Write(dataout.bussize - 1);
                    tw.Write(":0] " + dataout.PinName + ";\n");
                }
                else
                {
                    tw.Write("\twire " + dataout.PinName + ";\n");
                }
            }

            tw.Write("\tinteger error, ch;");

            int tv_count = 0;

            //Adds the bus sizes of each input and output to generate the width of the
            //expected test vectors
            foreach (Pin instance in tempInputs.Pins)
            {
                tv_count += instance.bussize;
            }
            foreach (Pin instance in outputs.Pins)
            {
                tv_count += instance.bussize;
            }

            tw.Write("\n\n\n\treg[31:0] vectornum, errors;\n");
            tw.Write("\n\treg[" + (tv_count - 1) + ":0] testvectors[10000:0];\n");

            tw.Write("\n\t//Instantiate the Unit Under Test (UUT)\n\t"
                     + moduleName + " uut(\n");


            i = 0;

            //System.Windows.Forms.MessageBox.Show(clkVar.PinName + !clkVar.PinName.Equals("auto_clk"));
            //Lists the inputs and outputs for module instantiation
            if (!clkVar.PinName.Equals("auto_clock"))
            {
                tw.Write("\t\t." + clkVar.PinName + "(" + clkVar.PinName + ")");
            }

            foreach (Pin datain in tempInputs.Pins)
            {
                if ((clkVar.PinName.Equals("auto_clock")) && (i == 0))
                {
                    tw.Write("\t\t." + datain.PinName + "(" + datain.PinName + ")");
                }
                else
                {
                    tw.Write(",\n\t\t." + datain.PinName + "(" + datain.PinName + ")");
                }
                i++;
            }

            foreach (Pin dataout in outputs.Pins)
            {
                tw.Write(",\n\t\t." + dataout.PinName + "(" + dataout.PinName + ")");
            }

            tw.Close();
            fs.Close();

            return(tv_count);
        }
Esempio n. 22
0
        private void InitializeStartUpComboList()
        {
            this.SearchType = new List <string>();
            this.SearchType.Add("Add hoc");
            this.SearchType.Add("By Class, Section and Roll");
            this.SearchType.Add("Bulk");

            this.VillList = new List <string>();
            VillList.Add("Bakharpur");
            VillList.Add("Bamongram");
            VillList.Add("Chamagram");
            VillList.Add("Chaspara");
            VillList.Add("Goyeshbari");
            VillList.Add("Harugram");
            VillList.Add("Jalalpur");
            VillList.Add("Mosimpur");
            VillList.Add("Nazirpur");
            VillList.Add("Paharpur");
            VillList.Add("Sujapur");

            this.POList = new List <string>();
            POList.Add("Bakharpur");
            POList.Add("Bamongram");
            POList.Add("Chaspara");
            POList.Add("Chhoto Sujapur");
            POList.Add("Fatehkhani");
            POList.Add("Gayeshbari");
            POList.Add("Jalalpur");
            POList.Add("Mosimpur");
            POList.Add("Sujapur");

            this.PSList = new List <string>();
            PSList.Add("Kaliachak");

            this.DistList = new List <string>();
            DistList.Add("Malda");

            this.PinList = new List <string>();
            PinList.Add("732206");

            this.Gender = new List <string>();
            Gender.Add("Boy");
            Gender.Add("Girl");

            this.SchoolClass = new List <string>();
            SchoolClass.Add("V");
            SchoolClass.Add("VI");
            SchoolClass.Add("VII");
            SchoolClass.Add("VIII");
            SchoolClass.Add("IX");
            SchoolClass.Add("X");
            SchoolClass.Add("XI");
            SchoolClass.Add("XII");

            this.SchoolSection = new List <string>();
            SchoolSection.Add("A");
            SchoolSection.Add("B");
            SchoolSection.Add("C");
            SchoolSection.Add("D");
            SchoolSection.Add("E");
        }
 static void Benchmark(PinList list, int n)
 {
     Pinned[] objs = new Pinned [n];
     Work(list, objs, 0);
 }
Esempio n. 24
0
        /// <summary>
        /// Method compares inputs and outputs generated by the circuit and truthtable
        /// recognizers, attempts to reconcile the order and generated an appropriate
        /// Verilog testbench
        /// </summary>
        /// <param name="tv">List of Pins containing circuit input/outputs recognized
        /// by the truthtable recognizer</param>
        /// <param name="circ">List of superwires contained in the CircuitRec object</param>
        /// <returns>List of pins containing the correct pin order</param>
        /// <param name="filename">Name of the xml/verilog file that contains the
        /// circuit whose inputs/outputs are to be rectified</param>
        /// <returns>List of pins containing the correct pin order</returns>
        public List <Pin> inOutRectify(List <Pin> tv, List <Mesh> circ, String filename)
        {
            //get the input/output pins from circuitrec
            PinList synthPins = new PinList(MeshToPins(circ));


            //initialize output list
            List <Pin> order = new List <Pin>();
            Pin        clkPin;

            String dir    = Path.GetDirectoryName(filename);
            String module = Path.GetFileNameWithoutExtension(filename);

            int i = 0;

            //Get the clock variable
            clkPin = synthPins.clk_var();

            //Remove the clock variable from synthPins
            synthPins.clk_rm(clkPin);

            //foreach (Pin instance in synthPins.Pins)
            //{
            //    Console.WriteLine(instance.PinName + " " + instance.bussize);
            //}

            order.Add(clkPin);

            //If there is a mismatch between number of inputs/outputs
            //return an error
            if (tv.Count != synthPins.Count)
            {
                MessageBox.Show("Mismatch between number of truth table and circuit inputs/outputs", "In/Out Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            int flipped = 0;

            //Looks for each pin that exists in the testvector file in the circuit
            //if it exists in the circuit, it is added to this list of pin outputs
            foreach (Pin instance in tv)
            {
                i = indexFind(synthPins.Pins, instance);

                if (i < synthPins.Pins.Count)
                {
                    if (instance.Polarity.Equals(synthPins.Pins[i].Polarity))
                    {
                        //if the pins have the same input/output type, add it to the
                        //return list and remove it from synthpins
                        order.Add(instance);
                        synthPins.RemoveAt(i);
                    }
                    else
                    {
                        flipped++;
                    }
                }
            }

            //if all inputs/outputs match except every input/output has the wrong
            //polarity, return an error
            if (flipped == synthPins.Count)
            {
                MessageBox.Show("Truthtable inputs/outputs appear to have been flipped", "Input/Output Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            //if some inputs/outputs could not be matched up, return an error
            if (synthPins.Pins.Count > 0)
            {
                //MessageBox.Show("here");
                //foreach (Pin instance in synthPins.Pins)
                //{
                //    Console.WriteLine(instance.PinName + " " + instance.bussize);
                //}
                //MessageBox.Show("there");
                MessageBox.Show("Input/Output lists could not be rectified", "Input/Output Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            Module mod = new Module("testBench");

            //write out a testbench with inputs/outputs in the appropriate order
            TestBenchWriter tbw = new TestBenchWriter(dir, pins2mod(order, module));

            tbw.writeBench();

            return(order);
        }
 PinList(PinList n)
 {
     next = n;
 }