コード例 #1
0
        private bool MethodSignatureHasVarsNeedingCallingConventionConverter_NativeLayout(TypeSystemContext context, RuntimeSignature methodSig)
        {
            NativeReader           reader = GetNativeLayoutInfoReader(methodSig);
            NativeParser           parser = new NativeParser(reader, methodSig.NativeLayoutOffset);
            NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoByHandle(new TypeManagerHandle(methodSig.ModuleHandle));

            MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
            uint numGenArgs     = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0;
            uint parameterCount = parser.GetUnsigned();

            // Check the return type of the method
            if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, module, context, HasVarsInvestigationLevel.Parameter))
            {
                return(true);
            }

            // Check the parameters of the method
            for (uint i = 0; i < parameterCount; i++)
            {
                if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, module, context, HasVarsInvestigationLevel.Parameter))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        public CallSite(
            bool hasThis,
            bool explicitThis,
            MethodCallingConvention callConv,
            TypeSignature returnType,
            IReadOnlyList <TypeSignature> arguments,
            int varArgIndex,
            int genericParameterCount)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }

            _hasThis               = hasThis;
            _explicitThis          = hasThis && explicitThis;
            _genericParameterCount = genericParameterCount;
            _callConv              = callConv;
            _returnType            = returnType;
            _arguments             = arguments ?? ReadOnlyList <TypeSignature> .Empty;

            if (callConv == MethodCallingConvention.VarArgs)
            {
                _varArgIndex = varArgIndex;
            }
        }
