Ejemplo n.º 1
0
        /// <summary>
        /// Recursive function to populate the reachable basic blocks list.
        /// </summary>
        /// <param name="actual">Actual BasicBlock to start from (exclusive)</param>
        /// <param name="direction">The direction to go to while collecting reachable basic blocks</param>
        private static void recursive(BasicBlock actual, Common.Direction direction)
        {
            DoneIDs.Add(actual.ID);
            //If it's not the last or the first basic block, then we add then to the list
            //Both had to be out of the list to avoid problems during data analysis
            if (actual.getPredecessors.Count > 0 && actual.getSuccessors.Count > 0)
            {
                ReachableBasicBlocks.Add(actual);
            }

            List <BasicBlock> bblist = (direction == Common.Direction.Up) ? actual.getPredecessors : actual.getSuccessors;

            foreach (BasicBlock block in bblist)
            {
                if (!DoneIDs.Contains(block.ID))
                {
                    recursive(block, direction);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to get all the reachable basic blocks by the actual basic block.
        /// </summary>
        /// <param name="actual">Actual BasicBlock to start from (exclusive)</param>
        /// <param name="direction">The direction to go to while collecting reachable basic blocks</param>
        public static List <BasicBlock> GetReachableBasicBlocks(BasicBlock actual, Common.Direction direction)
        {
            /*
             * Cleaning the done_ids and reachable_basic_blocks lists, so they won't be influenced by the algorithm's
             * previous runs (if these exist).
             */
            DoneIDs.Clear();
            ReachableBasicBlocks.Clear();

            /*
             * Populating the list
             */
            recursive(actual, direction);
            ReachableBasicBlocks = ReachableBasicBlocks.Distinct().ToList();
            ReachableBasicBlocks.Remove(actual);

            /*
             * In the end we clear the done_ids list, so it won't influence the algorithm's
             * future runs (if these will exist).
             */
            DoneIDs.Clear();
            return(ReachableBasicBlocks);
        }