Esempio n. 1
0
        /// <summary>
        /// Build Shingle blocks from the graph. An instruction can only be
        /// in one block at a time, so at each point in the graph where the
        /// successors > 1 or the predecessors > 1, we create a new node.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="instructions"></param>
        /// <returns></returns>
        public SortedList <Address, ShingleBlock> BuildBlocks(
            DiGraph <Address> g,
            SortedList <Address, MachineInstruction> instructions)
        {
            // Remember, the graph is backwards!
            var activeBlocks = new List <ShingleBlock>();
            var allBlocks    = new SortedList <Address, ShingleBlock>();
            var wl           = instructions.Keys.ToSortedSet();

            while (wl.Count > 0)
            {
                var addr = wl.First();
                wl.Remove(addr);
                var instr = instructions[addr];
                var block = new ShingleBlock {
                    BaseAddress = addr
                };
                allBlocks.Add(addr, block);
                bool terminateNow      = false;
                bool terminateDeferred = false;
                for (;;)
                {
                    var addrInstrEnd = instr.Address + instr.Length;
                    if ((instr.InstructionClass & InstructionClass.Transfer) != 0)
                    {
                        if ((instr.InstructionClass & DT) == DT)
                        {
                            terminateDeferred = true;
                        }
                        else
                        {
                            terminateNow = true;
                        }
                    }
                    else
                    {
                        terminateNow = terminateDeferred;
                    }
                    if (terminateNow ||
                        !wl.Contains(addrInstrEnd) ||
                        !g.Nodes.Contains(addrInstrEnd) ||
                        g.Successors(addrInstrEnd).Count != 1)
                    {
                        block.EndAddress = addrInstrEnd;
                        break;
                    }

                    wl.Remove(addrInstrEnd);
                    instr        = instructions[addrInstrEnd];
                    terminateNow = terminateDeferred;
                }
            }
            return(allBlocks);
        }
Esempio n. 2
0
        /// <summary>
        /// Build Shingle blocks from the graph. An instruction can only be 
        /// in one block at a time, so at each point in the graph where the 
        /// successors > 1 or the predecessors > 1, we create a new node.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="instructions"></param>
        /// <returns></returns>
        public SortedList<Address,ShingleBlock> BuildBlocks(
            DiGraph<Address> g,
            SortedList<Address,MachineInstruction> instructions)
        {
            // Remember, the graph is backwards!
            var activeBlocks = new List<ShingleBlock>();
            var allBlocks = new SortedList<Address, ShingleBlock>();
            var wl = instructions.Keys.ToSortedSet();
            while (wl.Count > 0)
            {
                var addr = wl.First();
                wl.Remove(addr);
                var instr = instructions[addr];
                var block = new ShingleBlock { BaseAddress = addr };
                allBlocks.Add(addr, block);
                bool terminateNow = false;
                bool terminateDeferred = false;
                for (;;)
                {
                    var addrInstrEnd = instr.Address + instr.Length;
                    if ((instr.InstructionClass & InstructionClass.Transfer) != 0)
                    {
                        if ((instr.InstructionClass & DT) == DT)
                        {
                            terminateDeferred = true;
                        }
                        else
                        {
                            terminateNow = true;
                        }
                    }
                    else
                    {
                        terminateNow = terminateDeferred;
                    }
                    if (terminateNow || 
                        !wl.Contains(addrInstrEnd) ||
                        !g.Nodes.Contains(addrInstrEnd) || 
                        g.Successors(addrInstrEnd).Count != 1)
                    {
                        block.EndAddress = addrInstrEnd;
                        break;
                    }

                    wl.Remove(addrInstrEnd);
                    instr = instructions[addrInstrEnd];
                    terminateNow = terminateDeferred;
                }
            }
            return allBlocks;
        }