public EncodedFlow(List<Flow> flows, int order)
        {
            Contract.Requires(flows != null && flows.Any());
            Contract.Requires(flows.All(f => f.Target.Equals(flows.First().Target)));

            Targets = new SignalRef[] { flows.First().Target };
            EncodedSymbols = new int[flows.Count];
            Order = order;
            _bwdEnc = new List<ParFlow>();
            int i = 0;
            foreach (var flow in flows)
            {
                int sym = 0;
                if (!FlowMatrix.IsDontCareFlow(flow))
                {
                    var vflow = flow as ValueFlow;
                    Flow cflow;
                    if (vflow != null)
                        cflow = FlowMatrix.AsDontCareFlow(vflow);
                    else
                        cflow = flow;
                    var cpflow = new ParFlow(new Flow[] { cflow });
                    if (!_fwdEnc.TryGetValue(cpflow, out sym))
                    {
                        sym = ++NumSymbols;
                        _fwdEnc[cpflow] = sym;
                        _bwdEnc.Add(new ParFlow(new Flow[] { cflow }));
                    }
                }
                EncodedSymbols[i] = sym;
                i++;
            }
            if (_bwdEnc.Count == 0)
            {
                var dummy = new ParFlow();
                _bwdEnc.Add(dummy);
                _fwdEnc[dummy] = 1;
                NumSymbols = 1;
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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;
            }
        }
示例#5
0
 public override Expression TransformLiteralReference(LiteralReference expr)
 {
     var sref = expr.ReferencedObject as SignalRef;
     if (sref != null)
     {
         var iaa = sref.Indices.Select(ia => ia.Select(i => MakeIntegerResult(i.Accept(this))).ToArray());
         sref = new SignalRef(
             sref.Desc,
             sref.Prop,
             iaa,
             sref.IndexSample,
             sref.IsStaticIndex);
         expr = new LiteralReference(sref, expr.Mode);
     }
     return expr;
 }
 public object DefaultEvalSignalRef(SignalRef signalRef)
 {
     return SignalRef.DefaultEval(signalRef, this);
 }
示例#7
0
 /// <summary>
 /// Removes the dataflow targeting specified signal at specified c-step
 /// </summary>
 /// <param name="cstep">the c-step</param>
 /// <param name="target">target to which dataflow is to be removed</param>
 public void Remove(int cstep, SignalRef target)
 {
     _graphs[cstep].Remove(target);
 }
 /// <summary>
 /// Constructs a concurrent statement.
 /// </summary>
 /// <param name="targetSignal">signal transfer target</param>
 /// <param name="sourceExpression">transfer expression</param>
 public ConcurrentStatement(SignalRef targetSignal, Expression sourceExpression)
 {
     TargetSignal = targetSignal;
     SourceExpression = sourceExpression;
 }
示例#9
0
 public IEnumerable<Flow> GetFlowsTo(SignalRef target)
 {
     Flow flow;
     if (_flows.TryGetValue(target, out flow))
         return Enumerable.Repeat(flow, 1);
     else
         return Enumerable.Empty<Flow>();
 }
