Package org.apache.flex.abc.semantics

Examples of org.apache.flex.abc.semantics.Instruction


            InstructionList result = createInstructionList(iNode);

            result.addAll(replicate(this.runtimeQualifier));

            //  Ensure the last instruction is an OP_coerce to Namespace.
            Instruction last = result.lastElement();

            if  (
                    last.getOpcode() != OP_coerce ||
                    last.getOperandCount() == 0 ||
                    ! namespaceType.equals(last.getOperand(0))
                )
            {
                result.addInstruction(OP_coerce, namespaceType);
            }
View Full Code Here


                            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);
View Full Code Here

        switch (prev.getOpcode())
        {
            case OP_jump:
            {
                InstructionInfo prev2 = previous(idx + 1);
                Instruction insn = prev2.getInstruction();
                if (insn != null && insn.isBranch() && insn.getTarget() == l)
                {
                    // If the previous instructions were an if that jumped here, and it
                    // only jumped over another jump, then we can invert the if instruction
                    // and save a jump
                    //   iffalse L1, jump L2, L1    -> iftrue L2, L1
                    Instruction newIf = invertIf(prev2, prev);
                    if (newIf != null)
                    {
                        if (kind == LabelKind.LABEL_CURRENT)
                        {
                            // labelCurrent, so we need to preserve the last instruction
View Full Code Here

     * Helper method to invert if expr target jump other-target to if not expr
     * other-target Used to optimize some common patterns with if's and jumps
     */
    private Instruction invertIf(InstructionInfo oldIf, InstructionInfo oldJump)
    {
        Instruction newIf = null;
        switch (oldIf.getOpcode())
        {
            case OP_ifeq:
            {
                newIf = InstructionFactory.createModifiedInstruction(OP_ifne, oldJump.getInstruction());
View Full Code Here

                continue;

            //  If the last instruction in the block
            //  is a jump, leave room for the instruction,
            //  but don't emit it yet.
            Instruction last = b.get(b.size() - 1);

            if (last.isBranch())
            {
                if (last.getOpcode() == OP_lookupswitch)
                {
                    //  Switch table contains a U30 case count and S24 offsets.
                    int switch_size = 1 + sizeOfU30(last.getOperandCount()) + SIZEOF_S24 * last.getOperandCount();
                    code_len += switch_size;
                }
                else
                {
                    assert (null != last.getTarget());
                    //  Reserve space for a branch instruction.
                    code_len += 4;
                }
            }
        }

        //  Note: Can't compute code_start until we've seen
        //  how big this U30 is.
        result.writeU30(code_len);
        int code_start = result.size();

        //  Now we can resolve labels to their code offsets.
        //  Copy the linear code sequences into the main ABCWriter,
        //  and emit the branch and lookupswitch instructions.
        for (IBasicBlock b : f.getCfg().getBlocksInEntryOrder())
        {
            writers.get(b).writeTo(result);
            if (b.size() > 0)
            {
                Instruction last = b.get(b.size() - 1);

                if (last.isBranch())
                {
                    if (OP_lookupswitch == last.getOpcode())
                    {
                        emitLookupswitch(result, code_start, f, last, block_offsets);
                    }
                    else
                    {
                        assert (last.getTarget() != null);

                        emitBranch(result, last.getOpcode(), f.getBlock(last.getTarget(), !allowBadJumps), code_start, block_offsets, code_len);
                    }
                }
            }
        }

View Full Code Here

    void emitBlock(IBasicBlock b, ABCWriter blockWriter)
    {
        for (int i = 0; i < b.size() && !b.get(i).isBranch(); i++)
        {
            Instruction insn = b.get(i);

            blockWriter.write(insn.getOpcode());
            switch (insn.getOpcode())
            {
                case OP_hasnext2:
                {
                    blockWriter.writeU30((Integer)insn.getOperand(0));
                    blockWriter.writeU30((Integer)insn.getOperand(1));
                    break;
                }
                case OP_findproperty:
                case OP_findpropstrict:
                case OP_getlex:
                case OP_getsuper:
                case OP_setsuper:
                case OP_deleteproperty:
                case OP_getdescendants:
                case OP_getproperty:
                case OP_setproperty:
                case OP_initproperty:
                case OP_istype:
                case OP_coerce:
                case OP_astype:
                case OP_finddef:
                {
                    blockWriter.writeU30(namePool.id((Name)insn.getOperand(0)));
                    break;
                }
                case OP_callproperty:
                case OP_callproplex:
                case OP_callpropvoid:
                case OP_callsuper:
                case OP_callsupervoid:
                case OP_constructprop:
                {
                    blockWriter.writeU30(namePool.id((Name)insn.getOperand(0)));
                    blockWriter.writeU30((Integer)insn.getOperand(1));
                    break;
                }
                case OP_constructsuper:
                case OP_call:
                case OP_construct:
                case OP_newarray:
                case OP_newobject:
                case OP_getlocal:
                case OP_setlocal:
                case OP_getslot:
                case OP_setslot:
                case OP_kill:
                case OP_inclocal:
                case OP_declocal:
                case OP_inclocal_i:
                case OP_declocal_i:
                case OP_newcatch:
                case OP_getglobalslot:
                case OP_setglobalslot:
                case OP_applytype:
                case OP_getscopeobject:
                case OP_pushshort:
                {
                    blockWriter.writeU30(insn.getImmediate());
                    break;
                }
                case OP_pushbyte:
                {
                    blockWriter.write(insn.getImmediate());
                    break;
                }
                case OP_newclass:
                {
                    blockWriter.writeU30(getClassId((ClassInfo)insn.getOperand(0)));
                    break;
                }
                case OP_newfunction:
                {
                    blockWriter.writeU30(getMethodId((MethodInfo)insn.getOperand(0)));
                    break;
                }
                case OP_callstatic:
                {
                    blockWriter.writeU30(getMethodId((MethodInfo)insn.getOperand(0)));
                    blockWriter.writeU30((Integer)(insn.getOperand(1)));
                    break;
                }
                case OP_pushstring:
                case OP_dxns:
                case OP_debugfile:
                {
                    blockWriter.writeU30(stringPool.id(insn.getOperand(0).toString()));
                    break;
                }
                case OP_pushnamespace:
                {
                    blockWriter.writeU30(nsPool.id((Namespace)insn.getOperand(0)));
                    break;
                }
                case OP_pushint:
                {
                    blockWriter.writeU30(intPool.id((Integer)insn.getOperand(0)));
                    break;
                }
                case OP_pushuint:
                {
                    blockWriter.writeU30(uintPool.id((Long)insn.getOperand(0)));
                    break;
                }
                case OP_pushdouble:
                {
                    blockWriter.writeU30(doublePool.id((Double)insn.getOperand(0)));
                    break;
                }
                case OP_debugline:
                case OP_bkptline:
                {
                    blockWriter.writeU30(insn.getImmediate());
                    break;
                }
                case OP_debug:
                {
                    blockWriter.write((Integer)(insn.getOperand(0)));
                    blockWriter.writeU30(stringPool.id(insn.getOperand(1).toString()));
                    blockWriter.write((Integer)insn.getOperand(2));
                    blockWriter.writeU30(0);
                    break;
                }
            }
        }
View Full Code Here

                }
                */
                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())
                        {
                            case OP_debugfile:
                            case OP_pushstring:
                                constantStr = "\"" + stringToEscapedString((String) inst.getOperand(0)) + "\"";
                                break;
                            case OP_lookupswitch:
                                constantStr = stringForLookupSwitch(inst, mb, blockNames, cfg);
                                break;
                        }
                    }
                    tablePrinter.addRow(new String[]{offset + "    ",
                            Instruction.decodeOp(inst.getOpcode()),
                            constantStr,
                            inst.isImmediate() ? String.valueOf(inst.getImmediate()) : ""
                            // TODO : Use FrameModelEncoder to keep track
                            // TODO: of stack/local values
                            //(inst.getStackDepth() == null ? "" : "// stack: " + inst.getStackDepth()),
                            //(inst.getState() == null ? "" : "// stack["+inst.getState().stackDepth+"]: " + inst.getState().stackTypeString()),
                            //(inst.getState() == null ? "" : "// locals: " + inst.getState().localsTypeString()),
View Full Code Here

        String debugFile = null;
        int debugLine = LexicalScope.DEBUG_LINE_UNKNOWN;
        final ArrayList<Instruction> srcInstructions = src.getInstructions();
        for (int i = 0; i < srcInstructions.size(); i++)
        {
            final Instruction insn = srcInstructions.get(i);
            if (insn.getOpcode() == OP_debugfile)
            {
                debugFile = (String)insn.getOperand(0);
            }
            else if (insn.getOpcode() == OP_debugline)
            {
                debugLine = insn.getImmediate();
                break;
            }
        }

        InstructionList result = new DebugInfoInstructionList(dest.size() + 2);
View Full Code Here

        result.addInstruction(OP_applytype, 1);
        result.pushNumericConstant(elements.size());
        result.addInstruction(OP_construct, 1);

        //  Share this instruction; there may be many elements.
        Instruction setter = arrayAccess(iNode, OP_setproperty);

        for ( int i = 0; i < elements.size(); i++ )
        {
            result.addInstruction(OP_dup);
            result.pushNumericConstant(i);
View Full Code Here

TOP

Related Classes of org.apache.flex.abc.semantics.Instruction

Copyright © 2018 www.massapicom. 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.