コード例 #1
0
ファイル: Context.cs プロジェクト: wyl2008056/Llvm.NET
        /// <summary>Creates a FunctionType with Debug information</summary>
        /// <param name="diBuilder"><see cref="DebugInfoBuilder"/>to use to create the debug information</param>
        /// <param name="isVarArg">Flag to indicate if this function is variadic</param>
        /// <param name="retType">Return type of the function</param>
        /// <param name="argTypes">Argument types of the function</param>
        /// <returns>Function signature</returns>
        public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                                    , bool isVarArg
                                                    , IDebugType <ITypeRef, DIType> retType
                                                    , IEnumerable <IDebugType <ITypeRef, DIType> > argTypes
                                                    )
        {
            if (diBuilder == null)
            {
                throw new ArgumentNullException(nameof(diBuilder));
            }

            if (!retType.HasDebugInfo( ))
            {
                throw new ArgumentNullException(nameof(retType), "Return type does not have debug information");
            }

            var  nativeArgTypes = new List <ITypeRef>( );
            var  debugArgTypes  = new List <DIType>( );
            var  msg            = new StringBuilder("One or more parameter types ar not valid:\n");
            bool hasParamErrors = false;

            foreach (var indexedPair in argTypes.Select((t, i) => new { Type = t, Index = i }))
            {
                if (indexedPair.Type == null)
                {
                    msg.AppendFormat("\tArgument {0} is null", indexedPair.Index);
                    hasParamErrors = true;
                }
                else
                {
                    nativeArgTypes.Add(indexedPair.Type.NativeType);
                    debugArgTypes.Add(indexedPair.Type.DIType);
                    if (indexedPair.Type.HasDebugInfo( ))
                    {
                        continue;
                    }

                    msg.AppendFormat("\tArgument {0} does not contain debug type information", indexedPair.Index);
                    hasParamErrors = true;
                }
            }

            // if any parameters don't have errors, then provide a hopefully helpful message indicating which one(s)
            if (hasParamErrors)
            {
                throw new ArgumentException(msg.ToString( ), nameof(argTypes));
            }

            var llvmType = GetFunctionType(retType.NativeType, nativeArgTypes, isVarArg);

            var diType = diBuilder.CreateSubroutineType(0, retType.DIType, debugArgTypes);

            Debug.Assert(diType != null && !diType.IsTemporary);

            return(new DebugFunctionType(llvmType, diType));
        }
コード例 #2
0
        /// <summary>Creates a FunctionType with Debug information</summary>
        /// <param name="diBuilder"><see cref="DebugInfoBuilder"/>to use to create the debug information</param>
        /// <param name="isVarArg">Flag to indicate if this function is variadic</param>
        /// <param name="retType">Return type of the function</param>
        /// <param name="argTypes">Argument types of the function</param>
        /// <returns>Function signature</returns>
        public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                                    , bool isVarArg
                                                    , [ValidatedNotNull] IDebugType <ITypeRef, DIType> retType
                                                    , [ValidatedNotNull] IEnumerable <IDebugType <ITypeRef, DIType> > argTypes
                                                    )
        {
            diBuilder.ValidateNotNull(nameof(diBuilder));
            retType.ValidateNotNull(nameof(retType));
            argTypes.ValidateNotNull(nameof(retType));

            if (!retType.HasDebugInfo( ))
            {
                throw new ArgumentNullException(nameof(retType), Resources.Return_type_does_not_have_debug_information);
            }

            var  nativeArgTypes = new List <ITypeRef>( );
            var  debugArgTypes  = new List <DIType>( );
            var  msg            = new StringBuilder(Resources.One_or_more_parameter_types_are_not_valid);
            bool hasParamErrors = false;

            foreach (var indexedPair in argTypes.Select((t, i) => new { Type = t, Index = i }))
            {
                if (indexedPair.Type == null)
                {
                    msg.AppendFormat(CultureInfo.CurrentCulture, Resources.Argument_0_is_null, indexedPair.Index);
                    hasParamErrors = true;
                }
                else
                {
                    nativeArgTypes.Add(indexedPair.Type.NativeType);
                    debugArgTypes.Add(indexedPair.Type.DIType);
                    if (indexedPair.Type.HasDebugInfo( ))
                    {
                        continue;
                    }

                    msg.AppendFormat(CultureInfo.CurrentCulture, Resources.Argument_0_does_not_contain_debug_type_information, indexedPair.Index);
                    hasParamErrors = true;
                }
            }

            // if any parameters have errors, then provide a hopefully helpful message indicating which one(s)
            if (hasParamErrors)
            {
                throw new ArgumentException(msg.ToString( ), nameof(argTypes));
            }

            var llvmType = GetFunctionType(retType.NativeType, nativeArgTypes, isVarArg);

            var diType = diBuilder.CreateSubroutineType(0, retType.DIType, debugArgTypes);

            Debug.Assert(diType != null && !diType.IsTemporary, Resources.Assert_Should_have_a_valid_non_temp_type_by_now);

            return(new DebugFunctionType(llvmType, diType));
        }