Esempio n. 1
0
		private void add_token_fixup (MemberInfo mi)
		{
			if (num_token_fixups == token_fixups.Length) {
				ILTokenInfo[] ntf = new ILTokenInfo [num_token_fixups * 2];
				token_fixups.CopyTo (ntf, 0);
				token_fixups = ntf;
			}
			token_fixups [num_token_fixups].member = mi;
			token_fixups [num_token_fixups++].code_pos = code_len;
		}
Esempio n. 2
0
		private void add_token_fixup (MemberInfo mi)
		{
			if (num_token_fixups == token_fixups.Length) {
				ILTokenInfo[] ntf = new ILTokenInfo [num_token_fixups * 2];
				token_fixups.CopyTo (ntf, 0);
				token_fixups = ntf;
			}
			token_fixups [num_token_fixups].member = mi;
			token_fixups [num_token_fixups++].code_pos = code_len;
		}
Esempio 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 ());
			}
		}
Esempio n. 4
0
		// Used by MethodBuilder.SetMethodBody
		internal void SetTokenFixups (ILTokenInfo[] tokenFixups) {
			this.token_fixups = tokenFixups;
		}
Esempio 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());
            }
        }