Inheritance: _SignatureHelper
Esempio n. 1
0
        internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName, 
            CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
        {
            // This is a kind of MethodInfo to represent methods for array type of unbaked type

            // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment
            // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing 
            // passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
            // the name of the method on Array. 
            // As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
            m_mdMethod = token;

            // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
            m_returnType = returnType;
            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = EmptyArray<Type>.Value; 
            }
   
            m_module = mod;
            m_containingType = arrayClass;
            m_name = methodName;
            m_callingConvention = callingConvention;

            m_signature = SignatureHelper.GetMethodSigHelper(
                mod, callingConvention, returnType, null, null, parameterTypes, null, null);
        }
Esempio n. 2
0
        private static IUnknownReleaseDelegate Create_IUnknownRelease()
        {
            DynamicMethod dm = new DynamicMethod("IUnknownRelease", typeof(int), new Type[] { typeof(IntPtr) }, DynamicModule);

            ILGenerator method = dm.GetILGenerator();

            // return functionPtr(...)

            method.Emit(OpCodes.Ldarg_0);

            // functionPtr = *(IntPtr*)(*(interfacePointer) + VTABLE_OFFSET)
            int iunknownReleaseOffset = ((int)IDispatchMethodIndices.IUnknown_Release) * Marshal.SizeOf(typeof(IntPtr));

            method.Emit(OpCodes.Ldarg_0);
            method.Emit(OpCodes.Ldind_I);
            method.Emit(OpCodes.Ldc_I4, iunknownReleaseOffset);
            method.Emit(OpCodes.Add);
            method.Emit(OpCodes.Ldind_I);

            System.Reflection.Emit.SignatureHelper signature = System.Reflection.Emit.SignatureHelper.GetMethodSigHelper(CallingConvention.Winapi, typeof(int));
            signature.AddArgument(typeof(IntPtr));
            method.Emit(OpCodes.Calli, signature);

            method.Emit(OpCodes.Ret);

            return((IUnknownReleaseDelegate)dm.CreateDelegate(typeof(IUnknownReleaseDelegate)));
        }
Esempio n. 3
0
        //***********************************************
        //
        // Constructor
        // 
        //***********************************************
        internal SymbolMethod(
            ModuleBuilder mod,
            MethodToken token,
            Type        arrayClass, 
            String      methodName, 
            CallingConventions callingConvention,
            Type        returnType,
            Type[]      parameterTypes)

        {
            m_module = mod;
            m_containingType = arrayClass;
            m_name = methodName;
            m_callingConvention = callingConvention;
            m_returnType = returnType;
            m_mdMethod = token;
            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
            }
            else
                m_parameterTypes = null;    
            m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes);
        }
Esempio n. 4
0
 // Constructs a PropertyBuilder.  
 //
 internal PropertyBuilder(
     ModuleBuilder       mod,            // the module containing this PropertyBuilder
     String              name,           // property name
     SignatureHelper     sig,            // property signature descriptor info
     PropertyAttributes  attr,           // property attribute such as DefaultProperty, Bindable, DisplayBind, etc
     Type                returnType,     // return type of the property.
     PropertyToken       prToken,        // the metadata token for this property
     TypeBuilder         containingType) // the containing type
 {
     if (name == null)
         throw new ArgumentNullException("name");
     if (name.Length == 0)
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     if (name[0] == '\0')
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     Contract.EndContractBlock();
     
     m_name = name;
     m_moduleBuilder = mod;
     m_signature = sig;
     m_attributes = attr;
     m_returnType = returnType;
     m_prToken = prToken;
     m_tkProperty = prToken.Token;
     m_containingType = containingType;
 }
Esempio n. 5
0
 internal static SignatureHelper GetMethodSpecSigHelper(Module scope, Type[] inst)
 {
     SignatureHelper sigHelp = new SignatureHelper(scope, MdSigCallingConvention.GenericInst);
     sigHelp.AddData(inst.Length);
     foreach(Type t in inst)
         sigHelp.AddArgument(t);
     return sigHelp;
 }
 internal PropertyBuilder(ModuleBuilder mod, string name, SignatureHelper sig, PropertyAttributes attr, Type returnType, System.Reflection.Emit.PropertyToken prToken, TypeBuilder containingType)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (name[0] == '\0')
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     }
     this.m_name = name;
     this.m_moduleBuilder = mod;
     this.m_signature = sig;
     this.m_attributes = attr;
     this.m_returnType = returnType;
     this.m_prToken = prToken;
     this.m_tkProperty = prToken.Token;
     this.m_containingType = containingType;
 }
 internal ILGenerator(MethodInfo methodBuilder, int size)
 {
     if (size < 0x10)
     {
         this.m_ILStream = new byte[0x10];
     }
     else
     {
         this.m_ILStream = new byte[size];
     }
     this.m_length = 0;
     this.m_labelCount = 0;
     this.m_fixupCount = 0;
     this.m_labelList = null;
     this.m_fixupData = null;
     this.m_exceptions = null;
     this.m_exceptionCount = 0;
     this.m_currExcStack = null;
     this.m_currExcStackCount = 0;
     this.m_RelocFixupList = new int[0x40];
     this.m_RelocFixupCount = 0;
     this.m_RVAFixupList = new int[0x40];
     this.m_RVAFixupCount = 0;
     this.m_ScopeTree = new ScopeTree();
     this.m_LineNumberInfo = new LineNumberInfo();
     this.m_methodBuilder = methodBuilder;
     this.m_localCount = 0;
     MethodBuilder builder = this.m_methodBuilder as MethodBuilder;
     if (builder == null)
     {
         this.m_localSignature = SignatureHelper.GetLocalVarSigHelper(null);
     }
     else
     {
         this.m_localSignature = SignatureHelper.GetLocalVarSigHelper(builder.GetTypeBuilder().Module);
     }
 }