コード例 #3
0
        private bool MethodSignatureHasVarsNeedingCallingConventionConverter_NativeLayout(TypeSystemContext context, IntPtr methodSig)
        {
            IntPtr       moduleHandle = RuntimeAugments.GetModuleFromPointer(methodSig);
            NativeReader reader       = GetNativeLayoutInfoReader(moduleHandle);
            NativeParser parser       = new NativeParser(reader, reader.AddressToOffset(methodSig));

            MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
            uint numGenArgs     = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0;
            uint parameterCount = parser.GetUnsigned();

            // Check the return type of the method
            if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, context, HasVarsInvestigationLevel.Parameter))
            {
                return(true);
            }

            // Check the parameters of the method
            for (uint i = 0; i < parameterCount; i++)
            {
                if (TypeSignatureHasVarsNeedingCallingConventionConverter(ref parser, context, HasVarsInvestigationLevel.Parameter))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
 public FunctionSignature(Type returnType, Type[] parameterTypes, MethodCallingConvention callingConvention, PInvokeInfo pinvoke)
 {
     ReturnType        = returnType;
     ParameterTypes    = parameterTypes;
     CallingConvention = callingConvention;
     PInvokeInfo       = pinvoke;
 }
コード例 #5
0
ファイル: MethodProcessor.cs プロジェクト: jvbsl/ImpWiz
        private MethodCallingConvention _convention = MethodCallingConvention.Default;//TODO: calling convention

        private void FindNames()
        {
            var attr = Method.PInvokeInfo;

            if (attr != null)
            {
                if (attr.IsCallConvCdecl)
                {
                    _convention = MethodCallingConvention.C;
                }
                else if (attr.IsCallConvFastcall)
                {
                    _convention = MethodCallingConvention.FastCall;
                }
                else if (attr.IsCallConvThiscall)
                {
                    _convention = MethodCallingConvention.ThisCall;
                }
                else if (attr.IsCallConvStdCall)
                {
                    _convention = MethodCallingConvention.StdCall;
                }
                else if (attr.IsCallConvWinapi)
                {
                    throw new NotSupportedException();
                }

                _libraryName = attr.Module.Name;
                _mangledName = attr.EntryPoint;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #6
0
        public override Vertex WriteVertex(NodeFactory factory)
        {
            MethodCallingConvention methodCallingConvention = default(MethodCallingConvention);

            if (_method.Signature.GenericParameterCount > 0)
            {
                methodCallingConvention |= MethodCallingConvention.Generic;
            }
            if (_method.Signature.IsStatic)
            {
                methodCallingConvention |= MethodCallingConvention.Static;
            }

            Debug.Assert(_method.Signature.Length == _parametersSig.Length);

            Vertex returnType = _returnTypeSig.WriteVertex(factory);

            Vertex[] parameters = new Vertex[_parametersSig.Length];
            for (int i = 0; i < _parametersSig.Length; i++)
            {
                parameters[i] = _parametersSig[i].WriteVertex(factory);
            }

            Vertex signature = GetNativeWriter(factory).GetMethodSigSignature((uint)methodCallingConvention, (uint)_method.Signature.GenericParameterCount, returnType, parameters);

            return(factory.MetadataManager.NativeLayoutInfo.SignaturesSection.Place(signature));
        }
コード例 #7
0
ファイル: MethodProcessor.cs プロジェクト: jvbsl/ImpWiz
        private void CreateInteropCall(ILProcessor processor, FieldDefinition fnPtr, MethodCallingConvention convention)
        {
            int index = 0;

            ReturnParameterMarshaler?.InitializeMarshalInfo(processor);

            Instruction cleanupInstructions = null;

            for (int i = 0; i < Method.Parameters.Count; i++)
            {
                var p          = Method.Parameters[i];
                var marshaller = MarshalProcessors[i];

                marshaller?.InitializeMarshalInfo(processor);

                if (marshaller == null)
                {
                    processor.Emit(OpCodes.Ldarg, index++);
                }
            }

            foreach (var mP in MarshalProcessors)
            {
                mP?.MarshalManaged(processor, cleanupInstructions);

                cleanupInstructions = mP?.CleanUpInstruction ?? cleanupInstructions;
            }

            CreatePrimitiveInterop(processor, fnPtr, convention, cleanupInstructions);

            ReturnParameterMarshaler?.MarshalNative(processor, cleanupInstructions);
        }
コード例 #8
0
        private void PrintMethodCallConv(MethodCallingConvention callConv)
        {
            switch (callConv)
            {
            case MethodCallingConvention.C:
                _builder.Append("cdecl ");
                break;

            case MethodCallingConvention.FastCall:
                _builder.Append("fastcall ");
                break;

            case MethodCallingConvention.StdCall:
                _builder.Append("stdcall ");
                break;

            case MethodCallingConvention.ThisCall:
                _builder.Append("thiscall ");
                break;

            case MethodCallingConvention.VarArgs:
                _builder.Append("vararg ");
                break;
            }
        }
コード例 #9
0
 internal MethodReference(string name, bool hasThis,
                          bool explicitThis, MethodCallingConvention callConv) : this(name)
 {
     m_parameters   = new ParameterDefinitionCollection(this);
     m_hasThis      = hasThis;
     m_explicitThis = explicitThis;
     m_callConv     = callConv;
 }
コード例 #10
0
 public MethodReference(string name, TypeReference declaringType, TypeReference returnType, bool hasThis, bool explicitThis, MethodCallingConvention callingConvention)
     : this(name, returnType)
 {
     this.DeclaringType = declaringType;
     this.HasThis = hasThis;
     this.ExplicitThis = explicitThis;
     this.CallingConvention = callingConvention;
 }
コード例 #11
0
ファイル: MethodReference.cs プロジェクト: NALSS/Telegraph
        public MethodReference(string name,
			TypeReference declaringType, TypeReference returnType,
			bool hasThis, bool explicitThis, MethodCallingConvention callConv)
            : this(name, hasThis, explicitThis, callConv)
        {
            this.DeclaringType = declaringType;
            this.ReturnType.ReturnType = returnType;
        }
コード例 #12
0
 public MethodReference(string name,
                        TypeReference declaringType, TypeReference returnType,
                        bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
     this(name, hasThis, explicitThis, callConv)
 {
     this.DeclaringType         = declaringType;
     this.ReturnType.ReturnType = returnType;
 }
コード例 #13
0
ファイル: MethodReference.cs プロジェクト: NALSS/Telegraph
        internal MethodReference(string name, bool hasThis,
			bool explicitThis, MethodCallingConvention callConv)
            : this(name)
        {
            m_parameters = new ParameterDefinitionCollection (this);
            m_hasThis = hasThis;
            m_explicitThis = explicitThis;
            m_callConv = callConv;
        }
コード例 #14
0
        public FunctionSignature(IABI abi, Type returnType, Type[] parameterTypes, MethodCallingConvention callingConvention, PInvokeInfo pinvoke)
        {
            ReturnType = new FunctionParameterType(abi, returnType);
            ParameterTypes = new FunctionParameterType[parameterTypes.Length];
            for (int index = 0; index < parameterTypes.Length; index++)
                ParameterTypes[index] = new FunctionParameterType(abi, parameterTypes[index]);

            CallingConvention = callingConvention;
            PInvokeInfo = pinvoke;
        }
コード例 #15
0
        internal bool GetCallingConverterDataFromMethodSignature_NativeLayout_Common(
            TypeSystemContext context,
            RuntimeSignature methodSig,
            Instantiation typeInstantiation,
            Instantiation methodInstantiation,
            out bool hasThis,
            out TypeDesc[] parameters,
            out bool[] parametersWithGenericDependentLayout,
            NativeReader nativeReader)
        {
            NativeLayoutInfoLoadContext nativeLayoutContext = new NativeLayoutInfoLoadContext();

            nativeLayoutContext._module                = (NativeFormatModuleInfo)methodSig.GetModuleInfo();
            nativeLayoutContext._typeSystemContext     = context;
            nativeLayoutContext._typeArgumentHandles   = typeInstantiation;
            nativeLayoutContext._methodArgumentHandles = methodInstantiation;

            NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoByHandle(new TypeManagerHandle(methodSig.ModuleHandle));
            NativeReader           reader = GetNativeLayoutInfoReader(methodSig);
            NativeParser           parser = new NativeParser(reader, methodSig.NativeLayoutOffset);

            MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();

            hasThis = !callingConvention.HasFlag(MethodCallingConvention.Static);

            if (callingConvention.HasFlag(MethodCallingConvention.Generic))
            {
                parser.SkipInteger(); // numGenArgs
            }

            uint parameterCount = parser.GetUnsigned();

            parameters = new TypeDesc[parameterCount + 1];
            parametersWithGenericDependentLayout = new bool[parameterCount + 1];

            // One extra parameter to account for the return type
            for (uint i = 0; i <= parameterCount; i++)
            {
                // NativeParser is a struct, so it can be copied.
                NativeParser parserCopy = parser;

                // Parse the signature twice. The first time to find out the exact type of the signature
                // The second time to identify if the parameter loaded via the signature should be forced to be
                // passed byref as part of the universal generic calling convention.
                parameters[i] = GetConstructedTypeFromParserAndNativeLayoutContext(ref parser, nativeLayoutContext);
                parametersWithGenericDependentLayout[i] = TypeSignatureHasVarsNeedingCallingConventionConverter(ref parserCopy, module, context, HasVarsInvestigationLevel.Parameter);
                if (parameters[i] == null)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #16
0
ファイル: FunctionSignature.cs プロジェクト: uppi/SharpLang
        public FunctionSignature(IABI abi, Type returnType, Type[] parameterTypes, MethodCallingConvention callingConvention, PInvokeInfo pinvoke)
        {
            ReturnType     = new FunctionParameterType(abi, returnType);
            ParameterTypes = new FunctionParameterType[parameterTypes.Length];
            for (int index = 0; index < parameterTypes.Length; index++)
            {
                ParameterTypes[index] = new FunctionParameterType(abi, parameterTypes[index]);
            }

            CallingConvention = callingConvention;
            PInvokeInfo       = pinvoke;
        }
コード例 #17
0
 public ReferencedCallSite(
     AssemblyManager assemblyManager, bool hasThis, bool explicitThis, int varArgIndex,
     MethodCallingConvention callConv, IType returnType, IReadOnlyList <IType> arguments)
 {
     _hasThis         = hasThis;
     _explicitThis    = explicitThis;
     _callConv        = callConv;
     _returnType      = returnType;
     _arguments       = arguments;
     _varArgIndex     = varArgIndex;
     _assemblyManager = assemblyManager;
 }
コード例 #18
0
ファイル: MethodDefinition.cs プロジェクト: sidecut/xaeios
        public MethodDefinition(string name, RVA rva,
			MethodAttributes attrs, MethodImplAttributes implAttrs,
			bool hasThis, bool explicitThis, MethodCallingConvention callConv)
            : base(name, hasThis, explicitThis, callConv)
        {
            m_rva = rva;
            m_attributes = attrs;
            m_implAttrs = implAttrs;

            if (!IsStatic)
                m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null);
        }
コード例 #19
0
        private uint GetGenericArgCountFromSig(NativeParser parser)
        {
            MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();

            if ((callingConvention & MethodCallingConvention.Generic) == MethodCallingConvention.Generic)
            {
                return(parser.GetUnsigned());
            }
            else
            {
                return(0);
            }
        }
コード例 #20
0
        public MethodDefinition(string name, RVA rva,
                                MethodAttributes attrs, MethodImplAttributes implAttrs,
                                bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
            base(name, hasThis, explicitThis, callConv)
        {
            m_rva        = rva;
            m_attributes = attrs;
            m_implAttrs  = implAttrs;

            if (!IsStatic)
            {
                m_this = new ParameterDefinition("this", 0, (ParameterAttributes)0, null);
            }
        }
コード例 #21
0
    string StringifyCallingConvention(MethodCallingConvention cconv)
    {
        switch (cconv)
        {
        case MethodCallingConvention.Default:
            return("default");

        case MethodCallingConvention.VarArg:
            return("vararg");

        default:
            throw new NotImplementedException(cconv.ToString());
        }
    }
コード例 #22
0
        private static bool CompareCallingConventions(MethodCallingConvention callingConvention, MethodBase methodBase)
        {
            if (callingConvention.HasFlag(MethodCallingConvention.Static) != methodBase.IsStatic)
            {
                return(false);
            }

            if (callingConvention.HasFlag(MethodCallingConvention.Generic) != (methodBase.IsGenericMethod | methodBase.IsGenericMethodDefinition))
            {
                return(false);
            }

            return(true);
        }
コード例 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="signature">The signature.</param>
        public MethodSignature(MethodSignature signature)
            : base(signature)
        {
            this.methodCallingConvention = signature.methodCallingConvention;
            this.hasExplicitThis         = signature.hasExplicitThis;
            this.hasThis               = signature.hasThis;
            this.returnType            = signature.returnType;
            this.genericParameterCount = signature.genericParameterCount;

            this.parameters = new SigType[signature.parameters.Length];
            for (int i = 0; i < signature.parameters.Length; i++)
            {
                this.parameters[i] = signature.parameters[i];
            }
        }
コード例 #24
0
 public static CallingConvention CecilCConvToInteropCConv(MethodCallingConvention methodCallingConvention)
 {
     switch (methodCallingConvention)
       {
     case MethodCallingConvention.C:
       return CallingConvention.Cdecl;
     case MethodCallingConvention.FastCall:
       return CallingConvention.FastCall;
     case MethodCallingConvention.StdCall:
       return CallingConvention.StdCall;
     case MethodCallingConvention.ThisCall:
       return CallingConvention.ThisCall;
     default:
       return CallingConvention.Winapi;
       }
 }
コード例 #25
0
ファイル: CecilUtils.cs プロジェクト: still-adam-k/mbunit-v3
        public static CallingConventions GetCallingConventions(MethodReference methodReference)
        {
            MethodCallingConvention c = (MethodCallingConvention)((int)methodReference.CallingConvention & 0x0f);

            switch (c)
            {
            case MethodCallingConvention.ThisCall:
                return(CallingConventions.HasThis);

            case MethodCallingConvention.VarArg:
                return(CallingConventions.VarArgs);

            default:
                return(CallingConventions.Standard);
            }
        }
コード例 #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="returnType">Type of the return value.</param>
        /// <param name="parameters">The parameter types.</param>
        public MethodSignature(SigType returnType, SigType[] parameters)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException(@"returnType");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(@"parameters");
            }

            this.methodCallingConvention = MethodCallingConvention.Default;
            this.hasExplicitThis         = false;
            this.hasThis               = false;
            this.parameters            = parameters;
            this.returnType            = returnType;
            this.genericParameterCount = 0;
        }
コード例 #27
0
        /// <summary>
        /// Adds a new method to the <paramref name="typeDef">target type</paramref>.
        /// </summary>
        /// <param name="typeDef">The type that will hold the newly-created method.</param>
        /// <param name="attributes">The <see cref="Mono.Cecil.MethodAttributes"/> parameter that describes the characteristics of the method.</param>
        /// <param name="methodName">The name to be given to the new method.</param>
        /// <param name="returnType">The method return type.</param>
        /// <param name="callingConvention">The calling convention of the method being created.</param>
        /// <param name="parameterTypes">The list of argument types that will be used to define the method signature.</param>
        /// <returns>A <see cref="MethodDefinition"/> instance that represents the newly-created method.</returns>
        public static MethodDefinition DefineMethod(this TypeDefinition typeDef, string methodName,
                                                    MethodAttributes attributes, MethodCallingConvention callingConvention, Type returnType, params Type[] parameterTypes)
        {
            var method = new MethodDefinition(methodName, attributes, null)
            {
                CallingConvention = callingConvention
            };

            typeDef.Methods.Add(method);

            // Match the parameter types
            method.AddParameters(parameterTypes);

            // Match the return type
            method.SetReturnType(returnType);

            return(method);
        }
コード例 #28
0
        internal bool IsStaticMethodSignature(RuntimeSignature methodSig)
        {
            if (methodSig.IsNativeLayoutSignature)
            {
                NativeReader reader = GetNativeLayoutInfoReader(methodSig.ModuleHandle);
                NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset);

                MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
                return(callingConvention.HasFlag(MethodCallingConvention.Static));
            }
            else
            {
                var metadataReader = ModuleList.Instance.GetMetadataReaderForModule(methodSig.ModuleHandle);
                var methodHandle   = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);

                var method = methodHandle.GetMethod(metadataReader);
                return((method.Flags & MethodAttributes.Static) != 0);
            }
        }
コード例 #29
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected sealed override void ParseSignature(SignatureReader reader)
        {
            byte value = reader.ReadByte();

            // Check for instance signature
            if (HAS_THIS == (value & HAS_THIS))
            {
                hasThis = true;
            }

            if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS))
            {
                hasExplicitThis = true;
            }

            if (GENERIC == (value & GENERIC))
            {
                methodCallingConvention = MethodCallingConvention.Generic;
                genericParameterCount   = reader.ReadCompressedInt32();
            }
            else if (VARARG == (value & VARARG))
            {
                methodCallingConvention = MethodCallingConvention.VarArg;
            }
            else if ((value & 0x1F) != 0x00)
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            // Number of parameters
            int paramCount = reader.ReadCompressedInt32();

            parameters = new SigType[paramCount];

            // Read the return type
            returnType = SigType.ParseTypeSignature(reader);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
            {
                parameters[i] = SigType.ParseTypeSignature(reader);
            }
        }