示例#10
0
 /// <summary>
 /// Creates a dataflow which transfers the "don't care" literal to a signal target of choice
 /// </summary>
 /// <param name="target">signal target</param>
 /// <returns>the resulting dataflow</returns>
 public static ValueFlow CreateDontCareFlow(SignalRef target)
 {
     return new ValueFlow(StdLogicVector.DCs(
         Marshal.SerializeForHW(target.Desc.InitialValue).Size), target);
 }
 private IEnumerable<SignalArgumentDescriptor> InspectMethod(MethodDescriptor md)
 {
     List<Statement> stmts = md.Implementation.Body.GetAtomicStatements();
     IEnumerable<StoreStatement> stores = stmts.Select(s => s as StoreStatement).Where(s => s != null);
     Dictionary<ISignalOrPortDescriptor, SignalArgumentDescriptor> map =
         new Dictionary<ISignalOrPortDescriptor, SignalArgumentDescriptor>();
     int order = md.GetArguments().Count();
     foreach (StoreStatement stmt in stores)
     {
         SignalRef sref = stmt.Container as SignalRef;
         if (sref == null)
             continue;
         if (sref.Desc is SignalArgumentDescriptor)
             continue;
         SignalArgumentDescriptor sad;
         if (!map.TryGetValue(sref.Desc, out sad))
         {
             string name = "a_" + sref.Desc.Name;
             SignalDescriptor sd = sref.Desc as SignalDescriptor;
             PortDescriptor pd = sref.Desc as PortDescriptor;
             SignalBase signalInst;
             if (pd != null)
                 signalInst = ((SignalDescriptor)pd.BoundSignal).Instance;
             else
                 signalInst = sd.Instance;
             ArgumentDescriptor.EArgDirection flowDir;
             if (pd == null)
             {
                 flowDir = ArgumentDescriptor.EArgDirection.InOut;
             }
             else
             {
                 switch (pd.Direction)
                 {
                     case EFlowDirection.In:
                         flowDir = ArgumentDescriptor.EArgDirection.In;
                         break;
                     case EFlowDirection.InOut:
                         flowDir = ArgumentDescriptor.EArgDirection.InOut;
                         break;
                     case EFlowDirection.Out:
                         flowDir = ArgumentDescriptor.EArgDirection.Out;
                         break;
                     default:
                         throw new NotImplementedException();
                 }
             }
             sad = new SignalArgumentDescriptor(
                 SignalRef.Create(sref.Desc, SignalRef.EReferencedProperty.Instance),
                 ArgumentDescriptor.EArgDirection.In,
                 flowDir,
                 EVariability.Constant,
                 order++);
             map[sref.Desc] = sad;
         }
         SignalRef srefArg = new SignalRef(sad, sref.Prop, sref.Indices, sref.IndexSample, sref.IsStaticIndex);
         stmt.Container = srefArg;
     }
     foreach (SignalArgumentDescriptor sad in map.Values)
         md.AddChild(sad, sad.Argument.Name);
     return map.Values.OrderBy(k => k.Order);
 }
示例#12
0
 public int GetValueWordWidth(SignalRef target)
 {
     return _widthMap[target];
 }
示例#13
0
 public int GetValueWordOffset(SignalRef target)
 {
     return _offsetMap[target];
 }
        public override bool Rewrite(
            CodeDescriptor decompilee,
            MethodBase callee,
            StackElement[] args,
            IDecompiler stack,
            IFunctionBuilder builder)
        {
            if (args.Length < 2)
                throw new InvalidOperationException("The attribute SignalIndexer was applied to the wrong method");

            LiteralReference refExpr = args[0].Expr as LiteralReference;
            if (refExpr == null)
                throw new InvalidOperationException("Unable to resolve port/signal reference expression");

            DimSpec[] dimSamples = new DimSpec[args.Length - 1];
            Expression[] indices = args.Skip(1).Select(arg => arg.Expr).ToArray();
            bool isStatic = true;
            for (int i = 1; i < args.Length; i++)
            {
                var convidx = TypeConversions.ConvertValue(args[i].Sample, typeof(int));
                if (convidx != null)
                {
                    dimSamples[i - 1] = (int)convidx;
                }
                else if (args[i].Sample is Range)
                {
                    dimSamples[i - 1] = (Range)args[i].Sample;
                }
                else
                {
                    dimSamples = null;
                    break;
                }

                // EVariability.LocalVariable is not static as well, since variables
                // inside for loops will have that variability.
                if (args[i].Variability != EVariability.Constant)
                    isStatic = false;
            }
            IndexSpec indexSpec = null;
            indexSpec = new IndexSpec(dimSamples);

            SignalRef sigRef = null;
            LambdaLiteralVisitor llv = new LambdaLiteralVisitor()
            {
                OnVisitConstant = x =>
                {
                    sigRef = new SignalRef(
                        ((SignalBase)x.ConstantValue).Descriptor,
                        SignalRef.EReferencedProperty.Instance,
                        new Expression[][] { indices }, indexSpec, isStatic);
                },
                OnVisitFieldRef = x => { throw new InvalidOperationException(); },
                OnVisitSignalRef = x =>
                {
                    sigRef = new SignalRef(
                        x.Desc,
                        x.Prop,
                        x.Indices.Concat(new Expression[][] { indices }),
                        indexSpec.Project(x.IndexSample),
                        x.IsStaticIndex && isStatic);
                },
                OnVisitVariable = x => { throw new InvalidOperationException(); },
                OnVisitThisRef = x => { throw new InvalidOperationException(); }
            };
            refExpr.ReferencedObject.Accept(llv);

            object rsample = null;

            Type[] argTypes = args
                .Skip(1)
                .Select(a => a.Expr.ResultType.CILType)
                .ToArray();
            object[] argSamples = args
                .Select(a => a.Sample)
                .ToArray();
            MethodInfo indexerSampleMethod = callee.DeclaringType.GetMethod(
                "GetIndexerSample",
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                argTypes,
                null);
            if (indexerSampleMethod != null && argSamples.All(a => a != null))
            {
                rsample = indexerSampleMethod.Invoke(argSamples);
            }
            else
            {
                try
                {
                    rsample = callee.Invoke(args.Select(x => x.Sample).ToArray());
                }
                catch (TargetInvocationException)
                {
                }
            }
            stack.Push(sigRef, rsample);
            return true;
        }
