예제 #1
0
        public void StageSchedule(Func <TInput> inputsFactory)
        {
            this.inputsFactory = inputsFactory;

            if (State == null && NextState == null)
            {
                var stageInputs     = inputsFactory();
                var nextStageInputs = inputsFactory();

                if (stageMap != null)
                {
                    State     = RTLPipelineStageTools.RecurviseResetToDefaults(stageMap(stageInputs));
                    NextState = RTLPipelineStageTools.RecurviseResetToDefaults(stageMap(nextStageInputs));
                }
                else if (stageMapWithState != null)
                {
                    var virtualState = RTLModuleHelper.Activate <TOutput>();
                    rtlModule.OnRelatedObjectCreating(virtualState);

                    State = RTLPipelineStageTools.RecurviseResetToDefaults(stageMapWithState(stageInputs, virtualState));

                    var virtualNextState = RTLModuleHelper.Activate <TOutput>();
                    rtlModule.OnRelatedObjectCreating(virtualNextState);

                    NextState = RTLPipelineStageTools.RecurviseResetToDefaults(stageMapWithState(nextStageInputs, virtualNextState));
                }
                else if (stageMapWithStateAndControl != null)
                {
                    var virtualState = RTLModuleHelper.Activate <TOutput>();
                    rtlModule.OnRelatedObjectCreating(virtualState);

                    State = RTLPipelineStageTools.RecurviseResetToDefaults(stageMapWithStateAndControl(stageInputs, virtualState, ManagedSignals));

                    var virtualNextState = RTLModuleHelper.Activate <TOutput>();
                    rtlModule.OnRelatedObjectCreating(virtualNextState);

                    NextState = RTLPipelineStageTools.RecurviseResetToDefaults(stageMapWithStateAndControl(nextStageInputs, virtualNextState, ManagedSignals));
                }
                else
                {
                    throw new Exception($"Pipeline stage is not initialized with scheduling method");
                }

                RTLPipelineStageTools.CarryOverAutoPropagateValues(stageInputs, State);
                rtlModule.OnRelatedObjectCreating(State);

                RTLPipelineStageTools.CarryOverAutoPropagateValues(nextStageInputs, NextState);
                rtlModule.OnRelatedObjectCreating(NextState);
            }

            nextStage?.StageSchedule(() => State);
        }
예제 #2
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))
                });
            }
        }