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);
        }
Exemplo n.º 5
0
        public virtual void PopulateSnapshot(VCDSignalsSnapshot snapshot, RTLModuleSnapshotConfig config = null)
        {
            config = config ?? RTLModuleSnapshotConfig.Default;
            try
            {
                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.Inputs))
                {
                    currentSnapshot = snapshot.Scope("Inputs");
                    foreach (var prop in InputProps)
                    {
                        currentMember = prop;
                        var value = currentMember.GetValue(Inputs);
                        currentSnapshot.SetVariables(ToVCDVariables(currentMember, value));
                    }
                }

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.Outputs))
                {
                    currentSnapshot = snapshot.Scope("Outputs");
                    foreach (var prop in OutputProps)
                    {
                        currentMember = prop;
                        var value = currentMember.GetValue(this);
                        currentSnapshot.SetVariables(ToVCDVariables(currentMember, value));
                    }
                }

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.Internals))
                {
                    currentSnapshot = snapshot.Scope("Internals");
                    foreach (var prop in InternalProps)
                    {
                        currentMember = prop;
                        var value = currentMember.GetValue(this);
                        currentSnapshot.SetVariables(ToVCDVariables(currentMember, value));
                    }
                }

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.Modules))
                {
                    currentSnapshot = null;
                    foreach (var m in ModuleProps.Where(m => RTLModuleHelper.IsField(m)))
                    {
                        var value = m.GetValue(this);
                        currentMember = m;

                        if (value is IRTLCombinationalModule module)
                        {
                            var moduleScope = snapshot.Scope(m.Name);

                            module.PopulateSnapshot(moduleScope);
                            continue;
                        }

                        // TODO: support for modules array
                    }
                }
            }
            catch (VCDSnapshotException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ThrowVCDException(ex);
            }
        }
Exemplo n.º 6
0
        public override void PopulateSnapshot(VCDSignalsSnapshot snapshot, RTLModuleSnapshotConfig config = null)
        {
            config = config ?? RTLModuleSnapshotConfig.Default;
            try
            {
                base.PopulateSnapshot(snapshot, config);

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.State))
                {
                    currentSnapshot = snapshot.Scope("State");
                    if (State == null)
                    {
                        throw new NullReferenceException("State is not initialized");
                    }

                    foreach (var prop in StateProps)
                    {
                        // TODO: support arrays in VCD
                        if (prop.GetMemberType().IsArray)
                        {
                            continue;
                        }

                        currentMember = prop;
                        var value = currentMember.GetValue(State);
                        currentSnapshot.SetVariables(ToVCDVariables(currentMember, value));
                    }
                }

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.NextState))
                {
                    currentSnapshot = snapshot.Scope("NextState");
                    if (NextState == null)
                    {
                        throw new NullReferenceException("NextState is not initialized");
                    }

                    foreach (var prop in StateProps)
                    {
                        // TODO: support arrays in VCD
                        if (prop.GetMemberType().IsArray)
                        {
                            continue;
                        }

                        currentMember = prop;
                        var value = currentMember.GetValue(NextState);
                        currentSnapshot.SetVariables(ToVCDVariables(currentMember, value));
                    }
                }

                if (config.IsIncluded(RTLModuleSnapshotConfigInclude.Pipelines))
                {
                    var pipelinesScope = snapshot.Scope("Pipelines");
                    currentSnapshot = pipelinesScope;
                    foreach (var pipelineProp in PipelineProps)
                    {
                        var pipeline = pipelineProp.GetValue(this) as IRTLPipeline;
                        var head     = pipeline.Diag.Head;

                        var pipelineScope = pipelinesScope.Scope(pipelineProp.Name);
                        currentSnapshot = pipelineScope.Scope("Control");
                        currentSnapshot.SetVariables(ToVCDVariables("", head.PipelineControl, true));

                        currentSnapshot = pipelineScope.Scope("Preview");
                        currentSnapshot.SetVariables(ToVCDVariables("", head.PipelinePreview, true));

                        var stagesScope = pipelineScope.Scope("Stages");

                        foreach (var stage in pipeline.Diag.Stages)
                        {
                            var index      = pipeline.Diag.Stages.IndexOf(stage);
                            var stageScope = stagesScope.Scope($"Stage{index}");

                            currentSnapshot = stageScope.Scope("Inputs");

                            currentSnapshot = stageScope.Scope("State");
                            var stateMember = stage.GetType().GetMember("State")[0];
                            currentSnapshot.SetVariables(ToVCDVariables("", stage.StateValue));

                            currentSnapshot = stageScope.Scope("NextState");
                            var nextStateMember = stage.GetType().GetMember("NextState")[0];
                            currentSnapshot.SetVariables(ToVCDVariables("", stage.NextStateValue));

                            var managed = stage.ManagedSignals;
                            currentSnapshot = stageScope.Scope("Control");
                            currentSnapshot.SetVariables(ToVCDVariables("", managed.Control, true));

                            currentSnapshot = stageScope.Scope("Request");
                            currentSnapshot.SetVariables(ToVCDVariables("", managed.Request, true));

                            currentSnapshot = stageScope.Scope("Preview");
                            currentSnapshot.SetVariables(ToVCDVariables("", managed.Preview, true));
                        }
                    }

                    currentSnapshot = null;
                }
            }
            catch (VCDSnapshotException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ThrowVCDException(ex);
            }
        }