Example #1
0
        static void ResetInstruction(MonoXIL.Cecil.Cil.MethodBody body)
        {
            int offset       = 0;
            var instructions = body.Instructions;

            wxb.RefType refType    = new RefType(instructions);
            var         items      = (Instruction[])refType.GetField("items");
            var         count      = instructions.Count;
            var         stack_size = 0;
            var         max_stack  = 0;
            Dictionary <Instruction, int> stack_sizes = null;

            if (body.HasExceptionHandlers)
            {
                ComputeExceptionHandlerStackSize(body, ref stack_sizes);
            }

            for (int i = 0; i < count; i++)
            {
                var instruction = items[i];
                instruction.Offset = offset;
                offset            += instruction.GetSize();

                ComputeStackSize(instruction, ref stack_sizes, ref stack_size, ref max_stack);
            }

            wxb.RefType body_refType = new RefType(body);
            body_refType.SetField("code_size", offset);
            body_refType.SetField("max_stack_size", max_stack);
        }
Example #2
0
        static void ComputeExceptionHandlerStackSize(MonoXIL.Cecil.Cil.MethodBody body, ref Dictionary <Instruction, int> stack_sizes)
        {
            var exception_handlers = body.ExceptionHandlers;

            for (int i = 0; i < exception_handlers.Count; i++)
            {
                var exception_handler = exception_handlers[i];

                switch (exception_handler.HandlerType)
                {
                case ExceptionHandlerType.Catch:
                    AddExceptionStackSize(exception_handler.HandlerStart, ref stack_sizes);
                    break;

                case ExceptionHandlerType.Filter:
                    AddExceptionStackSize(exception_handler.FilterStart, ref stack_sizes);
                    AddExceptionStackSize(exception_handler.HandlerStart, ref stack_sizes);
                    break;
                }
            }
        }