Ejemplo n.º 1
0
        public void Translate(Mono.Cecil.Cil.Instruction inst)
        {
            switch (inst.OpCode.Code)
            {
            case Code.Throw:
            case Code.Rethrow:  Translate_Throw(inst);      break;

            case Code.Leave:
            case Code.Leave_S:  Translate_Leave(inst);      break;

            case Code.Endfinally:            Translate_Endfinally(inst.Offset); break;

            case Code.Endfilter:                    Translate_Endfilter(inst);  return;

            default:                                throw new InvalidProgramException();
            }

            //
            // these instructions break the normal flow of execution and clear the
            // stack frame.  if the following instruction already has a stack frame,
            // due to some earlier forward jump, we load that frame
            //

            CilMain.LoadFrameOrClearStack(stackMap, inst);

            locals.TrackUnconditionalBranch(inst);
        }
Ejemplo n.º 2
0
        public static void Straight(JavaCode code, Code cilOp, CodeLocals locals,
                                    Mono.Cecil.Cil.Instruction cilInst)
        {
            //
            // a straight branch maps to the corresponding compare logic
            // (beq = ceq, bgt = cgt, blt = clt), plus logic for brtrue.
            //

            byte   op;
            ushort nextInstOffset = 0;

            if (cilOp == Code.Br || cilOp == Code.Br_S)
            {
                if (cilInst.Operand is Mono.Cecil.Cil.Instruction inst)
                {
                    if (inst == cilInst.Next)
                    {
                        op = 0x00; // nop
                    }
                    else
                    {
                        op = 0xA7; // goto
                        if (cilInst.Next != null)
                        {
                            nextInstOffset = (ushort)cilInst.Next.Offset;
                        }
                    }
                }
                else
                {
                    throw new InvalidProgramException();
                }
            }
            else
            {
                var stackTop = code.StackMap.PopStack(CilMain.Where);
                op = Common(code, cilOp, cilInst, stackTop);
            }

            Finish(code, locals, cilInst, op);

            if (nextInstOffset != 0)
            {
                if (!code.StackMap.LoadFrame(nextInstOffset, true, null))
                {
                    if (op == 0xA7 /* goto */)
                    {
                        locals.TrackUnconditionalBranch(cilInst);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void Process(int numCastableInterfaces)
        {
            code = newMethod.Code = new JavaCode(newMethod);
            var oldLabel = code.SetLabel(0xFFFF);

            locals     = new CodeLocals(method, defMethod, code);
            arrays     = new CodeArrays(code, locals);
            exceptions = new CodeExceptions(defMethodBody, code, locals);

            InsertMethodInitCode(numCastableInterfaces);

            code.SetLabel(oldLabel);

            stackMap = code.StackMap;
            stackMap.SaveFrame(0, false, CilMain.Where);

            ProcessInstructions();

            (code.MaxLocals, code.MaxStack) = locals.GetMaxLocalsAndStack();
            locals.TrackUnconditionalBranch(null);
        }