Beispiel #1
0
        private bool ShouldCodeLabelBeEvaluated(CodeLabel label, int stage)
        {
            if (label.Stage == stage)
            {
                var scount = label.ScheduleCount;

                // Trace("should {0} {1}", label.OriginalGate, label.OriginalGate.GetType().Name);

                if (label.OriginalGate.Type == GateType.Input && scount > 0)
                {
                    return(true);
                }
                else if (scount > 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private void AddToGateMap(IGate gate, CodeLabel label)
        {
            gate = gate.Simplify();

            if (!_gatemap.ContainsKey(gate.ID))
            {
                _gatemap.Add(gate.ID, label);
            }
        }
Beispiel #3
0
 internal void SetLabel(int stage, CodeLabel label)
 {
     _labels[stage] = label;
 }
Beispiel #4
0
        private CodeLabel AddCodeLabel(int stage, IGate g, bool makelabels)
        {
            CodeLabel label;
            var       e = g;

            var labelkey = GetCodeLabelIdentifier(stage, g);

            if (makelabels)
            {
                e = MakeCodeLabels(stage, e);

                e = Gate.Simplify(e);
            }

            if (!_labels.ContainsKey(labelkey))
            {
                // not found in table ...
                if (null != OnBeforeAddLabel)
                {
                    // client may do something about it
                    var r = OnBeforeAddLabel(stage, e);

                    if (r != e)
                    {
                        if (_gatemap.TryGetValue(r.ID, out label))
                        {
                            return(label);
                        }
                        else
                        {
                            throw new Exception("unexpected, gate not found.");
                        }
                    }
                }
            }


            if (!_labels.TryGetValue(labelkey, out label))
            {
                if (null == label)
                {
                    // construct a new label
                    var labelindex = _lseed++;
                    //var name = "u_" + stage + "_" + labelindex;
                    var name = "_c" + labelindex;

                    var newlabel = new CodeLabel(this, stage, labelindex, name, e);

                    // Gate.TraceLabel(g, newlabel.Gate, stage + " create  {0} ...", newlabel);

                    // look for a reduced label.
                    var r  = newlabel.Gate;
                    var lg = newlabel.Gate as LabelGate;
                    if (null == lg)
                    {
                        var derivedkey = GetCodeLabelIdentifier(stage, r);

                        if (!_labels.TryGetValue(derivedkey, out label))
                        {
                            _labels[derivedkey] = newlabel;

                            Gate.TraceLabel(g, newlabel.Gate, stage + " insert <" + derivedkey + ">");

                            AddToGateMap(r, label);
                        }
                        else
                        {
                            // forget
                            newlabel = null;
                        }
                    }
                    else
                    {
                    }

                    if (null != newlabel)
                    {
                        label             = newlabel;
                        _labels[labelkey] = label;

                        AddToGateMap(label.Gate, label);

                        Gate.TraceLabel(g, newlabel.Gate, stage + " insert <" + labelkey + ">");
                    }

                    AddToGateMap(e, label);
                }
            }

            AddToGateMap(g, label);

            return(label);
        }
Beispiel #5
0
 public LabelGate(CodeLabel label)
 {
     Label = label;
 }
Beispiel #6
0
 public void Queue(CodeLabel label)
 {
     _queue.Add(label);
 }
Beispiel #7
0
 public LabelGate(CodeLabel label)
 {
     Label = label;
 }
Beispiel #8
0
        private bool ShouldCodeLabelBeEvaluated(CodeLabel label, int stage)
        {
            if (label.Stage == stage)
            {
                var scount = label.ScheduleCount;

                // Trace("should {0} {1}", label.OriginalGate, label.OriginalGate.GetType().Name);

                if (label.OriginalGate.Type == GateType.Input && scount > 0)
                {
                    return true;
                }
                else if (scount > 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
Beispiel #9
0
        private void AddToGateMap(IGate gate, CodeLabel label)
        {
            gate = gate.Simplify();

            if (!_gatemap.ContainsKey(gate.ID))
            {
                _gatemap.Add(gate.ID, label);
            }
        }
Beispiel #10
0
        private CodeLabel AddCodeLabel(int stage, IGate g, bool makelabels)
        {
            CodeLabel label;
            var e = g;

            var labelkey = GetCodeLabelIdentifier(stage, g);

            if (makelabels)
            {
                e = MakeCodeLabels(stage, e);

                e = Gate.Simplify(e);
            }

            if(!_labels.ContainsKey(labelkey))
            {
                // not found in table ...
                if (null != OnBeforeAddLabel)
                {
                    // client may do something about it
                    var r = OnBeforeAddLabel(stage, e);

                    if(r != e)
                    {
                        if(_gatemap.TryGetValue(r.ID, out label))
                        {
                            return label;
                        }
                        else
                        {
                            throw new Exception("unexpected, gate not found.");
                        }
                    }
                }
            }

            if (!_labels.TryGetValue(labelkey, out label))
            {
                if (null == label)
                {
                    // construct a new label
                    var labelindex = _lseed++;
                    //var name = "u_" + stage + "_" + labelindex;
                    var name = "_c" + labelindex;

                    var newlabel = new CodeLabel(this, stage, labelindex, name, e);

                    // Gate.TraceLabel(g, newlabel.Gate, stage + " create  {0} ...", newlabel);

                    // look for a reduced label.
                    var r = newlabel.Gate;
                    var lg = newlabel.Gate as LabelGate;
                    if (null == lg)
                    {
                        var derivedkey = GetCodeLabelIdentifier(stage, r);

                        if (!_labels.TryGetValue(derivedkey, out label))
                        {
                            _labels[derivedkey] = newlabel;

                            Gate.TraceLabel(g, newlabel.Gate, stage + " insert <" + derivedkey + ">");

                            AddToGateMap(r, label);
                        }
                        else
                        {
                            // forget
                            newlabel = null;
                        }

                    }
                    else
                    {

                    }

                    if (null != newlabel)
                    {
                        label = newlabel;
                        _labels[labelkey] = label;

                        AddToGateMap(label.Gate, label);

                        Gate.TraceLabel(g, newlabel.Gate, stage + " insert <" + labelkey + ">");
                    }

                    AddToGateMap(e, label);
                }
            }

            AddToGateMap(g, label);

            return label;
        }
Beispiel #11
0
 public void Queue(CodeLabel label)
 {
     _queue.Add(label);
 }