Esempio n. 8
0
        public override bool Equals(object?obj)
        {
            if (!(obj is MethodBuilder))
            {
                return(false);
            }
            if (!m_strName.Equals(((MethodBuilder)obj).m_strName))
            {
                return(false);
            }

            if (m_iAttributes != (((MethodBuilder)obj).m_iAttributes))
            {
                return(false);
            }

            SignatureHelper thatSig = ((MethodBuilder)obj).GetMethodSignature();

            if (thatSig.Equals(GetMethodSignature()))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        internal static SignatureHelper GetMethodSigHelper(
            Module?scope, CallingConventions callingConvention, int cGenericParam,
            Type?returnType, Type[]?requiredReturnTypeCustomModifiers, Type[]?optionalReturnTypeCustomModifiers,
            Type[]?parameterTypes, Type[][]?requiredParameterTypeCustomModifiers, Type[][]?optionalParameterTypeCustomModifiers)
        {
            SignatureHelper        sigHelp;
            MdSigCallingConvention intCall;

            if (returnType == null)
            {
                returnType = typeof(void);
            }

            intCall = MdSigCallingConvention.Default;

            if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
            {
                intCall = MdSigCallingConvention.Vararg;
            }

            if (cGenericParam > 0)
            {
                intCall |= MdSigCallingConvention.Generic;
            }

            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
            {
                intCall |= MdSigCallingConvention.HasThis;
            }

            sigHelp = new SignatureHelper(scope, intCall, cGenericParam, returnType,
                                          requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);
            sigHelp.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);

            return(sigHelp);
        }
