private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g) { if (g.Type == GateType.Input) { if (g is LabelGate) { var lg = (LabelGate)g; lg.Label.Evaluate(cg); } } else { var list = new List <IGate>(); foreach (var i in g.GetInputs()) { var u = i; var l = _gc.GetScheduledLabel(u); if (null != l) { u = l; } else { u = EvaluateRecurse(cg, u); } list.Add(u); } g = SMG.Common.Gate.Compose(g.Type, list); } return(g); }
/// <summary> /// Evaluates the label into a code generator, once. /// </summary> /// <param name="cg">The code writer.</param> public void Evaluate(ICodeLabelEvaluator cg) { if (!IsEvaluated) { EvaluateOnce(cg); IsEvaluated = true; } }
/// <summary> /// Emits code to initialize labels up to the given stage. /// </summary> /// <param name="writer">To code writer where to evaluate the labels to.</param> /// <param name="stage">Evaluate variables scheduled up to this stage.</param> public void Emit(ICodeLabelEvaluator cg, int stage) { var labels = _queue.Where(l => l.Stage <= stage).ToList(); foreach (var label in labels) { Gate.TraceLabel(label.Gate, label.OriginalGate, "emit"); label.Evaluate(cg); _queue.Remove(label); } }
private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g) { if (g.Type == GateType.Input) { if (g is LabelGate) { var lg = (LabelGate)g; lg.Label.Evaluate(cg); } } else { var list = new List<IGate>(); foreach (var i in g.GetInputs()) { var u = i; var l = _gc.GetScheduledLabel(u); if (null != l) { u = l; } else { u = EvaluateRecurse(cg, u); } list.Add(u); } g = SMG.Common.Gate.Compose(g.Type, list); } return g; }
private void EvaluateOnce(ICodeLabelEvaluator cg) { var g = EvaluateRecurse(cg, _originalgate); cg.EmitCodeLabelAssignment(Name, g); }
/// <summary> /// Emits code to initialize labels up to the given stage. /// </summary> /// <param name="writer">To code writer where to evaluate the labels to.</param> /// <param name="stage">Evaluate variables scheduled up to this stage.</param> public void Emit(ICodeLabelEvaluator cg, int stage) { var labels = _queue.Where(l => l.Stage <= stage).ToList(); foreach(var label in labels) { Gate.TraceLabel(label.Gate, label.OriginalGate, "emit"); label.Evaluate(cg); _queue.Remove(label); } }