public IEnumerable <ParFlow> ToFlow(int numCsteps, ParFlow neutralFlow, bool[,] pipeEnMatrix) { int muxCount = _pipeInSignals.Count; int[,] flowMatrix = new int[numCsteps, muxCount]; // 1st pass: set some arbitrary MUX selection for (int i = 0; i < numCsteps; i++) { for (int j = 0; j < muxCount; j++) { if (_preds[j].Any()) { flowMatrix[i, j] = _preds[j].First(); } else { flowMatrix[i, j] = -1; } } } // 2nd pass: reset MUX selection whenever neutral flow requires // some value transfer which is not "don't care" foreach (var flow in neutralFlow.Flows) { if (FlowMatrix.IsDontCareFlow(flow) || !_signal2Idx.IsCached(flow.Target)) { continue; } int idx = _signal2Idx[flow.Target]; for (int i = 0; i < numCsteps; i++) { flowMatrix[i, idx] = -1; } } // 3rd pass: transfer MUX reservations to matrix for (int i = 0; i < _resTable.Count; i++) { var rmap = _resTable[i]; var pi = _pipes[i]; foreach (var kvp in rmap) { flowMatrix[kvp.Key + pi.delay, pi.sink] = i; } } var pipeen = pipeEnMatrix; // last pass: convert to flows for (int i = 0; i < numCsteps; i++) { var flows = new List <Flow>(); for (int j = 0; j < muxCount; j++) { int k = flowMatrix[i, j]; if (k >= 0) { flows.Add( new SignalFlow( _pipeOutSignals[k].ToSignalRef(SignalRef.EReferencedProperty.Cur), _pipeInSignals[j].ToSignalRef(SignalRef.EReferencedProperty.Next))); } } for (int pipe = 0; pipe < _pipes.Count; pipe++) { if (!_pipes[pipe].useEn) { continue; } flows.Add( new ValueFlow( pipeen[i, pipe] ? StdLogic._1 : StdLogic._0, _pipeEnSignals[pipe].ToSignalRef(SignalRef.EReferencedProperty.Next))); } yield return(new ParFlow(flows)); } }