[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / bindings / go / llvm / dibuilder.go
blob98c11c151153b86e3ad47259ee61e62e957741d5
1 //===- dibuilder.go - Bindings for DIBuilder ------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines bindings for the DIBuilder class.
11 //===----------------------------------------------------------------------===//
13 package llvm
16 #include "IRBindings.h"
17 #include <stdlib.h>
19 import "C"
21 import (
22 "debug/dwarf"
23 "unsafe"
26 type DwarfTag uint32
28 const (
29 DW_TAG_lexical_block DwarfTag = 0x0b
30 DW_TAG_compile_unit DwarfTag = 0x11
31 DW_TAG_variable DwarfTag = 0x34
32 DW_TAG_base_type DwarfTag = 0x24
33 DW_TAG_pointer_type DwarfTag = 0x0F
34 DW_TAG_structure_type DwarfTag = 0x13
35 DW_TAG_subroutine_type DwarfTag = 0x15
36 DW_TAG_file_type DwarfTag = 0x29
37 DW_TAG_subprogram DwarfTag = 0x2E
38 DW_TAG_auto_variable DwarfTag = 0x100
39 DW_TAG_arg_variable DwarfTag = 0x101
42 const (
43 FlagPrivate = 1 << iota
44 FlagProtected
45 FlagFwdDecl
46 FlagAppleBlock
47 FlagBlockByrefStruct
48 FlagVirtual
49 FlagArtificial
50 FlagExplicit
51 FlagPrototyped
52 FlagObjcClassComplete
53 FlagObjectPointer
54 FlagVector
55 FlagStaticMember
56 FlagIndirectVariable
57 FlagArgumentNotModified
60 type DwarfLang uint32
62 const (
63 // http://dwarfstd.org/ShowIssue.php?issue=101014.1&type=open
64 DW_LANG_Go DwarfLang = 0x0016
67 type DwarfTypeEncoding uint32
69 const (
70 DW_ATE_address DwarfTypeEncoding = 0x01
71 DW_ATE_boolean DwarfTypeEncoding = 0x02
72 DW_ATE_complex_float DwarfTypeEncoding = 0x03
73 DW_ATE_float DwarfTypeEncoding = 0x04
74 DW_ATE_signed DwarfTypeEncoding = 0x05
75 DW_ATE_signed_char DwarfTypeEncoding = 0x06
76 DW_ATE_unsigned DwarfTypeEncoding = 0x07
77 DW_ATE_unsigned_char DwarfTypeEncoding = 0x08
78 DW_ATE_imaginary_float DwarfTypeEncoding = 0x09
79 DW_ATE_packed_decimal DwarfTypeEncoding = 0x0a
80 DW_ATE_numeric_string DwarfTypeEncoding = 0x0b
81 DW_ATE_edited DwarfTypeEncoding = 0x0c
82 DW_ATE_signed_fixed DwarfTypeEncoding = 0x0d
83 DW_ATE_unsigned_fixed DwarfTypeEncoding = 0x0e
84 DW_ATE_decimal_float DwarfTypeEncoding = 0x0f
85 DW_ATE_UTF DwarfTypeEncoding = 0x10
86 DW_ATE_lo_user DwarfTypeEncoding = 0x80
87 DW_ATE_hi_user DwarfTypeEncoding = 0xff
90 // DIBuilder is a wrapper for the LLVM DIBuilder class.
91 type DIBuilder struct {
92 ref C.LLVMDIBuilderRef
93 m Module
96 // NewDIBuilder creates a new DIBuilder, associated with the given module.
97 func NewDIBuilder(m Module) *DIBuilder {
98 d := C.LLVMCreateDIBuilder(m.C)
99 return &DIBuilder{ref: d, m: m}
102 // Destroy destroys the DIBuilder.
103 func (d *DIBuilder) Destroy() {
104 C.LLVMDisposeDIBuilder(d.ref)
107 // FInalize finalizes the debug information generated by the DIBuilder.
108 func (d *DIBuilder) Finalize() {
109 C.LLVMDIBuilderFinalize(d.ref)
112 // DICompileUnit holds the values for creating compile unit debug metadata.
113 type DICompileUnit struct {
114 Language DwarfLang
115 File string
116 Dir string
117 Producer string
118 Optimized bool
119 Flags string
120 RuntimeVersion int
123 // CreateCompileUnit creates compile unit debug metadata.
124 func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
125 file := C.CString(cu.File)
126 defer C.free(unsafe.Pointer(file))
127 dir := C.CString(cu.Dir)
128 defer C.free(unsafe.Pointer(dir))
129 producer := C.CString(cu.Producer)
130 defer C.free(unsafe.Pointer(producer))
131 flags := C.CString(cu.Flags)
132 defer C.free(unsafe.Pointer(flags))
133 result := C.LLVMDIBuilderCreateCompileUnit(
134 d.ref,
135 C.LLVMDWARFSourceLanguage(cu.Language),
136 C.LLVMDIBuilderCreateFile(d.ref, file, C.size_t(len(cu.File)), dir, C.size_t(len(cu.Dir))),
137 producer, C.size_t(len(cu.Producer)),
138 C.LLVMBool(boolToCInt(cu.Optimized)),
139 flags, C.size_t(len(cu.Flags)),
140 C.unsigned(cu.RuntimeVersion),
141 /*SplitName=*/ nil, 0,
142 C.LLVMDWARFEmissionFull,
143 /*DWOId=*/ 0,
144 /*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
145 /*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
147 return Metadata{C: result}
150 // CreateFile creates file debug metadata.
151 func (d *DIBuilder) CreateFile(filename, dir string) Metadata {
152 cfilename := C.CString(filename)
153 defer C.free(unsafe.Pointer(cfilename))
154 cdir := C.CString(dir)
155 defer C.free(unsafe.Pointer(cdir))
156 result := C.LLVMDIBuilderCreateFile(d.ref,
157 cfilename, C.size_t(len(filename)),
158 cdir, C.size_t(len(dir)))
159 return Metadata{C: result}
162 // DILexicalBlock holds the values for creating lexical block debug metadata.
163 type DILexicalBlock struct {
164 File Metadata
165 Line int
166 Column int
169 // CreateLexicalBlock creates lexical block debug metadata.
170 func (d *DIBuilder) CreateLexicalBlock(diScope Metadata, b DILexicalBlock) Metadata {
171 result := C.LLVMDIBuilderCreateLexicalBlock(
172 d.ref,
173 diScope.C,
174 b.File.C,
175 C.unsigned(b.Line),
176 C.unsigned(b.Column),
178 return Metadata{C: result}
181 func (d *DIBuilder) CreateLexicalBlockFile(diScope Metadata, diFile Metadata, discriminator int) Metadata {
182 result := C.LLVMDIBuilderCreateLexicalBlockFile(d.ref, diScope.C, diFile.C,
183 C.unsigned(discriminator))
184 return Metadata{C: result}
187 // DIFunction holds the values for creating function debug metadata.
188 type DIFunction struct {
189 Name string
190 LinkageName string
191 File Metadata
192 Line int
193 Type Metadata
194 LocalToUnit bool
195 IsDefinition bool
196 ScopeLine int
197 Flags int
198 Optimized bool
201 // CreateFunction creates function debug metadata.
202 func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata {
203 name := C.CString(f.Name)
204 defer C.free(unsafe.Pointer(name))
205 linkageName := C.CString(f.LinkageName)
206 defer C.free(unsafe.Pointer(linkageName))
207 result := C.LLVMDIBuilderCreateFunction(
208 d.ref,
209 diScope.C,
210 name, C.size_t(len(f.Name)),
211 linkageName, C.size_t(len(f.LinkageName)),
212 f.File.C,
213 C.unsigned(f.Line),
214 f.Type.C,
215 C.LLVMBool(boolToCInt(f.LocalToUnit)),
216 C.LLVMBool(boolToCInt(f.IsDefinition)),
217 C.unsigned(f.ScopeLine),
218 C.LLVMDIFlags(f.Flags),
219 C.LLVMBool(boolToCInt(f.Optimized)),
221 return Metadata{C: result}
224 // DIAutoVariable holds the values for creating auto variable debug metadata.
225 type DIAutoVariable struct {
226 Name string
227 File Metadata
228 Line int
229 Type Metadata
230 AlwaysPreserve bool
231 Flags int
232 AlignInBits uint32
235 // CreateAutoVariable creates local variable debug metadata.
236 func (d *DIBuilder) CreateAutoVariable(scope Metadata, v DIAutoVariable) Metadata {
237 name := C.CString(v.Name)
238 defer C.free(unsafe.Pointer(name))
239 result := C.LLVMDIBuilderCreateAutoVariable(
240 d.ref,
241 scope.C,
242 name, C.size_t(len(v.Name)),
243 v.File.C,
244 C.unsigned(v.Line),
245 v.Type.C,
246 C.LLVMBool(boolToCInt(v.AlwaysPreserve)),
247 C.LLVMDIFlags(v.Flags),
248 C.uint32_t(v.AlignInBits),
250 return Metadata{C: result}
253 // DIParameterVariable holds the values for creating parameter variable debug metadata.
254 type DIParameterVariable struct {
255 Name string
256 File Metadata
257 Line int
258 Type Metadata
259 AlwaysPreserve bool
260 Flags int
262 // ArgNo is the 1-based index of the argument in the function's
263 // parameter list.
264 ArgNo int
267 // CreateParameterVariable creates parameter variable debug metadata.
268 func (d *DIBuilder) CreateParameterVariable(scope Metadata, v DIParameterVariable) Metadata {
269 name := C.CString(v.Name)
270 defer C.free(unsafe.Pointer(name))
271 result := C.LLVMDIBuilderCreateParameterVariable(
272 d.ref,
273 scope.C,
274 name, C.size_t(len(v.Name)),
275 C.unsigned(v.ArgNo),
276 v.File.C,
277 C.unsigned(v.Line),
278 v.Type.C,
279 C.LLVMBool(boolToCInt(v.AlwaysPreserve)),
280 C.LLVMDIFlags(v.Flags),
282 return Metadata{C: result}
285 // DIBasicType holds the values for creating basic type debug metadata.
286 type DIBasicType struct {
287 Name string
288 SizeInBits uint64
289 Encoding DwarfTypeEncoding
292 // CreateBasicType creates basic type debug metadata.
293 func (d *DIBuilder) CreateBasicType(t DIBasicType) Metadata {
294 name := C.CString(t.Name)
295 defer C.free(unsafe.Pointer(name))
296 result := C.LLVMDIBuilderCreateBasicType(
297 d.ref,
298 name,
299 C.size_t(len(t.Name)),
300 C.uint64_t(t.SizeInBits),
301 C.LLVMDWARFTypeEncoding(t.Encoding),
302 C.LLVMDIFlags(0),
304 return Metadata{C: result}
307 // DIPointerType holds the values for creating pointer type debug metadata.
308 type DIPointerType struct {
309 Pointee Metadata
310 SizeInBits uint64
311 AlignInBits uint32 // optional
312 AddressSpace uint32
313 Name string // optional
316 // CreatePointerType creates a type that represents a pointer to another type.
317 func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata {
318 name := C.CString(t.Name)
319 defer C.free(unsafe.Pointer(name))
320 result := C.LLVMDIBuilderCreatePointerType(
321 d.ref,
322 t.Pointee.C,
323 C.uint64_t(t.SizeInBits),
324 C.uint32_t(t.AlignInBits),
325 C.unsigned(t.AddressSpace),
326 name,
327 C.size_t(len(t.Name)),
329 return Metadata{C: result}
332 // DISubroutineType holds the values for creating subroutine type debug metadata.
333 type DISubroutineType struct {
334 // File is the file in which the subroutine type is defined.
335 File Metadata
337 // Parameters contains the subroutine parameter types,
338 // including the return type at the 0th index.
339 Parameters []Metadata
341 Flags int
344 // CreateSubroutineType creates subroutine type debug metadata.
345 func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Metadata {
346 params, length := llvmMetadataRefs(t.Parameters)
347 result := C.LLVMDIBuilderCreateSubroutineType(
348 d.ref,
349 t.File.C,
350 params,
351 length,
352 C.LLVMDIFlags(t.Flags),
354 return Metadata{C: result}
357 // DIStructType holds the values for creating struct type debug metadata.
358 type DIStructType struct {
359 Name string
360 File Metadata
361 Line int
362 SizeInBits uint64
363 AlignInBits uint32
364 Flags int
365 DerivedFrom Metadata
366 Elements []Metadata
367 VTableHolder Metadata // optional
368 UniqueID string
371 // CreateStructType creates struct type debug metadata.
372 func (d *DIBuilder) CreateStructType(scope Metadata, t DIStructType) Metadata {
373 elements, length := llvmMetadataRefs(t.Elements)
374 name := C.CString(t.Name)
375 uniqueID := C.CString(t.UniqueID)
376 defer C.free(unsafe.Pointer(name))
377 defer C.free(unsafe.Pointer(uniqueID))
378 result := C.LLVMDIBuilderCreateStructType(
379 d.ref,
380 scope.C,
381 name,
382 C.size_t(len(t.Name)),
383 t.File.C,
384 C.unsigned(t.Line),
385 C.uint64_t(t.SizeInBits),
386 C.uint32_t(t.AlignInBits),
387 C.LLVMDIFlags(t.Flags),
388 t.DerivedFrom.C,
389 elements,
390 length,
391 C.unsigned(0), // Optional Objective-C runtime version.
392 t.VTableHolder.C,
393 uniqueID,
394 C.size_t(len(t.UniqueID)),
396 return Metadata{C: result}
399 // DIReplaceableCompositeType holds the values for creating replaceable
400 // composite type debug metadata.
401 type DIReplaceableCompositeType struct {
402 Tag dwarf.Tag
403 Name string
404 File Metadata
405 Line int
406 RuntimeLang int
407 SizeInBits uint64
408 AlignInBits uint32
409 Flags int
410 UniqueID string
413 // CreateReplaceableCompositeType creates replaceable composite type debug metadata.
414 func (d *DIBuilder) CreateReplaceableCompositeType(scope Metadata, t DIReplaceableCompositeType) Metadata {
415 name := C.CString(t.Name)
416 uniqueID := C.CString(t.UniqueID)
417 defer C.free(unsafe.Pointer(name))
418 defer C.free(unsafe.Pointer(uniqueID))
419 result := C.LLVMDIBuilderCreateReplaceableCompositeType(
420 d.ref,
421 C.unsigned(t.Tag),
422 name,
423 C.size_t(len(t.Name)),
424 scope.C,
425 t.File.C,
426 C.unsigned(t.Line),
427 C.unsigned(t.RuntimeLang),
428 C.uint64_t(t.SizeInBits),
429 C.uint32_t(t.AlignInBits),
430 C.LLVMDIFlags(t.Flags),
431 uniqueID,
432 C.size_t(len(t.UniqueID)),
434 return Metadata{C: result}
437 // DIMemberType holds the values for creating member type debug metadata.
438 type DIMemberType struct {
439 Name string
440 File Metadata
441 Line int
442 SizeInBits uint64
443 AlignInBits uint32
444 OffsetInBits uint64
445 Flags int
446 Type Metadata
449 // CreateMemberType creates struct type debug metadata.
450 func (d *DIBuilder) CreateMemberType(scope Metadata, t DIMemberType) Metadata {
451 name := C.CString(t.Name)
452 defer C.free(unsafe.Pointer(name))
453 result := C.LLVMDIBuilderCreateMemberType(
454 d.ref,
455 scope.C,
456 name,
457 C.size_t(len(t.Name)),
458 t.File.C,
459 C.unsigned(t.Line),
460 C.uint64_t(t.SizeInBits),
461 C.uint32_t(t.AlignInBits),
462 C.uint64_t(t.OffsetInBits),
463 C.LLVMDIFlags(t.Flags),
464 t.Type.C,
466 return Metadata{C: result}
469 // DISubrange describes an integer value range.
470 type DISubrange struct {
471 Lo int64
472 Count int64
475 // DIArrayType holds the values for creating array type debug metadata.
476 type DIArrayType struct {
477 SizeInBits uint64
478 AlignInBits uint32
479 ElementType Metadata
480 Subscripts []DISubrange
483 // CreateArrayType creates struct type debug metadata.
484 func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata {
485 subscriptsSlice := make([]Metadata, len(t.Subscripts))
486 for i, s := range t.Subscripts {
487 subscriptsSlice[i] = d.getOrCreateSubrange(s.Lo, s.Count)
489 subscripts, length := llvmMetadataRefs(subscriptsSlice)
490 result := C.LLVMDIBuilderCreateArrayType(
491 d.ref,
492 C.uint64_t(t.SizeInBits),
493 C.uint32_t(t.AlignInBits),
494 t.ElementType.C,
495 subscripts,
496 length,
498 return Metadata{C: result}
501 // DITypedef holds the values for creating typedef type debug metadata.
502 type DITypedef struct {
503 Type Metadata
504 Name string
505 File Metadata
506 Line int
507 Context Metadata
510 // CreateTypedef creates typedef type debug metadata.
511 func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata {
512 name := C.CString(t.Name)
513 defer C.free(unsafe.Pointer(name))
514 result := C.LLVMDIBuilderCreateTypedef(
515 d.ref,
516 t.Type.C,
517 name,
518 C.size_t(len(t.Name)),
519 t.File.C,
520 C.unsigned(t.Line),
521 t.Context.C,
523 return Metadata{C: result}
526 // getOrCreateSubrange gets a metadata node for the specified subrange,
527 // creating if required.
528 func (d *DIBuilder) getOrCreateSubrange(lo, count int64) Metadata {
529 result := C.LLVMDIBuilderGetOrCreateSubrange(d.ref, C.int64_t(lo), C.int64_t(count))
530 return Metadata{C: result}
533 // getOrCreateArray gets a metadata node containing the specified values,
534 // creating if required.
535 func (d *DIBuilder) getOrCreateArray(values []Metadata) Metadata {
536 if len(values) == 0 {
537 return Metadata{}
539 data, length := llvmMetadataRefs(values)
540 result := C.LLVMDIBuilderGetOrCreateArray(d.ref, data, C.size_t(length))
541 return Metadata{C: result}
544 // getOrCreateTypeArray gets a metadata node for a type array containing the
545 // specified values, creating if required.
546 func (d *DIBuilder) getOrCreateTypeArray(values []Metadata) Metadata {
547 if len(values) == 0 {
548 return Metadata{}
550 data, length := llvmMetadataRefs(values)
551 result := C.LLVMDIBuilderGetOrCreateTypeArray(d.ref, data, C.size_t(length))
552 return Metadata{C: result}
555 // CreateExpression creates a new descriptor for the specified
556 // variable which has a complex address expression for its address.
557 func (d *DIBuilder) CreateExpression(addr []int64) Metadata {
558 var data *C.int64_t
559 if len(addr) > 0 {
560 data = (*C.int64_t)(unsafe.Pointer(&addr[0]))
562 result := C.LLVMDIBuilderCreateExpression(d.ref, data, C.size_t(len(addr)))
563 return Metadata{C: result}
566 // InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the
567 // specified basic block for the given value and associated debug metadata.
568 func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) Value {
569 loc := C.LLVMDIBuilderCreateDebugLocation(
570 d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C)
571 result := C.LLVMDIBuilderInsertDeclareAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
572 return Value{C: result}
575 // InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the
576 // specified basic block for the given value and associated debug metadata.
577 func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) Value {
578 loc := C.LLVMDIBuilderCreateDebugLocation(
579 d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C)
580 result := C.LLVMDIBuilderInsertDbgValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
581 return Value{C: result}
584 func (v Value) SetSubprogram(sp Metadata) {
585 C.LLVMSetSubprogram(v.C, sp.C)
588 func boolToCInt(v bool) C.int {
589 if v {
590 return 1
592 return 0
595 //-------------------------------------------------------------------------
596 // llvm.Metadata
597 //-------------------------------------------------------------------------
599 func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) {
600 ptr, nvals := llvmMetadataRefs(mds)
601 md.C = C.LLVMTemporaryMDNode(c.C, ptr, C.size_t(nvals))
602 return
605 func (md Metadata) ReplaceAllUsesWith(new Metadata) {
606 C.LLVMMetadataReplaceAllUsesWith(md.C, new.C)
609 type MetadataKind C.LLVMMetadataKind
611 const (
612 MDStringMetadataKind = C.LLVMMDStringMetadataKind
613 ConstantAsMetadataMetadataKind = C.LLVMConstantAsMetadataMetadataKind
614 LocalAsMetadataMetadataKind = C.LLVMLocalAsMetadataMetadataKind
615 DistinctMDOperandPlaceholderMetadataKind = C.LLVMDistinctMDOperandPlaceholderMetadataKind
616 MDTupleMetadataKind = C.LLVMMDTupleMetadataKind
617 DILocationMetadataKind = C.LLVMDILocationMetadataKind
618 DIExpressionMetadataKind = C.LLVMDIExpressionMetadataKind
619 DIGlobalVariableExpressionMetadataKind = C.LLVMDIGlobalVariableExpressionMetadataKind
620 GenericDINodeMetadataKind = C.LLVMGenericDINodeMetadataKind
621 DISubrangeMetadataKind = C.LLVMDISubrangeMetadataKind
622 DIEnumeratorMetadataKind = C.LLVMDIEnumeratorMetadataKind
623 DIBasicTypeMetadataKind = C.LLVMDIBasicTypeMetadataKind
624 DIDerivedTypeMetadataKind = C.LLVMDIDerivedTypeMetadataKind
625 DICompositeTypeMetadataKind = C.LLVMDICompositeTypeMetadataKind
626 DISubroutineTypeMetadataKind = C.LLVMDISubroutineTypeMetadataKind
627 DIFileMetadataKind = C.LLVMDIFileMetadataKind
628 DICompileUnitMetadataKind = C.LLVMDICompileUnitMetadataKind
629 DISubprogramMetadataKind = C.LLVMDISubprogramMetadataKind
630 DILexicalBlockMetadataKind = C.LLVMDILexicalBlockMetadataKind
631 DILexicalBlockFileMetadataKind = C.LLVMDILexicalBlockFileMetadataKind
632 DINamespaceMetadataKind = C.LLVMDINamespaceMetadataKind
633 DIModuleMetadataKind = C.LLVMDIModuleMetadataKind
634 DITemplateTypeParameterMetadataKind = C.LLVMDITemplateTypeParameterMetadataKind
635 DITemplateValueParameterMetadataKind = C.LLVMDITemplateValueParameterMetadataKind
636 DIGlobalVariableMetadataKind = C.LLVMDIGlobalVariableMetadataKind
637 DILocalVariableMetadataKind = C.LLVMDILocalVariableMetadataKind
638 DILabelMetadataKind = C.LLVMDILabelMetadataKind
639 DIObjCPropertyMetadataKind = C.LLVMDIObjCPropertyMetadataKind
640 DIImportedEntityMetadataKind = C.LLVMDIImportedEntityMetadataKind
641 DIMacroMetadataKind = C.LLVMDIMacroMetadataKind
642 DIMacroFileMetadataKind = C.LLVMDIMacroFileMetadataKind
643 DICommonBlockMetadataKind = C.LLVMDICommonBlockMetadataKind
646 // Kind returns the metadata kind.
647 func (md Metadata) Kind() MetadataKind {
648 return MetadataKind(C.LLVMGetMetadataKind(md.C))
651 // FileDirectory returns the directory of a DIFile metadata node.
652 func (md Metadata) FileDirectory() string {
653 var length C.unsigned
654 ptr := C.LLVMDIFileGetDirectory(md.C, &length)
655 return string(((*[1 << 20]byte)(unsafe.Pointer(ptr)))[:length:length])
658 // FileFilename returns the filename of a DIFile metadata node.
659 func (md Metadata) FileFilename() string {
660 var length C.unsigned
661 ptr := C.LLVMDIFileGetFilename(md.C, &length)
662 return string(((*[1 << 20]byte)(unsafe.Pointer(ptr)))[:length:length])
665 // FileSource returns the source of a DIFile metadata node.
666 func (md Metadata) FileSource() string {
667 var length C.unsigned
668 ptr := C.LLVMDIFileGetSource(md.C, &length)
669 return string(((*[1 << 20]byte)(unsafe.Pointer(ptr)))[:length:length])
672 // LocationLine returns the line number of a DILocation.
673 func (md Metadata) LocationLine() uint {
674 return uint(C.LLVMDILocationGetLine(md.C))
677 // LocationColumn returns the column (offset from the start of the line) of a
678 // DILocation.
679 func (md Metadata) LocationColumn() uint {
680 return uint(C.LLVMDILocationGetColumn(md.C))
683 // LocationScope returns the local scope associated with this debug location.
684 func (md Metadata) LocationScope() Metadata {
685 return Metadata{C.LLVMDILocationGetScope(md.C)}
688 // LocationInlinedAt return the "inline at" location associated with this debug
689 // location.
690 func (md Metadata) LocationInlinedAt() Metadata {
691 return Metadata{C.LLVMDILocationGetInlinedAt(md.C)}
694 // ScopeFile returns the file (DIFile) of a given scope.
695 func (md Metadata) ScopeFile() Metadata {
696 return Metadata{C.LLVMDIScopeGetFile(md.C)}