当前位置: 首页>>代码示例>>C#>>正文


C# MethodReference.MangledName方法代码示例

本文整理汇总了C#中Mono.Cecil.MethodReference.MangledName方法的典型用法代码示例。如果您正苦于以下问题:C# MethodReference.MangledName方法的具体用法?C# MethodReference.MangledName怎么用?C# MethodReference.MangledName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.MethodReference的用法示例。


在下文中一共展示了MethodReference.MangledName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFunction

        /// <summary>
        /// Creates the function.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <returns></returns>
        Function CreateFunction(MethodReference method)
        {
            Function function;
            if (functions.TryGetValue(method, out function))
                return function;

            var numParams = method.Parameters.Count;
            if (method.HasThis)
                numParams++;
            var parameterTypes = new Type[numParams];
            var parameterTypesLLVM = new TypeRef[numParams];
            var declaringType = CreateType(ResolveGenericsVisitor.Process(method, method.DeclaringType));
            for (int index = 0; index < numParams; index++)
            {
                TypeReference parameterTypeReference;
                if (method.HasThis && index == 0)
                {
                    parameterTypeReference = declaringType.TypeReference;

                    // Value type uses ByReference type for this
                    if (parameterTypeReference.IsValueType)
                        parameterTypeReference = parameterTypeReference.MakeByReferenceType();
                }
                else
                {
                    var parameter = method.Parameters[method.HasThis ? index - 1 : index];
                    parameterTypeReference = ResolveGenericsVisitor.Process(method, parameter.ParameterType);
                }
                var parameterType = CreateType(parameterTypeReference);
                if (parameterType.DefaultType.Value == IntPtr.Zero)
                    throw new InvalidOperationException();
                parameterTypes[index] = parameterType;
                parameterTypesLLVM[index] = parameterType.DefaultType;
            }

            var returnType = CreateType(ResolveGenericsVisitor.Process(method, method.ReturnType));

            // Generate function global
            bool isExternal = method.DeclaringType.Resolve().Module.Assembly != assembly;
            var methodMangledName = Regex.Replace(method.MangledName(), @"(\W)", "_");
            var functionType = LLVM.FunctionType(returnType.DefaultType, parameterTypesLLVM, false);

            var resolvedMethod = method.Resolve();
            var hasDefinition = resolvedMethod != null
                && (resolvedMethod.HasBody
                    || ((resolvedMethod.ImplAttributes & (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime)) != 0));
            var functionGlobal = hasDefinition
                ? LLVM.AddFunction(module, methodMangledName, functionType)
                : LLVM.ConstPointerNull(LLVM.PointerType(functionType, 0));

            function = new Function(declaringType, method, functionType, functionGlobal, returnType, parameterTypes);
            functions.Add(method, function);

            if (hasDefinition)
            {
                if (isExternal)
                {
                    // External weak linkage
                    LLVM.SetLinkage(functionGlobal, Linkage.ExternalWeakLinkage);
                }
                else
                {
                    // Need to compile
                    EmitFunction(function);
                }
            }

            return function;
        }
开发者ID:frje,项目名称:SharpLang,代码行数:74,代码来源:Compiler.Function.cs

示例2: CreateFunction


//.........这里部分代码省略.........

            var functionSignature = new FunctionSignature(abi, returnType, parameterTypes, callingConvention, pinvokeInfo);
            var functionType = CreateFunctionTypeLLVM(functionSignature);

            // If we have an external with generic parameters, let's try to do some generic sharing (we can write only one in C++)
            bool isInternal = resolvedMethod != null && ((resolvedMethod.ImplAttributes & MethodImplAttributes.InternalCall) != 0);
            if (isInternal && resolvedMethod.HasGenericParameters && resolvedMethod.GenericParameters.All(x => x.HasReferenceTypeConstraint))
            {
                // Check if this isn't the shareable method (in which case we should do normal processing)
                if (!((GenericInstanceMethod)method).GenericArguments.All(x => MemberEqualityComparer.Default.Equals(x, @object.TypeReferenceCecil)))
                {
                    // Let's share it with default method
                    var sharedGenericInstance = new GenericInstanceMethod(resolvedMethod);
                    foreach (var genericParameter in resolvedMethod.GenericParameters)
                    {
                        sharedGenericInstance.GenericArguments.Add(@object.TypeReferenceCecil);
                    }

                    var sharedMethod = GetFunction(sharedGenericInstance);

                    // Cast shared function to appropriate pointer type
                    var sharedFunctionGlobal = LLVM.ConstPointerCast(sharedMethod.GeneratedValue, LLVM.PointerType(functionType, 0));
                    function = new Function(declaringType, method, functionType, sharedFunctionGlobal, functionSignature);
                    functions.Add(method, function);

                    return function;
                }
            }

            // Determine if type and function is local, and linkage type
            bool isLocal;
            var linkageType = GetLinkageType(method.DeclaringType, out isLocal);
            if (isInternal)
            {
                // Should be switched to non-weak when we have complete implementation of every internal calls
                linkageType = Linkage.ExternalWeakLinkage;
            }
            else if (resolvedMethod != null && resolvedMethod.HasGenericParameters)
            {
                isLocal = true;
                linkageType = Linkage.LinkOnceAnyLinkage;
            }

            bool isRuntime = resolvedMethod != null && ((resolvedMethod.ImplAttributes & MethodImplAttributes.Runtime) != 0);
            bool isInterfaceMethod = declaringType.TypeDefinitionCecil.IsInterface;
            var hasDefinition = resolvedMethod != null && (resolvedMethod.HasBody || isInternal || isRuntime);

            var methodMangledName = Regex.Replace(method.MangledName(), @"(\W)", "_");
            var functionGlobal = hasDefinition
                ? LLVM.AddFunction(module, methodMangledName, functionType)
                : LLVM.ConstPointerNull(LLVM.PointerType(functionType, 0));

            // Interface method uses a global so that we can have a unique pointer to use as IMT key
            if (isInterfaceMethod)
            {
                // For test code only: Use linkonce instead of linkageType so that we know if type was forced
                if (TestMode)
                {
                    isLocal = true;
                    linkageType = Linkage.LinkOnceAnyLinkage;
                }

                functionGlobal = LLVM.AddGlobal(module, LLVM.Int8TypeInContext(context), methodMangledName);
                if (isLocal)
                    LLVM.SetInitializer(functionGlobal, LLVM.ConstNull(LLVM.Int8TypeInContext(context)));
                LLVM.SetLinkage(functionGlobal, linkageType);
            }

            if (hasDefinition)
            {
                ApplyFunctionAttributes(functionSignature, functionGlobal);
            }

            function = new Function(declaringType, method, functionType, functionGlobal, functionSignature);
            functions.Add(method, function);

            if (hasDefinition)
            {
                switch (callingConvention)
                {
                    case MethodCallingConvention.StdCall:
                        LLVM.SetFunctionCallConv(functionGlobal, (uint)CallConv.X86StdcallCallConv);
                        break;
                    case MethodCallingConvention.FastCall:
                        LLVM.SetFunctionCallConv(functionGlobal, (uint)CallConv.X86FastcallCallConv);
                        break;
                }

                if (isLocal && !isInternal)
                {
                    // Need to compile
                    EmitFunction(function);
                }

                // Apply linkage
                LLVM.SetLinkage(functionGlobal, linkageType);
            }

            return function;
        }
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:101,代码来源:Compiler.Function.cs


注:本文中的Mono.Cecil.MethodReference.MangledName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。