Esempio n. 10
0
        public static SignatureHelper GetPropertySigHelper(Module?mod, CallingConventions callingConvention,
                                                           Type?returnType, Type[]?requiredReturnTypeCustomModifiers, Type[]?optionalReturnTypeCustomModifiers,
                                                           Type[]?parameterTypes, Type[][]?requiredParameterTypeCustomModifiers, Type[][]?optionalParameterTypeCustomModifiers)
        {
            SignatureHelper sigHelp;

            if (returnType == null)
            {
                returnType = typeof(void);
            }

            MdSigCallingConvention intCall = MdSigCallingConvention.Property;

            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
            {
                intCall |= MdSigCallingConvention.HasThis;
            }

            sigHelp = new SignatureHelper(mod, intCall,
                                          returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);
            sigHelp.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);

            return(sigHelp);
        }
        internal static SignatureHelper GetMethodSigHelper(Module scope, CallingConventions callingConvention, int cGenericParam, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
        {
            if (returnType == null)
            {
                returnType = typeof(void);
            }
            System.Reflection.MdSigCallingConvention convention = System.Reflection.MdSigCallingConvention.Default;
            if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
            {
                convention = System.Reflection.MdSigCallingConvention.C | System.Reflection.MdSigCallingConvention.FastCall;
            }
            if (cGenericParam > 0)
            {
                convention = (System.Reflection.MdSigCallingConvention)((byte)(convention | (System.Reflection.MdSigCallingConvention.Default | System.Reflection.MdSigCallingConvention.Generic)));
            }
            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
            {
                convention = (System.Reflection.MdSigCallingConvention)((byte)(convention | (System.Reflection.MdSigCallingConvention.Default | System.Reflection.MdSigCallingConvention.HasThis)));
            }
            SignatureHelper helper = new SignatureHelper(scope, convention, cGenericParam, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);

            helper.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
            return(helper);
        }
Esempio n. 12
0
        internal static SignatureHelper GetMethodSigHelper(
            Module mod,
            CallingConventions callingConvention,
            Type returnType,
            Type[]          parameterTypes)
        {
            SignatureHelper sigHelp;
            int             intCall;

            if (returnType == null)
            {
                returnType = typeof(void);
            }

            intCall = IMAGE_CEE_CS_CALLCONV_DEFAULT;
            if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
            {
                intCall = IMAGE_CEE_CS_CALLCONV_VARARG;
            }

            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
            {
                intCall |= IMAGE_CEE_CS_CALLCONV_HASTHIS;
            }

            sigHelp = new SignatureHelper(mod, intCall, (Type)returnType);

            if (parameterTypes != null)
            {
                for (int i = 0; i < parameterTypes.Length; i++)
                {
                    sigHelp.AddArgument(parameterTypes[i]);
                }
            }
            return(sigHelp);
        }
Esempio n. 13
0
 internal int GetSignatureToken(SignatureHelper sigHelper)
 {
     ArgumentNullException.ThrowIfNull(sigHelper);
     return(GetToken(sigHelper));
 }
Esempio n. 14
0
		public int GetToken (SignatureHelper helper) {
			return mb.GetToken (helper);
		}
Esempio n. 15
0
		public SignatureToken GetSignatureToken (SignatureHelper sigHelper)
		{
			if (sigHelper == null)
				throw new ArgumentNullException ("sigHelper");
			return new SignatureToken (GetToken (sigHelper));
		}
Esempio n. 16
0
        /// <include file='doc\SignatureHelper.uex' path='docs/doc[@for="SignatureHelper.GetMethodSigHelper2"]/*' />
        public static SignatureHelper GetMethodSigHelper(
            Module          mod, 
            CallingConvention unmanagedCallConv, 
            Type            returnType) 
        {
            SignatureHelper sigHelp;
            int             intCall;
                
            if (returnType == null)
            {
                returnType = typeof(void);
            }            

            if (unmanagedCallConv ==  CallingConvention.Cdecl)
                intCall = IMAGE_CEE_UNMANAGED_CALLCONV_C;
            else if (unmanagedCallConv ==  CallingConvention.StdCall)
                intCall = IMAGE_CEE_UNMANAGED_CALLCONV_STDCALL;
            else if (unmanagedCallConv ==  CallingConvention.ThisCall)
                intCall = IMAGE_CEE_UNMANAGED_CALLCONV_THISCALL;
            else if (unmanagedCallConv ==  CallingConvention.FastCall)
                intCall = IMAGE_CEE_UNMANAGED_CALLCONV_FASTCALL;
            else
                throw new ArgumentException(Environment.GetResourceString("Argument_UnknownUnmanagedCallConv"), "unmanagedCallConv");                          
            
            sigHelp = new SignatureHelper(mod, intCall, (Type)returnType);
            
            return sigHelp;
        }
Esempio n. 17
0
        private void Init(
            String name,
            MethodAttributes attributes,
            CallingConventions callingConvention,
            Type returnType,
            Type[]              parameterTypes,
            Module mod,
            TypeBuilder type,
            bool bIsGlobalMethod)
        {
            m_strName        = name;
            m_localSignature = SignatureHelper.GetLocalVarSigHelper(mod);
            m_module         = mod;
            m_containingType = type;
            if (returnType == null)
            {
                m_returnType = typeof(void);
            }
            else
            {
                m_returnType = returnType;
            }

            if ((attributes & MethodAttributes.Static) == 0)
            {
                // turn on the has this calling convention
                callingConvention = callingConvention | CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                //A method can't be both static and virtual
                throw new ArgumentException(Environment.GetResourceString("Arg_NoStaticVirtual"));
            }
            if ((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName)
            {
                if ((type.Attributes & TypeAttributes.Interface) == TypeAttributes.Interface)
                {
                    // methods on interface have to be abstract + virtual except special name methods(such as type initializer
                    if ((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) != (MethodAttributes.Abstract | MethodAttributes.Virtual))
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod"));
                    }
                }
            }

            m_callingConvention = callingConvention;
            m_returnType        = returnType;

            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = null;
            }

            m_signature       = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes);
            m_iAttributes     = attributes;
            m_bIsGlobalMethod = bIsGlobalMethod;
            m_bIsBaked        = false;
            m_fInitLocals     = true;

            m_localSymInfo = new LocalSymInfo();
            m_ubBody       = null;
            m_ilGenerator  = null;


            // default is managed IL
            // Manged IL has bit flag 0x0020 set off

            m_dwMethodImplFlags = MethodImplAttributes.IL;
        }
Esempio n. 18
0
 internal VarArgMethod(RuntimeMethodInfo method, SignatureHelper signature)
 {
     m_method    = method;
     m_signature = signature;
 }
Esempio n. 19
0
 public int GetToken(SignatureHelper helper)
 {
     return(m.AddRef(helper));
 }
Esempio n. 20
0
        internal static SignatureHelper GetMethodSigHelper(
            Module scope, CallingConventions callingConvention, int cGenericParam,
            Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers,
            Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
        {
            SignatureHelper sigHelp;
            MdSigCallingConvention intCall;
                
            if (returnType == null)
            {
                returnType = typeof(void);
            }            

            intCall = MdSigCallingConvention.Default;

            if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
                intCall = MdSigCallingConvention.Vararg;

            if (cGenericParam > 0)
            {
                intCall |= MdSigCallingConvention.Generic;
            }

            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
                intCall |= MdSigCallingConvention.HasThis;

            sigHelp = new SignatureHelper(scope, intCall, cGenericParam, returnType, 
                                            requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);            
            sigHelp.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);

            return sigHelp;
        }
 /// <summary>Returns a signature helper for a method with a standard calling convention, given the method's module, return type, and argument types.</summary>
 /// <returns>The SignatureHelper object for a method.</returns>
 /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param>
 /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param>
 /// <param name="parameterTypes">The types of the arguments of the method, or null if the method has no arguments. </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="mod" /> is null.-or-An element of <paramref name="parameterTypes" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.</exception>
 public static SignatureHelper GetMethodSigHelper(Module mod, Type returnType, Type[] parameterTypes)
 {
     return(SignatureHelper.GetMethodSigHelper(mod, CallingConventions.Standard, (CallingConvention)0, returnType, parameterTypes));
 }
 public virtual new void Emit(OpCode opcode, SignatureHelper signature)
 {
 }
