示例#1
0
 public DominatorsTree(ControlFlowGraph cfg)
 {
     dominators  = new Dictionary <BasicBlock, List <BasicBlock> >();
     controlFlow = cfg;
 }
示例#2
0
 public ReachingTransferFunc(ControlFlowGraph g)
 {
     Defs(g.blocks);
     Kills(g.blocks);
 }
示例#3
0
        public INsOUTs ExecuteNonGeneric(ControlFlowGraph g)
        {
            var blocks = g.blocks;
            var INs    = new Dictionary <BasicBlock, Dictionary <string, SemilatticeValue> >();
            var OUTs   = new Dictionary <BasicBlock, Dictionary <string, SemilatticeValue> >();

            var variables = new HashSet <string>();

            foreach (var block in blocks)
            {
                foreach (var instr in block.Instructions)
                {
                    if (instr.Result != "" && !instr.Result.StartsWith("#") && !instr.Result.StartsWith("L") && !variables.Contains(instr.Result))
                    {
                        variables.Add(instr.Result);
                    }

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

                    if (instr.Argument2 != "" && !instr.Argument2.StartsWith("#") && !instr.Argument2.StartsWith("L") && 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, SemilatticeValue>();

            foreach (var elem in variables)
            {
                temp.Add(elem, new SemilatticeValue(SemilatticeData.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._parents[block.Index].Select(z => z.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
            });
        }