public VarInfoTable Transfer(BasicBlock basicBlock, VarInfoTable input, ILatticeOperations <VarInfoTable> ops)
        {
            var table = input.Copy();

            VarInfo Get(Expr e)
            {
                if (e is IntConst c)
                {
                    return(new VarInfo(VarInfo.Flag.Const, c.Num));
                }
                if (e is Var v)
                {
                    return(table[v.Id].Copy());
                }
                return(new VarInfo(VarInfo.Flag.NAC));
            }

            foreach (var line in basicBlock.CodeList.OfType <Assign>())
            {
                if (line.Left is null)
                {
                    table[line.Result.Id] = Get(line.Right);
                }
                else
                {
                    var vi1 = Get(line.Right);
                    var vi2 = Get(line.Left);

                    table[line.Result.Id] = VarInfo.MergeBin(vi1, vi2, line.Operation);
                }
            }
            return(table);
        }
Beispiel #2
0
        public HashSet <Guid> Transfer(BasicBlock basicBlock, HashSet <Guid> input, ILatticeOperations <HashSet <Guid> > ops)
        {
            var(e_gen, e_kill) = GetEGenEKill(basicBlock);
            var inset = new HashSet <Guid>(input);

            return(new HashSet <Guid>(inset.Except(e_kill).Union(e_gen)));
        }
 public IterativeAlgorithm(ILatticeOperations <VarInfoTable> ops)
 {
     base.Finish = (x, y) => VarInfoTable.AreEqual(x.Item2, y.Item2);
     base.Fill   = () => (ops.Upper, ops.Upper);
 }
Beispiel #4
0
        public Dictionary <Guid, VarValue> Transfer(BasicBlock basicBlock, Dictionary <Guid, VarValue> input, ILatticeOperations <Dictionary <Guid, VarValue> > ops)
        {
            var res = input.ToDictionary(entry => entry.Key, entry => entry.Value);

            foreach (var node in basicBlock.CodeList)
            {
                if (node is Assign)
                {
                    var asNode = node as Assign;
                    if (asNode.Left == null && asNode.Right is IntConst)
                    {
                        res[asNode.Result.Id] = new VarValue(asNode.Right as IntConst);
                    }
                    if (asNode.Left != null && asNode.Right != null)
                    {
                        if ((asNode.Left is IntConst || res[(asNode.Left as Var).Id].varType == VarValue.Type.CONST) &&
                            (asNode.Right is IntConst || res[(asNode.Right as Var).Id].varType == VarValue.Type.CONST))
                        {
                            var left  = new VarValue();
                            var right = new VarValue();

                            if (asNode.Left is IntConst)
                            {
                                left = new VarValue(asNode.Left as IntConst);
                            }
                            else
                            {
                                left = res[(asNode.Left as Var).Id];
                            }

                            if (asNode.Right is IntConst)
                            {
                                right = new VarValue(asNode.Right as IntConst);
                            }
                            else
                            {
                                right = res[(asNode.Right as Var).Id];
                            }

                            res[asNode.Result.Id] = VarValue.UseOperation(left, right, asNode.Operation);
                        }
                        else if (asNode.Left is Var && res[(asNode.Left as Var).Id].varType == VarValue.Type.NAC ||
                                 asNode.Right is Var && res[(asNode.Right as Var).Id].varType == VarValue.Type.NAC)
                        {
                            res[asNode.Result.Id] = new VarValue(asNode.Result);
                        }

                        else
                        {
                            res[asNode.Result.Id] = new VarValue();
                        }
                    }
                }
            }
            return(res);
        }
Beispiel #5
0
 public InOutData <HashSet <Guid> > Analyze(ControlFlowGraph graph, ILatticeOperations <HashSet <Guid> > ops, ITransferFunction <HashSet <Guid> > f)
 {
     var data = new InOutData <HashSet <Guid> >
     {
        public InOutData <Dictionary <Guid, VarValue> > Analyze(ControlFlowGraph graph, ILatticeOperations <Dictionary <Guid, VarValue> > ops, ITransferFunction <Dictionary <Guid, VarValue> > f)
        {
            var data = new InOutData <Dictionary <Guid, VarValue> >();

            foreach (var node in graph.CFGNodes)
            {
                data[node] = (ops.Lower, ops.Lower);
            }
            var outChanged = true;

            while (outChanged)
            {
                outChanged = false;
                foreach (var block in graph.CFGNodes)
                {
                    var inset = block.Parents.Aggregate(ops.Lower, (x, y)
                                                        => ops.Operator(x, data[y].Item2));
                    var outset = f.Transfer(block, inset, ops);
                    if (outset.Count == data[block].Item2.Count && !outset.Except(data[block].Item2).Any())
                    {
                        outChanged  = true;
                        data[block] = (inset, outset);
                    }
                }
            }
            return(data);
        }
Beispiel #7
0
 /// <summary>
 /// Передаточная функция
 /// </summary>
 /// <returns>OUT множество</returns>
 /// <param name="basicBlock">базовый блок</param>
 /// <param name="input">IN множество</param>
 /// <param name="ops">набор операций над решеткой</param>
 public T Transfer(BasicBlock basicBlock, T input, ILatticeOperations <T> ops)
 {
     return(this.f2.Transfer(basicBlock, this.f1.Transfer(basicBlock, input, ops), ops));
 }