コード例 #30
0
        internal bool IsStaticMethodSignature(RuntimeSignature methodSig)
        {
            if (methodSig.IsNativeLayoutSignature)
            {
                NativeReader reader = GetNativeLayoutInfoReader(methodSig);
                NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset);

                MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
                return(callingConvention.HasFlag(MethodCallingConvention.Static));
            }
            else
            {
                ModuleInfo module = methodSig.GetModuleInfo();

#if ECMA_METADATA_SUPPORT
                if (module is NativeFormatModuleInfo)
#endif
                {
                    NativeFormatModuleInfo nativeFormatModule = (NativeFormatModuleInfo)module;
                    var metadataReader = nativeFormatModule.MetadataReader;
                    var methodHandle   = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);

                    var method = methodHandle.GetMethod(metadataReader);
                    return((method.Flags & MethodAttributes.Static) != 0);
                }
#if ECMA_METADATA_SUPPORT
                else
                {
                    EcmaModuleInfo ecmaModuleInfo = (EcmaModuleInfo)module;
                    var            metadataReader = ecmaModuleInfo.MetadataReader;
                    var            ecmaHandle     = (System.Reflection.Metadata.MethodDefinitionHandle)System.Reflection.Metadata.Ecma335.MetadataTokens.Handle(methodSig.Token);
                    var            method         = metadataReader.GetMethodDefinition(ecmaHandle);
                    var            blobHandle     = method.Signature;
                    var            blobReader     = metadataReader.GetBlobReader(blobHandle);
                    byte           sigByte        = blobReader.ReadByte();
                    return((sigByte & (byte)System.Reflection.Metadata.SignatureAttributes.Instance) == 0);
                }
