private unsafe void ReadExceptions(DynamicResolver dynamicResolver, int excCount)
        {
            var buf             = stackalloc CORINFO_EH_CLAUSE[1];
            var exceptionClause = &buf[0];

            for (int i = 0; i < excCount; ++i)
            {
                dynamicResolver.GetEHInfo(i, exceptionClause);

                var handler = new ExceptionHandler((ExceptionHandlerType)exceptionClause->Flags);

                handler.TryStart = GetInstruction(exceptionClause->TryOffset);
                handler.TryEnd   = GetInstruction(handler.TryStart.Offset + exceptionClause->TryLength);

                handler.HandlerStart = GetInstruction(exceptionClause->HandlerOffset);
                handler.HandlerEnd   = GetInstruction(handler.HandlerStart.Offset + exceptionClause->HandlerLength);

                switch (handler.HandlerType)
                {
                case ExceptionHandlerType.Catch:
                    var token = new MetadataToken((uint)exceptionClause->ClassTokenOrFilterOffset);
                    handler.CatchType = resolveTokens ? ResolveToken(token) : token;
                    break;

                case ExceptionHandlerType.Filter:
                    handler.FilterStart = GetInstruction(exceptionClause->ClassTokenOrFilterOffset);
                    break;
                }

                ExceptionHandlers.Add(handler);
            }
        }
Beispiel #2
0
 public static void Init()
 {
     DynamicMethodWrapper.Init();
     DynamicILGenerator.Init();
     DynamicILInfoWrapper.Init();
     DynamicScope.Init();
     DynamicResolver.Init();
 }
        public MethodBodyOnDynamicILInfo(DynamicMethod dynamicMethod, GrEmit.Utils.DynamicILInfo dynamicILInfo, bool resolveTokens)
            : base(GetMethodSignature(dynamicILInfo), resolveTokens)
        {
            scope = new DynamicILInfoWrapper(dynamicILInfo).m_scope;
            using (var dynamicResolver = new DynamicResolver(dynamicMethod, dynamicILInfo))
            {
                int stackSize;
                int initLocals;
                int EHCount;

                var code = dynamicResolver.GetCodeInfo(out stackSize, out initLocals, out EHCount);

                MaxStack   = stackSize;
                InitLocals = initLocals != 0;

                SetLocalSignature(dynamicResolver.m_localSignature);

                ILCodeReader.Read(code, ResolveToken, resolveTokens, this);

                ExceptionsInfoReader.Read(dynamicResolver.GetRawEHInfo(), ResolveToken, resolveTokens, this);
            }
        }
        public MethodBodyOnDynamicILGenerator(DynamicMethod dynamicMethod, ILGenerator ilGenerator, bool resolveTokens)
            : base(GetMethodSignature(ilGenerator), resolveTokens)
        {
            scope = new DynamicILGenerator(ilGenerator).m_scope;
            using (var dynamicResolver = new DynamicResolver(dynamicMethod, ilGenerator))
            {
                int stackSize;
                int initLocals;
                int EHCount;

                var code = dynamicResolver.GetCodeInfo(out stackSize, out initLocals, out EHCount);

                MaxStack   = stackSize;
                InitLocals = initLocals != 0;

                SetLocalSignature(dynamicResolver.m_localSignature);

                ILCodeReader.Read(code, ResolveToken, resolveTokens, this);

                ReadExceptions(dynamicResolver, EHCount);
            }
        }