public void AddVCD(VCD vcd, bool isVerilogVCD)
        {
            Timeline     = new VCDTimeline(vcd);
            IsVerilogVCD = isVerilogVCD;

            SetCircuitState(Timeline.TimeInterval.StartInclusive);
        }
Example #2
0
        internal static void VerifyInferTypes(string moduleName, string extension, bool isVerilogVCD, string modulePath)
        {
            CircuitGraph graph = VerifyMakeGraph(moduleName, extension, modulePath);

            using VCD vcd = LoadVCD(moduleName, modulePath);

            foreach (var variables in vcd.Variables)
            {
                foreach (var variable in variables)
                {
                    ScalarIO varCon = graph.GetConnection(variable, isVerilogVCD);
                    if (varCon == null)
                    {
                        continue;
                    }

                    ref BinaryVarValue actual = ref varCon.GetValue();
                    if (!varCon.Value.IsInitialized())
                    {
                        continue;
                    }
                    if (variable.Size != actual.Bits.Length)
                    {
                        Console.WriteLine($"Ref: {variable.Reference}, Expected: {variable.Size}, Actual: {actual.Bits.Length}");
                    }
                    Assert.AreEqual(variable.Size, actual.Bits.Length);
                }
            }
        public void ParseScopeMismatchOpen1()
        {
            string vcdString = @"
$scope module lol $end
$enddefinitions $end";
            VCD    vcd       = Parse.FromString(vcdString);
        }
Example #4
0
        static void Main(string[] args)
        {
            const string TestDir = @"...";
            Stopwatch    timer   = new Stopwatch();

            if (true)
            {
                timer.Start();
                VerifyComputeGraph("TileTester_4", "lo.fir", true, TestDir);
                timer.Stop();
            }
            else
            {
                using VCD vcd = VCDReader.Parse.FromFile(Path.Combine(TestDir, "TileTester_6.vcd"));
                //using VCD vcd = VCDReader.Parse.FromFile(Path.Combine(TestDir, "TileTester_8.vcd"));
                //using VCD vcd = VCDReader.Parse.FromFile(Path.Combine(TestDir, "TileTester_4.vcd"));
                //using VCD vcd = VCDReader.Parse.FromFile(Path.Combine(TestDir, "TileTester_5.vcd"));

                timer.Start();
                new VCDTimeline(vcd);
                timer.Stop();
            }

            Console.WriteLine((timer.ElapsedMilliseconds / 1000.0f).ToString("N2"));
            Console.ReadLine();
        }
        public void ParseScopeOpen2Closed2()
        {
            string vcdString = @"
$scope module lol $end
$upscope $end
$scope module fish $end
$upscope $end
$enddefinitions $end";
            VCD    vcd       = Parse.FromString(vcdString);

            Assert.AreEqual(4, vcd.Declarations.Count);
            Assert.IsTrue(vcd.Declarations[0] is Scope);
            Assert.IsTrue(vcd.Declarations[1] is UpScope);
            Assert.IsTrue(vcd.Declarations[2] is Scope);
            Assert.IsTrue(vcd.Declarations[3] is UpScope);

            var decl = vcd.Declarations[0] as Scope;

            Assert.AreEqual(ScopeType.Module, decl.Type);
            Assert.AreEqual("lol", decl.Name);

            decl = vcd.Declarations[2] as Scope;
            Assert.AreEqual(ScopeType.Module, decl.Type);
            Assert.AreEqual("fish", decl.Name);
        }
        public void ParseDumpVars()
        {
            Scope scope = new Scope(ScopeType.Module, "tester1");

            Scope[] scopes = { scope };

            IDeclCmd[] expectedDecls = new IDeclCmd[]
            {
                scope,
                new VarDef(VarType.Wire, 4, "'", "values_2/in", scopes),
                new VarDef(VarType.Wire, 4, "(", "values_1", scopes),
                new VarDef(VarType.Wire, 1, "-", "clock", scopes),
                new VarDef(VarType.Wire, 4, ".", "values_0", scopes),
                new UpScope()
            };

            ISimCmd[] expectedSimCmds = new ISimCmd[]
            {
                new DumpVars(new List <VarValue>()
                {
                    new BinaryVarValue(new BitState[] { BitState.Zero, BitState.Zero, BitState.Zero, BitState.Zero }, new List <VarDef>()
                    {
                        (VarDef)expectedDecls[1]
                    }, true),
                    new BinaryVarValue(new BitState[] { BitState.Zero, BitState.Zero, BitState.Zero, BitState.Zero }, new List <VarDef>()
                    {
                        (VarDef)expectedDecls[4]
                    }, true),
                    new BinaryVarValue(new BitState[] { BitState.Zero, BitState.Zero, BitState.Zero, BitState.Zero }, new List <VarDef>()
                    {
                        (VarDef)expectedDecls[2]
                    }, true),
                    new BinaryVarValue(new BitState[] { BitState.Zero }, new List <VarDef>()
                    {
                        (VarDef)expectedDecls[3]
                    }, true)
                })
            };

            string vcdString = @"
$scope module tester1 $end
$var wire 4 ' values_2/in $end
$var wire 4 ( values_1 $end
$var wire 1 - clock $end
$var wire 4 . values_0 $end
$upscope $end
$enddefinitions $end
$dumpvars
b0000 '
b0000 .
b0000 (
0-
$end";
            VCD    vcd       = Parse.FromString(vcdString);

            TestTools.VerifyDeclarations(expectedDecls, vcd.Declarations);
            TestTools.VerifySimCmds(expectedSimCmds, vcd.GetSimulationCommands().ToArray());
        }
        public void ParseDate()
        {
            string vcdString = @"
$date test $end 
$enddefinitions $end";
            VCD    vcd       = Parse.FromString(vcdString);

            Assert.AreEqual(1, vcd.Declarations.Count);
            Assert.IsTrue(vcd.Declarations[0] is Date);

            var decl = vcd.Declarations[0] as Date;

            Assert.AreEqual("test", decl.Content);
        }
        public void ParseVersion()
        {
            string vcdString = @"
$version test $lol $end 
$enddefinitions $end";
            VCD    vcd       = Parse.FromString(vcdString);

            Assert.AreEqual(1, vcd.Declarations.Count);
            Assert.IsTrue(vcd.Declarations[0] is VCDReader.Version);

            var decl = vcd.Declarations[0] as VCDReader.Version;

            Assert.AreEqual("test", decl.VersionText);
            Assert.AreEqual("$lol", decl.SystemTask);
        }
        public void ParseSimTime()
        {
            ISimCmd[] expectedSimCmds = new ISimCmd[]
            {
                new SimTime(0),
                new SimTime(53)
            };

            string vcdString = @"
$enddefinitions $end
#0
#53";
            VCD    vcd       = Parse.FromString(vcdString);

            TestTools.VerifySimCmds(expectedSimCmds, vcd.GetSimulationCommands().ToArray());
        }
Example #10
0
        /// <summary>
        /// Builds the File parts
        /// </summary>
        private void Build()
        {
            foreach (var commandset in CommandSets)
            {
                Root.Add(commandset.GetElement());
            }
            VCD.Add(Root);

            if (!CommandSets.Any())
            {
                throw new Exception("Voice Command Definitions require at least 1 Command Set");
            }
            else if (CommandSets.Count > 15)
            {
                throw new FieldOverflowException(CommandSets, "Voice Command Definitions can only have up to 15 Languages");
            }
        }
        public void ParseScopeOpen1Closed1()
        {
            foreach (ScopeType scopeType in Enum.GetValues(typeof(ScopeType)))
            {
                string vcdString = @$ "
$scope {scopeType.ToString().ToLower()} lol $end
$upscope $end
$enddefinitions $end";
                VCD    vcd       = Parse.FromString(vcdString);

                Assert.AreEqual(2, vcd.Declarations.Count);
                Assert.IsTrue(vcd.Declarations[0] is Scope);
                Assert.IsTrue(vcd.Declarations[1] is UpScope);

                var decl = vcd.Declarations[0] as Scope;
                Assert.AreEqual(scopeType, decl.Type);
                Assert.AreEqual("lol", decl.Name);
            }
        }
Example #12
0
        internal static void VerifyChiselTest(string moduleName, string extension)
        {
            const string modulePath = "ChiselTests";

            CircuitGraph lowFirGraph = null;

            if (extension == "fir")
            {
                string loFirPath = Path.Combine(modulePath, $"{moduleName}.lo.fir");
                lowFirGraph = VerifyCanCreateGraphFromFile(loFirPath);
            }

            string       firPath = Path.Combine(modulePath, $"{moduleName}.{extension}");
            CircuitGraph graph   = VerifyCanCreateGraphFromFile(firPath, lowFirGraph);

            using VCD vcd = VCDReader.Parse.FromFile($"{modulePath}/{moduleName}.vcd");
            VCDTimeline timeline = new VCDTimeline(vcd);

            VerifyCircuitState(graph, timeline, isLoFIRRTL(extension), false);
        }
Example #13
0
        public VCDTimeline(VCD vcd)
        {
            this.TimeScale = vcd.Time;

            var          simCommands = vcd.GetSimulationCommands();
            SimPass      firstCmd    = simCommands.First();
            CircuitState segmentStartState;

            if (firstCmd.SimCmd is DumpVars initDump)
            {
                segmentStartState = new CircuitState(initDump);
            }
            else
            {
                segmentStartState = new CircuitState(vcd.Variables.ToList());
                simCommands       = simCommands.Prepend(firstCmd);
            }
            CircuitState followState = segmentStartState.Copy();

            ulong                  startTime            = 0;
            const int              maxChangesPerSegment = 100_000;
            List <BinaryVarValue>  binChanges           = new List <BinaryVarValue>(maxChangesPerSegment);
            List <TimeStepChanges> stepChanges          = new List <TimeStepChanges>();
            int currTimeStepStart  = 0;
            int currTimeStepLength = 0;


            foreach (var simCmd in simCommands)
            {
                if (simCmd.SimCmd is SimTime time)
                {
                    if (currTimeStepLength > 0)
                    {
                        StateCount++;
                        TimeStepChanges timeStep = new TimeStepChanges(startTime, currTimeStepStart, currTimeStepLength);
                        currTimeStepStart += currTimeStepLength;
                        currTimeStepLength = 0;

                        stepChanges.Add(timeStep);

                        //If segment is full then store the segment and
                        //prepare for the next segment
                        if (binChanges.Count > maxChangesPerSegment)
                        {
                            TimeSpan tSpan = new TimeSpan(stepChanges.First().Time, time.Time);
                            SegmentChanges.Add(new TimeSegmentChanges(tSpan, segmentStartState, binChanges.ToArray(), stepChanges));
                            currTimeStepStart  = 0;
                            currTimeStepLength = 0;

                            segmentStartState = followState;
                            followState       = segmentStartState.Copy();

                            binChanges.Clear();
                            stepChanges = new List <TimeStepChanges>();
                        }
                    }
                    startTime = time.Time;
                }
                else if (simCmd.BinValue.HasValue)
                {
                    followState.AddChange(simCmd.BinValue.Value);
                    binChanges.Add(simCmd.BinValue.Value);
                    currTimeStepLength++;
                }
            }

            //Add last segment if it's not empty.
            //Segment isn't added by above loop if the vcd file doesn't
            //end with a simulation time command.
            if (currTimeStepLength > 0)
            {
                stepChanges.Add(new TimeStepChanges(startTime, currTimeStepStart, currTimeStepLength));
            }
            if (stepChanges.Count > 0)
            {
                TimeSpan tSpan = new TimeSpan(stepChanges.First().Time, stepChanges.Last().Time + 1);
                SegmentChanges.Add(new TimeSegmentChanges(tSpan, segmentStartState, binChanges.ToArray(), stepChanges));
            }

            this.TimeInterval = new TimeSpan(SegmentChanges.First().TimeInterval.StartInclusive, SegmentChanges.Last().TimeInterval.EndExclusive);
        }
Example #14
0
 private static VCDTimeline MakeTimeline(string moduleName, string modulePath)
 {
     using VCD vcd = LoadVCD(moduleName, modulePath);
     return(new VCDTimeline(vcd));
 }
Example #15
0
 public override string ToString()
 {
     Build(); return(VCD.ToString());
 }
Example #16
0
 /// <summary>
 /// Saves VCD to Storage File of your creation, ensure that it replaces itself
 /// </summary>
 /// <param name="File">File to save to</param>
 public async Task SaveToFile(StorageFile File)
 {
     Build(); using (var stream = await File.OpenStreamForWriteAsync()) { VCD.Save(stream); }
 }