Exemplo n.º 1
0
		public virtual Label BeginExceptionBlock ()
		{
			//System.Console.WriteLine ("Begin Block");
			if (open_blocks == null)
				open_blocks = new Stack (defaultExceptionStackSize);
			
			if (ex_handlers != null) {
				cur_block = ex_handlers.Length;
				ILExceptionInfo[] new_ex = new ILExceptionInfo [cur_block + 1];
				System.Array.Copy (ex_handlers, new_ex, cur_block);
				ex_handlers = new_ex;
			} else {
				ex_handlers = new ILExceptionInfo [1];
				cur_block = 0;
			}
			open_blocks.Push (cur_block);
			ex_handlers [cur_block].start = code_len;
			return ex_handlers [cur_block].end = DefineLabel ();
		}
Exemplo n.º 2
0
		public virtual Label BeginExceptionBlock ()
		{
			//System.Console.WriteLine ("Begin Block");
			if (open_blocks == null)
				open_blocks = new Stack (defaultExceptionStackSize);
			
			if (ex_handlers != null) {
				cur_block = ex_handlers.Length;
				ILExceptionInfo[] new_ex = new ILExceptionInfo [cur_block + 1];
				System.Array.Copy (ex_handlers, new_ex, cur_block);
				ex_handlers = new_ex;
			} else {
				ex_handlers = new ILExceptionInfo [1];
				cur_block = 0;
			}
			open_blocks.Push (cur_block);
			ex_handlers [cur_block].start = code_len;
			return ex_handlers [cur_block].end = DefineLabel ();
		}
Exemplo n.º 3
0
		internal void Init (byte[] il, int maxStack, byte[] localSignature,
			IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
		{
			SetCode (il, maxStack);

			// FIXME: Process local signature

			// Process exception handlers
			if (exceptionHandlers != null) {
				// Group exception handlers by try blocks
				var tryBlocks = new Dictionary <Tuple<int, int>, List<ExceptionHandler>> ();
				foreach (var h in exceptionHandlers) {
					List<ExceptionHandler> list;
					var key = new Tuple <int, int> (h.TryOffset, h.TryLength);
					if (!tryBlocks.TryGetValue (key, out list)) {
						list = new List<ExceptionHandler> ();
						tryBlocks.Add (key, list);
					}
					list.Add (h);
				}

				// Generate ILExceptionInfo from tryBlocks
				var infos = new List<ILExceptionInfo> ();
				foreach (var kv in tryBlocks) {
					var info = new ILExceptionInfo () {
						start = kv.Key.Item1,
						len = kv.Key.Item2,
						handlers = new ILExceptionBlock [kv.Value.Count],
					};
					infos.Add (info);
					var i = 0;
					foreach (var b in kv.Value) {
						info.handlers [i++] = new ILExceptionBlock () {
							start = b.HandlerOffset,
							len = b.HandlerLength,
							filter_offset = b.FilterOffset,
							type = (int) b.Kind,
							extype = module.ResolveType (b.ExceptionTypeToken),
						};
					}
				}

				SetExceptionHandlers (infos.ToArray ());
			}

			// Process token fixups
			if (tokenFixups != null) {
				var tokenInfos = new List<ILTokenInfo> ();
				foreach (var pos in tokenFixups) {
					var token = (int) BitConverter.ToUInt32 (il, pos);
					var tokenInfo = new ILTokenInfo () {
						code_pos = pos,
						member = ((ModuleBuilder) module).ResolveOrGetRegisteredToken (token, null, null)
					};
					tokenInfos.Add (tokenInfo);
				}

				SetTokenFixups (tokenInfos.ToArray ());
			}
		}
Exemplo n.º 4
0
		// Used by MethodBuilder.SetMethodBody
		internal void SetExceptionHandlers (ILExceptionInfo[] exHandlers) {
			this.ex_handlers = exHandlers;
		}
Exemplo n.º 5
0
        internal void Init(byte[] il, int maxStack, byte[] localSignature,
                           IEnumerable <ExceptionHandler> exceptionHandlers, IEnumerable <int> tokenFixups)
        {
            SetCode(il, maxStack);

            // FIXME: Process local signature

            // Process exception handlers
            if (exceptionHandlers != null)
            {
                // Group exception handlers by try blocks
                var tryBlocks = new Dictionary <Tuple <int, int>, List <ExceptionHandler> > ();
                foreach (var h in exceptionHandlers)
                {
                    List <ExceptionHandler> list;
                    var key = new Tuple <int, int> (h.TryOffset, h.TryLength);
                    if (!tryBlocks.TryGetValue(key, out list))
                    {
                        list = new List <ExceptionHandler> ();
                        tryBlocks.Add(key, list);
                    }
                    list.Add(h);
                }

                // Generate ILExceptionInfo from tryBlocks
                var infos = new List <ILExceptionInfo> ();
                foreach (var kv in tryBlocks)
                {
                    var info = new ILExceptionInfo()
                    {
                        start    = kv.Key.Item1,
                        len      = kv.Key.Item2,
                        handlers = new ILExceptionBlock [kv.Value.Count],
                    };
                    infos.Add(info);
                    var i = 0;
                    foreach (var b in kv.Value)
                    {
                        info.handlers [i++] = new ILExceptionBlock()
                        {
                            start         = b.HandlerOffset,
                            len           = b.HandlerLength,
                            filter_offset = b.FilterOffset,
                            type          = (int)b.Kind,
                            extype        = module.ResolveType(b.ExceptionTypeToken),
                        };
                    }
                }

                SetExceptionHandlers(infos.ToArray());
            }

            // Process token fixups
            if (tokenFixups != null)
            {
                var tokenInfos = new List <ILTokenInfo> ();
                foreach (var pos in tokenFixups)
                {
                    var token     = (int)BitConverter.ToUInt32(il, pos);
                    var tokenInfo = new ILTokenInfo()
                    {
                        code_pos = pos,
                        member   = ((ModuleBuilder)module).ResolveOrGetRegisteredToken(token, null, null)
                    };
                    tokenInfos.Add(tokenInfo);
                }

                SetTokenFixups(tokenInfos.ToArray());
            }
        }