示例#15
0
 /// <summary>
 /// Returns all dataflows targeting specified signal, regardless of their activation times.
 /// </summary>
 /// <param name="target">signal target to query for</param>
 /// <returns>all dataflows targeting specified signal</returns>
 public IEnumerable<Flow> GetFlowsTo(SignalRef target)
 {
     return _graphs.SelectMany(g => g.GetFlowsTo(target))
         .Union(_neutral.GetFlowsTo(target))
         .Distinct();
 }
        public override IStorableLiteral ImplementDeclaration(CodeDescriptor container, object sample, ParameterInfo pi)
        {
            var signal = sample as SignalBase;
            if (signal == null)
                throw new ArgumentException("Signal instance null");

            Type etype = pi.ParameterType;
            ArgumentDescriptor.EArgDirection flowDir;
            if (typeof(IInOutPort).IsAssignableFrom(etype))
                flowDir = ArgumentDescriptor.EArgDirection.InOut;
            else if (typeof(IInPort).IsAssignableFrom(etype))
                flowDir = ArgumentDescriptor.EArgDirection.In;
            else if (typeof(IOutPort).IsAssignableFrom(etype))
                flowDir = ArgumentDescriptor.EArgDirection.Out;
            else
                throw new NotImplementedException();

            var sref = new SignalRef(signal.Descriptor, SignalRef.EReferencedProperty.Instance);

            SignalArgumentDescriptor desc = new SignalArgumentDescriptor(
                sref,
                ArgumentDescriptor.EArgDirection.In,
                flowDir,
                EVariability.Constant,
                pi.Position);
            container.AddChild(desc, sref.Name);

            return sref;
        }
示例#17
0
 public void Remove(SignalRef target)
 {
     _flows.Remove(target);
     Debug.Assert(_flows.Values.All(f => f is ValueFlow || !((SignalFlow)f).Source.Equals(target)));
 }
 public void VisitSignalRef(SignalRef signalRef)
 {
     _result = signalRef;
 }
示例#19
0
 private static SignalRef DieWithUnknownSensitivityIfNull(SignalRef sref)
 {
     if (sref == null)
         throw new InvalidOperationException("Sensitivity signal unknown to declaring component");
     return sref;
 }
示例#20
0
 public object EvalSignalRef(SignalRef signalRef)
 {
     return DoEvalSignalRef(signalRef);
 }
