Esempio n. 1
0
 /// <summary>
 /// Обратные рёбра
 /// </summary>
 /// <returns>Список обратных рёбер</returns>
 public static IReadOnlyList <(BasicBlock, BasicBlock)> GetBackEdges(this ControlFlowGraph cfg)
 => new BackEdges(cfg).BackEdgesFromCFG;
Esempio n. 2
0
        public INsOUTs ExecuteNonGeneric(ControlFlowGraph g)
        {
            var blocks = g.GetCurrentBasicBlocks();
            var INs    = new Dictionary <BasicBlock, Dictionary <string, LatticeValue> >();
            var OUTs   = new Dictionary <BasicBlock, Dictionary <string, LatticeValue> >();

            var variables = new HashSet <string>();

            foreach (var block in blocks)
            {
                foreach (var instr in block.GetInstructions())
                {
                    if (CheckStr(instr.Result) && !variables.Contains(instr.Result))
                    {
                        variables.Add(instr.Result);
                    }

                    if (CheckStr(instr.Argument1) && instr.Argument1 != "True" &&
                        instr.Argument1 != "False" && !int.TryParse(instr.Argument1, out var temp1) && !variables.Contains(instr.Argument1))
                    {
                        variables.Add(instr.Argument1);
                    }

                    if (CheckStr(instr.Argument2) && instr.Argument2 != "True" && instr.Argument2 != "False" &&
                        !int.TryParse(instr.Argument2, out var temp2) && !variables.Contains(instr.Argument2))
                    {
                        variables.Add(instr.Argument2);
                    }
                }
            }
            var temp = new Dictionary <string, LatticeValue>();

            foreach (var elem in variables)
            {
                temp.Add(elem, new LatticeValue(LatticeTypeData.UNDEF));
            }

            foreach (var block in blocks)
            {
                INs.Add(block, temp.ToDictionary(entry => entry.Key, entry => entry.Value));
                OUTs.Add(block, temp.ToDictionary(entry => entry.Key, entry => entry.Value));
            }

            var Changed = true;

            while (Changed)
            {
                Changed = false;
                foreach (var block in blocks)
                {
                    var parents = g.GetParentsBasicBlocks(g.VertexOf(block)).Select(x => x.block);
                    INs[block] = parents.Select(x => OUTs[x])
                                 .Aggregate(temp.ToDictionary(entry => entry.Key, entry => entry.Value), (x, y) => Collect(x, y));
                    var newOut = Transfer(block, INs[block]);
                    if (OUTs[block].Where(entry => newOut[entry.Key] != entry.Value).Any())
                    {
                        Changed     = true;
                        OUTs[block] = newOut;
                    }
                }
            }

            return(new INsOUTs {
                IN = INs, OUT = OUTs
            });
        }
Esempio n. 3
0
 /// <summary>
 /// Приводимость графа
 /// </summary>
 public static bool IsReducibleGraph(this ControlFlowGraph cfg)
 => new BackEdges(cfg).GraphIsReducible;