Ejemplo n.º 1
0
 public Instruction(ILRange range, OpCode opcode, object?argument)
 {
     Kind     = InstructionKind.OpCode;
     Range    = range;
     OpCode   = opcode;
     Argument = argument;
 }
Ejemplo n.º 2
0
            ImmutableArray <HandlerBlock> .Builder FindHandlersMatchingTryBlock(ILRange range)
            {
                foreach (var item in _pendingTryBlocks)
                {
                    if (item.TryRange == range)
                    {
                        return(item.Handlers);
                    }
                }

                var builder = new TryBuilder(range, CreateSection(range));

                _pendingTryBlocks.Add(builder);
                return(builder.Handlers);
            }
Ejemplo n.º 3
0
            public BaseSection CreateSection(ILRange range)
            {
                var sections = ExtractSectionsInRange(range);

                if (sections.Count == 0)
                {
                    return(new ILSection(range));
                }
                else if (sections.Count == 1 && sections[0].Range == range)
                {
                    return(sections[0]);
                }

                sections.Sort((x, y) => x.Range.Offset.CompareTo(y.Range.Offset));
                return(CreateSequenceSection(range, sections));
            }
Ejemplo n.º 4
0
        // Creates a section from the provided values, assuming the handlers are ordered correctly.
        public static BaseSection Create(ILRange range, IEnumerable <ExceptionHandler> handlers)
        {
            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            var generator = Builder.New();

            foreach (var handler in handlers)
            {
                generator.Add(handler);
            }

            var result = generator.CreateSection(range);

            generator.VerifyEmpty();
            return(result);
        }
Ejemplo n.º 5
0
            List <BaseSection> ExtractSectionsInRange(ILRange range)
            {
                var builder = new List <BaseSection>();
                var write   = 0;

                for (var read = 0; read < _pendingTryBlocks.Count; read++)
                {
                    var item = _pendingTryBlocks[read];

                    if (range.Contains(item.TryRange))
                    {
                        var newItem = item.Complete();

                        if (!range.Contains(newItem.Range))
                        {
                            throw new CannotGenerateSectionException();
                        }

                        foreach (var other in builder)
                        {
                            if (newItem.Range.Overlaps(other.Range))
                            {
                                throw new CannotGenerateSectionException();
                            }
                        }

                        builder.Add(newItem);
                    }
                    else
                    {
                        if (write != read)
                        {
                            _pendingTryBlocks[write] = item;
                        }

                        write++;
                    }
                }

                _pendingTryBlocks.RemoveRange(write, _pendingTryBlocks.Count - write);
                return(builder);
            }
Ejemplo n.º 6
0
            HandlerBlock CreateHandlerBlock(ExceptionHandler handler)
            {
                var handlerSection = CreateSection(handler.HandlerRange);

                if (handler.Type == ExceptionHandlingClauseOptions.Filter)
                {
                    var filterStart = new Label(handler.FilterOrType);
                    var filterRange = new ILRange(filterStart, handler.HandlerRange.Offset - filterStart);

                    return(new HandlerBlock(
                               handler.Type,
                               CreateSection(filterRange),
                               handlerSection));
                }
                else
                {
                    return(new HandlerBlock(
                               handler.Type,
                               new MetadataToken(handler.FilterOrType),
                               handlerSection));
                }
            }
Ejemplo n.º 7
0
 public TryBuilder(ILRange tryRange, BaseSection trySection)
 {
     TryRange   = tryRange;
     TrySection = trySection;
     Handlers   = ImmutableArray.CreateBuilder <HandlerBlock>();
 }
Ejemplo n.º 8
0
 static Label End(ILRange range) => range.Offset + range.Length;
Ejemplo n.º 9
0
 public ExceptionHandler(ExceptionHandlingClauseOptions type, ILRange tryRange, ILRange handlerRange, int filterOrType)
 {
     Type         = type;
     TryRange     = tryRange;
     HandlerRange = handlerRange;
     FilterOrType = filterOrType;
 }
Ejemplo n.º 10
0
 public TryBlockSection(ILRange range, BaseSection tryBlock, ImmutableArray <HandlerBlock> handlerBlocks)
     : base(range)
 {
     TryBlock      = tryBlock;
     HandlerBlocks = handlerBlocks;
 }
Ejemplo n.º 11
0
 public Instruction(ILRange range)
 {
     Kind  = InstructionKind.Invalid;
     Range = range;
 }