Ejemplo n.º 1
0
        /// <summary>
        /// Првоерка цикла на естественность
        /// </summary>
        /// <param name="loop">Проверяемый цикл</param>
        /// <param name="cfg">Граф потока управления</param>
        /// <returns>
        /// Вернет флаг, естественнен ли он
        /// </returns>
        private static bool IsNaturalLoop(IReadOnlyCollection <BasicBlock> loop, ControlFlowGraph cfg)
        {
            foreach (var bblock in loop.Skip(1))
            {
                var parents = cfg.GetParentsBasicBlocks(cfg.VertexOf(bblock));
                if (parents.Count > 1)
                {
                    foreach (var parent in parents.Select(x => x.block))
                    {
                        if (!loop.Contains(parent))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Првоерка цикла на естественность
        /// </summary>
        /// <param name="loop">Проверяемый цикл</param>
        /// <param name="cfg">Граф потока управления</param>
        /// <returns>
        /// Вернет флаг, естественнен ли он
        /// </returns>
        private static bool IsNaturalLoop(List <BasicBlock> loop, ControlFlowGraph cfg)
        {
            for (var i = 1; i < loop.Count; i++)
            {
                var parents = cfg.GetParentsBasicBlocks(cfg.VertexOf(loop[i]));
                if (parents.Count > 1)
                {
                    foreach (var parent in parents.Select(x => x.block))
                    {
                        if (!loop.Contains(parent))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
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
            });
        }