Esempio n. 23
0
 /// <summary>Puts the specified instruction and a signature token onto the Microsoft intermediate language (MSIL) stream of instructions.</summary>
 /// <param name="opcode">The MSIL instruction to be emitted onto the stream. </param>
 /// <param name="signature">A helper for constructing a signature token. </param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="signature" /> is null. </exception>
 /// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
 public static ILGenerator FluentEmit(this ILGenerator generator, System.Reflection.Emit.OpCode opcode, System.Reflection.Emit.SignatureHelper signature)
 {
     generator.Emit(opcode, signature);
     return(generator);
 }
        /// <summary>Checks if this instance is equal to the given object.</summary>
        /// <returns>true if the given object is a SignatureHelper and represents the same signature; otherwise, false.</returns>
        /// <param name="obj">The object with which this instance should be compared. </param>
        public override bool Equals(object obj)
        {
            SignatureHelper signatureHelper = obj as SignatureHelper;

            if (signatureHelper == null)
            {
                return(false);
            }
            if (signatureHelper.module != this.module || signatureHelper.returnType != this.returnType || signatureHelper.callConv != this.callConv || signatureHelper.unmanagedCallConv != this.unmanagedCallConv)
            {
                return(false);
            }
            if (this.arguments != null)
            {
                if (signatureHelper.arguments == null)
                {
                    return(false);
                }
                if (this.arguments.Length != signatureHelper.arguments.Length)
                {
                    return(false);
                }
                for (int i = 0; i < this.arguments.Length; i++)
                {
                    if (!signatureHelper.arguments[i].Equals(this.arguments[i]))
                    {
                        return(false);
                    }
                }
            }
            else if (signatureHelper.arguments != null)
            {
                return(false);
            }
            return(SignatureHelper.CompareOK(signatureHelper.modreqs, this.modreqs) && SignatureHelper.CompareOK(signatureHelper.modopts, this.modopts));
        }
Esempio n. 25
0
 public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
 {
     // TODO
     return(new SignatureToken(0));
 }
Esempio n. 26
0
		public int GetToken (SignatureHelper helper) {
			return m.AddRef (helper);
		}
Esempio n. 27
0
 internal int GetToken(SignatureHelper helper)
 {
     return(getToken(this, helper, true));
 }
Esempio n. 28
0
        public static SignatureHelper GetMethodSigHelper(Module mod, CallingConvention unmanagedCallConv, Type returnType)
        {
            SignatureHelper sigHelp;
            MdSigCallingConvention intCall;
                
            if (returnType == null)
                returnType = typeof(void);

            if (unmanagedCallConv == CallingConvention.Cdecl)
            {
                intCall = MdSigCallingConvention.C;
            }
            else if (unmanagedCallConv == CallingConvention.StdCall || unmanagedCallConv == CallingConvention.Winapi)
            {
                intCall = MdSigCallingConvention.StdCall;
            }
            else if (unmanagedCallConv == CallingConvention.ThisCall)
            {
                intCall = MdSigCallingConvention.ThisCall;
            }
            else if (unmanagedCallConv == CallingConvention.FastCall)
            {
                intCall = MdSigCallingConvention.FastCall;
            }
            else
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_UnknownUnmanagedCallConv"), nameof(unmanagedCallConv));                          
            }
            
            sigHelp = new SignatureHelper(mod, intCall, returnType, null, null);
            
            return sigHelp;
        }
