Esempio n. 1
0
        public void TranslateIndices(IInstructionList list)
        {
            //Note: The base value for the program counter is the instruction address following the instruction.
            if (IsSwitch)
            {
                int origin = _offset;

                //default case offset
                var def      = _operands[SW_Default];
                int defIndex = (int)def.Value;
                def.Value = list[defIndex].Offset - origin;

                //cases
                var cases = (int[])_operands[SW_Cases].Value;
                for (int j = 0; j < cases.Length; ++j)
                {
                    int index = cases[j];
                    cases[j] = list[index].Offset - origin;
                }
            }
            else if (IsBranch)
            {
                int origin = _offset + 4;
                int index  = BranchTargetIndex;
                var op     = _operands[0];
                if (index >= list.Count)
                {
                    index = list.Count - 1;
                }
                op.Value = list[index].Offset - origin;
            }
        }
Esempio n. 2
0
        public void TranslateOffsets(IInstructionList list)
        {
            if (IsSwitch)
            {
                int origin = _offset;

                var def    = _operands[SW_Default];
                int offset = origin + (int)def.Value;
                int index  = list.GetOffsetIndex(offset);
                list[index].IsBranchTarget = true;
                def.Value = index;

                var offsets = (int[])_operands[SW_Cases].Value;
                for (int i = 0; i < offsets.Length; ++i)
                {
                    offset = origin + offsets[i];
                    index  = list.GetOffsetIndex(offset);
                    list[index].IsBranchTarget = true;
                    offsets[i] = index;
                }
            }
            else if (IsBranch)
            {
                var op     = _operands[0];
                int offset = _offset + 4 + (int)op.Value;
                int index  = list.GetOffsetIndex(offset);
                list[index].IsBranchTarget = true;
                op.Value = index;
            }
        }
Esempio n. 3
0
        private static int GetOffsetIndex(IInstructionList code, int offset)
        {
            int i = code.GetOffsetIndex(offset);

            if (i < 0)
            {
                throw Errors.ABC.InvalidBranchOffset.CreateException();
            }
            return(i);
        }
Esempio n. 4
0
 public void TranslateOffsets(IInstructionList list)
 {
     if (IsSwitch)
     {
         var offsets = (int[])Value;
         for (int j = 0; j < offsets.Length; ++j)
         {
             int index = list.GetOffsetIndex(offsets[j]);
             list[index].IsBranchTarget = true;
             offsets[j] = index;
         }
     }
     else if (IsBranch)
     {
         int index = list.GetOffsetIndex((int)Value);
         list[index].IsBranchTarget = true;
         Value = index;
     }
 }
Esempio n. 5
0
        private HandlerBlock CreateHandlerBlock(IMethod method, IMethodContext context, IInstructionList code, SEHBlock block)
        {
            switch (block.Type)
            {
            case SEHFlags.Catch:
            {
                int token = block.Value;

                var type = context.ResolveType(method, token);
                if (!HasGenericExceptions && type.IsGenericContext())
                {
                    _genericFlags |= GenericFlags.HasGenericExceptions;
                }

                var h = new HandlerBlock(BlockType.Catch)
                {
                    ExceptionType = type
                };
                return(h);
            }

            case SEHFlags.Filter:
            {
                var h = new HandlerBlock(BlockType.Filter)
                {
                    FilterIndex = code.GetOffsetIndex(block.Value)
                };
                return(h);
            }

            case SEHFlags.Finally:
                return(new HandlerBlock(BlockType.Finally));

            case SEHFlags.Fault:
                return(new HandlerBlock(BlockType.Fault));

            default:
                throw new IndexOutOfRangeException();
            }
        }