示例#21
0
                public void VisitSignalRef(SignalRef signalRef)
                {
                    ISignalOrPortDescriptor desc = signalRef.Desc;
                    SignalRef remappedRef = signalRef.AssimilateIndices();
                    if (_vhdg._curComponent != null && 
                        !(signalRef.Desc is SignalArgumentDescriptor))
                    {
                        remappedRef = signalRef.RelateToComponent(_vhdg._curComponent);
                        if (remappedRef == null)
                            throw new InvalidOperationException("Referenced signal unknown to declaring component");
                    }
                    string name = remappedRef.Name;
                    StringBuilder sb = new StringBuilder();
                    var udesc = desc.GetUnindexedContainer();
                    sb.Append(_vhdg.MakeIDName(name, udesc.GetBoundSignal()));
                    if (!remappedRef.IsStaticIndex ||
                        !remappedRef.IndexSample.Equals(udesc.ElementType.Index))
                    {
                        foreach (Expression[] indexSpec in remappedRef.GetFullIndices())
                        {
                            if (indexSpec.Length == 0)
                                continue;

                            sb.Append("(");
                            bool first = true;
                            foreach (Expression index in indexSpec.Reverse())
                            {
                                if (first)
                                    first = false;
                                else
                                    sb.Append(", ");
                                sb.Append(index.ToString(_vhdg));
                            }
                            sb.Append(")");
                        }
                    }
                    switch (signalRef.Prop)
                    {
                        case SignalRef.EReferencedProperty.ChangedEvent:
                            Result = "-- changed event not supported";
                            break;

                        case SignalRef.EReferencedProperty.Cur:
                        case SignalRef.EReferencedProperty.Instance:
                        case SignalRef.EReferencedProperty.Next:
                            Result = sb.ToString();
                            break;

                        case SignalRef.EReferencedProperty.Pre:
                            sb.Append("'pre");
                            Result = sb.ToString();
                            break;

                        case SignalRef.EReferencedProperty.RisingEdge:
                            Result = "rising_edge(" + sb.ToString() + ")";
                            break;

                        case SignalRef.EReferencedProperty.FallingEdge:
                            Result = "falling_edge(" + sb.ToString() + ")";
                            break;

                        default:
                            throw new NotImplementedException();
                    }
                }
示例#22
0
 public void VisitSignalRef(SignalRef signalRef)
 {
     OnVisitSignalRef(signalRef);
 }
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="prop">kind of property being represented</param>
 public SignalProperty(SignalRef.EReferencedProperty prop)
 {
     Prop = prop;
 }
示例#24
0
 public void VisitSignalRef(SignalRef signalRef)
 {
     OnVisitSignalRef(signalRef);
 }
        public override bool Rewrite(
            CodeDescriptor decompilee,
            MethodBase callee,
            StackElement[] args,
            IDecompiler stack,
            IFunctionBuilder builder)
        {
            if (args.Length == 0)
                throw new InvalidOperationException("The attribute SignalProperty was applied to the wrong method");

            LiteralReference refExpr = args[0].Expr as LiteralReference;
            if (refExpr == null)
                throw new InvalidOperationException("Unable to resolve port/signal reference expression");

            ISignal sigSample = args[0].Sample as ISignal;

            SignalRef sigRef = null;
            LambdaLiteralVisitor llv = new LambdaLiteralVisitor()
            {
                OnVisitConstant = x =>
                {
                    sigRef = ((ISignal)x.ConstantValue).ToSignalRef(Prop);
                },
                OnVisitSignalRef = x =>
                {
                    sigRef = new SignalRef(x.Desc, Prop, x.Indices, x.IndexSample, x.IsStaticIndex);
                },
                OnVisitVariable = x =>
                {
                    SignalArgumentDescriptor desc = decompilee.GetSignalArguments().Where(y => y.Name.Equals(x.Name)).Single();
                    sigRef = new SignalRef(desc, Prop);
                },
                OnVisitFieldRef = x =>
                {
                    sigRef = ((ISignal)x.FieldDesc.ConstantValue).ToSignalRef(Prop);
                },
                OnVisitThisRef = x => { throw new InvalidOperationException(); },
                OnVisitArrayRef = x => { throw new InvalidOperationException(); }
            };
            refExpr.ReferencedObject.Accept(llv);

            ParameterInfo[] pis = callee.GetParameters();
            switch (Prop)
            {
                case SignalRef.EReferencedProperty.ChangedEvent:
                case SignalRef.EReferencedProperty.Cur:
                case SignalRef.EReferencedProperty.FallingEdge:
                case SignalRef.EReferencedProperty.Pre:
                case SignalRef.EReferencedProperty.RisingEdge:
                    //if (pis.Length != 0 || callee.IsStatic)
                    //    throw new InvalidOperationException("The attribute SignalProperty was applied to the wrong method.");

                    switch (Prop)
                    {
                        case SignalRef.EReferencedProperty.Cur:
                        case SignalRef.EReferencedProperty.Pre:
                            stack.Push(
                                sigRef,
                                sigSample != null ? sigSample.InitialValueObject : null);
                            break;

                        case SignalRef.EReferencedProperty.ChangedEvent:
                            stack.Push(
                                sigRef,
                                null);
                            break;

                        case SignalRef.EReferencedProperty.FallingEdge:
                        case SignalRef.EReferencedProperty.RisingEdge:
                            stack.Push(
                                sigRef,
                                false);
                            break;

                        default:
                            throw new NotImplementedException();
                    }
                    break;

                case SignalRef.EReferencedProperty.Next:
                    if (pis.Length != 1 || callee.IsStatic)
                        throw new InvalidOperationException("The attribute SignalProperty was applied to the wrong method.");

                    builder.Store(sigRef, args[1].Expr);
                    decompilee.AddDrivenSignal(sigRef.Desc);
                    break;

                default:
                    throw new NotImplementedException();
            }
            return true;
        }
