Exemplo n.º 1
0
            public void SetOutputs(StallControlTestOutput expected)
            {
                var members = RTLReflectionTools.RecursiveMembers(expected.GetType());

                foreach (var m in members)
                {
                    var signalValue = m.GetValue(expected);

                    if (!signalAsserts.ContainsKey(m.Name))
                    {
                        signalAsserts[m.Name] = new List <SignalAssert>();
                    }

                    var at = offset + (currentClock) * clockDuration + 1000;

                    switch (signalValue)
                    {
                    case bool v:
                        signalAsserts[m.Name].Add(new SignalAssert()
                        {
                            value = new RTLBitArray(v), at = at
                        });
                        break;

                    case byte b:
                        signalAsserts[m.Name].Add(new SignalAssert()
                        {
                            value = new RTLBitArray(b), at = at
                        });
                        break;
                    }
                }
            }
Exemplo n.º 2
0
        public static void CarryOverAutoPropagateValues <TSource, TTarget>(TSource source, TTarget target)
        {
            var sourceType    = typeof(TSource);
            var sourceMembers = RTLReflectionTools.SynthesizableMembers(sourceType);

            var targetType    = typeof(TTarget);
            var targetMembers = RTLReflectionTools.SynthesizableMembers(targetType);

            foreach (var m in targetMembers)
            {
                var targetValue = m.GetValue(target);
                if (targetValue != null)
                {
                    return;
                }

                var sourceMember = sourceMembers.SingleOrDefault(s => s == m);
                if (sourceMember == null)
                {
                    throw new Exception($"Member value is null on target ({targetType}.{m.Name}). Source type {sourceType.Name} does not contain fallback member");
                }

                var carryOverValue = sourceMember.GetValue(source);
                if (carryOverValue == null)
                {
                    throw new Exception($"Member value is null on target ({targetType}.{m.Name}). Source type {sourceType.Name} returned null fallback value");
                }

                var backingField = getBackingField(target, m);
                backingField.SetValue(target, carryOverValue);
            }
        }
Exemplo n.º 3
0
        public static T RecurviseResetToDefaults <T>(T value)
        {
            var type = value.GetType();

            foreach (var m in RTLReflectionTools.SynthesizableMembers(type))
            {
                var memberType   = m.GetMemberType();
                var memberValue  = m.GetValue(value);
                var backingField = getBackingField(value, m);

                if (memberValue is RTLBitArray bitArray)
                {
                    backingField.SetValue(value, new RTLBitArray().Resized(bitArray.Size).TypeChanged(bitArray.DataType));
                    continue;
                }

                if (RTLModuleHelper.IsSynthesizableSignalType(memberType))
                {
                    if (RTLReflectionTools.TryGetNullableType(memberType, out var actualType))
                    {
                        backingField.SetValue(value, Activator.CreateInstance(actualType));
                    }
                    else
                    {
                        backingField.SetValue(value, Activator.CreateInstance(memberType));
                    }
                    continue;
                }

                if (RTLModuleHelper.IsSynthesizableObject(memberType))
                {
                    RecurviseResetToDefaults(memberValue);
                    continue;
                }

                if (RTLModuleHelper.IsSynthesizableArrayType(memberType))
                {
                    var emptyArray = Array.CreateInstance(memberType.GetElementType(), (memberValue as Array).Length);
                    backingField.SetValue(value, emptyArray);
                    continue;
                }
            }

            return(value);
        }
Exemplo n.º 4
0
            public void setInputs(StallControlTestPipelineModuleInputs inputs)
            {
                var members = RTLReflectionTools.RecursiveMembers(inputs.GetType());

                foreach (var m in members)
                {
                    var signalValue = (bool)m.GetValue(inputs);

                    if (!signalsValues.ContainsKey(m.Name))
                    {
                        signalsValues[m.Name] = new List <SignalValue>()
                        {
                            new SignalValue()
                            {
                                value = signalValue, duration = offset
                            }
                        };
                    }
                    else
                    {
                        var list      = signalsValues[m.Name];
                        var lastValue = list.Last();
                        if (lastValue.value != signalValue)
                        {
                            list.Add(new SignalValue()
                            {
                                value = signalValue, duration = clockDuration
                            });
                        }
                        else
                        {
                            lastValue.duration += clockDuration;
                        }
                    }
                }
            }
Exemplo n.º 5
0
        protected virtual IEnumerable <VCDVariable> ToVCDVariables(string name, object value, bool includeToolkitTypes = false)
        {
            if (value == null)
            {
                return(Enumerable.Empty <VCDVariable>());
            }

            var recursivePrefix = string.IsNullOrEmpty(name) ? "" : $"{name}_";

            switch (value)
            {
            case Enum v:
                return(new[]
                {
                    new VCDVariable($"{name}ToString", value.ToString(), VCDSizeOfValue("")),
                    new VCDVariable($"{name}", value, VCDSizeOfValue(value))
                });

            case RTLBitArray b:
                return(new[]
                {
                    new VCDVariable($"{name}", value, VCDSizeOfValue(value))
                });

            default:
                var valueType = value.GetType();
                if (value.GetType().IsClass)
                {
                    var result = new List <VCDVariable>();

                    var props = RTLReflectionTools.SynthesizableMembers(valueType, includeToolkitTypes);
                    foreach (var m in props)
                    {
                        var memberValue = m.GetValue(value) ?? RTLModuleHelper.Activate(m.GetMemberType());

                        result.AddRange(ToVCDVariables(m, memberValue, recursivePrefix));
                    }

                    return(result);
                }

                if (valueType.IsConstructedGenericType)
                {
                    var genericType = valueType.GetGenericTypeDefinition();

                    // TODO: something smarter then this
                    if (genericType.Name.StartsWith("ValueTuple`"))
                    {
                        var result = new List <VCDVariable>();

                        var props = RTLReflectionTools.SynthesizableMembers(valueType, includeToolkitTypes).Where(m => m.Name.StartsWith("Item"));
                        foreach (var m in props)
                        {
                            var memberValue = m.GetValue(value) ?? RTLModuleHelper.Activate(m.GetMemberType());

                            result.AddRange(ToVCDVariables(m, memberValue, recursivePrefix));
                        }

                        return(result);
                    }
                }

                return(new[]
                {
                    new VCDVariable($"{name}", value, VCDSizeOfValue(value))
                });
            }
        }