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 pathDebugStructType.cs
More file actions
213 lines (193 loc) · 10.1 KB
/
Copy pathDebugStructType.cs
File metadata and controls
213 lines (193 loc) · 10.1 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Llvm.NET.Types;
namespace Llvm.NET.DebugInfo
{
public class DebugStructType
: DebugType<IStructType, DICompositeType>
, IStructType
{
public DebugStructType( NativeModule module
, string nativeName
, DIScope scope
, string name
, DIFile diFile
, uint line
, DebugInfoFlags debugFlags
, IEnumerable<DebugMemberInfo> debugElements
, DIType derivedFrom = null
, bool packed = false
, uint? bitSize = null
, uint bitAlignment = 0
)
{
module.VerifyArgNotNull( nameof( module ) );
DebugMembers = new ReadOnlyCollection<DebugMemberInfo>( debugElements as IList<DebugMemberInfo> ?? debugElements.ToList( ) );
NativeType = module.Context.CreateStructType( nativeName, packed, debugElements.Select( e => e.DebugType ).ToArray( ) );
DIType = module.DIBuilder.CreateReplaceableCompositeType( Tag.StructureType
, name
, scope
, diFile
, line
);
var memberTypes = from memberInfo in DebugMembers
select CreateMemberType( module, memberInfo );
var concreteType = module.DIBuilder.CreateStructType( scope: scope
, name: name
, file: diFile
, line: line
, bitSize: bitSize ?? module.Layout.BitSizeOf( NativeType )
, bitAlign: bitAlignment
, debugFlags: debugFlags
, derivedFrom: derivedFrom
, elements: memberTypes
);
// assignment performs RAUW
DIType = concreteType;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Justification = "VerifyArgNotNull" )]
public DebugStructType( IStructType llvmType
, NativeModule module
, DIScope scope
, string name
, DIFile file
, uint line
, DebugInfoFlags debugFlags
, DIType derivedFrom
, IEnumerable<DIType> elements
, uint alignment = 0
)
: base( llvmType )
{
module.VerifyArgNotNull( nameof( module ) );
DIType = module.DIBuilder
.CreateStructType( scope
, name
, file
, line
, module.Layout.BitSizeOf( llvmType )
, alignment
, debugFlags
, derivedFrom
, elements
);
}
public DebugStructType( IStructType llvmType
, NativeModule module
, DIScope scope
, string name
, DIFile file
, uint line
)
: base( llvmType )
{
DIType = module.VerifyArgNotNull( nameof( module ) )
.DIBuilder
.CreateReplaceableCompositeType( Tag.StructureType
, name
, scope
, file
, line
);
}
public DebugStructType( NativeModule module
, string nativeName
, DIScope scope
, string name
, DIFile file = null
, uint line = 0
)
: this( module.VerifyArgNotNull( nameof( module ) ).Context.CreateStructType( nativeName )
, module
, scope
, name
, file
, line
)
{
}
public bool IsOpaque => NativeType.IsOpaque;
public bool IsPacked => NativeType.IsPacked;
public IReadOnlyList<ITypeRef> Members => NativeType.Members;
public string Name => NativeType.Name;
public void SetBody( bool packed, params ITypeRef[ ] elements )
{
NativeType.SetBody( packed, elements );
}
public void SetBody( bool packed
, NativeModule module
, DIScope scope
, DIFile diFile
, uint line
, DebugInfoFlags debugFlags
, IEnumerable<DebugMemberInfo> debugElements
)
{
var debugMembersArray = debugElements as IList<DebugMemberInfo> ?? debugElements.ToList();
var nativeElements = debugMembersArray.Select( e => e.DebugType.NativeType );
SetBody( packed, module, scope, diFile, line, debugFlags, nativeElements, debugMembersArray );
}
public void SetBody( bool packed
, NativeModule module
, DIScope scope
, DIFile diFile
, uint line
, DebugInfoFlags debugFlags
, IEnumerable<ITypeRef> nativeElements
, IEnumerable<DebugMemberInfo> debugElements
, DIType derivedFrom = null
, uint? bitSize = null
, uint bitAlignment = 0
)
{
DebugMembers = new ReadOnlyCollection<DebugMemberInfo>( debugElements as IList<DebugMemberInfo> ?? debugElements.ToList( ) );
SetBody( packed, nativeElements.ToArray() );
var memberTypes = from memberInfo in DebugMembers
select CreateMemberType( module, memberInfo );
var concreteType = module.DIBuilder.CreateStructType( scope: scope
, name: DIType.Name
, file: diFile
, line: line
, bitSize: bitSize ?? module.Layout.BitSizeOf( NativeType )
, bitAlign: bitAlignment
, debugFlags: debugFlags
, derivedFrom: derivedFrom
, elements: memberTypes
);
DIType = concreteType;
}
private DIDerivedType CreateMemberType( NativeModule module, DebugMemberInfo memberInfo )
{
UInt64 bitSize;
UInt32 bitAlign;
UInt64 bitOffset;
// if explicit layout info provided, use it;
// otherwise use module.Layout as the default
if( memberInfo.ExplicitLayout != null )
{
bitSize = memberInfo.ExplicitLayout.BitSize;
bitAlign = memberInfo.ExplicitLayout.BitAlignment;
bitOffset = memberInfo.ExplicitLayout.BitOffset;
}
else
{
bitSize = module.Layout.BitSizeOf( memberInfo.DebugType.NativeType );
bitAlign = 0;
bitOffset = module.Layout.BitOffsetOfElement( NativeType, memberInfo.Index );
}
return module.DIBuilder.CreateMemberType( scope: DIType
, name: memberInfo.Name
, file: memberInfo.File
, line: memberInfo.Line
, bitSize: bitSize
, bitAlign: bitAlign
, bitOffset: bitOffset
, debugFlags: memberInfo.DebugInfoFlags
, type: memberInfo.DebugType.DIType
);
}
public IReadOnlyList<DebugMemberInfo> DebugMembers { get; private set; }
}
}