示例#26
0
 /// <summary>
 /// Constructs a signal reference literal, based on another one.
 /// </summary>
 /// <param name="other">signal reference literal to copy from</param>
 public SignalRef(SignalRef other)
 {
     Desc = other.Desc;
     Prop = other.Prop;
     Indices = new List<Expression[]>(other.Indices);
     IndexSample = other.IndexSample;
     IsStaticIndex = other.IsStaticIndex;
 }
 public override void RewriteRead(CodeDescriptor decompilee, FieldInfo field, object instance, IDecompiler stack, IFunctionBuilder builder)
 {
     SignalBase sigInst = (SignalBase)field.GetValue(instance);
     SignalRef sigRef = new SignalRef(sigInst.Descriptor, SignalRef.EReferencedProperty.Instance);
     stack.Push(sigRef, sigInst);
 }
示例#28
0
        private IEnumerable<ITimedFlow> ConstructNetwork(SignalRef target, IEnumerable<ITimedFlow> flows)
        {
            var groupedByDelay = flows
                .GroupBy(tf => tf is TimedSignalFlow ? ((TimedSignalFlow)tf).Delay : 0)
                .OrderBy(grp => grp.Key);
            var curTarget = target;
            int remainingFanIn = flows.Count();
            long generation = 0;
            var pumpOut = new List<SignalFlow>();
            foreach (var delayGroup in groupedByDelay)
            {
                foreach (var tflow in delayGroup)
                {
                    var tsf = tflow as TimedSignalFlow;
                    var tvf = tflow as TimedValueFlow;
                    if (tsf != null)
                    {
                        long flowDelay = tsf.Delay - generation;
                        if (flowDelay == 0)
                        {
                            yield return new TimedSignalFlow(tsf.Source, curTarget, tsf.Time, 0);
                        }
                        else
                        {
                            SignalBase tmpSig = Signals.CreateInstance(tsf.Source.Desc.InitialValue);
                            tmpSig.Descriptor.TagTemporary(_tmpIdx++);
                            yield return new TimedSignalFlow(
                                tsf.Source, 
                                tmpSig.ToSignalRef(SignalRef.EReferencedProperty.Next), 
                                tsf.Time, 0);
                            yield return new TimedSignalFlow(
                                tmpSig.ToSignalRef(SignalRef.EReferencedProperty.Cur),
                                curTarget,
                                tsf.Time + flowDelay, 0);
                        }
                        long start = tsf.Time + tsf.Delay;
                        foreach (var pump in pumpOut)
                        {
                            yield return new TimedSignalFlow(pump.Source, pump.Target, start, 0);
                            start--;
                        }
                    }
                    else
                    {
                        // remark: as of now, delay is always 0
                        yield return new TimedValueFlow(tvf.Value, curTarget, tvf.Time);
                    }
                }
                long delay = delayGroup.Key;
                remainingFanIn -= delayGroup.Count();
#if false
                if (remainingFanIn > 1)
                {
                    var stageInSignal = _binder.GetSignal(EPortUsage.Default,
                        "icn_" + target.Desc.Name + "_" + generation + "_in",
                        null,
                        target.Desc.InitialValue);
                    var stageOutSignal = _binder.GetSignal(EPortUsage.Default,
                        "icn_" + target.Desc.Name + "_" + generation + "_out",
                        null,
                        target.Desc.InitialValue);
                    _stageInSignals.Add(stageInSignal);
                    _stageOutSignals.Add(stageOutSignal);
                    var pumpSource = new SignalRef(stageOutSignal.ToSignalRef(SignalRef.EReferencedProperty.Cur));
                    pumpOut.Add(new SignalFlow(pumpSource, curTarget));
                    curTarget = new SignalRef(stageInSignal.ToSignalRef(SignalRef.EReferencedProperty.Next));
                    ++generation;
                }
#endif
            }
        }
