Example #1
0
 /// <summary>Initializes a new instance of the <see cref="DebugPointerType"/> class.</summary>
 /// <param name="debugElementType">Debug type of the pointee</param>
 /// <param name="module"><see cref="BitcodeModule"/> used for creating the pointer type and debug information</param>
 /// <param name="addressSpace">Target address space for the pointer [Default: 0]</param>
 /// <param name="name">Name of the type [Default: null]</param>
 /// <param name="alignment">Alignment on pointer</param>
 public DebugPointerType(IDebugType <ITypeRef, DIType> debugElementType, BitcodeModule module, uint addressSpace = 0, string name = null, uint alignment = 0)
     : this(debugElementType.ValidateNotNull(nameof(debugElementType)).NativeType
            , module
            , debugElementType.ValidateNotNull(nameof(debugElementType)).DIType
            , addressSpace
            , name
            , alignment
            )
 {
 }
Example #2
0
        private static DICompositeType BuildDebugType([ValidatedNotNull] IArrayType llvmType
                                                      , [ValidatedNotNull] IDebugType <ITypeRef, DIType> elementType
                                                      , [ValidatedNotNull] BitcodeModule module
                                                      , uint count
                                                      , uint lowerBound
                                                      , uint alignment
                                                      )
        {
            llvmType.ValidateNotNull(nameof(llvmType));
            elementType.ValidateNotNull(nameof(elementType));
            module.ValidateNotNull(nameof(module));

            if (llvmType.ElementType.GetTypeRef( ) != elementType.GetTypeRef( ))
            {
                throw new ArgumentException(Resources.ElementType_doesn_t_match_array_element_type);
            }

            if (llvmType.IsSized)
            {
                return(module.DIBuilder.CreateArrayType(module.Layout.BitSizeOf(llvmType)
                                                        , alignment
                                                        , elementType.DIType ! // validated not null in constructor
                                                        , module.DIBuilder.CreateSubRange(lowerBound, count)
                                                        ));
            }

            return(module.DIBuilder.CreateReplaceableCompositeType(Tag.ArrayType
                                                                   , string.Empty
                                                                   , module.DICompileUnit ?? default
                                                                   , default
Example #3
0
 /// <summary>Initializes a new instance of the <see cref="DebugArrayType"/> class.</summary>
 /// <param name="elementType">Type of elements in the array</param>
 /// <param name="module"><see cref="BitcodeModule"/> to use for the context of the debug information</param>
 /// <param name="count">Number of elements in the array</param>
 /// <param name="lowerBound"><see cref="LowerBound"/> value for the array indices [Default: 0]</param>
 public DebugArrayType(IDebugType <ITypeRef, DIType> elementType, BitcodeModule module, uint count, uint lowerBound = 0)
     : this(elementType.ValidateNotNull(nameof(elementType)).CreateArrayType(count)
            , elementType
            , module
            , count
            , lowerBound
            )
 {
 }
Example #4
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));
        }
Example #5
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), "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 are 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, "Should have a valid non temp type by now");

            return(new DebugFunctionType(llvmType, diType));
        }
Example #6
0
 /// <summary>Initializes a new instance of the <see cref="DebugArrayType"/> class</summary>
 /// <param name="llvmType">Underlying LLVM array type to bind debug info to</param>
 /// <param name="elementType">Array element type with debug information</param>
 /// <param name="module">module to use for creating debug information</param>
 /// <param name="count">Number of elements in the array</param>
 /// <param name="lowerBound">Lower bound of the array [default = 0]</param>
 /// <param name="alignment">Alignment for the type</param>
 public DebugArrayType(IArrayType llvmType
                       , IDebugType <ITypeRef, DIType> elementType
                       , BitcodeModule module
                       , uint count
                       , uint lowerBound = 0
                       , uint alignment  = 0
                       )
     : base(llvmType, BuildDebugType(llvmType, elementType, module, count, lowerBound, alignment))
 {
     elementType.ValidateNotNull(nameof(elementType));
     elementType.DIType.ValidateNotNull($"{nameof( elementType )}.{nameof( elementType.DIType )}");
     DebugElementType = elementType;
 }
 /// <summary>Initializes a new instance of the <see cref="DebugFunctionType"/> class.</summary>
 /// <param name="llvmType">Native LLVM function signature</param>
 /// <param name="module"><see cref="BitcodeModule"/> to use when construction debug information</param>
 /// <param name="debugFlags"><see cref="DebugInfoFlags"/> for this signature</param>
 /// <param name="retType">Return type for the function</param>
 /// <param name="argTypes">Potentially empty set of argument types for the signature</param>
 public DebugFunctionType(IFunctionType llvmType
                          , BitcodeModule module
                          , DebugInfoFlags debugFlags
                          , IDebugType <ITypeRef, DIType> retType
                          , params IDebugType <ITypeRef, DIType>[] argTypes
                          )
     : base(llvmType.ValidateNotNull(nameof(llvmType))
            , module.ValidateNotNull(nameof(module))
            .DIBuilder.CreateSubroutineType(debugFlags
                                            , retType.ValidateNotNull(nameof(retType)).DIType
                                            , argTypes.Select(t => t.DIType)
                                            )
            )
 {
 }
Example #8
0
        /// <summary>Initializes a new instance of the <see cref="DebugArrayType"/> class</summary>
        /// <param name="llvmType">Underlying LLVM array type to bind debug info to</param>
        /// <param name="elementType">Array element type with debug information</param>
        /// <param name="module">module to use for creating debug information</param>
        /// <param name="count">Number of elements in the array</param>
        /// <param name="lowerBound">Lower bound of the array [default = 0]</param>
        /// <param name="alignment">Alignment for the type</param>
        public DebugArrayType(IArrayType llvmType
                              , IDebugType <ITypeRef, DIType> elementType
                              , BitcodeModule module
                              , uint count
                              , uint lowerBound = 0
                              , uint alignment  = 0
                              )
            : base(llvmType)
        {
            llvmType.ValidateNotNull(nameof(llvmType));
            elementType.ValidateNotNull(nameof(elementType));

            if (llvmType.ElementType.GetTypeRef() != elementType.GetTypeRef())
            {
                throw new ArgumentException("elementType doesn't match array element type");
            }

            DIType           = CreateDebugInfoForArray(llvmType, elementType, module, count, lowerBound, alignment);
            DebugElementType = elementType;
        }