Example #1
0
        internal static void LoadFrameOrClearStack(JavaStackMap stackMap,
                                                   Mono.Cecil.Cil.Instruction inst)
        {
            // following any instruction that breaks the normal flow of execution,
            // we need to load an stack frame already recorded for some following
            // instruction, if any (e.g. as part of a conditional branch sequence).
            // if there isn't such a frame, just clear and reset the stack frame.

            for (;;)
            {
                inst = inst.Next;
                if (inst == null)
                {
                    break;
                }
                if (stackMap.LoadFrame((ushort)inst.Offset, true, null))
                {
                    return;
                }
                var flowControl = inst.OpCode.FlowControl;
                if (flowControl == Mono.Cecil.Cil.FlowControl.Branch ||
                    flowControl == Mono.Cecil.Cil.FlowControl.Break ||
                    flowControl == Mono.Cecil.Cil.FlowControl.Cond_Branch ||
                    flowControl == Mono.Cecil.Cil.FlowControl.Return ||
                    flowControl == Mono.Cecil.Cil.FlowControl.Throw)
                {
                    break;
                }
            }

            stackMap.ClearStack();
        }
Example #2
0
        public CodeLocals(CilMethod myMethod, MethodDefinition defMethod, JavaCode code)
        {
            this.code = code;
            stackMap  = code.StackMap = new JavaStackMap();

            InitLocals(myMethod, defMethod);
            WriteDebugData(myMethod.DeclType);
        }
Example #3
0
        public CodeExceptions(MethodBody body, JavaCode _code, CodeLocals locals)
        {
            tryClauses   = new List <TryClause>();
            catchClauses = new Dictionary <int, CatchClause>();
            code         = _code;
            stackMap     = code.StackMap;
            this.locals  = locals;

            if (body.HasExceptionHandlers)
            {
                if (!InitExceptionClauses(body))
                {
                    throw CilMain.Where.Exception("error in exception handlers data");
                }
            }
        }
Example #4
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);
        }
Example #5
0
 public CodeArrays(JavaCode _code, CodeLocals _locals)
 {
     locals   = _locals;
     code     = _code;
     stackMap = code.StackMap;
 }