public void VisitSignalRef(SignalRef signalRef) { switch (signalRef.Prop) { case SignalRef.EReferencedProperty.Instance: case SignalRef.EReferencedProperty.ChangedEvent: { Result = true; SignalDescriptor sd = signalRef.Desc as SignalDescriptor; if (sd != null) { switch (signalRef.Prop) { case SignalRef.EReferencedProperty.Instance: ConstValue = sd.SignalInstance; break; case SignalRef.EReferencedProperty.ChangedEvent: ConstValue = sd.SignalInstance.ChangedEvent; break; default: throw new NotImplementedException(); } } } break; default: Result = false; break; } }
public static object DefaultEval(SignalRef signalRef, IEvaluator eval) { SignalDescriptor sd = signalRef.Desc as SignalDescriptor; if (sd == null) { throw new BreakEvaluationException(); } SignalBase sinst = sd.SignalInstance; dynamic sobj = sinst; if (signalRef.Indices != null && signalRef.Indices.Count() > 0) { foreach (Expression[] indices in signalRef.Indices) { object[] indexvs = indices.Select(x => x.Eval(eval)).ToArray(); Type[] indexts = indexvs.Select(x => x.GetType()).ToArray(); Type vtype = sobj.GetType(); PropertyInfo prop = vtype.GetProperty("Item", indexts); if (prop == null) { throw new InvalidOperationException("Indexer property not found"); } sobj = prop.GetValue(sobj, indexvs); } } switch (signalRef.Prop) { case SignalRef.EReferencedProperty.ChangedEvent: return(sobj.ChangedEvent); case SignalRef.EReferencedProperty.Cur: if (sinst.Context.State == DesignContext.ESimState.Simulation) { return(sobj.Cur); } else { return(sobj.InitialValue); } case SignalRef.EReferencedProperty.FallingEdge: if (sinst.Context.State == DesignContext.ESimState.Simulation) { return(((In <StdLogic>)sobj).FallingEdge()); } else { return(false); } case SignalRef.EReferencedProperty.RisingEdge: if (sinst.Context.State == DesignContext.ESimState.Simulation) { return(((In <StdLogic>)sobj).RisingEdge()); } else { return(false); } case SignalRef.EReferencedProperty.Instance: return(sobj); case SignalRef.EReferencedProperty.Next: throw new InvalidOperationException(); case SignalRef.EReferencedProperty.Pre: if (sinst.Context.State == DesignContext.ESimState.Simulation) { return(sobj.Pre); } else { return(sobj.InitialValue); } default: throw new NotImplementedException(); } }