Esempio n. 29
0
        private static IDispatchInvokeDelegate Create_IDispatchInvoke(bool returnResult)
        {
            const int dispatchPointerIndex = 0;
            const int memberDispIdIndex    = 1;
            const int flagsIndex           = 2;
            const int dispParamsIndex      = 3;
            const int resultIndex          = 4;
            const int exceptInfoIndex      = 5;
            const int argErrIndex          = 6;

            Debug.Assert(argErrIndex + 1 == typeof(IDispatchInvokeDelegate).GetMethod("Invoke").GetParameters().Length);

            Type[] paramTypes = new Type[argErrIndex + 1];
            paramTypes[dispatchPointerIndex] = typeof(IntPtr);
            paramTypes[memberDispIdIndex]    = typeof(int);
            paramTypes[flagsIndex]           = typeof(ComTypes.INVOKEKIND);
            paramTypes[dispParamsIndex]      = typeof(ComTypes.DISPPARAMS).MakeByRefType();
            paramTypes[resultIndex]          = typeof(Variant).MakeByRefType();
            paramTypes[exceptInfoIndex]      = typeof(ExcepInfo).MakeByRefType();
            paramTypes[argErrIndex]          = typeof(uint).MakeByRefType();

            // Define the dynamic method in our assembly so we skip verification
            DynamicMethod dm     = new DynamicMethod("IDispatchInvoke", typeof(int), paramTypes, DynamicModule);
            ILGenerator   method = dm.GetILGenerator();

            // return functionPtr(...)

            EmitLoadArg(method, dispatchPointerIndex);
            EmitLoadArg(method, memberDispIdIndex);

            // burn the address of our empty IID in directly.  This is never freed, relocated, etc...
            // Note passing this as a Guid directly results in a ~30% perf hit for IDispatch invokes so
            // we also pass it directly as an IntPtr instead.
            if (IntPtr.Size == 4)
            {
                method.Emit(OpCodes.Ldc_I4, UnsafeMethods.NullInterfaceId.ToInt32()); // riid
            }
            else
            {
                method.Emit(OpCodes.Ldc_I8, UnsafeMethods.NullInterfaceId.ToInt64()); // riid
            }

            method.Emit(OpCodes.Conv_I);

            method.Emit(OpCodes.Ldc_I4_0); // lcid
            EmitLoadArg(method, flagsIndex);

            EmitLoadArg(method, dispParamsIndex);

            if (returnResult)
            {
                EmitLoadArg(method, resultIndex);
            }
            else
            {
                method.Emit(OpCodes.Ldsfld, typeof(IntPtr).GetField("Zero"));
            }

            EmitLoadArg(method, exceptInfoIndex);
            EmitLoadArg(method, argErrIndex);

            // functionPtr = *(IntPtr*)(*(dispatchPointer) + VTABLE_OFFSET)
            int idispatchInvokeOffset = ((int)IDispatchMethodIndices.IDispatch_Invoke) * Marshal.SizeOf(typeof(IntPtr));

            EmitLoadArg(method, dispatchPointerIndex);
            method.Emit(OpCodes.Ldind_I);
            method.Emit(OpCodes.Ldc_I4, idispatchInvokeOffset);
            method.Emit(OpCodes.Add);
            method.Emit(OpCodes.Ldind_I);

            System.Reflection.Emit.SignatureHelper signature = System.Reflection.Emit.SignatureHelper.GetMethodSigHelper(CallingConvention.Winapi, typeof(int));
            Type[] invokeParamTypes = new Type[] {
                typeof(IntPtr),     // dispatchPointer
                typeof(int),        // memberDispId
                typeof(IntPtr),     // riid
                typeof(int),        // lcid
                typeof(ushort),     // flags
                typeof(IntPtr),     // dispParams
                typeof(IntPtr),     // result
                typeof(IntPtr),     // excepInfo
                typeof(IntPtr),     // argErr
            };
            signature.AddArguments(invokeParamTypes, null, null);
            method.Emit(OpCodes.Calli, signature);

            method.Emit(OpCodes.Ret);
            return((IDispatchInvokeDelegate)dm.CreateDelegate(typeof(IDispatchInvokeDelegate)));
        }
Esempio n. 30
0
        // Constructor.
        internal MethodBuilder(TypeBuilder type, String name,
                               MethodAttributes attributes,
                               CallingConventions callingConvention,
                               Type returnType, Type[] parameterTypes)
        {
            // Validate the parameters.
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            else if (name == String.Empty)
            {
                throw new ArgumentException(_("Emit_NameEmpty"));
            }
            if (returnType == null)
            {
                returnType = typeof(void);
            }
            if ((attributes & MethodAttributes.Static) == 0)
            {
                callingConvention |= CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                throw new ArgumentException
                          (_("Emit_BothStaticAndVirtual"));
            }
            if ((type.Attributes & TypeAttributes.ClassSemanticsMask)
                == TypeAttributes.Interface &&
                (attributes & MethodAttributes.SpecialName) == 0)
            {
                if ((attributes & (MethodAttributes.Virtual |
                                   MethodAttributes.Abstract))
                    != (MethodAttributes.Virtual |
                        MethodAttributes.Abstract))
                {
                    throw new ArgumentException
                              (_("Emit_InterfaceMethodAttrs"));
                }
            }

            // Set the local state.
            this.type          = type;
            this.bodySet       = false;
            this.initLocals    = true;
            this.explicitBody  = null;
            this.ilGenerator   = null;
            this.returnType    = returnType;
            this.returnBuilder = null;
            this.numParams     = (parameterTypes != null
                                                                        ? parameterTypes.Length : 0);

            // Register this item to be detached later.
            type.module.assembly.AddDetach(this);

            // Create the method signature.
            helper = SignatureHelper.GetMethodSigHelper
                         (type.module, callingConvention,
                         (CallingConvention)0,
                         returnType, parameterTypes);

            // Create the method.
            lock (typeof(AssemblyBuilder))
            {
                this.privateData = ClrMethodCreate
                                       (((IClrProgramItem)type).ClrHandle, name,
                                       attributes, helper.sig);
            }

            // Add the method to the type for post-processing.
            type.AddMethod(this);
        }
Esempio n. 31
0
        private int GetTokenForVarArgMethod(DynamicMethod dm, SignatureHelper sig)
        {
            VarArgMethod varArgMeth = new VarArgMethod(dm, sig);

            return(m_scope.GetTokenFor(varArgMeth));
        }
Esempio n. 32
0
        // Define signature token given a signature helper. This will define a metadata
        // token for the signature described by SignatureHelper.
        /// <include file='doc\ModuleBuilder.uex' path='docs/doc[@for="ModuleBuilder.GetSignatureToken"]/*' />
        public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
        {
            BCLDebug.Log("DYNIL","## DYNIL LOGGING: ModuleBuilder.GetSignatureToken( )");
            
            int sigLength;
            byte[] sigBytes;
    
            if (sigHelper == null)
            {
                throw new ArgumentNullException("sigHelper");
            }

            // get the signature in byte form
            sigBytes = sigHelper.InternalGetSignature(out sigLength);
            return new SignatureToken(TypeBuilder.InternalGetTokenFromSig(this, sigBytes, sigLength), this);
        }
        public SignatureToken GetSignatureToken(SignatureHelper !sigHelper)
        {
            CodeContract.Requires(sigHelper != null);

            return(default(SignatureToken));
        }
 /// <summary>Returns a signature helper for a method given the method's module, unmanaged calling convention, and return type.</summary>
 /// <returns>The SignatureHelper object for a method.</returns>
 /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param>
 /// <param name="unmanagedCallConv">The unmanaged calling convention of the method. </param>
 /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="mod" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.-or-<paramref name="unmanagedCallConv" /> is an unknown unmanaged calling convention.</exception>
 public static SignatureHelper GetMethodSigHelper(Module mod, CallingConvention unmanagedCallConv, Type returnType)
 {
     return(SignatureHelper.GetMethodSigHelper(mod, CallingConventions.Standard, unmanagedCallConv, returnType, null));
 }
