Beispiel #1
0
        private static TryCatchBlock CreateTryBlock(ILStream code, int tryOffset, int tryLength)
        {
            int entryIndex = code.GetOffsetIndex(tryOffset);
            int exitIndex  = GetIndex(code, tryOffset, tryLength);
            var tryBlock   = new TryCatchBlock
            {
                EntryPoint = code[entryIndex],
                ExitPoint  = code[exitIndex]
            };

            return(tryBlock);
        }
Beispiel #2
0
        private static int GetIndex(ILStream code, int offset, int length)
        {
            int index = code.GetOffsetIndex(offset + length);

            if (index == code.Count - 1)
            {
                return(index);
            }

            index--;
            return(index >= 0 ? index : code.Count - 1);
        }
Beispiel #3
0
        private IReadOnlyList <TryCatchBlock> TranslateSehBlocks(IMethod method, IMethodContext context, IList <SEHBlock> blocks, ILStream code)
        {
            var           list     = new List <TryCatchBlock>();
            var           handlers = new BlockList();
            TryCatchBlock tryBlock = null;
            int           n        = blocks.Count;

            for (int i = 0; i < n; ++i)
            {
                var block = blocks[i];
                tryBlock = EnshureTryBlock(blocks, i, tryBlock, code, block, list);
                var handler    = CreateHandlerBlock(method, context, code, block);
                int entryIndex = code.GetOffsetIndex(block.HandlerOffset);
                int exitIndex  = GetIndex(code, block.HandlerOffset, block.HandlerLength);
                handler.EntryPoint = code[entryIndex];
                handler.ExitPoint  = code[exitIndex];
                tryBlock.Handlers.Add(handler);
                handlers.Add(handler);
            }

            //set parents
            for (int i = 0; i < list.Count; ++i)
            {
                var block  = list[i];
                var parent = FindParent(list, block);
                if (parent != null)
                {
                    parent.Add(block);
                    list.RemoveAt(i);
                    --i;
                }
            }

            foreach (var block in list)
            {
                SetupInstructions(code, block);
            }

            return(list.AsReadOnlyList());
        }