Examples of IFlowgraph


Examples of org.apache.flex.abc.graph.IFlowgraph

     * Walk the control flow graph and remove unreachable blocks.
     */
    @Override
    public void visitEnd()
    {
        IFlowgraph cfg = this.mbi.getCfg();
        List<IBasicBlock> blocks = cfg.getBlocksInEntryOrder();
        boolean lastBlockWasReachable = true;

        int blockIdx = 0;
        while ( blockIdx < blocks.size() )
        {
            IBasicBlock b = blocks.get(blockIdx);
            boolean isReachable = cfg.isReachable(b);

            // Only advance the block index if the current
            // block is removed.
            int previousBlockCount = blocks.size();

            if ( ! isReachable )
            {
                //  Don't remove unreachable blocks that are the final block in an exception handler,
                //  unless they're also the first block in the exception handler.  The AVM depends on
                //  these blocks under some circumstances.  However, the block's instructions can be
                //  coalesced to a single OP_nop.
                boolean safeToRemove = true;

                for ( ExceptionInfo ex: this.mbi.getExceptions() )
                {
                    IBasicBlock toBlock = this.mbi.getCfg().getBlock(ex.getTo());
                    if ( b.equals(toBlock) )
                    {
                        IBasicBlock fromBlock = this.mbi.getCfg().getBlock(ex.getFrom());

                        int tryFrom = blocks.indexOf(fromBlock);
                        int tryTo   = blocks.indexOf(toBlock);
                        assert tryFrom >= 0 && tryTo >= tryFrom;

                        for ( int j = tryTo - 1; safeToRemove && j >= tryFrom; j-- )
                            safeToRemove = !cfg.isReachable(blocks.get(j));
                       
                        if ( !safeToRemove )
                        {
                            //  Can't remove it, but compact it: remove executable
                            //  instructions, then write a single OP_nop as necessary.

                            Iterator<Instruction> it = b.getInstructions().iterator();

                            while ( it.hasNext() )
                            {
                                Instruction insn = it.next();

                                if ( insn.isExecutable() )
                                    it.remove();
                            }

                            b.getInstructions().add(InstructionFactory.getInstruction(ABCConstants.OP_nop));
                            break;
                        }
                    }
                }

                if ( safeToRemove )
                {
                    //  Only remove the Block if it contains executable and non-NOP instructions.
                    for ( int j = 0; j < b.size(); j++ )
                    {
                        Instruction insn = b.get(j);
                        if ( insn.isExecutable() && insn.getOpcode() != ABCConstants.OP_nop )
                        {
                            //  Only emit a diagnostic if b is the first unreachable block
                            //  encountered in this sequence.
                            if ( lastBlockWasReachable )
                                this.diagnostics.unreachableBlock(this.mbi, this.mbi.getCfg(), b);
                            cfg.removeUnreachableBlock(b);
                            break;
                        }
                    }
                }
            }
View Full Code Here

Examples of org.apache.flex.abc.graph.IFlowgraph

                }

                printer.unindent();
                printer.println("}");
            }
            IFlowgraph cfg = mb.getCfg();
            Map<IBasicBlock, String> blockNames = new HashMap<IBasicBlock, String>();
            int i = 0;
            for (IBasicBlock block : cfg.getBlocksInEntryOrder())
            {
                blockNames.put(block, "bb" + i++);
            }
            int offset = 0;
            for (IBasicBlock block : cfg.getBlocksInEntryOrder())
            {
                printer.println(blockNames.get(block));
                printer.indent();
                // TODO: preds
                //printer.println("preds=[" + block.getPredeccessor()mb.blocks[i].getPredIds(mb.blocks).join(", ") + "]");
                Collection<? extends IBasicBlock> succs = block.getSuccessors();
                List<String> succNames = new ArrayList<String>();
                for (IBasicBlock s : succs)
                    succNames.add(blockNames.get(s));

                printer.println("succs=[" + joinOn(",", succNames) + "]");
                /*
                // TODO: implement this with FrameModelEncoder
                if(mb.blocks[i].state != null) {
                    printer.println("verification = " + (mb.blocks[i].state.verifyError == null ? "ok" : "failed: " + mb.blocks[i].state.verifyError));
                }
                */
                tablePrinter = new TablePrinter(4, 2);
                for (int j = 0; j < block.size(); j++)
                {
                    Instruction inst = block.get(j);
                    String constantStr = "";

                    if (inst.hasOperands() && inst.getOperand(0) instanceof Name)
                    {
                        constantStr = nameToString((Name) inst.getOperand(0));
                    }
                    else if (inst.isBranch() && inst.getOpcode() != OP_lookupswitch)
                    {
                        constantStr = blockNames.get(cfg.getBlock((Label) inst.getOperand(0)));
                    }
                    else
                    {
                        switch (inst.getOpcode())
                        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.