X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FIKVM.Reflection%2FEmit%2FMethodBuilder.cs;h=486e74c91ad677d7097b89e87aa61cad26f43fc8;hb=29f274c5d1acec1130683cbdd77daf309a21f909;hp=89778acdb4787c09d4106d3a3fbfc12ce2c1e623;hpb=90adf67203078c752c74abfd0d8d45a7341e1376;p=mono.git diff --git a/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs b/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs index 89778acdb47..486e74c91ad 100644 --- a/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs +++ b/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs @@ -367,6 +367,10 @@ namespace IKVM.Reflection.Emit public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { CheckSig(); + if (gtpb != null) + { + throw new InvalidOperationException("Generic parameters already defined."); + } gtpb = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) { @@ -622,6 +626,54 @@ namespace IKVM.Reflection.Emit this.ModuleBuilder.AddUnmanagedExport(name, ordinal, this, new RelativeVirtualAddress(0xFFFFFFFF)); } + public void CreateMethodBody(byte[] il, int count) + { + if (il == null) + { + throw new NotSupportedException(); + } + if (il.Length != count) + { + Array.Resize(ref il, count); + } + SetMethodBody(il, 16, null, null, null); + } + + public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable exceptionHandlers, IEnumerable tokenFixups) + { + ByteBuffer bb = this.ModuleBuilder.methodBodies; + + if (localSignature == null && exceptionHandlers == null && maxStack <= 8 && il.Length < 64) + { + rva = bb.Position; + ILGenerator.WriteTinyHeader(bb, il.Length); + } + else + { + // fat headers require 4-byte alignment + bb.Align(4); + rva = bb.Position; + ILGenerator.WriteFatHeader(bb, initLocals, exceptionHandlers != null, (ushort)maxStack, il.Length, + localSignature == null ? 0 : this.ModuleBuilder.GetSignatureToken(localSignature, localSignature.Length).Token); + } + + if (tokenFixups != null) + { + ILGenerator.AddTokenFixups(bb.Position, this.ModuleBuilder.tokenFixupOffsets, tokenFixups); + } + bb.Write(il); + + if (exceptionHandlers != null) + { + List exceptions = new List(); + foreach (ExceptionHandler block in exceptionHandlers) + { + exceptions.Add(new ILGenerator.ExceptionBlock(block)); + } + ILGenerator.WriteExceptionHandlers(bb, exceptions); + } + } + internal void Bake() { this.nameIndex = this.ModuleBuilder.Strings.Add(name);