We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
-
Expand
Microsoft.Win32
-
Expand
Microsoft.Win32.SafeHandles
-
Expand
System
-
Expand
System.Runtime.Hosting
-
Expand
System.Runtime.InteropServices
-
Expand
System.Runtime.CompilerServices
-
Expand
System.Collections
-
Expand
System.Collections.Generic
-
Expand
System.Collections.ObjectModel
-
Expand
System.Configuration.Assemblies
-
Expand
System.Diagnostics
-
Expand
System.Diagnostics.CodeAnalysis
-
Expand
System.Diagnostics.SymbolStore
-
Expand
System.Globalization
-
Expand
System.IO
-
Expand
System.IO.IsolatedStorage
-
Expand
System.Reflection
-
Expand
System.Reflection.Cache
-
Expand
System.Reflection.Emit
-
Expand
__ExceptionInfo
-
Expand
__ExceptionInstance
-
Expand
__FixupData
-
Expand
AssemblyBuilder
-
Expand
AssemblyBuilderAccess
-
Expand
AssemblyBuilderData
-
Expand
ConstructorBuilder
-
Expand
ConstructorOnTypeBuilderInstantiation
-
Expand
CustAttr
-
Expand
CustomAttributeBuilder
-
Expand
DestroyScout
-
Expand
DynamicILGenerator
-
Expand
DynamicILInfo
-
Expand
DynamicMethod
-
Expand
DynamicResolver
-
Expand
DynamicScope
-
Expand
EmptyCAHolder
-
Expand
Entry
-
Expand
EnumBuilder
-
Expand
EventBuilder
-
Expand
EventToken
-
Expand
FieldBuilder
-
Expand
FieldOnTypeBuilderInstantiation
-
Expand
FieldToken
-
Expand
FlowControl
-
Expand
Format
-
Expand
GenericMethodInfo
-
Expand
GenericTypeParameterBuilder
-
Expand
ILGenerator
-
AddFixup(Label, int, int)
-
BakeByteArray()
-
BeginCatchBlock(Type)
-
BeginExceptFilterBlock()
-
BeginExceptionBlock()
-
BeginFaultBlock()
-
BeginFinallyBlock()
-
BeginScope()
-
CalculateNumberOfExceptions(__ExceptionInfo)
-
DeclareLocal(Type)
-
DeclareLocal(Type, bool)
-
DefineLabel()
-
Emit(OpCode)
-
Emit(OpCode, byte)
-
Emit(OpCode, ConstructorInfo)
-
Emit(OpCode, double)
-
Emit(OpCode, FieldInfo)
-
Emit(OpCode, float)
-
Emit(OpCode, int)
-
Emit(OpCode, Label)
-
Emit(OpCode, Label)
-
Emit(OpCode, LocalBuilder)
-
Emit(OpCode, long)
-
Emit(OpCode, MethodInfo)
-
Emit(OpCode, sbyte)
-
Emit(OpCode, short)
-
Emit(OpCode, SignatureHelper)
-
Emit(OpCode, string)
-
Emit(OpCode, Type)
-
EmitCall(OpCode, MethodInfo, Type)
-
EmitCalli(OpCode, CallingConvention, Type, Type)
-
EmitCalli(OpCode, CallingConventions, Type, Type, Type)
-
EmitWriteLine(FieldInfo)
-
EmitWriteLine(LocalBuilder)
-
EmitWriteLine(string)
-
EndExceptionBlock()
-
EndScope()
-
EnlargeArray(__ExceptionInfo)
-
EnlargeArray(__FixupData)
-
EnlargeArray(byte)
-
EnlargeArray(byte, int)
-
EnlargeArray(int)
-
EnlargeArray(Type)
-
EnsureCapacity(int)
-
GetExceptions()
-
GetIDsOfNames(Guid, IntPtr, uint, uint, IntPtr)
-
GetLabelPos(Label)
-
GetMaxStackSize()
-
GetMemberRefSignature(CallingConventions, Type, Type, Type)
-
GetMemberRefSignature(CallingConventions, Type, Type, Type, int)
-
GetMemberRefToken(MethodBase, Type)
-
GetMethodToken(MethodBase, Type)
-
GetRVAFixups()
-
GetTokenFixups()
-
GetTypeInfo(uint, uint, IntPtr)
-
GetTypeInfoCount(uint)
-
ILGenerator(int)
-
ILGenerator(MethodInfo)
-
ILGenerator(MethodInfo, int)
-
InternalEmit(OpCode)
-
Invoke(uint, Guid, uint, short, IntPtr, IntPtr, IntPtr, IntPtr)
-
MarkLabel(Label)
-
MarkSequencePoint(ISymbolDocumentWriter, int, int, int, int)
-
PutInteger4(int, int, byte)
-
RecordTokenFixup()
-
SortExceptions(__ExceptionInfo)
-
ThrowException(Type)
-
UpdateStackSize(OpCode, int)
-
UsingNamespace(string)
-
Expand
Label
-
Expand
LineNumberInfo
-
Expand
LocalBuilder
-
Expand
LocalSymInfo
-
Expand
MethodBuilder
-
Expand
MethodBuilderInstantiation
-
Expand
MethodOnTypeBuilderInstantiation
-
Expand
MethodRental
-
Expand
MethodToken
-
Expand
ModuleBuilder
-
Expand
ModuleBuilderData
-
Expand
OpCode
-
Expand
OpCodes
-
Expand
OpCodeType
-
Expand
OperandType
-
Expand
PackingSize
-
Expand
ParameterBuilder
-
Expand
ParameterToken
-
Expand
PEFileKinds
-
Expand
PropertyBuilder
-
Expand
PropertyToken
-
Expand
REDocument
-
Expand
ResWriterData
-
Expand
RTDynamicMethod
-
Expand
ScopeAction
-
Expand
ScopeTree
-
Expand
SecurityControlFlags
-
Expand
SignatureHelper
-
Expand
SignatureToken
-
Expand
StackBehaviour
-
Expand
StringToken
-
Expand
SymbolMethod
-
Expand
SymbolType
-
Expand
SymCustomAttr
-
Expand
TypeBuilder
-
Expand
TypeBuilderInstantiation
-
Expand
TypeKind
-
Expand
TypeNameBuilder
-
Expand
TypeToken
-
Expand
UnmanagedMarshal
-
Expand
VarArgMethod
-
Expand
System.Resources
-
Expand
System.Runtime
-
Expand
System.Runtime.InteropServices.Expando
-
Expand
System.Runtime.ConstrainedExecution
-
Expand
System.Runtime.Remoting.Activation
-
Expand
System.Runtime.Remoting.Messaging
-
Expand
System.Runtime.Remoting.Channels
-
Expand
System.Runtime.Remoting.Lifetime
-
Expand
System.Runtime.Remoting
-
Expand
System.Runtime.Remoting.Contexts
-
Expand
System.Runtime.Remoting.Proxies
-
Expand
System.Runtime.Remoting.Metadata
-
Expand
System.Runtime.Remoting.Metadata.W3cXsd2001
-
Expand
System.Runtime.Remoting.Services
-
Expand
System.Runtime.Serialization
-
Expand
System.Runtime.Serialization.Formatters
-
Expand
System.Runtime.Serialization.Formatters.Binary
-
Expand
System.Runtime.Versioning
-
Expand
System.Security
-
Expand
System.Security.Cryptography
-
Expand
System.Security.Cryptography.X509Certificates
-
Expand
System.Security.Permissions
-
Expand
System.Security.Policy
-
Expand
System.Security.Principal
-
Expand
System.Security.Util
-
Expand
System.Text
-
Expand
System.Threading
-
Expand
System.Runtime.Remoting.Channels.Http
-
Expand
System.Runtime.Remoting.Channels.Tcp
-
Expand
System.Runtime.Remoting.MetadataServices
-
Expand
System.Runtime.Serialization.Formatters.Soap.Xml
-
Expand
System.Runtime.Serialization.Formatters.Soap
-
Expand
Microsoft.Tools.Caspol
-
Expand
Microsoft.Tools.Build
-
Expand
Microsoft.CSharp
-
Expand
System.CodeDom
-
Expand
System.CodeDom.Compiler
-
Expand
System.Collections.Specialized
-
Expand
System.ComponentModel
-
Expand
System.ComponentModel.Design
-
Expand
System.ComponentModel.Design.Serialization
-
Expand
System.Configuration
-
Expand
System.Web
-
Expand
System.Configuration.Provider
-
Expand
System.Configuration.Internal
-
Expand
System.Internal
-
Expand
System.Windows.Forms
-
Expand
System.Net
-
Expand
System.Net.Sockets
-
Expand
System.Net.NetworkInformation
-
Expand
System.Net.ComImports
-
Expand
System.Net.Security
-
Expand
System.Net.Cache
-
Expand
System.Net.Configuration
-
Expand
System.Text.RegularExpressions
-
Expand
System.Tools
-
Expand
System.IO.Compression
-
Expand
System.IO.Ports
-
Expand
System.Security.AccessControl
-
Expand
System.Xml
-
Expand
System.Xml.XPath.DataBinding
-
Expand
System.Xml.Schema
-
Expand
System.Xml.Serialization
-
Expand
System.Xml.Serialization.Advanced
-
Expand
System.Xml.Serialization.Configuration
-
Expand
System.Xml.XPath
-
Expand
System.Xml.Xsl
-
Expand
System.Xml.Xsl.IlGen
-
Expand
System.Xml.Xsl.Qil
-
Expand
System.Xml.Xsl.Runtime
-
Expand
System.Xml.Xsl.XPath
-
Expand
System.Xml.Xsl.Xslt
-
Expand
System.Xml.Xsl.XsltOld
-
Expand
System.Xml.Xsl.XsltOld.Debugger
-
Expand
Microsoft.JScript
-
Expand
Microsoft.Vsa
-
Expand
Microsoft.JScript.Vsa
- namespace System.Reflection.Emit
- {
- using System;
- using TextWriter = System.IO.TextWriter;
- using System.Diagnostics.SymbolStore;
- using System.Runtime.InteropServices;
- using System.Reflection;
- using System.Security.Permissions;
- using System.Globalization;
-
- [ClassInterface(ClassInterfaceType.None)]
- [ComDefaultInterface(typeof(_ILGenerator))]
- [System.Runtime.InteropServices.ComVisible(true)]
- public class ILGenerator : _ILGenerator
- {
- #region Const Members
- internal const byte PrefixInstruction = (byte)255;
- internal const int defaultSize = 16;
- internal const int DefaultFixupArraySize = 64;
- internal const int DefaultLabelArraySize = 16;
- internal const int DefaultExceptionArraySize = 8;
- #endregion
-
- #region Internal Statics
- static internal int[] EnlargeArray(int[] incoming)
- {
- int[] temp = new int[incoming.Length * 2];
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal byte[] EnlargeArray(byte[] incoming)
- {
- byte[] temp = new byte[incoming.Length * 2];
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal byte[] EnlargeArray(byte[] incoming, int requiredSize)
- {
- byte[] temp = new byte[requiredSize];
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal __FixupData[] EnlargeArray(__FixupData[] incoming)
- {
- __FixupData[] temp = new __FixupData[incoming.Length * 2];
-
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal Type[] EnlargeArray(Type[] incoming)
- {
- Type[] temp = new Type[incoming.Length * 2];
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal __ExceptionInfo[] EnlargeArray(__ExceptionInfo[] incoming)
- {
- __ExceptionInfo[] temp = new __ExceptionInfo[incoming.Length * 2];
- Array.Copy(incoming, temp, incoming.Length);
- return temp;
- }
-
- static internal int CalculateNumberOfExceptions(__ExceptionInfo[] excp)
- {
- int num = 0;
- if (excp == null)
- return 0;
- for (int i = 0; i < excp.Length; i++)
- num += excp[i].GetNumberOfCatches();
- return num;
- }
-
- #endregion
-
- #region Internal Data Members
- internal int m_length;
- internal byte[] m_ILStream;
-
- internal int[] m_labelList;
- internal int m_labelCount;
-
- internal __FixupData[] m_fixupData;
-
-
-
-
-
-
- internal int m_fixupCount;
-
- internal int[] m_RVAFixupList;
- internal int m_RVAFixupCount;
-
- internal int[] m_RelocFixupList;
- internal int m_RelocFixupCount;
-
- internal int m_exceptionCount;
- internal int m_currExcStackCount;
- internal __ExceptionInfo[] m_exceptions;
-
- internal __ExceptionInfo[] m_currExcStack;
-
- internal ScopeTree m_ScopeTree;
-
- internal LineNumberInfo m_LineNumberInfo;
-
- internal MethodInfo m_methodBuilder;
- internal int m_localCount;
- internal SignatureHelper m_localSignature;
-
- internal int m_maxStackSize = 0;
-
- internal int m_maxMidStack = 0;
-
- internal int m_maxMidStackCur = 0;
-
- #endregion
- #region Constructor
-
-
- internal ILGenerator(MethodInfo methodBuilder) : this(methodBuilder, 64)
- {
- }
-
- internal ILGenerator(MethodInfo methodBuilder, int size)
- {
- if (size < defaultSize) {
- m_ILStream = new byte[defaultSize];
- }
- else {
- m_ILStream = new byte[size];
- }
-
- m_length = 0;
-
- m_labelCount = 0;
- m_fixupCount = 0;
- m_labelList = null;
-
- m_fixupData = null;
-
- m_exceptions = null;
- m_exceptionCount = 0;
- m_currExcStack = null;
- m_currExcStackCount = 0;
-
- m_RelocFixupList = new int[DefaultFixupArraySize];
- m_RelocFixupCount = 0;
- m_RVAFixupList = new int[DefaultFixupArraySize];
- m_RVAFixupCount = 0;
-
-
- m_ScopeTree = new ScopeTree();
- m_LineNumberInfo = new LineNumberInfo();
- m_methodBuilder = methodBuilder;
-
-
- m_localCount = 0;
- MethodBuilder mb = m_methodBuilder as MethodBuilder;
- if (mb == null)
- m_localSignature = SignatureHelper.GetLocalVarSigHelper(null);
- else
- m_localSignature = SignatureHelper.GetLocalVarSigHelper(mb.GetTypeBuilder().Module);
- }
-
- internal ILGenerator(int size)
- {
- if (size < defaultSize)
- m_ILStream = new byte[defaultSize];
- else
- m_ILStream = new byte[size];
- m_length = 0;
-
- m_labelCount = 0;
- m_fixupCount = 0;
- m_labelList = null;
-
- m_fixupData = null;
-
- m_exceptions = null;
- m_exceptionCount = 0;
- m_currExcStack = null;
- m_currExcStackCount = 0;
-
- m_RelocFixupList = new int[DefaultFixupArraySize];
- m_RelocFixupCount = 0;
- m_RVAFixupList = new int[DefaultFixupArraySize];
- m_RVAFixupCount = 0;
-
-
- m_ScopeTree = new ScopeTree();
- m_LineNumberInfo = new LineNumberInfo();
- m_methodBuilder = null;
-
-
- m_localCount = 0;
- m_localSignature = SignatureHelper.GetLocalVarSigHelper(null);
- }
-
- #endregion
-
- #region Private Members
- private void RecordTokenFixup()
- {
- if (m_RelocFixupCount >= m_RelocFixupList.Length)
- m_RelocFixupList = EnlargeArray(m_RelocFixupList);
-
- m_RelocFixupList[m_RelocFixupCount++] = m_length;
- }
-
- #endregion
-
- #region Internal Members
- internal void InternalEmit(OpCode opcode)
- {
- if (opcode.m_size == 1) {
- m_ILStream[m_length++] = opcode.m_s2;
- }
- else {
- m_ILStream[m_length++] = opcode.m_s1;
- m_ILStream[m_length++] = opcode.m_s2;
- }
-
- UpdateStackSize(opcode, opcode.StackChange());
-
- }
-
- internal void UpdateStackSize(OpCode opcode, int stackchange)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- m_maxMidStackCur += stackchange;
- if (m_maxMidStackCur > m_maxMidStack)
- m_maxMidStack = m_maxMidStackCur;
- else if (m_maxMidStackCur < 0)
- m_maxMidStackCur = 0;
-
-
-
-
-
- if (opcode.EndsUncondJmpBlk()) {
- m_maxStackSize += m_maxMidStack;
- m_maxMidStack = 0;
- m_maxMidStackCur = 0;
- }
- }
-
- internal virtual int GetMethodToken(MethodBase method, Type[] optionalParameterTypes)
- {
- int tk = 0;
- ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
-
- if (method.IsGenericMethod) {
-
- MethodInfo methodInfoUnbound = method as MethodInfo;
-
- if (!method.IsGenericMethodDefinition && method is MethodInfo)
- methodInfoUnbound = ((MethodInfo)method).GetGenericMethodDefinition();
-
- if (methodInfoUnbound.Module != m_methodBuilder.Module || (methodInfoUnbound.DeclaringType != null && methodInfoUnbound.DeclaringType.IsGenericType))
- tk = GetMemberRefToken(methodInfoUnbound, null);
- else
- tk = modBuilder.GetMethodToken(methodInfoUnbound).Token;
-
-
- int sigLength;
- byte[] sigBytes = SignatureHelper.GetMethodSpecSigHelper(modBuilder, method.GetGenericArguments()).InternalGetSignature(out sigLength);
-
-
- tk = TypeBuilder.InternalDefineMethodSpec(tk, sigBytes, sigLength, modBuilder);
- }
- else {
- if (((method.CallingConvention & CallingConventions.VarArgs) == 0) && (method.DeclaringType == null || !method.DeclaringType.IsGenericType)) {
- if (method is MethodInfo)
- tk = modBuilder.GetMethodToken(method as MethodInfo).Token;
- else
- tk = modBuilder.GetConstructorToken(method as ConstructorInfo).Token;
- }
- else {
- tk = GetMemberRefToken(method, optionalParameterTypes);
- }
- }
-
- return tk;
- }
-
- internal virtual int GetMemberRefToken(MethodBase method, Type[] optionalParameterTypes)
- {
- Type[] parameterTypes;
- Type returnType;
- int tkParent;
- ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
- int cGenericParameters = 0;
-
- if (method.IsGenericMethod) {
- if (!method.IsGenericMethodDefinition)
- throw new InvalidOperationException();
-
- cGenericParameters = method.GetGenericArguments().Length;
- }
-
- if (optionalParameterTypes != null) {
- if ((method.CallingConvention & CallingConventions.VarArgs) == 0) {
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
- }
- }
-
- if (method.DeclaringType.IsGenericType) {
- MethodBase methDef = null;
-
- if (method is MethodOnTypeBuilderInstantiation) {
- methDef = (method as MethodOnTypeBuilderInstantiation).m_method;
- }
- else if (method is ConstructorOnTypeBuilderInstantiation) {
- methDef = (method as ConstructorOnTypeBuilderInstantiation).m_ctor;
- }
- else if (method is MethodBuilder || method is ConstructorBuilder) {
-
- methDef = method;
- }
- else if (method.IsGenericMethod) {
- methDef = ((MethodInfo)method).GetGenericMethodDefinition();
- methDef = methDef.Module.ResolveMethod(methDef.MetadataTokenInternal, methDef.GetGenericArguments(), methDef.DeclaringType != null ? methDef.DeclaringType.GetGenericArguments() : null) as MethodBase;
- }
- else {
- methDef = method;
- methDef = method.Module.ResolveMethod(method.MetadataTokenInternal, null, methDef.DeclaringType != null ? methDef.DeclaringType.GetGenericArguments() : null) as MethodBase;
- }
-
- parameterTypes = methDef.GetParameterTypes();
- returnType = methDef.GetReturnType();
- }
- else {
- parameterTypes = method.GetParameterTypes();
- returnType = method.GetReturnType();
- }
-
- if (method.DeclaringType.IsGenericType) {
- int length;
- byte[] sig = SignatureHelper.GetTypeSigToken(modBuilder, method.DeclaringType).InternalGetSignature(out length);
- tkParent = modBuilder.InternalGetTypeSpecTokenWithBytes(sig, length);
- }
- else if (method.Module != modBuilder) {
-
- tkParent = modBuilder.GetTypeToken(method.DeclaringType).Token;
- }
- else {
-
- if (method is MethodInfo)
- tkParent = modBuilder.GetMethodToken(method as MethodInfo).Token;
- else
- tkParent = modBuilder.GetConstructorToken(method as ConstructorInfo).Token;
- }
-
- int sigLength;
- byte[] sigBytes = GetMemberRefSignature(method.CallingConvention, returnType, parameterTypes, optionalParameterTypes, cGenericParameters).InternalGetSignature(out sigLength);
-
- return modBuilder.InternalGetMemberRefFromSignature(tkParent, method.Name, sigBytes, sigLength);
- }
-
- internal virtual SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
- {
- return GetMemberRefSignature(call, returnType, parameterTypes, optionalParameterTypes, 0);
- }
-
- internal virtual SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes, int cGenericParameters)
- {
- int cParams;
- int i;
- SignatureHelper sig;
-
- if (parameterTypes == null) {
- cParams = 0;
- }
- else {
- cParams = parameterTypes.Length;
- }
-
- sig = SignatureHelper.GetMethodSigHelper(m_methodBuilder.Module, call, returnType, cGenericParameters);
-
- for (i = 0; i < cParams; i++)
- sig.AddArgument(parameterTypes[i]);
-
- if (optionalParameterTypes != null && optionalParameterTypes.Length != 0) {
-
- sig.AddSentinel();
-
- for (i = 0; i < optionalParameterTypes.Length; i++)
- sig.AddArgument(optionalParameterTypes[i]);
- }
-
- return sig;
- }
-
- internal virtual byte[] BakeByteArray()
- {
-
-
-
-
-
- int newSize;
- int updateAddr;
- byte[] newBytes;
-
- if (m_currExcStackCount != 0) {
- throw new ArgumentException(Environment.GetResourceString("Argument_UnclosedExceptionBlock"));
- }
- if (m_length == 0)
- return null;
-
-
- newSize = m_length;
-
-
- newBytes = new byte[newSize];
-
-
- Array.Copy(m_ILStream, newBytes, newSize);
-
-
-
-
- for (int i = 0; i < m_fixupCount; i++) {
- updateAddr = GetLabelPos(m_fixupData[i].m_fixupLabel) - (m_fixupData[i].m_fixupPos + m_fixupData[i].m_fixupInstSize);
-
-
-
- if (m_fixupData[i].m_fixupInstSize == 1) {
-
-
- if (updateAddr < SByte.MinValue || updateAddr > SByte.MaxValue) {
-
- throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("NotSupported_IllegalOneByteBranch"), m_fixupData[i].m_fixupPos, updateAddr));
- }
-
-
- if (updateAddr < 0) {
-
- newBytes[m_fixupData[i].m_fixupPos] = (byte)(256 + updateAddr);
- }
- else {
- newBytes[m_fixupData[i].m_fixupPos] = (byte)updateAddr;
- }
- }
- else {
-
- PutInteger4(updateAddr, m_fixupData[i].m_fixupPos, newBytes);
- }
- }
- return newBytes;
- }
-
- internal virtual __ExceptionInfo[] GetExceptions()
- {
- __ExceptionInfo[] temp;
- if (m_currExcStackCount != 0) {
- throw new NotSupportedException(Environment.GetResourceString(ResId.Argument_UnclosedExceptionBlock));
- }
-
- if (m_exceptionCount == 0) {
- return null;
- }
-
- temp = new __ExceptionInfo[m_exceptionCount];
- Array.Copy(m_exceptions, temp, m_exceptionCount);
- SortExceptions(temp);
- return temp;
- }
-
- internal virtual void EnsureCapacity(int size)
- {
-
- if (m_length + size >= m_ILStream.Length) {
- if (m_length + size >= 2 * m_ILStream.Length) {
- m_ILStream = EnlargeArray(m_ILStream, m_length + size);
- }
- else {
- m_ILStream = EnlargeArray(m_ILStream);
- }
- }
- }
-
- internal virtual int PutInteger4(int value, int startPos, byte[] array)
- {
-
-
- array[startPos++] = (byte)value;
- array[startPos++] = (byte)(value >> 8);
- array[startPos++] = (byte)(value >> 16);
- array[startPos++] = (byte)(value >> 24);
- return startPos;
- }
-
- internal virtual int GetLabelPos(Label lbl)
- {
-
-
-
- int index = lbl.GetLabelValue();
-
- if (index < 0 || index >= m_labelCount)
- throw new ArgumentException(Environment.GetResourceString("Argument_BadLabel"));
-
- if (m_labelList[index] < 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_BadLabelContent"));
-
- return m_labelList[index];
- }
-
- internal virtual void AddFixup(Label lbl, int pos, int instSize)
- {
-
-
-
- if (m_fixupData == null) {
- m_fixupData = new __FixupData[DefaultFixupArraySize];
- }
-
- if (m_fixupCount >= m_fixupData.Length) {
- m_fixupData = EnlargeArray(m_fixupData);
- }
-
- m_fixupData[m_fixupCount].m_fixupPos = pos;
- m_fixupData[m_fixupCount].m_fixupLabel = lbl;
- m_fixupData[m_fixupCount].m_fixupInstSize = instSize;
- m_fixupCount++;
- }
-
- internal virtual int GetMaxStackSize()
- {
- MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
- if (methodBuilder == null)
- throw new NotSupportedException();
- return m_maxStackSize + methodBuilder.GetNumberOfExceptions();
- }
-
- internal virtual void SortExceptions(__ExceptionInfo[] exceptions)
- {
-
- int least;
- __ExceptionInfo temp;
- int length = exceptions.Length;
- for (int i = 0; i < length; i++) {
- least = i;
- for (int j = i + 1; j < length; j++) {
- if (exceptions[least].IsInner(exceptions[j])) {
- least = j;
- }
- }
- temp = exceptions[i];
- exceptions[i] = exceptions[least];
- exceptions[least] = temp;
- }
- }
-
- internal virtual int[] GetTokenFixups()
- {
-
- int[] narrowTokens = new int[m_RelocFixupCount];
- Array.Copy(m_RelocFixupList, narrowTokens, m_RelocFixupCount);
- return narrowTokens;
- }
-
- internal virtual int[] GetRVAFixups()
- {
-
- int[] narrowRVAs = new int[m_RVAFixupCount];
- Array.Copy(m_RVAFixupList, narrowRVAs, m_RVAFixupCount);
- return narrowRVAs;
- }
- #endregion
-
- #region Public Members
-
- #region Emit
- public virtual void Emit(OpCode opcode)
- {
- EnsureCapacity(3);
- InternalEmit(opcode);
-
- }
-
- public virtual void Emit(OpCode opcode, byte arg)
- {
- EnsureCapacity(4);
- InternalEmit(opcode);
- m_ILStream[m_length++] = arg;
- }
-
- [CLSCompliant(false)]
- public void Emit(OpCode opcode, sbyte arg)
- {
-
-
- EnsureCapacity(4);
- InternalEmit(opcode);
- if (arg < 0) {
- m_ILStream[m_length++] = (byte)(256 + arg);
- }
- else {
- m_ILStream[m_length++] = (byte)arg;
- }
- }
-
- public virtual void Emit(OpCode opcode, short arg)
- {
-
- EnsureCapacity(5);
- InternalEmit(opcode);
- m_ILStream[m_length++] = (byte)arg;
- m_ILStream[m_length++] = (byte)(arg >> 8);
- }
-
- public virtual void Emit(OpCode opcode, int arg)
- {
-
- EnsureCapacity(7);
- InternalEmit(opcode);
- m_length = PutInteger4(arg, m_length, m_ILStream);
- }
-
- public virtual void Emit(OpCode opcode, MethodInfo meth)
- {
- if (opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)) {
- EmitCall(opcode, meth, null);
- }
- else {
- int stackchange = 0;
-
- if (meth == null)
- throw new ArgumentNullException("meth");
-
- int tk = GetMethodToken(meth, null);
-
- EnsureCapacity(7);
- InternalEmit(opcode);
-
- UpdateStackSize(opcode, stackchange);
- RecordTokenFixup();
- m_length = PutInteger4(tk, m_length, m_ILStream);
- }
- }
-
-
- public virtual void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
- {
- int stackchange = 0;
- SignatureHelper sig;
- if (optionalParameterTypes != null) {
- if ((callingConvention & CallingConventions.VarArgs) == 0) {
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
- }
- }
-
- ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
- sig = GetMemberRefSignature(callingConvention, returnType, parameterTypes, optionalParameterTypes);
-
- EnsureCapacity(7);
- Emit(OpCodes.Calli);
-
-
- BCLDebug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode passed to EmitCalli.");
-
- if (returnType != typeof(void))
- stackchange++;
-
- if (parameterTypes != null)
- stackchange -= parameterTypes.Length;
-
- if (optionalParameterTypes != null)
- stackchange -= optionalParameterTypes.Length;
-
- if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
- stackchange--;
-
- stackchange--;
- UpdateStackSize(opcode, stackchange);
-
- RecordTokenFixup();
- m_length = PutInteger4(modBuilder.GetSignatureToken(sig).Token, m_length, m_ILStream);
- }
-
- public virtual void EmitCalli(OpCode opcode,