Exemple #1
0
        public override void Process()
        {
            var movedBlocks = new HashSet <Block>();
            var stack       = new Stack <IEnumerator <Block> >();

            stack.Push(new Block[] { Block }.Cast <Block>().GetEnumerator());
            while (stack.Count != 0)
            {
                DumpBlocks(Block.Procedure);
                var e = stack.Peek();
                if (!e.MoveNext())
                {
                    stack.Pop();
                    continue;
                }
                var b = e.Current;
                if (b.Procedure == ProcNew || b == b.Procedure.ExitBlock || b.Procedure.EntryBlock.Succ[0] == b)
                {
                    continue;
                }

                trace.Verbose("PBW:     Visiting block {0}, stack depth {1}", b.DisplayName, stack.Count);
                var replacer = new IdentifierRelocator(b.Procedure.Frame, ProcNew.Frame);
                b.Procedure.RemoveBlock(b);
                ProcNew.AddBlock(b);
                b.Procedure = ProcNew;
                movedBlocks.Add(b);
                foreach (var stm in b.Statements)
                {
                    if (stm.LinearAddress == 0x00000000000009c4)
                    {
                        stm.ToString();
                    }
                    stm.Instruction = replacer.ReplaceIdentifiers(stm.Instruction);
                }
                if (b.Succ.Count > 0)
                {
                    stack.Push(b.Succ.GetEnumerator());
                }
            }
            foreach (var b in movedBlocks)
            {
                FixExitEdges(b);
                FixInboundEdges(b);
                FixOutboundEdges(b);
                //  SanityCheck(b);
            }
        }
Exemple #2
0
        public override void Process()
        {
            var movedBlocks = new HashSet <Block>();
            var stack       = new Stack <IEnumerator <Block> >();

            stack.Push(new Block[] { Block }.Cast <Block>().GetEnumerator());
            var replacer = new IdentifierRelocator(ProcNew.Frame);

            while (stack.Count != 0)
            {
                DumpBlocks(Block.Procedure);
                var e = stack.Peek();
                if (!e.MoveNext())
                {
                    stack.Pop();
                    continue;
                }
                var b = e.Current;
                if (b.Procedure == ProcNew || b == b.Procedure.ExitBlock || b.Procedure.EntryBlock.Succ[0] == b)
                {
                    continue;
                }

                DebugEx.Inform(trace, "PromoteBlock visiting block {0}, stack depth {1}", b.Name, stack.Count);
                b.Procedure.RemoveBlock(b);
                ProcNew.AddBlock(b);
                b.Procedure = ProcNew;
                movedBlocks.Add(b);
                foreach (var stm in b.Statements)
                {
                    stm.Instruction = replacer.ReplaceIdentifiers(stm.Instruction);
                }
                if (b.Succ.Count > 0)
                {
                    stack.Push(b.Succ.GetEnumerator());
                }
            }
            foreach (var b in movedBlocks)
            {
                FixExitEdges(b);
                FixInboundEdges(b);
                FixOutboundEdges(b);
            }
        }