llvm.org GIT mirror llvm / 80548aa
Add C API bindings for DIBuilder 'Type' APIs This patch adds a set of unstable C API bindings to the DIBuilder interface for creating structure, function, and aggregate types. This patch also removes the existing implementations of these functions from the Go bindings and updates the Go API to fit the new C APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328953 91177308-0d34-0410-b5e6-96231b3b80d8 Harlan Haskins 2 years ago
7 changed file(s) with 604 addition(s) and 165 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/IR/Module.h"
1818
1919 using namespace llvm;
20
21 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
22 Module *m = unwrap(mref);
23 return wrap(new DIBuilder(*m));
24 }
25
26 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
27 DIBuilder *d = unwrap(dref);
28 delete d;
29 }
3020
3121 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
3222 LLVMMetadataRef Scope,
8070 return wrap(D->createParameterVariable(
8171 unwrap(Scope), Name, ArgNo, unwrap(File), Line,
8272 unwrap(Ty), AlwaysPreserve, static_cast(Flags)));
83 }
84
85 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
86 const char *Name,
87 uint64_t SizeInBits,
88 unsigned Encoding) {
89 DIBuilder *D = unwrap(Dref);
90 return wrap(D->createBasicType(Name, SizeInBits, Encoding));
91 }
92
93 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
94 LLVMMetadataRef PointeeType,
95 uint64_t SizeInBits,
96 uint32_t AlignInBits,
97 const char *Name) {
98 DIBuilder *D = unwrap(Dref);
99 return wrap(D->createPointerType(unwrap(PointeeType), SizeInBits,
100 AlignInBits, /* DWARFAddressSpace */ None,
101 Name));
102 }
103
104 LLVMMetadataRef
105 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
106 LLVMMetadataRef ParameterTypes) {
107 DIBuilder *D = unwrap(Dref);
108 return wrap(
109 D->createSubroutineType(DITypeRefArray(unwrap(ParameterTypes))));
110 }
111
112 LLVMMetadataRef LLVMDIBuilderCreateStructType(
113 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
114 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
115 uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
116 LLVMMetadataRef ElementTypes) {
117 DIBuilder *D = unwrap(Dref);
118 return wrap(D->createStructType(
119 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
120 SizeInBits, AlignInBits, static_cast(Flags),
121 DerivedFrom ? unwrap(DerivedFrom) : nullptr,
122 ElementTypes ? DINodeArray(unwrap(ElementTypes)) : nullptr));
123 }
124
125 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
126 LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
127 LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
128 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
129 unsigned Flags) {
130 DIBuilder *D = unwrap(Dref);
131 return wrap(D->createReplaceableCompositeType(
132 Tag, Name, unwrap(Scope), File ? unwrap(File) : nullptr,
133 Line, RuntimeLang, SizeInBits, AlignInBits,
134 static_cast(Flags)));
135 }
136
137 LLVMMetadataRef
138 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
139 const char *Name, LLVMMetadataRef File,
140 unsigned Line, uint64_t SizeInBits,
141 uint32_t AlignInBits, uint64_t OffsetInBits,
142 unsigned Flags, LLVMMetadataRef Ty) {
143 DIBuilder *D = unwrap(Dref);
144 return wrap(D->createMemberType(
145 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
146 SizeInBits, AlignInBits, OffsetInBits,
147 static_cast(Flags), unwrap(Ty)));
148 }
149
150 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
151 uint64_t SizeInBits,
152 uint32_t AlignInBits,
153 LLVMMetadataRef ElementType,
154 LLVMMetadataRef Subscripts) {
155 DIBuilder *D = unwrap(Dref);
156 return wrap(D->createArrayType(SizeInBits, AlignInBits,
157 unwrap(ElementType),
158 DINodeArray(unwrap(Subscripts))));
15973 }
16074
16175 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
2727
2828 typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
2929
30 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m);
31
32 void LLVMDIBuilderDestroy(LLVMDIBuilderRef d);
33
3430 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D,
3531 LLVMMetadataRef Scope,
3632 LLVMMetadataRef File,
5652 LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, unsigned ArgNo,
5753 LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve,
5854 unsigned Flags);
59
60 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef D,
61 const char *Name,
62 uint64_t SizeInBits,
63 unsigned Encoding);
64
65 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef D,
66 LLVMMetadataRef PointeeType,
67 uint64_t SizeInBits,
68 uint32_t AlignInBits,
69 const char *Name);
70
71 LLVMMetadataRef
72 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef D, LLVMMetadataRef File,
73 LLVMMetadataRef ParameterTypes);
74
75 LLVMMetadataRef LLVMDIBuilderCreateStructType(
76 LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
77 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
78 uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
79 LLVMMetadataRef ElementTypes);
80
81 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
82 LLVMDIBuilderRef D, unsigned Tag, const char *Name, LLVMMetadataRef Scope,
83 LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang,
84 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Flags);
85
86 LLVMMetadataRef
87 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef D, LLVMMetadataRef Scope,
88 const char *Name, LLVMMetadataRef File,
89 unsigned Line, uint64_t SizeInBits,
90 uint32_t AlignInBits, uint64_t OffsetInBits,
91 unsigned Flags, LLVMMetadataRef Ty);
92
93 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef D,
94 uint64_t SizeInBits,
95 uint32_t AlignInBits,
96 LLVMMetadataRef ElementType,
97 LLVMMetadataRef Subscripts);
9855
9956 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D,
10057 LLVMMetadataRef Ty, const char *Name,
9494
9595 // NewDIBuilder creates a new DIBuilder, associated with the given module.
9696 func NewDIBuilder(m Module) *DIBuilder {
97 d := C.LLVMNewDIBuilder(m.C)
97 d := C.LLVMCreateDIBuilder(m.C)
9898 return &DIBuilder{ref: d, m: m}
9999 }
100100
101101 // Destroy destroys the DIBuilder.
102102 func (d *DIBuilder) Destroy() {
103 C.LLVMDIBuilderDestroy(d.ref)
103 C.LLVMDisposeDIBuilder(d.ref)
104104 }
105105
106106 // FInalize finalizes the debug information generated by the DIBuilder.
146146 return Metadata{C: result}
147147 }
148148
149 // CreateCompileUnit creates file debug metadata.
149 // CreateFile creates file debug metadata.
150150 func (d *DIBuilder) CreateFile(filename, dir string) Metadata {
151151 cfilename := C.CString(filename)
152152 defer C.free(unsafe.Pointer(cfilename))
165165 Column int
166166 }
167167
168 // CreateCompileUnit creates lexical block debug metadata.
168 // CreateLexicalBlock creates lexical block debug metadata.
169169 func (d *DIBuilder) CreateLexicalBlock(diScope Metadata, b DILexicalBlock) Metadata {
170170 result := C.LLVMDIBuilderCreateLexicalBlock(
171171 d.ref,
197197 Optimized bool
198198 }
199199
200 // CreateCompileUnit creates function debug metadata.
200 // CreateFunction creates function debug metadata.
201201 func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata {
202202 name := C.CString(f.Name)
203203 defer C.free(unsafe.Pointer(name))
295295 result := C.LLVMDIBuilderCreateBasicType(
296296 d.ref,
297297 name,
298 C.uint64_t(t.SizeInBits),
298 C.size_t(len(t.Name)),
299 C.unsigned(t.SizeInBits),
299300 C.unsigned(t.Encoding),
300301 )
301302 return Metadata{C: result}
306307 Pointee Metadata
307308 SizeInBits uint64
308309 AlignInBits uint32 // optional
310 AddressSpace uint32
309311 Name string // optional
310312 }
311313
312 // CreateBasicType creates basic type debug metadata.
314 // CreatePointerType creates a type that represents a pointer to another type.
313315 func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata {
314316 name := C.CString(t.Name)
315317 defer C.free(unsafe.Pointer(name))
316318 result := C.LLVMDIBuilderCreatePointerType(
317319 d.ref,
318320 t.Pointee.C,
319 C.uint64_t(t.SizeInBits),
320 C.uint32_t(t.AlignInBits),
321 name,
321 C.unsigned(t.SizeInBits),
322 C.unsigned(t.AlignInBits),
323 C.unsigned(t.AddressSpace),
324 name,
325 C.size_t(len(t.Name)),
322326 )
323327 return Metadata{C: result}
324328 }
331335 // Parameters contains the subroutine parameter types,
332336 // including the return type at the 0th index.
333337 Parameters []Metadata
338
339 Flags int
334340 }
335341
336342 // CreateSubroutineType creates subroutine type debug metadata.
337343 func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Metadata {
338 params := d.getOrCreateTypeArray(t.Parameters)
339 result := C.LLVMDIBuilderCreateSubroutineType(d.ref, t.File.C, params.C)
344 params, length := llvmMetadataRefs(t.Parameters)
345 result := C.LLVMDIBuilderCreateSubroutineType(
346 d.ref,
347 t.File.C,
348 params,
349 length,
350 C.LLVMDIFlags(t.Flags),
351 )
340352 return Metadata{C: result}
341353 }
342354
350362 Flags int
351363 DerivedFrom Metadata
352364 Elements []Metadata
365 VTableHolder Metadata // optional
366 UniqueID string
353367 }
354368
355369 // CreateStructType creates struct type debug metadata.
356370 func (d *DIBuilder) CreateStructType(scope Metadata, t DIStructType) Metadata {
357 elements := d.getOrCreateArray(t.Elements)
371 elements, length := llvmMetadataRefs(t.Elements)
358372 name := C.CString(t.Name)
359 defer C.free(unsafe.Pointer(name))
373 uniqueID := C.CString(t.UniqueID)
374 defer C.free(unsafe.Pointer(name))
375 defer C.free(unsafe.Pointer(uniqueID))
360376 result := C.LLVMDIBuilderCreateStructType(
361377 d.ref,
362378 scope.C,
363379 name,
380 C.size_t(len(t.Name)),
364381 t.File.C,
365382 C.unsigned(t.Line),
366 C.uint64_t(t.SizeInBits),
367 C.uint32_t(t.AlignInBits),
368 C.unsigned(t.Flags),
383 C.unsigned(t.SizeInBits),
384 C.unsigned(t.AlignInBits),
385 C.LLVMDIFlags(t.Flags),
369386 t.DerivedFrom.C,
370 elements.C,
387 elements,
388 length,
389 C.unsigned(0), // Optional Objective-C runtime version.
390 t.VTableHolder.C,
391 uniqueID,
392 C.uint64_t(len(t.UniqueID)),
371393 )
372394 return Metadata{C: result}
373395 }
383405 SizeInBits uint64
384406 AlignInBits uint32
385407 Flags int
408 UniqueID string
386409 }
387410
388411 // CreateReplaceableCompositeType creates replaceable composite type debug metadata.
389412 func (d *DIBuilder) CreateReplaceableCompositeType(scope Metadata, t DIReplaceableCompositeType) Metadata {
390413 name := C.CString(t.Name)
391 defer C.free(unsafe.Pointer(name))
414 uniqueID := C.CString(t.UniqueID)
415 defer C.free(unsafe.Pointer(name))
416 defer C.free(unsafe.Pointer(uniqueID))
392417 result := C.LLVMDIBuilderCreateReplaceableCompositeType(
393418 d.ref,
394419 C.unsigned(t.Tag),
395420 name,
421 C.size_t(len(t.Name)),
396422 scope.C,
397423 t.File.C,
398424 C.unsigned(t.Line),
399425 C.unsigned(t.RuntimeLang),
400 C.uint64_t(t.SizeInBits),
401 C.uint32_t(t.AlignInBits),
402 C.unsigned(t.Flags),
426 C.unsigned(t.SizeInBits),
427 C.unsigned(t.AlignInBits),
428 C.LLVMDIFlags(t.Flags),
429 uniqueID,
430 C.size_t(len(t.UniqueID)),
403431 )
404432 return Metadata{C: result}
405433 }
424452 d.ref,
425453 scope.C,
426454 name,
455 C.size_t(len(t.Name)),
427456 t.File.C,
428457 C.unsigned(t.Line),
429 C.uint64_t(t.SizeInBits),
430 C.uint32_t(t.AlignInBits),
431 C.uint64_t(t.OffsetInBits),
432 C.unsigned(t.Flags),
458 C.unsigned(t.SizeInBits),
459 C.unsigned(t.AlignInBits),
460 C.unsigned(t.OffsetInBits),
461 C.LLVMDIFlags(t.Flags),
433462 t.Type.C,
434463 )
435464 return Metadata{C: result}
455484 for i, s := range t.Subscripts {
456485 subscriptsSlice[i] = d.getOrCreateSubrange(s.Lo, s.Count)
457486 }
458 subscripts := d.getOrCreateArray(subscriptsSlice)
487 subscripts, length := llvmMetadataRefs(subscriptsSlice)
459488 result := C.LLVMDIBuilderCreateArrayType(
460489 d.ref,
461 C.uint64_t(t.SizeInBits),
462 C.uint32_t(t.AlignInBits),
490 C.unsigned(t.SizeInBits),
491 C.unsigned(t.AlignInBits),
463492 t.ElementType.C,
464 subscripts.C,
493 subscripts,
494 length,
465495 )
466496 return Metadata{C: result}
467497 }
121121 } LLVMDWARFEmissionKind;
122122
123123 /**
124 * An LLVM DWARF type encoding.
125 */
126 typedef unsigned LLVMDWARFTypeEncoding;
127
128 /**
124129 * The current debug metadata version number.
125130 */
126131 unsigned LLVMDebugMetadataVersion(void);
226231 unsigned Column, LLVMMetadataRef Scope,
227232 LLVMMetadataRef InlinedAt);
228233
234 /**
235 * Create subroutine type.
236 * \param File The file in which the subroutine resides.
237 * \param ParameterTypes An array of subroutine parameter types. This
238 * includes return type at 0th index.
239 * \param NumParameterTypes The number of parameter types in \c ParameterTypes
240 * \param Flags E.g.: \c LLVMDIFlagLValueReference.
241 * These flags are used to emit dwarf attributes.
242 */
243 LLVMMetadataRef
244 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
245 LLVMMetadataRef File,
246 LLVMMetadataRef *ParameterTypes,
247 unsigned NumParameterTypes,
248 LLVMDIFlags Flags);
249
250 /**
251 * Create debugging information entry for an enumeration.
252 * \param Builder The DIBuilder.
253 * \param Scope Scope in which this enumeration is defined.
254 * \param Name Enumeration name.
255 * \param NameLen Length of enumeration name.
256 * \param File File where this member is defined.
257 * \param LineNumber Line number.
258 * \param SizeInBits Member size.
259 * \param AlignInBits Member alignment.
260 * \param Elements Enumeration elements.
261 * \param NumElements Number of enumeration elements.
262 * \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
263 * \param UniqueIdentifier A unique identifier for the enum.
264 */
265 LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
266 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
267 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
268 unsigned SizeInBits, unsigned AlignInBits, LLVMMetadataRef *Elements,
269 unsigned NumElements, LLVMMetadataRef ClassTy);
270
271 /**
272 * Create debugging information entry for a union.
273 * \param Builder The DIBuilder.
274 * \param Scope Scope in which this union is defined.
275 * \param Name Union name.
276 * \param NameLen Length of union name.
277 * \param File File where this member is defined.
278 * \param LineNumber Line number.
279 * \param SizeInBits Member size.
280 * \param AlignInBits Member alignment.
281 * \param Flags Flags to encode member attribute, e.g. private
282 * \param Elements Union elements.
283 * \param NumElements Number of union elements.
284 * \param RunTimeLang Optional parameter, Objective-C runtime version.
285 * \param UniqueIdentifier A unique identifier for the union.
286 * \param UniqueIdentifierLen Length of unique identifier.
287 */
288 LLVMMetadataRef LLVMDIBuilderCreateUnionType(
289 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
290 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
291 unsigned SizeInBits, unsigned AlignInBits, LLVMDIFlags Flags,
292 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
293 const char *UniqueId, size_t UniqueIdLen);
294
295
296 /**
297 * Create debugging information entry for an array.
298 * \param Builder The DIBuilder.
299 * \param Size Array size.
300 * \param AlignInBits Alignment.
301 * \param Ty Element type.
302 * \param Subscripts Subscripts.
303 */
304 LLVMMetadataRef
305 LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, unsigned Size,
306 unsigned AlignInBits, LLVMMetadataRef Ty,
307 LLVMMetadataRef *Subscripts,
308 unsigned NumSubscripts);
309
310 /**
311 * Create debugging information entry for a vector type.
312 * \param Builder The DIBuilder.
313 * \param Size Vector size.
314 * \param AlignInBits Alignment.
315 * \param Ty Element type.
316 * \param Subscripts Subscripts.
317 */
318 LLVMMetadataRef
319 LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, unsigned Size,
320 unsigned AlignInBits, LLVMMetadataRef Ty,
321 LLVMMetadataRef *Subscripts,
322 unsigned NumSubscripts);
323
324 /**
325 * Create a DWARF unspecified type.
326 * \param Builder The DIBuilder.
327 * \param Name The unspecified type's name.
328 * \param NameLen Length of type name.
329 */
330 LLVMMetadataRef
331 LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name,
332 size_t NameLen);
333
334 /**
335 * Create debugging information entry for a basic
336 * type.
337 * \param Builder The DIBuilder.
338 * \param Name Type name.
339 * \param Name Length of type name.
340 * \param SizeInBits Size of the type.
341 * \param Encoding DWARF encoding code, e.g. \c LLVMDWARFTypeEncoding_float.
342 */
343 LLVMMetadataRef
344 LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
345 size_t NameLen, unsigned SizeInBits,
346 LLVMDWARFTypeEncoding Encoding);
347
348 /**
349 * Create debugging information entry for a pointer.
350 * \param Builder The DIBuilder.
351 * \param PointeeTy Type pointed by this pointer.
352 * \param SizeInBits Size.
353 * \param AlignInBits Alignment. (optional, pass 0 to ignore)
354 * \param DWARFAddressSpace DWARF address space. (optional, pass 0 to ignore)
355 * \param Name Pointer type name. (optional)
356 * \param Name Length of pointer type name. (optional)
357 */
358 LLVMMetadataRef LLVMDIBuilderCreatePointerType(
359 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
360 unsigned SizeInBits, unsigned AlignInBits, unsigned AddressSpace,
361 const char *Name, size_t NameLen);
362
363 /**
364 * Create debugging information entry for a struct.
365 * \param Builder The DIBuilder.
366 * \param Scope Scope in which this struct is defined.
367 * \param Name Struct name.
368 * \param Name Struct name length.
369 * \param File File where this member is defined.
370 * \param LineNumber Line number.
371 * \param SizeInBits Member size.
372 * \param AlignInBits Member alignment.
373 * \param Flags Flags to encode member attribute, e.g. private
374 * \param Elements Struct elements.
375 * \param RunTimeLang Optional parameter, Objective-C runtime version.
376 * \param VTableHolder The object containing the vtable for the struct.
377 * \param UniqueIdentifier A unique identifier for the struct.
378 * \param UniqueIdentifierLen Length of the unique identifier for the struct.
379 */
380 LLVMMetadataRef LLVMDIBuilderCreateStructType(
381 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
382 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
383 unsigned SizeInBits, unsigned AlignInBits, LLVMDIFlags Flags,
384 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
385 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
386 const char *UniqueId, size_t UniqueIdLen);
387
388 /**
389 * Create debugging information entry for a member.
390 * \param Builder The DIBuilder.
391 * \param Scope Member scope.
392 * \param Name Member name.
393 * \param File File where this member is defined.
394 * \param LineNo Line number.
395 * \param SizeInBits Member size.
396 * \param AlignInBits Member alignment.
397 * \param OffsetInBits Member offset.
398 * \param Flags Flags to encode member attribute, e.g. private
399 * \param Ty Parent type.
400 */
401 LLVMMetadataRef LLVMDIBuilderCreateMemberType(
402 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
403 size_t NameLen, LLVMMetadataRef File, unsigned LineNo,
404 unsigned SizeInBits, unsigned AlignInBits, unsigned OffsetInBits,
405 LLVMDIFlags Flags, LLVMMetadataRef Ty);
406
407 /**
408 * Create debugging information entry for a
409 * C++ static data member.
410 * \param Builder The DIBuilder.
411 * \param Scope Member scope.
412 * \param Name Member name.
413 * \param Name Length of member name.
414 * \param File File where this member is declared.
415 * \param LineNo Line number.
416 * \param Ty Type of the static member.
417 * \param Flags Flags to encode member attribute, e.g. private.
418 * \param Val Const initializer of the member.
419 * \param AlignInBits Member alignment.
420 */
421 LLVMMetadataRef
422 LLVMDIBuilderCreateStaticMemberType(
423 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
424 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
425 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
426 unsigned AlignInBits);
427
428 /**
429 * Create debugging information entry for a pointer to member.
430 * \param Builder The DIBuilder.
431 * \param PointeeType Type pointed to by this pointer.
432 * \param Class Type for which this pointer points to members of.
433 * \param SizeInBits Size.
434 * \param AlignInBits Alignment. (optional)
435 * \param Flags Flags.
436 */
437 LLVMMetadataRef
438 LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder,
439 LLVMMetadataRef PointeeType,
440 LLVMMetadataRef ClassType,
441 unsigned SizeInBits,
442 unsigned AlignInBits,
443 LLVMDIFlags Flags);
444
445 /**
446 * Create a new DIType* with the "object pointer"
447 * flag set.
448 * \param Builder The DIBuilder.
449 * \param Type The underlying type to which this pointer points.
450 */
451 LLVMMetadataRef
452 LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
453 LLVMMetadataRef Type);
454
455 /**
456 * Create debugging information entry for a qualified
457 * type, e.g. 'const int'.
458 * \param Tag Tag identifing type,
459 * e.g. LLVMDWARFTypeQualifier_volatile_type
460 * \param FromTy Base Type.
461 */
462 LLVMMetadataRef
463 LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
464 LLVMMetadataRef Type);
465
466 /**
467 * Create debugging information entry for a c++
468 * style reference or rvalue reference type.
469 */
470 LLVMMetadataRef
471 LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag,
472 LLVMMetadataRef Type);
473
474 /**
475 * Create C++11 nullptr type.
476 * \param Builder The DIBuilder.
477 */
478 LLVMMetadataRef
479 LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder);
480
481 /**
482 * Create a temporary forward-declared type.
483 * \param Builder The DIBuilder.
484 * \param Tag A unique tag for this type.
485 * \param Name Type name.
486 * \param NameLen Length of type name.
487 * \param Scope Type scope.
488 * \param File File where this type is defined.
489 * \param Line Line number where this type is defined.
490 */
491 LLVMMetadataRef
492 LLVMDIBuilderCreateReplaceableCompositeType(
493 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
494 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
495 unsigned RuntimeLang, unsigned SizeInBits, unsigned AlignInBits,
496 LLVMDIFlags Flags, const char *UniqueIdentifier,
497 size_t UniqueIdentifierLen);
498
499 /**
500 * Create debugging information entry for a bit field member.
501 * \param Builder The DIBuilder.
502 * \param Scope Member scope.
503 * \param Name Member name.
504 * \param NameLen Length of member name.
505 * \param File File where this member is defined.
506 * \param LineNo Line number.
507 * \param SizeInBits Member size.
508 * \param OffsetInBits Member offset.
509 * \param StorageOffsetInBits Member storage offset.
510 * \param Flags Flags to encode member attribute.
511 * \param Type Parent type.
512 */
513 LLVMMetadataRef
514 LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder,
515 LLVMMetadataRef Scope,
516 const char *Name, size_t NameLen,
517 LLVMMetadataRef File, unsigned LineNumber,
518 unsigned SizeInBits,
519 unsigned OffsetInBits,
520 unsigned StorageOffsetInBits,
521 LLVMDIFlags Flags, LLVMMetadataRef Type);
522
523 /**
524 * Create debugging information entry for a class.
525 * \param Scope Scope in which this class is defined.
526 * \param Name class name.
527 * \param File File where this member is defined.
528 * \param LineNumber Line number.
529 * \param SizeInBits Member size.
530 * \param AlignInBits Member alignment.
531 * \param OffsetInBits Member offset.
532 * \param Flags Flags to encode member attribute, e.g. private
533 * \param Elements class members.
534 * \param DerivedFrom Debug info of the base class of this type.
535 * \param TemplateParms Template type parameters.
536 */
537 LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder,
538 LLVMMetadataRef Scope, const char *Name, size_t NameLen,
539 LLVMMetadataRef File, unsigned LineNumber, unsigned SizeInBits,
540 unsigned AlignInBits, unsigned OffsetInBits, LLVMDIFlags Flags,
541 LLVMMetadataRef *Elements, unsigned NumElements,
542 LLVMMetadataRef DerivedFrom, LLVMMetadataRef TemplateParamsNode);
543
544 /**
545 * Create a new DIType* with "artificial" flag set.
546 * \param Builder The DIBuilder.
547 * \param Type The underlying type.
548 */
549 LLVMMetadataRef
550 LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
551 LLVMMetadataRef Type);
552
229553 #ifdef __cplusplus
230554 } /* end extern "C" */
231555 #endif
691691 llvm_unreachable("Unhandled Tag");
692692 }
693693
694 template DIT *unwrapDI(LLVMMetadataRef Ref) {
695 return (DIT *)(Ref ? unwrap(Ref) : nullptr);
696 }
697
698 static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) {
699 return static_cast(Flags);
700 }
701
694702 unsigned LLVMDebugMetadataVersion() {
695703 return DEBUG_METADATA_VERSION;
696704 }
726734 unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
727735 LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
728736 LLVMBool DebugInfoForProfiling) {
729 auto File = unwrap(FileRef);
737 auto File = unwrapDI(FileRef);
730738
731739 return wrap(unwrap(Builder)->createCompileUnit(
732740 map_from_llvmDWARFsourcelanguage(Lang), File,
752760 return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
753761 unwrap(InlinedAt)));
754762 }
763
764 LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
765 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
766 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
767 unsigned SizeInBits, unsigned AlignInBits, LLVMMetadataRef *Elements,
768 unsigned NumElements, LLVMMetadataRef ClassTy) {
769 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
770 NumElements});
771 return wrap(unwrap(Builder)->createEnumerationType(
772 unwrapDI(Scope), {Name, NameLen}, unwrapDI(File),
773 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI(ClassTy)));
774 }
775
776 LLVMMetadataRef LLVMDIBuilderCreateUnionType(
777 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
778 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
779 unsigned SizeInBits, unsigned AlignInBits, LLVMDIFlags Flags,
780 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
781 const char *UniqueId, size_t UniqueIdLen) {
782 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
783 NumElements});
784 return wrap(unwrap(Builder)->createUnionType(
785 unwrapDI(Scope), {Name, NameLen}, unwrapDI(File),
786 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
787 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
788 }
789
790
791 LLVMMetadataRef
792 LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, unsigned Size,
793 unsigned AlignInBits, LLVMMetadataRef Ty,
794 LLVMMetadataRef *Subscripts,
795 unsigned NumSubscripts) {
796 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
797 NumSubscripts});
798 return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
799 unwrapDI(Ty), Subs));
800 }
801
802 LLVMMetadataRef
803 LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, unsigned Size,
804 unsigned AlignInBits, LLVMMetadataRef Ty,
805 LLVMMetadataRef *Subscripts,
806 unsigned NumSubscripts) {
807 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
808 NumSubscripts});
809 return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
810 unwrapDI(Ty), Subs));
811 }
812
813 LLVMMetadataRef
814 LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
815 size_t NameLen, unsigned SizeInBits,
816 LLVMDWARFTypeEncoding Encoding) {
817 return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
818 SizeInBits, Encoding));
819 }
820
821 LLVMMetadataRef LLVMDIBuilderCreatePointerType(
822 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
823 unsigned SizeInBits, unsigned AlignInBits, unsigned AddressSpace,
824 const char *Name, size_t NameLen) {
825 return wrap(unwrap(Builder)->createPointerType(unwrapDI(PointeeTy),
826 SizeInBits, AlignInBits,
827 AddressSpace, {Name, NameLen}));
828 }
829
830 LLVMMetadataRef LLVMDIBuilderCreateStructType(
831 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
832 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
833 unsigned SizeInBits, unsigned AlignInBits, LLVMDIFlags Flags,
834 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
835 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
836 const char *UniqueId, size_t UniqueIdLen) {
837 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
838 NumElements});
839 return wrap(unwrap(Builder)->createStructType(
840 unwrapDI(Scope), {Name, NameLen}, unwrapDI(File),
841 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
842 unwrapDI(DerivedFrom), Elts, RunTimeLang,
843 unwrapDI(VTableHolder), {UniqueId, UniqueIdLen}));
844 }
845
846 LLVMMetadataRef LLVMDIBuilderCreateMemberType(
847 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
848 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
849 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
850 LLVMMetadataRef Ty) {
851 return wrap(unwrap(Builder)->createMemberType(unwrapDI(Scope),
852 {Name, NameLen}, unwrapDI(File), LineNo, SizeInBits, AlignInBits,
853 OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI(Ty)));
854 }
855
856 LLVMMetadataRef
857 LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name,
858 size_t NameLen) {
859 return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
860 }
861
862 LLVMMetadataRef
863 LLVMDIBuilderCreateStaticMemberType(
864 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
865 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
866 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
867 unsigned AlignInBits) {
868 return wrap(unwrap(Builder)->createStaticMemberType(
869 unwrapDI(Scope), {Name, NameLen},
870 unwrapDI(File), LineNumber, unwrapDI(Type),
871 map_from_llvmDIFlags(Flags), unwrap(ConstantVal),
872 AlignInBits));
873 }
874
875 LLVMMetadataRef
876 LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
877 LLVMMetadataRef Type) {
878 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI(Type)));
879 }
880
881 LLVMMetadataRef
882 LLVMDIBuilderCreateReplaceableCompositeType(
883 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen,
884 LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
885 unsigned RuntimeLang, unsigned SizeInBits, unsigned AlignInBits,
886 LLVMDIFlags Flags, const char *UniqueIdentifier,
887 unsigned UniqueIdentifierLen) {
888 return wrap(unwrap(Builder)->createReplaceableCompositeType(
889 Tag, {Name, NameLen}, unwrapDI(Scope),
890 unwrapDI(File), Line, RuntimeLang, SizeInBits,
891 AlignInBits, map_from_llvmDIFlags(Flags),
892 {UniqueIdentifier, UniqueIdentifierLen}));
893 }
894
895 LLVMMetadataRef
896 LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
897 LLVMMetadataRef Type) {
898 return wrap(unwrap(Builder)->createQualifiedType(Tag,
899 unwrapDI(Type)));
900 }
901
902 LLVMMetadataRef
903 LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag,
904 LLVMMetadataRef Type) {
905 return wrap(unwrap(Builder)->createReferenceType(Tag,
906 unwrapDI(Type)));
907 }
908
909 LLVMMetadataRef
910 LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) {
911 return wrap(unwrap(Builder)->createNullPtrType());
912 }
913
914 LLVMMetadataRef
915 LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder,
916 LLVMMetadataRef PointeeType,
917 LLVMMetadataRef ClassType,
918 unsigned SizeInBits,
919 unsigned AlignInBits,
920 LLVMDIFlags Flags) {
921 return wrap(unwrap(Builder)->createMemberPointerType(
922 unwrapDI(PointeeType),
923 unwrapDI(ClassType), AlignInBits, SizeInBits,
924 map_from_llvmDIFlags(Flags)));
925 }
926
927 LLVMMetadataRef
928 LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
929 LLVMMetadataRef Type) {
930 return wrap(unwrap(Builder)->createArtificialType(unwrapDI(Type)));
931 }
932
933 LLVMMetadataRef
934 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
935 LLVMMetadataRef File,
936 LLVMMetadataRef *ParameterTypes,
937 unsigned NumParameterTypes,
938 LLVMDIFlags Flags) {
939 auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
940 NumParameterTypes});
941 return wrap(unwrap(Builder)->createSubroutineType(
942 Elts, map_from_llvmDIFlags(Flags)));
943 }
33 ; CHECK-NEXT: source_filename = "debuginfo.c"
44
55 ; CHECK: !llvm.dbg.cu = !{!0}
6 ; CHECK-NEXT: !FooType = !{!2}
7
68 ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
7 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c\00", directory: ".")
9 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
10 ; CHECK-NEXT: !2 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !3, size: 192, dwarfAddressSpace: 0)
11 ; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", file: !1, size: 192, elements: !4, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
12 ; CHECK-NEXT: !4 = !{!5, !5, !5}
13 ; CHECK-NEXT: !5 = !DIBasicType(name: "Int64", size: 64)
1010 |* *|
1111 \*===----------------------------------------------------------------------===*/
1212
13 #include "llvm-c-test.h"
14 #include "llvm-c/Core.h"
1315 #include "llvm-c/DebugInfo.h"
1416 #include
17 #include
1518
1619 int llvm_test_dibuilder(void) {
17 LLVMModuleRef M = LLVMModuleCreateWithName("debuginfo.c");
20 const char *Filename = "debuginfo.c";
21 LLVMModuleRef M = LLVMModuleCreateWithName(Filename);
1822 LLVMDIBuilderRef DIB = LLVMCreateDIBuilder(M);
1923
20 LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, "debuginfo.c", 12,
21 ".", 1);
24 LLVMMetadataRef File = LLVMDIBuilderCreateFile(DIB, Filename,
25 strlen(Filename), ".", 1);
2226
23 LLVMDIBuilderCreateCompileUnit(DIB,
27 LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(DIB,
2428 LLVMDWARFSourceLanguageC, File,"llvm-c-test", 11, 0, NULL, 0, 0,
2529 NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0);
30
31 LLVMMetadataRef Int64Ty =
32 LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
33
34 LLVMMetadataRef StructDbgElts[] = {Int64Ty, Int64Ty, Int64Ty};
35 LLVMMetadataRef StructDbgTy =
36 LLVMDIBuilderCreateStructType(DIB, CompileUnit, "MyStruct",
37 8, File, 0, 192, 0, 0, NULL, StructDbgElts, 3,
38 LLVMDWARFSourceLanguageC, NULL, "MyStruct", 8);
39
40 LLVMMetadataRef StructDbgPtrTy =
41 LLVMDIBuilderCreatePointerType(DIB, StructDbgTy, 192, 0, 0, "", 0);
42
43 LLVMAddNamedMetadataOperand(M, "FooType",
44 LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy));
2645
2746 char *MStr = LLVMPrintModuleToString(M);
2847 puts(MStr);