示例#29
0
            public void VisitSignalRef(SignalRef signalRef)
            {
                ISignalOrPortDescriptor desc = signalRef.Desc;
                SignalRef remappedRef = signalRef;
                if (_SysCg._curComponent != null &&
                    !(signalRef.Desc is SignalArgumentDescriptor))
                {
                    /*
                    desc = _SysCg._curComponent.FindSignalOrPort(signalRef.Desc);
                    if (desc == null)
                        throw new InvalidOperationException("Referenced signal unknown to declaring component");
                     * */
                    remappedRef = signalRef.RelateToComponent(_SysCg._curComponent);
                    if (remappedRef == null)
                        throw new InvalidOperationException("Referenced signal unknown to declaring component");
                }
                string name = remappedRef.Name;

                string[] aux;
                StringBuilder sb = new StringBuilder();
                StringBuilder sb1 = new StringBuilder();
                var udesc = desc.GetUnindexedContainer();
                sb.Append(_SysCg.MakeIDName(name, desc.GetUnindexedContainer().GetBoundSignal()));
                if (!remappedRef.IsStaticIndex ||
                        !remappedRef.IndexSample.Equals(udesc.ElementType.Index))
                {
                    foreach (Expression[] indexSpec in remappedRef.GetFullIndices())
                    {
                        if (indexSpec.Length == 0)
                            continue;

                        bool first = true;
                        foreach (Expression index in indexSpec)
                        {
                            if (first)
                                first = false;
                            else
                                sb.Append(", ");
                            //sb.Append(index.ToString(_SysCg));
                            aux = index.ToString(_SysCg).Split(' ');
                            if (aux.Length == 3)
                                sb1.Append("(" + aux[0] + ", " + aux[2] + ")");
                            else
                            if (aux.Length == 1)
                                sb1.Append("[" + aux[0] + "]");
                            //else
                            //    sb.Append("Erro na geracao de incdices!");
                        }
                    }
                }
                //sb.Append(")");
                switch (signalRef.Prop)
                {
                    case SignalRef.EReferencedProperty.ChangedEvent:
                        sb.Append(".event()");
                        Result = sb.ToString();
                        break;

                    case SignalRef.EReferencedProperty.Cur:
                        if (desc.ElementType.CILType.IsArray)
                        {
                            if (sb1.Length > 0)
                                sb.Append(sb1);
                            sb.Append(".read()");
                        }
                        else
                        {
                            sb.Append(".read()");
                            if (sb1.Length > 0)
                                sb.Append(sb1);
                        }                       
                        Result = sb.ToString();
                        break;
                    case SignalRef.EReferencedProperty.Instance:
                    case SignalRef.EReferencedProperty.Next:
                        sb.Append(sb1);
                        Result = sb.ToString();
                        break;

                    case SignalRef.EReferencedProperty.Pre:
                    //sb.Append("'pre");
                    //Result = sb.ToString();
                    //break;

                    case SignalRef.EReferencedProperty.RisingEdge:
                        Result = sb.ToString() + ".posedge()";
                        break;

                    case SignalRef.EReferencedProperty.FallingEdge:
                        Result = sb.ToString() + ".negedge()";
                        break;

                    default:
                        throw new NotImplementedException();
                }
            }