Esempio n. 35
0
        /// <include file='doc\SignatureHelper.uex' path='docs/doc[@for="SignatureHelper.GetPropertySigHelper"]/*' />
        public static SignatureHelper GetPropertySigHelper(Module mod, Type returnType, Type[] parameterTypes) 
        {
            SignatureHelper sigHelp;
                
            if (returnType == null)
            {
                returnType = typeof(void);
            }            

            sigHelp = new SignatureHelper(mod, IMAGE_CEE_CS_CALLCONV_PROPERTY, (Type)returnType);
            
            if (parameterTypes != null)
            {
                for (int i=0; i<parameterTypes.Length; i++) 
                {
                    sigHelp.AddArgument(parameterTypes[i]);
                }
            }
            return sigHelp;
        }
 public virtual void Emit(OpCode opcode, SignatureHelper signature)
 {
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     int stackchange = 0;
     ModuleBuilder module = (ModuleBuilder) this.m_methodBuilder.Module;
     int token = module.GetSignatureToken(signature).Token;
     this.EnsureCapacity(7);
     this.InternalEmit(opcode);
     if (opcode.m_pop == StackBehaviour.Varpop)
     {
         stackchange -= signature.ArgumentCount;
         stackchange--;
         this.UpdateStackSize(opcode, stackchange);
     }
     this.RecordTokenFixup();
     this.PutInteger4(token);
 }
Esempio n. 37
0
		internal int GetToken (SignatureHelper helper) {
			return getToken (this, helper, true);
		}
 /// <summary>Returns a signature helper for a method given the method's module, calling convention, and return type.</summary>
 /// <returns>The SignatureHelper object for a method.</returns>
 /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param>
 /// <param name="callingConvention">The calling convention of the method. </param>
 /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="mod" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.</exception>
 public static SignatureHelper GetMethodSigHelper(Module mod, CallingConventions callingConvention, Type returnType)
 {
     return(SignatureHelper.GetMethodSigHelper(mod, callingConvention, (CallingConvention)0, returnType, null));
 }
Esempio n. 39
0
		public virtual void Emit (OpCode opcode, SignatureHelper signature)
		{
			int token = token_gen.GetToken (signature);
			make_room (6);
			ll_emit (opcode);
			emit_int (token);
		}
        internal SignatureHelper GetMethodSignature()
        {
            if (m_parameterTypes == null)
                m_parameterTypes = new Type[0];

            m_signature = SignatureHelper.GetMethodSigHelper (m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0, 
                m_returnType == null ? typeof(void) : m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers,
                m_parameterTypes, m_parameterTypeRequiredCustomModifiers, m_parameterTypeOptionalCustomModifiers);

            return m_signature;
        }