#endif
            }
        }
コード例 #31
0
        internal bool GetCallingConverterDataFromMethodSignature_NativeLayout(TypeSystemContext context, IntPtr methodSig, NativeLayoutInfoLoadContext nativeLayoutContext, out bool hasThis, out TypeDesc[] parameters, out bool[] parametersWithGenericDependentLayout)
        {
            hasThis    = false;
            parameters = null;

            IntPtr       moduleHandle = RuntimeAugments.GetModuleFromPointer(methodSig);
            NativeReader reader       = GetNativeLayoutInfoReader(moduleHandle);
            NativeParser parser       = new NativeParser(reader, reader.AddressToOffset(methodSig));

            MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();

            hasThis = !callingConvention.HasFlag(MethodCallingConvention.Static);

            uint numGenArgs = callingConvention.HasFlag(MethodCallingConvention.Generic) ? parser.GetUnsigned() : 0;

            uint parameterCount = parser.GetUnsigned();

            parameters = new TypeDesc[parameterCount + 1];
            parametersWithGenericDependentLayout = new bool[parameterCount + 1];

            // One extra parameter to account for the return type
            for (uint i = 0; i <= parameterCount; i++)
            {
                // NativeParser is a struct, so it can be copied.
                NativeParser parserCopy = parser;

                // Parse the signature twice. The first time to find out the exact type of the signature
                // The second time to identify if the parameter loaded via the signature should be forced to be
                // passed byref as part of the universal generic calling convention.
                parameters[i] = GetConstructedTypeFromParserAndNativeLayoutContext(ref parser, nativeLayoutContext);
                parametersWithGenericDependentLayout[i] = TypeSignatureHasVarsNeedingCallingConventionConverter(ref parserCopy, context, HasVarsInvestigationLevel.Parameter);
                if (parameters[i] == null)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #32
0
ファイル: MethodProcessor.cs プロジェクト: jvbsl/ImpWiz
        private static Type GetConvention(MethodCallingConvention convention)
        {
            switch (convention)
            {
            case MethodCallingConvention.C:
                return(typeof(System.Runtime.CompilerServices.CallConvCdecl));

            case MethodCallingConvention.Default:
                return(null);

            case MethodCallingConvention.FastCall:
                return(typeof(System.Runtime.CompilerServices.CallConvFastcall));

            case MethodCallingConvention.StdCall:
                return(typeof(System.Runtime.CompilerServices.CallConvStdcall));

            case MethodCallingConvention.ThisCall:
                return(typeof(System.Runtime.CompilerServices.CallConvThiscall));

            default:
                throw new NotSupportedException();
            }
        }
コード例 #33
0
        private bool CompareMethodSigs(NativeParser parser1, NativeFormatModuleInfo moduleHandle1, NativeParser parser2, NativeFormatModuleInfo moduleHandle2)
        {
            MethodCallingConvention callingConvention1 = (MethodCallingConvention)parser1.GetUnsigned();
            MethodCallingConvention callingConvention2 = (MethodCallingConvention)parser2.GetUnsigned();

            if (callingConvention1 != callingConvention2)
            {
                return(false);
            }

            if ((callingConvention1 & MethodCallingConvention.Generic) == MethodCallingConvention.Generic)
            {
                if (parser1.GetUnsigned() != parser2.GetUnsigned())
                {
                    return(false);
                }
            }

            uint parameterCount1 = parser1.GetUnsigned();
            uint parameterCount2 = parser2.GetUnsigned();

            if (parameterCount1 != parameterCount2)
            {
                return(false);
            }

            // Compare one extra parameter to account for the return type
            for (uint i = 0; i <= parameterCount1; i++)
            {
                if (!CompareTypeSigs(ref parser1, moduleHandle1, ref parser2, moduleHandle2))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #34
0
 private bool CompareCallingConventions(MethodCallingConvention callingConvention)
 {
     return (callingConvention.HasFlag(MethodCallingConvention.Static) == _isStatic) &&
         (callingConvention.HasFlag(MethodCallingConvention.Generic) == _isGeneric);
 }
コード例 #35
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override sealed void ParseSignature(SignatureReader reader)
        {
            byte value = reader.ReadByte();

            // Check for instance signature
            if (HAS_THIS == (value & HAS_THIS))
            {
                hasThis = true;
            }

            if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS))
            {
                hasExplicitThis = true;
            }

            if (GENERIC == (value & GENERIC))
            {
                methodCallingConvention = MethodCallingConvention.Generic;
                genericParameterCount = reader.ReadCompressedInt32();
            }
            else if (VARARG == (value & VARARG))
            {
                methodCallingConvention = MethodCallingConvention.VarArg;
            }
            else if ((value & 0x1F) != 0x00)
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            // Number of parameters
            int paramCount = reader.ReadCompressedInt32();
            parameters = new SigType[paramCount];

            // Read the return type
            returnType = SigType.ParseTypeSignature(reader);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
                parameters[i] = SigType.ParseTypeSignature(reader);
        }
コード例 #36
0
ファイル: FunctionPointerType.cs プロジェクト: sidecut/xaeios
 public FunctionPointerType(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
     : base(retType.ReturnType)
 {
     m_function = new MethodReference ("method", hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
コード例 #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="returnType">Type of the return value.</param>
        /// <param name="parameters">The parameter types.</param>
        public MethodSignature(SigType returnType, SigType[] parameters)
        {
            if (returnType == null)
                throw new ArgumentNullException(@"returnType");
            if (parameters == null)
                throw new ArgumentNullException(@"parameters");

            this.methodCallingConvention = MethodCallingConvention.Default;
            this.hasExplicitThis = false;
            this.hasThis = false;
            this.parameters = parameters;
            this.returnType = returnType;
            this.genericParameterCount = 0;
        }
コード例 #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="signature">The signature.</param>
        public MethodSignature(MethodSignature signature)
            : base(signature)
        {
            this.methodCallingConvention = signature.methodCallingConvention;
            this.hasExplicitThis = signature.hasExplicitThis;
            this.hasThis = signature.hasThis;
            this.returnType = signature.returnType;
            this.genericParameterCount = signature.genericParameterCount;

            this.parameters = new SigType[signature.parameters.Length];
            for (int i = 0; i < signature.parameters.Length; i++)
                this.parameters[i] = signature.parameters[i];
        }
コード例 #39
0
 private bool CompareCallingConventions(MethodCallingConvention callingConvention)
 {
     return((callingConvention.HasFlag(MethodCallingConvention.Static) == _isStatic) &&
            (callingConvention.HasFlag(MethodCallingConvention.Generic) == _isGeneric));
 }
コード例 #40
0
        /// <summary>
        /// Adds a new method to the <paramref name="typeDef">target type</paramref>.
        /// </summary>
        /// <param name="typeDef">The type that will hold the newly-created method.</param>
        /// <param name="attributes">The <see cref="Mono.Cecil.MethodAttributes"/> parameter that describes the characteristics of the method.</param>
        /// <param name="methodName">The name to be given to the new method.</param>
        /// <param name="returnType">The method return type.</param>
        /// <param name="callingConvention">The calling convention of the method being created.</param>
        /// <param name="parameterTypes">The list of argument types that will be used to define the method signature.</param>
        /// <returns>A <see cref="MethodDefinition"/> instance that represents the newly-created method.</returns>
        public static MethodDefinition DefineMethod(this TypeDefinition typeDef, string methodName,
            MethodAttributes attributes, MethodCallingConvention callingConvention, Type returnType, params Type[] parameterTypes)
        {
            var method = new MethodDefinition(methodName, attributes, null)
            {
                CallingConvention = callingConvention
            };

            typeDef.Methods.Add(method);

            // Match the parameter types
            method.AddParameters(parameterTypes);

            // Match the return type
            method.SetReturnType(returnType);

            return method;
        }
コード例 #41
0
        private string GetParameterDeclarationListText(IParameterDeclarationCollection value, MethodCallingConvention callingConvention)
        {
            using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                for (int i = 0; i < value.Count; i++)
                {
                    IType parameterType = value[i].ParameterType;
                    if ((parameterType != null) || ((i + 1) != value.Count))
                    {
                        if (i != 0)
                        {
                            writer.Write(",");
                        }

                        if (parameterType == null)
                        {
                            writer.Write("...");
                        }
                        else
                        {
                            writer.Write(this.GetTypeText(parameterType));
                        }
                    }
                }

                if (callingConvention == MethodCallingConvention.VariableArguments)
                {
                    if (value.Count > 0)
                    {
                        writer.Write(",");
                    }

                    writer.Write("...");
                }

                return writer.ToString();
            }
        }
コード例 #42
0
 public FunctionPointerType(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType) :
     base(retType.ReturnType)
 {
     m_function            = new MethodReference("method", hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
コード例 #43
0
ファイル: SignatureParsing.cs プロジェクト: noahfalk/corert
        private static bool CompareCallingConventions(MethodCallingConvention callingConvention, MethodBase methodBase)
        {
            if (callingConvention.HasFlag(MethodCallingConvention.Static) != methodBase.IsStatic)
                return false;

            if (callingConvention.HasFlag(MethodCallingConvention.Generic) != (methodBase.IsGenericMethod | methodBase.IsGenericMethodDefinition))
                return false;

            return true;
        }
コード例 #44
0
 public CallSite(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
 {
     m_function            = new MethodReference(string.Empty, hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
コード例 #45
0
ファイル: ildasm.cs プロジェクト: sesef/mono
	string StringifyCallingConvention (MethodCallingConvention cconv) {
		switch (cconv) {
		case MethodCallingConvention.Default:
			return "default";
		case MethodCallingConvention.VarArg:
			return "vararg";
		default:
			throw new NotImplementedException (cconv.ToString ());
		}
	}
コード例 #46
0
		public CallSite (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
		{
			m_function = new MethodReference (string.Empty, hasThis, explicitThis, callConv);
			m_function.ReturnType = retType;
		}
コード例 #47
0
ファイル: CodeDisassembler.cs プロジェクト: JamesLinus/ildasm
		void WriteMethodCallingConvention (MethodCallingConvention cc)
		{
			m_writer.WriteFlags ((int) cc, m_methodCallConvVals, m_methodCallConvMap);
		}