public void Run()
        {
            VCDSignalsSnapshot topLevelSnapshot = new VCDSignalsSnapshot("TOP");
            var controlScope = topLevelSnapshot.Scope("Control");
            var clockSignal  = controlScope.Add(new VCDVariable("Clock", true, 1));

            _topLevel.PopulateSnapshot(topLevelSnapshot);

            _vcdBuilder?.Init(topLevelSnapshot);

            var clock          = 0;
            var stageIteration = 0;

            while (clock < MaxClockCycles && (IsRunning?.Invoke(_topLevel) ?? true))
            {
                var currentTime = clock * 2 * MaxStageIterations;
                clockSignal.Value = true;

                stageIteration = 0;
                do
                {
                    currentTime++;

                    var modified = _topLevel.Stage(stageIteration);

                    _topLevel.PopulateSnapshot(topLevelSnapshot);
                    _vcdBuilder?.Snapshot(currentTime, topLevelSnapshot);

                    // no modules were modified during stage iteration, all converged
                    if (!modified)
                    {
                        break;
                    }
                }while (++stageIteration < MaxStageIterations);

                if (stageIteration >= MaxStageIterations)
                {
                    throw new MaxStageIterationReachedException();
                }

                OnPostStage?.Invoke(_topLevel);

                currentTime = clock * 2 * MaxStageIterations + MaxStageIterations;

                clockSignal.Value = false;
                _topLevel.PopulateSnapshot(topLevelSnapshot);
                _vcdBuilder?.Snapshot(currentTime, topLevelSnapshot);

                _topLevel.Commit();
                clock++;
            }
        }
        public void TraceToVCD(string outputFileName)
        {
            Console.WriteLine($"Tracing to: {outputFileName}");
            RecursiveCreateTargetDirectory(Path.GetDirectoryName(outputFileName));

            _vcdBuilder       = new VCDBuilder(outputFileName);
            _topLevelSnapshot = new VCDSignalsSnapshot("TOP");
            _simulatorContext.ControlScope = _topLevelSnapshot.Scope("Control");
            _simulatorContext.ClockSignal  = _simulatorContext.ControlScope.Add(new VCDVariable("Clock", true, 1));

            _topLevel.PopulateSnapshot(_topLevelSnapshot);
            _vcdBuilder.Init(_topLevelSnapshot);
        }
        public void Test()
        {
            var vcd      = new VCDBuilder(@"C:\tmp\1.vcd");
            var topScope = new VCDSignalsSnapshot("TOP");

            topScope.Add(new VCDVariable("data", (byte)0, 1));

            var childScope = topScope.Scope("ChildScope1");
            var signal1    = childScope.Add(new VCDVariable("Signal1", true, 1));
            var signal2    = childScope.Add(new VCDVariable("Signal2", "Value", 1));

            vcd.Init(topScope);

            signal1.Value = false;
            signal2.Value = "NewValue";
            vcd.Snapshot(10, topScope);
            vcd.Snapshot(20, null);
        }
        public void Test()
        {
            if (!Debugger.IsAttached)
            {
                Assert.Inconclusive("Run under debugger");
            }

            var vcd      = new VCDBuilder(@"C:\tmp\1.vcd");
            var topScope = new VCDSignalsSnapshot("TOP");

            topScope.Add(new VCDVariable("data", (byte)0, 1));

            var childScope = topScope.Scope("ChildScope1");
            var signal1    = childScope.Add(new VCDVariable("Signal1", true, 1));
            var signal2    = childScope.Add(new VCDVariable("Signal2", "Value", 1));

            vcd.Init(topScope);

            signal1.Value = false;
            signal2.Value = "NewValue";
            vcd.Snapshot(10, topScope);
            vcd.Snapshot(20, null);
        }