This repository was archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDebugArrayType.cs
More file actions
131 lines (117 loc) · 6.3 KB
/
Copy pathDebugArrayType.cs
File metadata and controls
131 lines (117 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using Llvm.NET.Types;
namespace Llvm.NET.DebugInfo
{
/// <summary>Provides debug information binding between an <see cref="IArrayType"/>and a <see cref="DICompositeType"/></summary>
public class DebugArrayType
: DebugType<IArrayType, DICompositeType>
, IArrayType
{
/// <summary>Creates a new <see cref="DebugArrayType"/></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
, NativeModule module
, uint count
, uint lowerBound = 0
, uint alignment = 0
)
: base( llvmType )
{
if( llvmType == null )
{
throw new ArgumentNullException( nameof( llvmType ) );
}
if( elementType == null )
{
throw new ArgumentNullException( nameof( elementType ) );
}
if( llvmType.ElementType.TypeHandle != elementType.TypeHandle )
{
throw new ArgumentException( "elementType doesn't match array element type" );
}
DIType = CreateDebugInfoForArray( llvmType, elementType, module, count, lowerBound, alignment );
DebugElementType = elementType;
}
/// <summary>Constructs a new <see cref="DebugArrayType"/></summary>
/// <param name="elementType">Type of elements in the array</param>
/// <param name="module"><see cref="NativeModule"/> 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, NativeModule module, uint count, uint lowerBound = 0 )
: this( elementType.VerifyArgNotNull( nameof( elementType ) ).CreateArrayType( count )
, elementType
, module
, count
, lowerBound
)
{
}
/// <summary>Constructs a new <see cref="DebugArrayType"/></summary>
/// <param name="llvmType">Native LLVM type for the elements</param>
/// <param name="module"><see cref="NativeModule"/> to use for the context of the debug information</param>
/// <param name="elementType">Debug type of the array elements</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( IArrayType llvmType, NativeModule module, DIType elementType, uint count, uint lowerBound = 0 )
: this( DebugType.Create( llvmType.VerifyArgNotNull( nameof( llvmType ) ).ElementType, elementType ), module, count, lowerBound )
{
}
/// <summary>Full <see cref="IDebugType{NativeT, DebugT}"/> type for the elements</summary>
public IDebugType<ITypeRef, DIType> DebugElementType { get; }
/// <inheritdoc/>
public ITypeRef ElementType => DebugElementType;
/// <inheritdoc/>
public uint Length => NativeType.Length;
/// <summary>Lower bound of the array, usually but not always zero</summary>
public uint LowerBound { get; }
/// <summary>Resolves a temporary metadata node for the array if full size information wasn't available at creation time</summary>
/// <param name="layout">Type layout information</param>
/// <param name="diBuilder">Debug information builder for creating the new debug information</param>
public void ResolveTemporary( DataLayout layout, DebugInfoBuilder diBuilder )
{
if( layout == null )
{
throw new ArgumentNullException( nameof( layout ) );
}
if( diBuilder == null )
{
throw new ArgumentNullException( nameof( diBuilder ) );
}
if( DIType.IsTemporary && !DIType.IsResolved )
{
DIType = diBuilder.CreateArrayType( layout.BitSizeOf( NativeType )
, layout.AbiBitAlignmentOf( NativeType )
, DebugElementType.DIType
, diBuilder.CreateSubRange( LowerBound, NativeType.Length )
);
}
}
private static DICompositeType CreateDebugInfoForArray( IArrayType llvmType
, IDebugType<ITypeRef, DIType> elementType
, NativeModule module
, uint count
, uint lowerBound
, uint alignment
)
{
if( llvmType.IsSized )
{
return module.DIBuilder.CreateArrayType( module.Layout.BitSizeOf( llvmType )
, alignment
, elementType.DIType
, module.DIBuilder.CreateSubRange( lowerBound, count )
);
}
else
{
return module.DIBuilder.CreateReplaceableCompositeType( Tag.ArrayType, string.Empty, module.DICompileUnit, null, 0 );
}
}
}
}