void Initialize() { Inputs = CreateAndInitializeRelatedObject <TInput>(); InputProps = RTLModuleHelper.SignalProperties(InputsType); OutputProps = RTLModuleHelper.OutputProperties(GetType()); InternalProps = RTLModuleHelper.InternalProperties(GetType()); ModuleProps = RTLModuleHelper.ModuleProperties(GetType()); ModuleDetails = new List <RTLModuleDetails>(); var fields = ModuleProps.Where(m => RTLModuleHelper.IsField(m)); foreach (var m in fields) { var value = m.GetValue(this); if (value == null) { throw new Exception($"Field {m.Name} returns null. Module should have an instance."); } var valueType = value.GetType(); if (value is IRTLCombinationalModule module) { ModuleDetails.Add(new RTLModuleDetails() { Module = module, Member = m, Name = m.Name }); continue; } if (valueType.IsArray) { var elementType = valueType.GetElementType(); if (typeof(IRTLCombinationalModule).IsAssignableFrom(elementType)) { ModuleDetails.AddRange( (value as IEnumerable).OfType <IRTLCombinationalModule>() .Select((iteration, idx) => { return(new RTLModuleDetails() { Module = iteration, Member = m, Name = $"{m.Name}{idx}" }); })); continue; } } throw new Exception($"Field {m.Name} is not a module. Actual type is {(value?.GetType()?.Name ?? "null")}"); } }
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); } }