Ejemplo n.º 1
0
 Node FloatUpToNeighbours(BasicBlock basicBlock)
 {
     // Find neighbour coresponding to the basickBlock
     Node targetNode = basicBlock;
     while(targetNode != null && targetNode.Parent != this.Parent) {
         targetNode = targetNode.Parent;
     }
     return targetNode;
 }
Ejemplo n.º 2
0
        public List<Node> SplitToBasicBlocks(List<ILNode> ast)
        {
            if (ast.Count == 0) return new List<Node>();

            List<Node> nodes = new List<Node>();

            BasicBlock basicBlock = null;

            for(int i = 0; i < ast.Count; i++) {
                if (i == 0 ||
                    ast[i] is ILLabel ||
                    ast[i - 1] is ILTryCatchBlock ||
                    ast[i] is ILTryCatchBlock ||
                    (ast[i - 1] is ILExpression) && ((ILExpression)ast[i - 1]).OpCode.IsBranch() ||
                    (ast[i] is ILExpression)     && ((ILExpression)ast[i]).OpCode.IsBranch())
                {
                    BasicBlock oldBB = basicBlock;
                    basicBlock = new BasicBlock();
                    if (methodEntry == null) methodEntry = basicBlock;
                    nodes.Add(basicBlock);
                    // Links
                    if (oldBB != null && ast[i - 1] is ILExpression && ((ILExpression)ast[i - 1]).OpCode.CanFallThough()) {
                        oldBB.FallThroughBasicBlock = basicBlock;
                        basicBlock.BasicBlockPredecessors.Add(oldBB);
                    }
                }
                if (ast[i] is ILTryCatchBlock) {
                    basicBlock.Childs.Add(ConvertTryCatch((ILTryCatchBlock)ast[i]));
                } else {
                    basicBlock.Body.Add(ast[i]);
                }
                if (ast[i] is ILLabel) {
                    labelToBasicBlock[(ILLabel)ast[i]] = basicBlock;
                }
            }

            return nodes;
        }