Esempio n. 41
0
		internal static SignatureHelper GetMethodSigHelper (Module mod, CallingConventions callingConvention, CallingConvention unmanagedCallingConvention, Type returnType,
														   Type [] parameters)
		{
			if (mod != null && !(mod is ModuleBuilder))
				throw new ArgumentException ("ModuleBuilder is expected");

			if (returnType == null)
				returnType = typeof (void);

			if (returnType.IsUserType)
				throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
			if (parameters != null) {
				for (int i = 0; i < parameters.Length; ++i)
					if (parameters [i].IsUserType)
						throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");

			}

			SignatureHelper helper = 
				new SignatureHelper ((ModuleBuilder)mod, SignatureHelperType.HELPER_METHOD);
			helper.returnType = returnType;
			helper.callConv = callingConvention;
			helper.unmanagedCallConv = unmanagedCallingConvention;

			if (parameters != null) {
				helper.arguments = new Type [parameters.Length];
				for (int i = 0; i < parameters.Length; ++i)
					helper.arguments [i] = parameters [i];
			}

			return helper;
		}
        private void Init(String name, MethodAttributes attributes, CallingConventions callingConvention,
            Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
            Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers, 
            Module mod, TypeBuilder type, bool bIsGlobalMethod)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            if (name.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");

            if (name[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");

            if (mod == null)
                throw new ArgumentNullException("mod");

            if (parameterTypes != null)
            {
                foreach(Type t in parameterTypes)
                {
                    if (t == null)
                        throw new ArgumentNullException("parameterTypes");
                }
            }

            m_link = type.m_currentMethod;
            type.m_currentMethod = this;
            m_strName = name;
            m_module = mod;
            m_containingType = type;
            m_localSignature = SignatureHelper.GetLocalVarSigHelper(mod);

            // 
            //if (returnType == null)
            //{
            //    m_returnType = typeof(void);
            //}
            //else
            {
                m_returnType = returnType;
            }

            if ((attributes & MethodAttributes.Static) == 0)
            {
                // turn on the has this calling convention
                callingConvention = callingConvention | CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                // A method can't be both static and virtual
                throw new ArgumentException(Environment.GetResourceString("Arg_NoStaticVirtual"));
            }

            if ((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName)
            {
                if ((type.Attributes & TypeAttributes.Interface) == TypeAttributes.Interface)
                {
                    // methods on interface have to be abstract + virtual except special name methods such as type initializer
                    if ((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) != 
                        (MethodAttributes.Abstract | MethodAttributes.Virtual) &&                         
                        (attributes & MethodAttributes.Static) == 0)
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod"));               
                }
            }

            m_callingConvention = callingConvention;

            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = null;
            }

            m_returnTypeRequiredCustomModifiers = returnTypeRequiredCustomModifiers;
            m_returnTypeOptionalCustomModifiers = returnTypeOptionalCustomModifiers;
            m_parameterTypeRequiredCustomModifiers = parameterTypeRequiredCustomModifiers;
            m_parameterTypeOptionalCustomModifiers = parameterTypeOptionalCustomModifiers;

//            m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, 
//                returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
//                parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);

            m_iAttributes = attributes;
            m_bIsGlobalMethod = bIsGlobalMethod;
            m_bIsBaked = false;
            m_fInitLocals = true;

            m_localSymInfo = new LocalSymInfo();
            m_ubBody = null;
            m_ilGenerator = null;

            // Default is managed IL. Manged IL has bit flag 0x0020 set off
            m_dwMethodImplFlags = MethodImplAttributes.IL;

            //int i = MetadataTokenInternal;
        }
Esempio n. 43
0
 public int GetToken(SignatureHelper helper)
 {
     return(mb.GetToken(helper));
 }
Esempio n. 44
0
 public virtual void Emit(OpCode opcode, SignatureHelper signature)
 {
     throw new PlatformNotSupportedException();
 }
Esempio n. 45
0
 /// <summary>Puts the specified instruction and a signature token onto the Microsoft intermediate language (MSIL) stream of instructions.</summary><param name="opcode">The MSIL instruction to be emitted onto the stream. </param><param name="signature">A helper for constructing a signature token. </param><exception cref="T:System.ArgumentNullException"><paramref name="signature" /> is null. </exception>
 public virtual void Emit(OpCode opcode, SignatureHelper signature)
 {
     throw new NotImplementedException();
 }
Esempio n. 46
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
        {
            // Define signature token given a signature helper. This will define a metadata
            // token for the signature described by SignatureHelper.

            if (sigHelper == null)
            {
                throw new ArgumentNullException("sigHelper");
            }
            Contract.EndContractBlock();

            int sigLength;
            byte[] sigBytes;
    
            // get the signature in byte form
            sigBytes = sigHelper.InternalGetSignature(out sigLength);
            return new SignatureToken(TypeBuilder.GetTokenFromSig(GetNativeHandle(), sigBytes, sigLength), this);
        }           
Esempio n. 47
0
 private int GetTokenForVarArgMethod(DynamicMethod dm, SignatureHelper sig)
 {
     return(this.m_scope.GetTokenFor(new VarArgMethod(dm, sig)));
 }
Esempio n. 48
0
        public virtual void Emit(OpCode opcode, SignatureHelper signature)
        {
            if (signature == null)
                throw new ArgumentNullException("signature");
            Contract.EndContractBlock();

            int stackchange = 0;
            ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
            SignatureToken sig = modBuilder.GetSignatureToken(signature);

            int tempVal = sig.Token;

            EnsureCapacity(7);
            InternalEmit(opcode);

            // The only IL instruction that has VarPop behaviour, that takes a
            // Signature token as a parameter is calli.  Pop the parameters and
            // the native function pointer.  To be conservative, do not pop the
            // this pointer since this information is not easily derived from
            // SignatureHelper.
            if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
            {
                Contract.Assert(opcode.Equals(OpCodes.Calli),
                                "Unexpected opcode encountered for StackBehaviour VarPop.");
                // Pop the arguments..
                stackchange -= signature.ArgumentCount;
                // Pop native function pointer off the stack.
                stackchange--;
                UpdateStackSize(opcode, stackchange);
            }

            RecordTokenFixup();
            PutInteger4(tempVal);
        }
Esempio n. 49
0
 internal VarArgMethod(DynamicMethod dm, SignatureHelper signature)
 {
     m_dynamicMethod = dm;
     m_signature     = signature;
 }
Esempio n. 50
0
        private int GetTokenForVarArgMethod(RuntimeMethodInfo rtMeth, SignatureHelper sig)
        {
#if FEATURE_APPX
            if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
#endif
            VarArgMethod varArgMeth = new VarArgMethod(rtMeth, sig);
            return m_scope.GetTokenFor(varArgMeth);
        }
Esempio n. 51
0
        private int GetTokenForVarArgMethod(RuntimeMethodInfo rtMeth, SignatureHelper sig)
        {
            VarArgMethod varArgMeth = new VarArgMethod(rtMeth, sig);

            return(m_scope.GetTokenFor(varArgMeth));
        }
Esempio n. 52
0
 private int GetTokenForVarArgMethod(DynamicMethod dm, SignatureHelper sig)
 {
     VarArgMethod varArgMeth = new VarArgMethod(dm, sig);
     return m_scope.GetTokenFor(varArgMeth);
 }
Esempio n. 53
0
        public void SetLocalSymInfo(String name, int startOffset, int endOffset)
        {
            ModuleBuilder   dynMod;
            SignatureHelper sigHelp;
            int             sigLength;

            byte[] signature;
            byte[] mungedSig;
            int    index;

            MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;

            if (methodBuilder == null)
            {
                // it's a light code gen entity
                throw new NotSupportedException();
            }
            dynMod = (ModuleBuilder)methodBuilder.Module;
            if (methodBuilder.IsTypeCreated())
            {
                // cannot change method after its containing type has been created
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated"));
            }

            // set the name and range of offset for the local
            if (dynMod.GetSymWriter() == null)
            {
                // cannot set local name if not debug module
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
            }

            sigHelp = SignatureHelper.GetFieldSigHelper(dynMod);
            sigHelp.AddArgument(m_localType);
            signature = sigHelp.InternalGetSignature(out sigLength);

            // The symbol store doesn't want the calling convention on the
            // front of the signature, but InternalGetSignature returns
            // the callinging convention. So we strip it off. This is a
            // bit unfortunate, since it means that we need to allocate
            // yet another array of bytes...
            mungedSig = new byte[sigLength - 1];
            Array.Copy(signature, 1, mungedSig, 0, sigLength - 1);

            index = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex();
            if (index == -1)
            {
                // top level scope information is kept with methodBuilder
                methodBuilder.m_localSymInfo.AddLocalSymInfo(
                    name,
                    mungedSig,
                    m_localIndex,
                    startOffset,
                    endOffset);
            }
            else
            {
                methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(
                    name,
                    mungedSig,
                    m_localIndex,
                    startOffset,
                    endOffset);
            }
        }
Esempio n. 54
0
        internal static SignatureHelper GetMethodSigHelper(
            Module          mod, 
            CallingConventions callingConvention, 
            Type            returnType, 
            Type[]          parameterTypes) 
        {
            SignatureHelper sigHelp;
            int             intCall;
                
            if (returnType == null)
            {
                returnType = typeof(void);
            }            

            intCall = IMAGE_CEE_CS_CALLCONV_DEFAULT;
            if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
            {
                intCall = IMAGE_CEE_CS_CALLCONV_VARARG;
            }

            if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
            {
                intCall |= IMAGE_CEE_CS_CALLCONV_HASTHIS;
            }

            sigHelp = new SignatureHelper(mod, intCall, (Type)returnType);
            
            if (parameterTypes != null)
            {
                for (int i=0; i<parameterTypes.Length; i++) 
                {
                    sigHelp.AddArgument(parameterTypes[i]);
                }
            }
            return sigHelp;
        }
Esempio n. 55
0
 internal VarArgMethod(DynamicMethod dm, SignatureHelper signature)
 {
     m_dynamicMethod = dm;
     m_signature = signature;
 }
Esempio n. 56
0
        public virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
        {
            SignatureHelper helper = SignatureHelper.GetMethodSigHelper(module, 0, unmanagedCallConv, returnType, parameterTypes);

            Emit(opcode, helper);
        }
Esempio n. 57
0
        internal ILGenerator(MethodInfo methodBuilder, int size)
        {
            Contract.Requires(methodBuilder != null);
            Contract.Requires(methodBuilder is MethodBuilder || methodBuilder is DynamicMethod);

            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 = null;
            m_RelocFixupCount = 0;

            // initialize the scope tree
            m_ScopeTree = new ScopeTree();
            m_LineNumberInfo = new LineNumberInfo();
            m_methodBuilder = methodBuilder;

            // initialize local signature
            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);
        }
Esempio n. 58
0
 internal VarArgMethod(RuntimeMethodInfo method, SignatureHelper signature)
 {
     m_method = method;
     m_signature = signature;
 }
Esempio n. 59
0
		/// <summary>
		/// Puts the specified instruction and a signature token onto the Microsoft intermediate language (MSIL)
		/// stream of instructions.
		/// </summary>
		public void Emit(OpCode opcode, SignatureHelper signature)
		{
			if (InterceptEmit(opcode, signature)) il.Emit(opcode, signature);
		}
Esempio n. 60
0
        public override void Emit(OpCode opcode, SignatureHelper signature)
        {
            if (signature == null)
                throw new ArgumentNullException(nameof(signature));
            Contract.EndContractBlock();

            int stackchange = 0;
            EnsureCapacity(7);
            InternalEmit(opcode);

            // The only IL instruction that has VarPop behaviour, that takes a
            // Signature token as a parameter is calli.  Pop the parameters and
            // the native function pointer.  To be conservative, do not pop the
            // this pointer since this information is not easily derived from
            // SignatureHelper.
            if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
            {
                Contract.Assert(opcode.Equals(OpCodes.Calli),
                                "Unexpected opcode encountered for StackBehaviour VarPop.");
                // Pop the arguments..
                stackchange -= signature.ArgumentCount;
                // Pop native function pointer off the stack.
                stackchange--;
                UpdateStackSize(opcode, stackchange);
            }

            int token = GetTokenForSig(signature.GetSignature(true)); ;
            PutInteger4(token);
        }