github.com/llir/llvm@v0.3.6/ir/metadata/specialized_metadata.go (about) 1 package metadata 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/llir/llvm/ir/enum" 8 ) 9 10 // ~~~ [ DIBasicType ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 12 // DIBasicType is a specialized metadata node. 13 type DIBasicType struct { 14 // Metadata ID associated with the specialized metadata node; -1 if not 15 // present. 16 MetadataID 17 // (optional) Distinct. 18 Distinct bool 19 20 Tag enum.DwarfTag // optional; zero value if not present. 21 Name string // optional; empty if not present. 22 Size uint64 // optional; zero value if not present. 23 Align uint64 // optional; zero value if not present. 24 Encoding enum.DwarfAttEncoding // optional; zero value if not present. 25 Flags enum.DIFlag // optional. 26 } 27 28 // String returns the LLVM syntax representation of the specialized metadata 29 // node. 30 func (md *DIBasicType) String() string { 31 return md.Ident() 32 } 33 34 // Ident returns the identifier associated with the specialized metadata node. 35 func (md *DIBasicType) Ident() string { 36 if md == nil { 37 return "null" 38 } 39 if md.MetadataID != -1 { 40 return md.MetadataID.Ident() 41 } 42 return md.LLString() 43 } 44 45 // LLString returns the LLVM syntax representation of the specialized metadata 46 // node. 47 // 48 // '!DIBasicType' '(' Fields=(DIBasicTypeField separator ',')* ')' 49 func (md *DIBasicType) LLString() string { 50 buf := &strings.Builder{} 51 if md.Distinct { 52 buf.WriteString("distinct ") 53 } 54 var fields []string 55 if md.Tag != 0 { 56 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 57 fields = append(fields, field) 58 } 59 if len(md.Name) > 0 { 60 field := fmt.Sprintf("name: %s", quote(md.Name)) 61 fields = append(fields, field) 62 } 63 if md.Size != 0 { 64 field := fmt.Sprintf("size: %d", md.Size) 65 fields = append(fields, field) 66 } 67 if md.Align != 0 { 68 field := fmt.Sprintf("align: %d", md.Align) 69 fields = append(fields, field) 70 } 71 if md.Encoding != 0 { 72 field := fmt.Sprintf("encoding: %s", md.Encoding) 73 fields = append(fields, field) 74 } 75 if md.Flags != 0 { 76 field := fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 77 fields = append(fields, field) 78 } 79 fmt.Fprintf(buf, "!DIBasicType(%s)", strings.Join(fields, ", ")) 80 return buf.String() 81 } 82 83 // SetDistinct specifies whether the metadata definition is dinstict. 84 func (md *DIBasicType) SetDistinct(distinct bool) { 85 md.Distinct = distinct 86 } 87 88 // ~~~ [ DICommonBlock ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 89 90 // DICommonBlock is a specialized metadata node. 91 type DICommonBlock struct { 92 // Metadata ID associated with the specialized metadata node; -1 if not 93 // present. 94 MetadataID 95 // (optional) Distinct. 96 Distinct bool 97 98 Scope Field // required. 99 Declaration Field // optional; nil if not present. 100 Name string // optional; empty if not present. 101 File *DIFile // required. 102 Line int64 // optional; zero value if not present. 103 } 104 105 // String returns the LLVM syntax representation of the specialized metadata 106 // node. 107 func (md *DICommonBlock) String() string { 108 return md.Ident() 109 } 110 111 // Ident returns the identifier associated with the specialized metadata node. 112 func (md *DICommonBlock) Ident() string { 113 if md == nil { 114 return "null" 115 } 116 if md.MetadataID != -1 { 117 return md.MetadataID.Ident() 118 } 119 return md.LLString() 120 } 121 122 // LLString returns the LLVM syntax representation of the specialized metadata 123 // node. 124 // 125 // '!DICommonBlock' '(' Fields=(DICommonBlockField separator ',')* ')' 126 func (md *DICommonBlock) LLString() string { 127 buf := &strings.Builder{} 128 if md.Distinct { 129 buf.WriteString("distinct ") 130 } 131 var fields []string 132 field := fmt.Sprintf("scope: %s", md.Scope) 133 fields = append(fields, field) 134 if md.Declaration != nil { 135 field := fmt.Sprintf("declaration: %s", md.Declaration) 136 fields = append(fields, field) 137 } 138 if len(md.Name) > 0 { 139 field := fmt.Sprintf("name: %s", quote(md.Name)) 140 fields = append(fields, field) 141 } 142 if md.File != nil { 143 field := fmt.Sprintf("file: %s", md.File) 144 fields = append(fields, field) 145 } 146 if md.Line != 0 { 147 field := fmt.Sprintf("line: %d", md.Line) 148 fields = append(fields, field) 149 } 150 fmt.Fprintf(buf, "!DICommonBlock(%s)", strings.Join(fields, ", ")) 151 return buf.String() 152 } 153 154 // SetDistinct specifies whether the metadata definition is dinstict. 155 func (md *DICommonBlock) SetDistinct(distinct bool) { 156 md.Distinct = distinct 157 } 158 159 // ~~~ [ DICompileUnit ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 160 161 // DICompileUnit is a specialized metadata node. 162 type DICompileUnit struct { 163 // Metadata ID associated with the specialized metadata node; -1 if not 164 // present. 165 MetadataID 166 // (optional) Distinct. 167 Distinct bool 168 169 Language enum.DwarfLang // required. 170 File *DIFile // required. 171 Producer string // optional; empty if not present. 172 IsOptimized bool // optional; zero value if not present. 173 Flags string // optional; empty if not present. 174 RuntimeVersion uint64 // optional; zero value if not present. 175 SplitDebugFilename string // optional; empty if not present. 176 EmissionKind enum.EmissionKind // optional; zero value if not present. 177 Enums *Tuple // optional; nil if not present. 178 RetainedTypes *Tuple // optional; nil if not present. 179 Globals *Tuple // optional; nil if not present. 180 Imports *Tuple // optional; nil if not present. 181 Macros *Tuple // optional; nil if not present. 182 DwoID uint64 // optional; zero value if not present. 183 SplitDebugInlining bool // optional; zero value if not present. 184 DebugInfoForProfiling bool // optional; zero value if not present. 185 NameTableKind enum.NameTableKind // optional; zero value if not present. 186 RangesBaseAddress bool // optional; zero value if not present. 187 Sysroot string // optional; zero value if not present. 188 SDK string // optional; zero value if not present. 189 } 190 191 // String returns the LLVM syntax representation of the specialized metadata 192 // node. 193 func (md *DICompileUnit) String() string { 194 return md.Ident() 195 } 196 197 // Ident returns the identifier associated with the specialized metadata node. 198 func (md *DICompileUnit) Ident() string { 199 if md == nil { 200 return "null" 201 } 202 if md.MetadataID != -1 { 203 return md.MetadataID.Ident() 204 } 205 return md.LLString() 206 } 207 208 // LLString returns the LLVM syntax representation of the specialized metadata 209 // node. 210 // 211 // '!DICompileUnit' '(' Fields=(DICompileUnitField separator ',')* ')' 212 func (md *DICompileUnit) LLString() string { 213 buf := &strings.Builder{} 214 if md.Distinct { 215 buf.WriteString("distinct ") 216 } 217 var fields []string 218 field := fmt.Sprintf("language: %s", md.Language) 219 fields = append(fields, field) 220 field = fmt.Sprintf("file: %s", md.File) 221 fields = append(fields, field) 222 if len(md.Producer) > 0 { 223 field = fmt.Sprintf("producer: %s", quote(md.Producer)) 224 fields = append(fields, field) 225 } 226 if md.IsOptimized { 227 field = fmt.Sprintf("isOptimized: %t", md.IsOptimized) 228 fields = append(fields, field) 229 } 230 if len(md.Flags) > 0 { 231 field = fmt.Sprintf("flags: %s", quote(md.Flags)) 232 fields = append(fields, field) 233 } 234 if md.RuntimeVersion != 0 { 235 field = fmt.Sprintf("runtimeVersion: %d", md.RuntimeVersion) 236 fields = append(fields, field) 237 } 238 if len(md.SplitDebugFilename) > 0 { 239 field = fmt.Sprintf("splitDebugFilename: %s", quote(md.SplitDebugFilename)) 240 fields = append(fields, field) 241 } 242 if md.EmissionKind != 0 { 243 field = fmt.Sprintf("emissionKind: %s", md.EmissionKind) 244 fields = append(fields, field) 245 } 246 if md.Enums != nil { 247 field = fmt.Sprintf("enums: %s", md.Enums) 248 fields = append(fields, field) 249 } 250 if md.RetainedTypes != nil { 251 field = fmt.Sprintf("retainedTypes: %s", md.RetainedTypes) 252 fields = append(fields, field) 253 } 254 if md.Globals != nil { 255 field = fmt.Sprintf("globals: %s", md.Globals) 256 fields = append(fields, field) 257 } 258 if md.Imports != nil { 259 field = fmt.Sprintf("imports: %s", md.Imports) 260 fields = append(fields, field) 261 } 262 if md.Macros != nil { 263 field = fmt.Sprintf("macros: %s", md.Macros) 264 fields = append(fields, field) 265 } 266 if md.DwoID != 0 { 267 field = fmt.Sprintf("dwoId: %d", md.DwoID) 268 fields = append(fields, field) 269 } 270 if md.SplitDebugInlining { 271 field = fmt.Sprintf("splitDebugInlining: %t", md.SplitDebugInlining) 272 fields = append(fields, field) 273 } 274 if md.DebugInfoForProfiling { 275 field = fmt.Sprintf("debugInfoForProfiling: %t", md.DebugInfoForProfiling) 276 fields = append(fields, field) 277 } 278 if md.NameTableKind != 0 { 279 field = fmt.Sprintf("nameTableKind: %s", md.NameTableKind) 280 fields = append(fields, field) 281 } 282 if md.RangesBaseAddress { 283 field = fmt.Sprintf("rangesBaseAddress: %t", md.RangesBaseAddress) 284 fields = append(fields, field) 285 } 286 if len(md.Sysroot) > 0 { 287 field = fmt.Sprintf("sysroot: %s", quote(md.Sysroot)) 288 fields = append(fields, field) 289 } 290 if len(md.SDK) > 0 { 291 field = fmt.Sprintf("sdk: %s", quote(md.SDK)) 292 fields = append(fields, field) 293 } 294 fmt.Fprintf(buf, "!DICompileUnit(%s)", strings.Join(fields, ", ")) 295 return buf.String() 296 } 297 298 // SetDistinct specifies whether the metadata definition is dinstict. 299 func (md *DICompileUnit) SetDistinct(distinct bool) { 300 md.Distinct = distinct 301 } 302 303 // ~~~ [ DICompositeType ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 304 305 // DICompositeType is a specialized metadata node. 306 type DICompositeType struct { 307 // Metadata ID associated with the specialized metadata node; -1 if not 308 // present. 309 MetadataID 310 // (optional) Distinct. 311 Distinct bool 312 313 Tag enum.DwarfTag // required. 314 Name string // optional; empty if not present. 315 Scope Field // optional; nil if not present. 316 File *DIFile // optional; nil if not present. 317 Line int64 // optional; zero value if not present. 318 BaseType Field // optional; nil if not present. 319 Size uint64 // optional; zero value if not present. 320 Align uint64 // optional; zero value if not present. 321 Offset uint64 // optional; zero value if not present. 322 Flags enum.DIFlag // optional. 323 Elements *Tuple // optional; nil if not present. 324 RuntimeLang enum.DwarfLang // optional; zero value if not present. 325 // *DIBasicType or *DICompositeType 326 VtableHolder Field // optional; nil if not present. 327 TemplateParams *Tuple // optional; nil if not present. 328 Identifier string // optional; empty if not present. 329 Discriminator Field // optional; nil if not present. 330 DataLocation Field // optional; nil if not present. 331 Associated Field // optional; nil if not present. 332 Allocated Field // optional; nil if not present. 333 Rank FieldOrInt // optional; nil if not present. 334 Annotations Field // optional; nil if not present. 335 } 336 337 // String returns the LLVM syntax representation of the specialized metadata 338 // node. 339 func (md *DICompositeType) String() string { 340 return md.Ident() 341 } 342 343 // Ident returns the identifier associated with the specialized metadata node. 344 func (md *DICompositeType) Ident() string { 345 if md == nil { 346 return "null" 347 } 348 if md.MetadataID != -1 { 349 return md.MetadataID.Ident() 350 } 351 return md.LLString() 352 } 353 354 // LLString returns the LLVM syntax representation of the specialized metadata 355 // node. 356 // 357 // '!DICompositeType' '(' Fields=(DICompositeTypeField separator ',')* ')' 358 func (md *DICompositeType) LLString() string { 359 buf := &strings.Builder{} 360 if md.Distinct { 361 buf.WriteString("distinct ") 362 } 363 var fields []string 364 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 365 fields = append(fields, field) 366 if len(md.Name) > 0 { 367 field := fmt.Sprintf("name: %s", quote(md.Name)) 368 fields = append(fields, field) 369 } 370 if md.Scope != nil { 371 field := fmt.Sprintf("scope: %s", md.Scope) 372 fields = append(fields, field) 373 } 374 if md.File != nil { 375 field := fmt.Sprintf("file: %s", md.File) 376 fields = append(fields, field) 377 } 378 if md.Line != 0 { 379 field := fmt.Sprintf("line: %d", md.Line) 380 fields = append(fields, field) 381 } 382 if md.BaseType != nil { 383 field := fmt.Sprintf("baseType: %s", md.BaseType) 384 fields = append(fields, field) 385 } 386 if md.Size != 0 { 387 field := fmt.Sprintf("size: %d", md.Size) 388 fields = append(fields, field) 389 } 390 if md.Align != 0 { 391 field := fmt.Sprintf("align: %d", md.Align) 392 fields = append(fields, field) 393 } 394 if md.Offset != 0 { 395 field := fmt.Sprintf("offset: %d", md.Offset) 396 fields = append(fields, field) 397 } 398 if md.Flags != 0 { 399 field = fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 400 fields = append(fields, field) 401 } 402 if md.Elements != nil { 403 field := fmt.Sprintf("elements: %s", md.Elements) 404 fields = append(fields, field) 405 } 406 if md.RuntimeLang != 0 { 407 field := fmt.Sprintf("runtimeLang: %s", md.RuntimeLang) 408 fields = append(fields, field) 409 } 410 if md.VtableHolder != nil { 411 field := fmt.Sprintf("vtableHolder: %s", md.VtableHolder) 412 fields = append(fields, field) 413 } 414 if md.TemplateParams != nil { 415 field := fmt.Sprintf("templateParams: %s", md.TemplateParams) 416 fields = append(fields, field) 417 } 418 if len(md.Identifier) > 0 { 419 field := fmt.Sprintf("identifier: %s", quote(md.Identifier)) 420 fields = append(fields, field) 421 } 422 if md.Discriminator != nil { 423 field := fmt.Sprintf("discriminator: %s", md.Discriminator) 424 fields = append(fields, field) 425 } 426 if md.DataLocation != nil { 427 field := fmt.Sprintf("dataLocation: %s", md.DataLocation) 428 fields = append(fields, field) 429 } 430 if md.Associated != nil { 431 field := fmt.Sprintf("associated: %s", md.Associated) 432 fields = append(fields, field) 433 } 434 if md.Allocated != nil { 435 field := fmt.Sprintf("allocated: %s", md.Allocated) 436 fields = append(fields, field) 437 } 438 if md.Rank != nil { 439 field := fmt.Sprintf("rank: %s", md.Rank) 440 fields = append(fields, field) 441 } 442 if md.Annotations != nil { 443 field := fmt.Sprintf("annotations: %s", md.Annotations) 444 fields = append(fields, field) 445 } 446 fmt.Fprintf(buf, "!DICompositeType(%s)", strings.Join(fields, ", ")) 447 return buf.String() 448 } 449 450 // SetDistinct specifies whether the metadata definition is dinstict. 451 func (md *DICompositeType) SetDistinct(distinct bool) { 452 md.Distinct = distinct 453 } 454 455 // ~~~ [ DIDerivedType ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 456 457 // DIDerivedType is a specialized metadata node. 458 type DIDerivedType struct { 459 // Metadata ID associated with the specialized metadata node; -1 if not 460 // present. 461 MetadataID 462 // (optional) Distinct. 463 Distinct bool 464 465 Tag enum.DwarfTag // required. 466 Name string // optional; empty if not present. 467 Scope Field // optional; nil if not present. 468 File *DIFile // optional; nil if not present. 469 Line int64 // optional; zero value if not present. 470 BaseType Field // required. 471 Size uint64 // optional; zero value if not present. 472 Align uint64 // optional; zero value if not present. 473 Offset uint64 // optional; zero value if not present. 474 Flags enum.DIFlag // optional. 475 ExtraData Field // optional; nil if not present. 476 DwarfAddressSpace uint64 // optional; zero value if not present. 477 Annotations Field // optional; nil if not present. 478 } 479 480 // String returns the LLVM syntax representation of the specialized metadata 481 // node. 482 func (md *DIDerivedType) String() string { 483 return md.Ident() 484 } 485 486 // Ident returns the identifier associated with the specialized metadata node. 487 func (md *DIDerivedType) Ident() string { 488 if md == nil { 489 return "null" 490 } 491 if md.MetadataID != -1 { 492 return md.MetadataID.Ident() 493 } 494 return md.LLString() 495 } 496 497 // LLString returns the LLVM syntax representation of the specialized metadata 498 // node. 499 // 500 // '!DIDerivedType' '(' Fields=(DIDerivedTypeField separator ',')* ')' 501 func (md *DIDerivedType) LLString() string { 502 buf := &strings.Builder{} 503 if md.Distinct { 504 buf.WriteString("distinct ") 505 } 506 var fields []string 507 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 508 fields = append(fields, field) 509 if len(md.Name) > 0 { 510 field := fmt.Sprintf("name: %s", quote(md.Name)) 511 fields = append(fields, field) 512 } 513 if md.Scope != nil { 514 field := fmt.Sprintf("scope: %s", md.Scope) 515 fields = append(fields, field) 516 } 517 if md.File != nil { 518 field := fmt.Sprintf("file: %s", md.File) 519 fields = append(fields, field) 520 } 521 if md.Line != 0 { 522 field := fmt.Sprintf("line: %d", md.Line) 523 fields = append(fields, field) 524 } 525 field = fmt.Sprintf("baseType: %s", md.BaseType) 526 fields = append(fields, field) 527 if md.Size != 0 { 528 field := fmt.Sprintf("size: %d", md.Size) 529 fields = append(fields, field) 530 } 531 if md.Align != 0 { 532 field := fmt.Sprintf("align: %d", md.Align) 533 fields = append(fields, field) 534 } 535 if md.Offset != 0 { 536 field := fmt.Sprintf("offset: %d", md.Offset) 537 fields = append(fields, field) 538 } 539 if md.Flags != 0 { 540 field = fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 541 fields = append(fields, field) 542 } 543 if md.ExtraData != nil { 544 field := fmt.Sprintf("extraData: %s", md.ExtraData) 545 fields = append(fields, field) 546 } 547 if md.DwarfAddressSpace != 0 { 548 field := fmt.Sprintf("dwarfAddressSpace: %d", md.DwarfAddressSpace) 549 fields = append(fields, field) 550 } 551 if md.Annotations != nil { 552 field := fmt.Sprintf("annotations: %s", md.Annotations) 553 fields = append(fields, field) 554 } 555 fmt.Fprintf(buf, "!DIDerivedType(%s)", strings.Join(fields, ", ")) 556 return buf.String() 557 } 558 559 // SetDistinct specifies whether the metadata definition is dinstict. 560 func (md *DIDerivedType) SetDistinct(distinct bool) { 561 md.Distinct = distinct 562 } 563 564 // ~~~ [ DIEnumerator ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 565 566 // DIEnumerator is a specialized metadata node. 567 type DIEnumerator struct { 568 // Metadata ID associated with the specialized metadata node; -1 if not 569 // present. 570 MetadataID 571 // (optional) Distinct. 572 Distinct bool 573 574 Name string // required. 575 Value int64 // required. 576 IsUnsigned bool // optional; zero value if not present. 577 } 578 579 // String returns the LLVM syntax representation of the specialized metadata 580 // node. 581 func (md *DIEnumerator) String() string { 582 return md.Ident() 583 } 584 585 // Ident returns the identifier associated with the specialized metadata node. 586 func (md *DIEnumerator) Ident() string { 587 if md == nil { 588 return "null" 589 } 590 if md.MetadataID != -1 { 591 return md.MetadataID.Ident() 592 } 593 return md.LLString() 594 } 595 596 // LLString returns the LLVM syntax representation of the specialized metadata 597 // node. 598 // 599 // '!DIEnumerator' '(' Fields=(DIEnumeratorField separator ',')* ')' 600 func (md *DIEnumerator) LLString() string { 601 buf := &strings.Builder{} 602 if md.Distinct { 603 buf.WriteString("distinct ") 604 } 605 var fields []string 606 field := fmt.Sprintf("name: %s", quote(md.Name)) 607 fields = append(fields, field) 608 if md.IsUnsigned { 609 field = fmt.Sprintf("value: %d", uint64(md.Value)) 610 } else { 611 field = fmt.Sprintf("value: %d", md.Value) 612 } 613 fields = append(fields, field) 614 if md.IsUnsigned { 615 field := fmt.Sprintf("isUnsigned: %t", md.IsUnsigned) 616 fields = append(fields, field) 617 } 618 fmt.Fprintf(buf, "!DIEnumerator(%s)", strings.Join(fields, ", ")) 619 return buf.String() 620 } 621 622 // SetDistinct specifies whether the metadata definition is dinstict. 623 func (md *DIEnumerator) SetDistinct(distinct bool) { 624 md.Distinct = distinct 625 } 626 627 // ~~~ [ DIExpression ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 628 629 // DIExpression is a specialized metadata node. 630 type DIExpression struct { 631 // Metadata ID associated with the specialized metadata node; -1 if not 632 // present. 633 MetadataID 634 // (optional) Distinct. 635 Distinct bool 636 637 Fields []DIExpressionField 638 } 639 640 // String returns the LLVM syntax representation of the specialized metadata 641 // node. 642 func (md *DIExpression) String() string { 643 return md.Ident() 644 } 645 646 // Ident returns the identifier associated with the specialized metadata node. 647 func (md *DIExpression) Ident() string { 648 if md == nil { 649 return "null" 650 } 651 if md.MetadataID != -1 { 652 return md.MetadataID.Ident() 653 } 654 return md.LLString() 655 } 656 657 // LLString returns the LLVM syntax representation of the specialized metadata 658 // node. 659 // 660 // '!DIExpression' '(' Fields=(DIExpressionField separator ',')* ')' 661 func (md *DIExpression) LLString() string { 662 buf := &strings.Builder{} 663 if md.Distinct { 664 buf.WriteString("distinct ") 665 } 666 buf.WriteString("!DIExpression(") 667 for i, field := range md.Fields { 668 if i != 0 { 669 buf.WriteString(", ") 670 } 671 buf.WriteString(field.String()) 672 } 673 buf.WriteString(")") 674 return buf.String() 675 } 676 677 // SetDistinct specifies whether the metadata definition is dinstict. 678 func (md *DIExpression) SetDistinct(distinct bool) { 679 md.Distinct = distinct 680 } 681 682 // ~~~ [ DIFile ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 683 684 // DIFile is a specialized metadata node. 685 type DIFile struct { 686 // Metadata ID associated with the specialized metadata node; -1 if not 687 // present. 688 MetadataID 689 // (optional) Distinct. 690 Distinct bool 691 692 Filename string // required. 693 Directory string // required. 694 Checksumkind enum.ChecksumKind // optional; zero value if not present. 695 Checksum string // optional; empty if not present. 696 Source string // optional; empty if not present. 697 } 698 699 // String returns the LLVM syntax representation of the specialized metadata 700 // node. 701 func (md *DIFile) String() string { 702 return md.Ident() 703 } 704 705 // Ident returns the identifier associated with the specialized metadata node. 706 func (md *DIFile) Ident() string { 707 if md == nil { 708 return "null" 709 } 710 if md.MetadataID != -1 { 711 return md.MetadataID.Ident() 712 } 713 return md.LLString() 714 } 715 716 // LLString returns the LLVM syntax representation of the specialized metadata 717 // node. 718 // 719 // '!DIFile' '(' Fields=(DIFileField separator ',')* ')' 720 func (md *DIFile) LLString() string { 721 buf := &strings.Builder{} 722 if md.Distinct { 723 buf.WriteString("distinct ") 724 } 725 var fields []string 726 field := fmt.Sprintf("filename: %s", quote(md.Filename)) 727 fields = append(fields, field) 728 field = fmt.Sprintf("directory: %s", quote(md.Directory)) 729 fields = append(fields, field) 730 if md.Checksumkind != 0 { 731 field := fmt.Sprintf("checksumkind: %s", md.Checksumkind) 732 fields = append(fields, field) 733 } 734 if len(md.Checksum) > 0 { 735 field := fmt.Sprintf("checksum: %s", quote(md.Checksum)) 736 fields = append(fields, field) 737 } 738 if len(md.Source) > 0 { 739 field := fmt.Sprintf("source: %s", quote(md.Source)) 740 fields = append(fields, field) 741 } 742 fmt.Fprintf(buf, "!DIFile(%s)", strings.Join(fields, ", ")) 743 return buf.String() 744 } 745 746 // SetDistinct specifies whether the metadata definition is dinstict. 747 func (md *DIFile) SetDistinct(distinct bool) { 748 md.Distinct = distinct 749 } 750 751 // ~~~ [ DIGlobalVariable ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 752 753 // DIGlobalVariable is a specialized metadata node. 754 type DIGlobalVariable struct { 755 // Metadata ID associated with the specialized metadata node; -1 if not 756 // present. 757 MetadataID 758 // (optional) Distinct. 759 Distinct bool 760 761 Name string // required. 762 Scope Field // optional; nil if not present. 763 LinkageName string // optional; empty if not present. 764 File *DIFile // optional; nil if not present. 765 Line int64 // optional; zero value if not present. 766 Type Field // optional; nil if not present. 767 IsLocal bool // optional; zero value if not present. 768 IsDefinition bool // optional; zero value if not present. 769 TemplateParams *Tuple // optional; nil if not present. 770 Declaration Field // optional; nil if not present. 771 Align uint64 // optional; zero value if not present. 772 Annotations Field // optional; nil if not present. 773 } 774 775 // String returns the LLVM syntax representation of the specialized metadata 776 // node. 777 func (md *DIGlobalVariable) String() string { 778 return md.Ident() 779 } 780 781 // Ident returns the identifier associated with the specialized metadata node. 782 func (md *DIGlobalVariable) Ident() string { 783 if md == nil { 784 return "null" 785 } 786 if md.MetadataID != -1 { 787 return md.MetadataID.Ident() 788 } 789 return md.LLString() 790 } 791 792 // LLString returns the LLVM syntax representation of the specialized metadata 793 // node. 794 // 795 // '!DIGlobalVariable' '(' Fields=(DIGlobalVariableField separator ',')* ')' 796 func (md *DIGlobalVariable) LLString() string { 797 buf := &strings.Builder{} 798 if md.Distinct { 799 buf.WriteString("distinct ") 800 } 801 var fields []string 802 field := fmt.Sprintf("name: %s", quote(md.Name)) 803 fields = append(fields, field) 804 if md.Scope != nil { 805 field := fmt.Sprintf("scope: %s", md.Scope) 806 fields = append(fields, field) 807 } 808 if len(md.LinkageName) > 0 { 809 field := fmt.Sprintf("linkageName: %s", quote(md.LinkageName)) 810 fields = append(fields, field) 811 } 812 if md.File != nil { 813 field := fmt.Sprintf("file: %s", md.File) 814 fields = append(fields, field) 815 } 816 if md.Line != 0 { 817 field := fmt.Sprintf("line: %d", md.Line) 818 fields = append(fields, field) 819 } 820 if md.Type != nil { 821 field := fmt.Sprintf("type: %s", md.Type) 822 fields = append(fields, field) 823 } 824 if md.IsLocal { 825 field = fmt.Sprintf("isLocal: %t", md.IsLocal) 826 fields = append(fields, field) 827 } 828 if md.IsDefinition { 829 field := fmt.Sprintf("isDefinition: %t", md.IsDefinition) 830 fields = append(fields, field) 831 } 832 if md.TemplateParams != nil { 833 field := fmt.Sprintf("templateParams: %s", md.TemplateParams) 834 fields = append(fields, field) 835 } 836 if md.Declaration != nil { 837 field := fmt.Sprintf("declaration: %s", md.Declaration) 838 fields = append(fields, field) 839 } 840 if md.Align != 0 { 841 field := fmt.Sprintf("align: %d", md.Align) 842 fields = append(fields, field) 843 } 844 if md.Annotations != nil { 845 field := fmt.Sprintf("annotations: %s", md.Annotations) 846 fields = append(fields, field) 847 } 848 fmt.Fprintf(buf, "!DIGlobalVariable(%s)", strings.Join(fields, ", ")) 849 return buf.String() 850 } 851 852 // SetDistinct specifies whether the metadata definition is dinstict. 853 func (md *DIGlobalVariable) SetDistinct(distinct bool) { 854 md.Distinct = distinct 855 } 856 857 // ~~~ [ DIGlobalVariableExpression ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 858 859 // DIGlobalVariableExpression is a specialized metadata node. 860 type DIGlobalVariableExpression struct { 861 // Metadata ID associated with the specialized metadata node; -1 if not 862 // present. 863 MetadataID 864 // (optional) Distinct. 865 Distinct bool 866 867 Var *DIGlobalVariable // required. 868 Expr *DIExpression // required. 869 } 870 871 // String returns the LLVM syntax representation of the specialized metadata 872 // node. 873 func (md *DIGlobalVariableExpression) String() string { 874 return md.Ident() 875 } 876 877 // Ident returns the identifier associated with the specialized metadata node. 878 func (md *DIGlobalVariableExpression) Ident() string { 879 if md == nil { 880 return "null" 881 } 882 if md.MetadataID != -1 { 883 return md.MetadataID.Ident() 884 } 885 return md.LLString() 886 } 887 888 // LLString returns the LLVM syntax representation of the specialized metadata 889 // node. 890 // 891 // '!DIGlobalVariableExpression' '(' Fields=(DIGlobalVariableExpressionField separator ',')* ')' 892 func (md *DIGlobalVariableExpression) LLString() string { 893 buf := &strings.Builder{} 894 if md.Distinct { 895 buf.WriteString("distinct ") 896 } 897 var fields []string 898 field := fmt.Sprintf("var: %s", md.Var) 899 fields = append(fields, field) 900 // NOTE: Should be required. Thus nil check should not be needed. However, 901 // Clang outputs `!0 = !DIGlobalVariableExpression(var: !1)` in cat.ll. 902 if md.Expr != nil { 903 field = fmt.Sprintf("expr: %s", md.Expr) 904 fields = append(fields, field) 905 } 906 fmt.Fprintf(buf, "!DIGlobalVariableExpression(%s)", strings.Join(fields, ", ")) 907 return buf.String() 908 } 909 910 // SetDistinct specifies whether the metadata definition is dinstict. 911 func (md *DIGlobalVariableExpression) SetDistinct(distinct bool) { 912 md.Distinct = distinct 913 } 914 915 // ~~~ [ DIImportedEntity ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 916 917 // DIImportedEntity is a specialized metadata node. 918 type DIImportedEntity struct { 919 // Metadata ID associated with the specialized metadata node; -1 if not 920 // present. 921 MetadataID 922 // (optional) Distinct. 923 Distinct bool 924 925 Tag enum.DwarfTag // required. 926 Scope Field // required. 927 Entity Field // optional; nil if not present. 928 File *DIFile // optional; nil if not present. 929 Line int64 // optional; zero value if not present. 930 Name string // optional; empty if not present. 931 Elements *Tuple // optional; nil if not present. 932 } 933 934 // String returns the LLVM syntax representation of the specialized metadata 935 // node. 936 func (md *DIImportedEntity) String() string { 937 return md.Ident() 938 } 939 940 // Ident returns the identifier associated with the specialized metadata node. 941 func (md *DIImportedEntity) Ident() string { 942 if md == nil { 943 return "null" 944 } 945 if md.MetadataID != -1 { 946 return md.MetadataID.Ident() 947 } 948 return md.LLString() 949 } 950 951 // LLString returns the LLVM syntax representation of the specialized metadata 952 // node. 953 // 954 // '!DIImportedEntity' '(' Fields=(DIImportedEntityField separator ',')* ')' 955 func (md *DIImportedEntity) LLString() string { 956 buf := &strings.Builder{} 957 if md.Distinct { 958 buf.WriteString("distinct ") 959 } 960 var fields []string 961 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 962 fields = append(fields, field) 963 field = fmt.Sprintf("scope: %s", md.Scope) 964 fields = append(fields, field) 965 if md.Entity != nil { 966 field := fmt.Sprintf("entity: %s", md.Entity) 967 fields = append(fields, field) 968 } 969 if md.File != nil { 970 field := fmt.Sprintf("file: %s", md.File) 971 fields = append(fields, field) 972 } 973 if md.Line != 0 { 974 field := fmt.Sprintf("line: %d", md.Line) 975 fields = append(fields, field) 976 } 977 if len(md.Name) > 0 { 978 field := fmt.Sprintf("name: %s", quote(md.Name)) 979 fields = append(fields, field) 980 } 981 if md.Elements != nil { 982 field := fmt.Sprintf("elements: %s", md.Elements) 983 fields = append(fields, field) 984 } 985 fmt.Fprintf(buf, "!DIImportedEntity(%s)", strings.Join(fields, ", ")) 986 return buf.String() 987 } 988 989 // SetDistinct specifies whether the metadata definition is dinstict. 990 func (md *DIImportedEntity) SetDistinct(distinct bool) { 991 md.Distinct = distinct 992 } 993 994 // ~~~ [ DILabel ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 995 996 // DILabel is a specialized metadata node. 997 type DILabel struct { 998 // Metadata ID associated with the specialized metadata node; -1 if not 999 // present. 1000 MetadataID 1001 // (optional) Distinct. 1002 Distinct bool 1003 1004 Scope Field // required. 1005 Name string // required. 1006 File *DIFile // required. 1007 Line int64 // required. 1008 } 1009 1010 // String returns the LLVM syntax representation of the specialized metadata 1011 // node. 1012 func (md *DILabel) String() string { 1013 return md.Ident() 1014 } 1015 1016 // Ident returns the identifier associated with the specialized metadata node. 1017 func (md *DILabel) Ident() string { 1018 if md == nil { 1019 return "null" 1020 } 1021 if md.MetadataID != -1 { 1022 return md.MetadataID.Ident() 1023 } 1024 return md.LLString() 1025 } 1026 1027 // LLString returns the LLVM syntax representation of the specialized metadata 1028 // node. 1029 // 1030 // '!DILabel' '(' Fields=(DILabelField separator ',')* ')' 1031 func (md *DILabel) LLString() string { 1032 buf := &strings.Builder{} 1033 if md.Distinct { 1034 buf.WriteString("distinct ") 1035 } 1036 var fields []string 1037 field := fmt.Sprintf("scope: %s", md.Scope) 1038 fields = append(fields, field) 1039 field = fmt.Sprintf("name: %s", quote(md.Name)) 1040 fields = append(fields, field) 1041 field = fmt.Sprintf("file: %s", md.File) 1042 fields = append(fields, field) 1043 field = fmt.Sprintf("line: %d", md.Line) 1044 fields = append(fields, field) 1045 fmt.Fprintf(buf, "!DILabel(%s)", strings.Join(fields, ", ")) 1046 return buf.String() 1047 } 1048 1049 // SetDistinct specifies whether the metadata definition is dinstict. 1050 func (md *DILabel) SetDistinct(distinct bool) { 1051 md.Distinct = distinct 1052 } 1053 1054 // ~~~ [ DILexicalBlock ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1055 1056 // DILexicalBlock is a specialized metadata node. 1057 type DILexicalBlock struct { 1058 // Metadata ID associated with the specialized metadata node; -1 if not 1059 // present. 1060 MetadataID 1061 // (optional) Distinct. 1062 Distinct bool 1063 1064 Scope Field // required. 1065 File *DIFile // optional; nil if not present. 1066 Line int64 // optional; zero value if not present. 1067 Column int64 // optional; zero value if not present. 1068 } 1069 1070 // String returns the LLVM syntax representation of the specialized metadata 1071 // node. 1072 func (md *DILexicalBlock) String() string { 1073 return md.Ident() 1074 } 1075 1076 // Ident returns the identifier associated with the specialized metadata node. 1077 func (md *DILexicalBlock) Ident() string { 1078 if md == nil { 1079 return "null" 1080 } 1081 if md.MetadataID != -1 { 1082 return md.MetadataID.Ident() 1083 } 1084 return md.LLString() 1085 } 1086 1087 // LLString returns the LLVM syntax representation of the specialized metadata 1088 // node. 1089 // 1090 // '!DILexicalBlock' '(' Fields=(DILexicalBlockField separator ',')* ')' 1091 func (md *DILexicalBlock) LLString() string { 1092 buf := &strings.Builder{} 1093 if md.Distinct { 1094 buf.WriteString("distinct ") 1095 } 1096 var fields []string 1097 field := fmt.Sprintf("scope: %s", md.Scope) 1098 fields = append(fields, field) 1099 if md.File != nil { 1100 field := fmt.Sprintf("file: %s", md.File) 1101 fields = append(fields, field) 1102 } 1103 if md.Line != 0 { 1104 field := fmt.Sprintf("line: %d", md.Line) 1105 fields = append(fields, field) 1106 } 1107 if md.Column != 0 { 1108 field := fmt.Sprintf("column: %d", md.Column) 1109 fields = append(fields, field) 1110 } 1111 fmt.Fprintf(buf, "!DILexicalBlock(%s)", strings.Join(fields, ", ")) 1112 return buf.String() 1113 } 1114 1115 // SetDistinct specifies whether the metadata definition is dinstict. 1116 func (md *DILexicalBlock) SetDistinct(distinct bool) { 1117 md.Distinct = distinct 1118 } 1119 1120 // ~~~ [ DILexicalBlockFile ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1121 1122 // DILexicalBlockFile is a specialized metadata node. 1123 type DILexicalBlockFile struct { 1124 // Metadata ID associated with the specialized metadata node; -1 if not 1125 // present. 1126 MetadataID 1127 // (optional) Distinct. 1128 Distinct bool 1129 1130 Scope Field // required. 1131 File *DIFile // optional; nil if not present. 1132 Discriminator uint64 // required. 1133 } 1134 1135 // String returns the LLVM syntax representation of the specialized metadata 1136 // node. 1137 func (md *DILexicalBlockFile) String() string { 1138 return md.Ident() 1139 } 1140 1141 // Ident returns the identifier associated with the specialized metadata node. 1142 func (md *DILexicalBlockFile) Ident() string { 1143 if md == nil { 1144 return "null" 1145 } 1146 if md.MetadataID != -1 { 1147 return md.MetadataID.Ident() 1148 } 1149 return md.LLString() 1150 } 1151 1152 // LLString returns the LLVM syntax representation of the specialized metadata 1153 // node. 1154 // 1155 // '!DILexicalBlockFile' '(' Fields=(DILexicalBlockFileField separator ',')* ')' 1156 func (md *DILexicalBlockFile) LLString() string { 1157 buf := &strings.Builder{} 1158 if md.Distinct { 1159 buf.WriteString("distinct ") 1160 } 1161 var fields []string 1162 field := fmt.Sprintf("scope: %s", md.Scope) 1163 fields = append(fields, field) 1164 if md.File != nil { 1165 field := fmt.Sprintf("file: %s", md.File) 1166 fields = append(fields, field) 1167 } 1168 field = fmt.Sprintf("discriminator: %d", md.Discriminator) 1169 fields = append(fields, field) 1170 fmt.Fprintf(buf, "!DILexicalBlockFile(%s)", strings.Join(fields, ", ")) 1171 return buf.String() 1172 } 1173 1174 // SetDistinct specifies whether the metadata definition is dinstict. 1175 func (md *DILexicalBlockFile) SetDistinct(distinct bool) { 1176 md.Distinct = distinct 1177 } 1178 1179 // ~~~ [ DILocalVariable ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1180 1181 // DILocalVariable is a specialized metadata node. 1182 type DILocalVariable struct { 1183 // Metadata ID associated with the specialized metadata node; -1 if not 1184 // present. 1185 MetadataID 1186 // (optional) Distinct. 1187 Distinct bool 1188 1189 Scope Field // required. 1190 Name string // optional; empty if not present. 1191 Arg uint64 // optional; zero value if not present. 1192 File *DIFile // optional; nil if not present. 1193 Line int64 // optional; zero value if not present. 1194 Type Field // optional; nil if not present. 1195 Flags enum.DIFlag // optional. 1196 Align uint64 // optional; zero value if not present. 1197 Annotations Field // optional; nil if not present. 1198 } 1199 1200 // String returns the LLVM syntax representation of the specialized metadata 1201 // node. 1202 func (md *DILocalVariable) String() string { 1203 return md.Ident() 1204 } 1205 1206 // Ident returns the identifier associated with the specialized metadata node. 1207 func (md *DILocalVariable) Ident() string { 1208 if md == nil { 1209 return "null" 1210 } 1211 if md.MetadataID != -1 { 1212 return md.MetadataID.Ident() 1213 } 1214 return md.LLString() 1215 } 1216 1217 // LLString returns the LLVM syntax representation of the specialized metadata 1218 // node. 1219 // 1220 // '!DILocalVariable' '(' Fields=(DILocalVariableField separator ',')* ')' 1221 func (md *DILocalVariable) LLString() string { 1222 buf := &strings.Builder{} 1223 if md.Distinct { 1224 buf.WriteString("distinct ") 1225 } 1226 var fields []string 1227 // Note, to match Clang output, the output order is changed to output name 1228 // before scope. 1229 if len(md.Name) > 0 { 1230 field := fmt.Sprintf("name: %s", quote(md.Name)) 1231 fields = append(fields, field) 1232 } 1233 if md.Arg != 0 { 1234 field := fmt.Sprintf("arg: %d", md.Arg) 1235 fields = append(fields, field) 1236 } 1237 field := fmt.Sprintf("scope: %s", md.Scope) 1238 fields = append(fields, field) 1239 if md.File != nil { 1240 field := fmt.Sprintf("file: %s", md.File) 1241 fields = append(fields, field) 1242 } 1243 if md.Line != 0 { 1244 field := fmt.Sprintf("line: %d", md.Line) 1245 fields = append(fields, field) 1246 } 1247 if md.Type != nil { 1248 field := fmt.Sprintf("type: %s", md.Type) 1249 fields = append(fields, field) 1250 } 1251 if md.Flags != 0 { 1252 field = fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 1253 fields = append(fields, field) 1254 } 1255 if md.Align != 0 { 1256 field := fmt.Sprintf("align: %d", md.Align) 1257 fields = append(fields, field) 1258 } 1259 if md.Annotations != nil { 1260 field := fmt.Sprintf("annotations: %s", md.Annotations) 1261 fields = append(fields, field) 1262 } 1263 fmt.Fprintf(buf, "!DILocalVariable(%s)", strings.Join(fields, ", ")) 1264 return buf.String() 1265 } 1266 1267 // SetDistinct specifies whether the metadata definition is dinstict. 1268 func (md *DILocalVariable) SetDistinct(distinct bool) { 1269 md.Distinct = distinct 1270 } 1271 1272 // ~~~ [ DILocation ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1273 1274 // DILocation is a specialized metadata node. 1275 type DILocation struct { 1276 // Metadata ID associated with the specialized metadata node; -1 if not 1277 // present. 1278 MetadataID 1279 // (optional) Distinct. 1280 Distinct bool 1281 1282 Line int64 // optional; zero value if not present. 1283 Column int64 // optional; zero value if not present. 1284 Scope Field // required. 1285 InlinedAt *DILocation // optional; nil if not present. 1286 IsImplicitCode bool // optional; zero value if not present. 1287 } 1288 1289 // String returns the LLVM syntax representation of the specialized metadata 1290 // node. 1291 func (md *DILocation) String() string { 1292 return md.Ident() 1293 } 1294 1295 // Ident returns the identifier associated with the specialized metadata node. 1296 func (md *DILocation) Ident() string { 1297 if md == nil { 1298 return "null" 1299 } 1300 if md.MetadataID != -1 { 1301 return md.MetadataID.Ident() 1302 } 1303 return md.LLString() 1304 } 1305 1306 // LLString returns the LLVM syntax representation of the specialized metadata 1307 // node. 1308 // 1309 // '!DILocation' '(' Fields=(DILocationField separator ',')* ')' 1310 func (md *DILocation) LLString() string { 1311 buf := &strings.Builder{} 1312 if md.Distinct { 1313 buf.WriteString("distinct ") 1314 } 1315 var fields []string 1316 if md.Line != 0 { 1317 field := fmt.Sprintf("line: %d", md.Line) 1318 fields = append(fields, field) 1319 } 1320 if md.Column != 0 { 1321 field := fmt.Sprintf("column: %d", md.Column) 1322 fields = append(fields, field) 1323 } 1324 field := fmt.Sprintf("scope: %s", md.Scope) 1325 fields = append(fields, field) 1326 if md.InlinedAt != nil { 1327 field := fmt.Sprintf("inlinedAt: %s", md.InlinedAt) 1328 fields = append(fields, field) 1329 } 1330 if md.IsImplicitCode { 1331 field := fmt.Sprintf("isImplicitCode: %t", md.IsImplicitCode) 1332 fields = append(fields, field) 1333 } 1334 fmt.Fprintf(buf, "!DILocation(%s)", strings.Join(fields, ", ")) 1335 return buf.String() 1336 } 1337 1338 // SetDistinct specifies whether the metadata definition is dinstict. 1339 func (md *DILocation) SetDistinct(distinct bool) { 1340 md.Distinct = distinct 1341 } 1342 1343 // ~~~ [ DIMacro ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1344 1345 // DIMacro is a specialized metadata node. 1346 type DIMacro struct { 1347 // Metadata ID associated with the specialized metadata node; -1 if not 1348 // present. 1349 MetadataID 1350 // (optional) Distinct. 1351 Distinct bool 1352 1353 Type enum.DwarfMacinfo // required. 1354 Line int64 // optional; zero value if not present. 1355 Name string // required. 1356 Value string // optional; empty if not present. 1357 } 1358 1359 // String returns the LLVM syntax representation of the specialized metadata 1360 // node. 1361 func (md *DIMacro) String() string { 1362 return md.Ident() 1363 } 1364 1365 // Ident returns the identifier associated with the specialized metadata node. 1366 func (md *DIMacro) Ident() string { 1367 if md == nil { 1368 return "null" 1369 } 1370 if md.MetadataID != -1 { 1371 return md.MetadataID.Ident() 1372 } 1373 return md.LLString() 1374 } 1375 1376 // LLString returns the LLVM syntax representation of the specialized metadata 1377 // node. 1378 // 1379 // '!DIMacro' '(' Fields=(DIMacroField separator ',')* ')' 1380 func (md *DIMacro) LLString() string { 1381 buf := &strings.Builder{} 1382 if md.Distinct { 1383 buf.WriteString("distinct ") 1384 } 1385 var fields []string 1386 field := fmt.Sprintf("type: %s", md.Type) 1387 fields = append(fields, field) 1388 if md.Line != 0 { 1389 field := fmt.Sprintf("line: %d", md.Line) 1390 fields = append(fields, field) 1391 } 1392 field = fmt.Sprintf("name: %s", quote(md.Name)) 1393 fields = append(fields, field) 1394 if len(md.Value) > 0 { 1395 field := fmt.Sprintf("value: %s", quote(md.Value)) 1396 fields = append(fields, field) 1397 } 1398 fmt.Fprintf(buf, "!DIMacro(%s)", strings.Join(fields, ", ")) 1399 return buf.String() 1400 } 1401 1402 // SetDistinct specifies whether the metadata definition is dinstict. 1403 func (md *DIMacro) SetDistinct(distinct bool) { 1404 md.Distinct = distinct 1405 } 1406 1407 // ~~~ [ DIMacroFile ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1408 1409 // DIMacroFile is a specialized metadata node. 1410 type DIMacroFile struct { 1411 // Metadata ID associated with the specialized metadata node; -1 if not 1412 // present. 1413 MetadataID 1414 // (optional) Distinct. 1415 Distinct bool 1416 1417 Type enum.DwarfMacinfo // optional; zero value if not present. 1418 Line int64 // optional; zero value if not present. 1419 File *DIFile // required. 1420 Nodes *Tuple // optional; nil if not present. 1421 } 1422 1423 // String returns the LLVM syntax representation of the specialized metadata 1424 // node. 1425 func (md *DIMacroFile) String() string { 1426 return md.Ident() 1427 } 1428 1429 // Ident returns the identifier associated with the specialized metadata node. 1430 func (md *DIMacroFile) Ident() string { 1431 if md == nil { 1432 return "null" 1433 } 1434 if md.MetadataID != -1 { 1435 return md.MetadataID.Ident() 1436 } 1437 return md.LLString() 1438 } 1439 1440 // LLString returns the LLVM syntax representation of the specialized metadata 1441 // node. 1442 // 1443 // '!DIMacroFile' '(' Fields=(DIMacroFileField separator ',')* ')' 1444 func (md *DIMacroFile) LLString() string { 1445 buf := &strings.Builder{} 1446 if md.Distinct { 1447 buf.WriteString("distinct ") 1448 } 1449 var fields []string 1450 if md.Type != 0 { 1451 field := fmt.Sprintf("type: %s", md.Type) 1452 fields = append(fields, field) 1453 } 1454 if md.Line != 0 { 1455 field := fmt.Sprintf("line: %d", md.Line) 1456 fields = append(fields, field) 1457 } 1458 field := fmt.Sprintf("file: %s", md.File) 1459 fields = append(fields, field) 1460 if md.Nodes != nil { 1461 field := fmt.Sprintf("nodes: %s", md.Nodes) 1462 fields = append(fields, field) 1463 } 1464 fmt.Fprintf(buf, "!DIMacroFile(%s)", strings.Join(fields, ", ")) 1465 return buf.String() 1466 } 1467 1468 // SetDistinct specifies whether the metadata definition is dinstict. 1469 func (md *DIMacroFile) SetDistinct(distinct bool) { 1470 md.Distinct = distinct 1471 } 1472 1473 // ~~~ [ DIModule ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1474 1475 // DIModule is a specialized metadata node. 1476 type DIModule struct { 1477 // Metadata ID associated with the specialized metadata node; -1 if not 1478 // present. 1479 MetadataID 1480 // (optional) Distinct. 1481 Distinct bool 1482 1483 Scope Field // required. 1484 Name string // required. 1485 ConfigMacros string // optional; empty if not present. 1486 IncludePath string // optional; empty if not present. 1487 APINotes string // optional; empty if not present. 1488 File Field // optional; empty if not present. 1489 Line int64 // optional; zero value if not present. 1490 IsDecl bool // optional; zero value if not present. 1491 } 1492 1493 // String returns the LLVM syntax representation of the specialized metadata 1494 // node. 1495 func (md *DIModule) String() string { 1496 return md.Ident() 1497 } 1498 1499 // Ident returns the identifier associated with the specialized metadata node. 1500 func (md *DIModule) Ident() string { 1501 if md == nil { 1502 return "null" 1503 } 1504 if md.MetadataID != -1 { 1505 return md.MetadataID.Ident() 1506 } 1507 return md.LLString() 1508 } 1509 1510 // LLString returns the LLVM syntax representation of the specialized metadata 1511 // node. 1512 // 1513 // '!DIModule' '(' Fields=(DIModuleField separator ',')* ')' 1514 func (md *DIModule) LLString() string { 1515 buf := &strings.Builder{} 1516 if md.Distinct { 1517 buf.WriteString("distinct ") 1518 } 1519 var fields []string 1520 field := fmt.Sprintf("scope: %s", md.Scope) 1521 fields = append(fields, field) 1522 field = fmt.Sprintf("name: %s", quote(md.Name)) 1523 fields = append(fields, field) 1524 if len(md.ConfigMacros) > 0 { 1525 field := fmt.Sprintf("configMacros: %s", quote(md.ConfigMacros)) 1526 fields = append(fields, field) 1527 } 1528 if len(md.IncludePath) > 0 { 1529 field := fmt.Sprintf("includePath: %s", quote(md.IncludePath)) 1530 fields = append(fields, field) 1531 } 1532 if len(md.APINotes) > 0 { 1533 field := fmt.Sprintf("apinotes: %s", quote(md.APINotes)) 1534 fields = append(fields, field) 1535 } 1536 if md.File != nil { 1537 field := fmt.Sprintf("file: %s", md.File) 1538 fields = append(fields, field) 1539 } 1540 if md.Line != 0 { 1541 field := fmt.Sprintf("line: %d", md.Line) 1542 fields = append(fields, field) 1543 } 1544 if md.IsDecl { 1545 field := fmt.Sprintf("isDecl: %v", md.IsDecl) 1546 fields = append(fields, field) 1547 } 1548 fmt.Fprintf(buf, "!DIModule(%s)", strings.Join(fields, ", ")) 1549 return buf.String() 1550 } 1551 1552 // SetDistinct specifies whether the metadata definition is dinstict. 1553 func (md *DIModule) SetDistinct(distinct bool) { 1554 md.Distinct = distinct 1555 } 1556 1557 // ~~~ [ DINamespace ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1558 1559 // DINamespace is a specialized metadata node. 1560 type DINamespace struct { 1561 // Metadata ID associated with the specialized metadata node; -1 if not 1562 // present. 1563 MetadataID 1564 // (optional) Distinct. 1565 Distinct bool 1566 1567 Scope Field // required. 1568 Name string // optional; empty if not present. 1569 ExportSymbols bool // optional; zero value if not present. 1570 } 1571 1572 // String returns the LLVM syntax representation of the specialized metadata 1573 // node. 1574 func (md *DINamespace) String() string { 1575 return md.Ident() 1576 } 1577 1578 // Ident returns the identifier associated with the specialized metadata node. 1579 func (md *DINamespace) Ident() string { 1580 if md == nil { 1581 return "null" 1582 } 1583 if md.MetadataID != -1 { 1584 return md.MetadataID.Ident() 1585 } 1586 return md.LLString() 1587 } 1588 1589 // LLString returns the LLVM syntax representation of the specialized metadata 1590 // node. 1591 // 1592 // '!DINamespace' '(' Fields=(DINamespaceField separator ',')* ')' 1593 func (md *DINamespace) LLString() string { 1594 buf := &strings.Builder{} 1595 if md.Distinct { 1596 buf.WriteString("distinct ") 1597 } 1598 var fields []string 1599 field := fmt.Sprintf("scope: %s", md.Scope) 1600 fields = append(fields, field) 1601 if len(md.Name) > 0 { 1602 field := fmt.Sprintf("name: %s", quote(md.Name)) 1603 fields = append(fields, field) 1604 } 1605 if md.ExportSymbols { 1606 field := fmt.Sprintf("exportSymbols: %t", md.ExportSymbols) 1607 fields = append(fields, field) 1608 } 1609 fmt.Fprintf(buf, "!DINamespace(%s)", strings.Join(fields, ", ")) 1610 return buf.String() 1611 } 1612 1613 // SetDistinct specifies whether the metadata definition is dinstict. 1614 func (md *DINamespace) SetDistinct(distinct bool) { 1615 md.Distinct = distinct 1616 } 1617 1618 // ~~~ [ DIObjCProperty ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1619 1620 // DIObjCProperty is a specialized metadata node. 1621 type DIObjCProperty struct { 1622 // Metadata ID associated with the specialized metadata node; -1 if not 1623 // present. 1624 MetadataID 1625 // (optional) Distinct. 1626 Distinct bool 1627 1628 Name string // optional; empty if not present. 1629 File *DIFile // optional; nil if not present. 1630 Line int64 // optional; zero value if not present. 1631 Setter string // optional; empty if not present. 1632 Getter string // optional; empty if not present. 1633 Attributes uint64 // optional; zero value if not present. 1634 Type Field // optional; nil if not present. 1635 } 1636 1637 // String returns the LLVM syntax representation of the specialized metadata 1638 // node. 1639 func (md *DIObjCProperty) String() string { 1640 return md.Ident() 1641 } 1642 1643 // Ident returns the identifier associated with the specialized metadata node. 1644 func (md *DIObjCProperty) Ident() string { 1645 if md == nil { 1646 return "null" 1647 } 1648 if md.MetadataID != -1 { 1649 return md.MetadataID.Ident() 1650 } 1651 return md.LLString() 1652 } 1653 1654 // LLString returns the LLVM syntax representation of the specialized metadata 1655 // node. 1656 // 1657 // '!DIObjCProperty' '(' Fields=(DIObjCPropertyField separator ',')* ')' 1658 func (md *DIObjCProperty) LLString() string { 1659 buf := &strings.Builder{} 1660 if md.Distinct { 1661 buf.WriteString("distinct ") 1662 } 1663 var fields []string 1664 if len(md.Name) > 0 { 1665 field := fmt.Sprintf("name: %s", quote(md.Name)) 1666 fields = append(fields, field) 1667 } 1668 if md.File != nil { 1669 field := fmt.Sprintf("file: %s", md.File) 1670 fields = append(fields, field) 1671 } 1672 if md.Line != 0 { 1673 field := fmt.Sprintf("line: %d", md.Line) 1674 fields = append(fields, field) 1675 } 1676 if len(md.Setter) > 0 { 1677 field := fmt.Sprintf("setter: %s", quote(md.Setter)) 1678 fields = append(fields, field) 1679 } 1680 if len(md.Getter) > 0 { 1681 field := fmt.Sprintf("getter: %s", quote(md.Getter)) 1682 fields = append(fields, field) 1683 } 1684 if md.Attributes != 0 { 1685 field := fmt.Sprintf("attributes: %d", md.Attributes) 1686 fields = append(fields, field) 1687 } 1688 if md.Type != nil { 1689 field := fmt.Sprintf("type: %s", md.Type) 1690 fields = append(fields, field) 1691 } 1692 fmt.Fprintf(buf, "!DIObjCProperty(%s)", strings.Join(fields, ", ")) 1693 return buf.String() 1694 } 1695 1696 // SetDistinct specifies whether the metadata definition is dinstict. 1697 func (md *DIObjCProperty) SetDistinct(distinct bool) { 1698 md.Distinct = distinct 1699 } 1700 1701 // ~~~ [ DIStringType ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1702 1703 // DIStringType is a specialized metadata node. 1704 type DIStringType struct { 1705 // Metadata ID associated with the specialized metadata node; -1 if not 1706 // present. 1707 MetadataID 1708 // (optional) Distinct. 1709 Distinct bool 1710 1711 Tag enum.DwarfTag // optional; zero value if not present. 1712 Name string // optional; empty if not present. 1713 StringLength Field // optional; nil if not present. 1714 StringLengthExpression Field // optional; nil if not present. 1715 StringLocationExpression Field // optional; nil if not present. 1716 Size uint64 // optional; zero value if not present. 1717 Align uint64 // optional; zero value if not present. 1718 Encoding enum.DwarfAttEncoding // optional; zero value if not present. 1719 } 1720 1721 // String returns the LLVM syntax representation of the specialized metadata 1722 // node. 1723 func (md *DIStringType) String() string { 1724 return md.Ident() 1725 } 1726 1727 // Ident returns the identifier associated with the specialized metadata node. 1728 func (md *DIStringType) Ident() string { 1729 if md == nil { 1730 return "null" 1731 } 1732 if md.MetadataID != -1 { 1733 return md.MetadataID.Ident() 1734 } 1735 return md.LLString() 1736 } 1737 1738 // LLString returns the LLVM syntax representation of the specialized metadata 1739 // node. 1740 // 1741 // '!DIStringType' '(' Fields=(DIStringTypeField separator ',')* ')' 1742 func (md *DIStringType) LLString() string { 1743 buf := &strings.Builder{} 1744 if md.Distinct { 1745 buf.WriteString("distinct ") 1746 } 1747 var fields []string 1748 if md.Tag != 0 { 1749 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 1750 fields = append(fields, field) 1751 } 1752 if len(md.Name) > 0 { 1753 field := fmt.Sprintf("name: %s", quote(md.Name)) 1754 fields = append(fields, field) 1755 } 1756 if md.StringLength != nil { 1757 field := fmt.Sprintf("stringLength: %s", md.StringLength) 1758 fields = append(fields, field) 1759 } 1760 if md.StringLengthExpression != nil { 1761 field := fmt.Sprintf("stringLengthExpression: %s", md.StringLengthExpression) 1762 fields = append(fields, field) 1763 } 1764 if md.StringLocationExpression != nil { 1765 field := fmt.Sprintf("stringLocationExpression: %s", md.StringLocationExpression) 1766 fields = append(fields, field) 1767 } 1768 if md.Size != 0 { 1769 field := fmt.Sprintf("size: %d", md.Size) 1770 fields = append(fields, field) 1771 } 1772 if md.Align != 0 { 1773 field := fmt.Sprintf("align: %d", md.Align) 1774 fields = append(fields, field) 1775 } 1776 if md.Encoding != 0 { 1777 field := fmt.Sprintf("encoding: %s", md.Encoding) 1778 fields = append(fields, field) 1779 } 1780 fmt.Fprintf(buf, "!DIStringType(%s)", strings.Join(fields, ", ")) 1781 return buf.String() 1782 } 1783 1784 // SetDistinct specifies whether the metadata definition is dinstict. 1785 func (md *DIStringType) SetDistinct(distinct bool) { 1786 md.Distinct = distinct 1787 } 1788 1789 // ~~~ [ DISubprogram ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1790 1791 // DISubprogram is a specialized metadata node. 1792 type DISubprogram struct { 1793 // Metadata ID associated with the specialized metadata node; -1 if not 1794 // present. 1795 MetadataID 1796 // (optional) Distinct. 1797 Distinct bool 1798 1799 Scope Field // optional; nil if not present. 1800 Name string // optional; empty if not present. 1801 LinkageName string // optional; empty if not present. 1802 File *DIFile // optional; nil if not present. 1803 Line int64 // optional; zero value if not present. 1804 Type Field // optional; nil if not present. 1805 IsLocal bool // optional; zero value if not present. 1806 IsDefinition bool // optional; zero value if not present. 1807 ScopeLine int64 // optional; zero value if not present. 1808 ContainingType Field // optional; nil if not present. 1809 Virtuality enum.DwarfVirtuality // optional; zero value if not present. 1810 VirtualIndex uint64 // optional; zero value if not present. 1811 ThisAdjustment int64 // optional; zero value if not present. 1812 Flags enum.DIFlag // optional. 1813 SPFlags enum.DISPFlag // optional. 1814 IsOptimized bool // optional; zero value if not present. 1815 Unit *DICompileUnit // optional; nil if not present. 1816 TemplateParams *Tuple // optional; nil if not present. 1817 Declaration Field // optional; nil if not present. 1818 RetainedNodes *Tuple // optional; nil if not present. 1819 ThrownTypes *Tuple // optional; nil if not present. 1820 Annotations Field // optional; nil if not present. 1821 } 1822 1823 // String returns the LLVM syntax representation of the specialized metadata 1824 // node. 1825 func (md *DISubprogram) String() string { 1826 return md.Ident() 1827 } 1828 1829 // Ident returns the identifier associated with the specialized metadata node. 1830 func (md *DISubprogram) Ident() string { 1831 if md == nil { 1832 return "null" 1833 } 1834 if md.MetadataID != -1 { 1835 return md.MetadataID.Ident() 1836 } 1837 return md.LLString() 1838 } 1839 1840 // LLString returns the LLVM syntax representation of the specialized metadata 1841 // node. 1842 // 1843 // '!DISubprogram' '(' Fields=(DISubprogramField separator ',')* ')' 1844 func (md *DISubprogram) LLString() string { 1845 buf := &strings.Builder{} 1846 if md.Distinct { 1847 buf.WriteString("distinct ") 1848 } 1849 var fields []string 1850 // Note, to match Clang output, the output order is changed to output name 1851 // before scope. 1852 if len(md.Name) > 0 { 1853 field := fmt.Sprintf("name: %s", quote(md.Name)) 1854 fields = append(fields, field) 1855 } 1856 // Note, to match Clang output, the output order is changed to output 1857 // linkageName before scope. 1858 if len(md.LinkageName) > 0 { 1859 field := fmt.Sprintf("linkageName: %s", quote(md.LinkageName)) 1860 fields = append(fields, field) 1861 } 1862 if md.Scope != nil { 1863 field := fmt.Sprintf("scope: %s", md.Scope) 1864 fields = append(fields, field) 1865 } 1866 if md.File != nil { 1867 field := fmt.Sprintf("file: %s", md.File) 1868 fields = append(fields, field) 1869 } 1870 if md.Line != 0 { 1871 field := fmt.Sprintf("line: %d", md.Line) 1872 fields = append(fields, field) 1873 } 1874 if md.Type != nil { 1875 field := fmt.Sprintf("type: %s", md.Type) 1876 fields = append(fields, field) 1877 } 1878 if md.IsLocal { 1879 field := fmt.Sprintf("isLocal: %t", md.IsLocal) 1880 fields = append(fields, field) 1881 } 1882 // Note: IsDefinition should be optional. However, Clang 9.0 produces 1883 // !DISubprogram specialized metadata nodes which looks as follows. 1884 // 1885 // !80 = !DISubprogram(name: "abs", scope: !81, file: !81, line: 840, type: !82, flags: DIFlagPrototyped, spFlags: 0) 1886 // 1887 // Since `spFlags` is optional and has the zero value, we should be able to 1888 // remove it. 1889 // 1890 // !80 = !DISubprogram(name: "abs", scope: !81, file: !81, line: 840, type: !82, flags: DIFlagPrototyped) 1891 // 1892 // However, doing so results in an error when run through `lli`, namely 1893 // `missing 'distinct', required for !DISubprogram that is a Definition`. 1894 // 1895 // Rather than including a "dummy" zero value for the spFlags enum, we 1896 // specify intent more clearly by stating whether the subprogram is a 1897 // definition or not. 1898 // 1899 // For this reason, we output isDefinition if it has a non-zero value or if 1900 // !DISubProgram is not distinct. 1901 if md.IsDefinition || !md.Distinct { 1902 field := fmt.Sprintf("isDefinition: %t", md.IsDefinition) 1903 fields = append(fields, field) 1904 } 1905 if md.ScopeLine != 0 { 1906 field := fmt.Sprintf("scopeLine: %d", md.ScopeLine) 1907 fields = append(fields, field) 1908 } 1909 if md.ContainingType != nil { 1910 field := fmt.Sprintf("containingType: %s", md.ContainingType) 1911 fields = append(fields, field) 1912 } 1913 if md.Virtuality != 0 { 1914 field := fmt.Sprintf("virtuality: %s", md.Virtuality) 1915 fields = append(fields, field) 1916 } 1917 if md.VirtualIndex != 0 { 1918 field := fmt.Sprintf("virtualIndex: %d", md.VirtualIndex) 1919 fields = append(fields, field) 1920 } 1921 if md.ThisAdjustment != 0 { 1922 field := fmt.Sprintf("thisAdjustment: %d", md.ThisAdjustment) 1923 fields = append(fields, field) 1924 } 1925 if md.Flags != 0 { 1926 field := fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 1927 fields = append(fields, field) 1928 } 1929 if md.SPFlags != 0 { 1930 field := fmt.Sprintf("spFlags: %s", dispFlagsString(md.SPFlags)) 1931 fields = append(fields, field) 1932 } 1933 if md.IsOptimized { 1934 field := fmt.Sprintf("isOptimized: %t", md.IsOptimized) 1935 fields = append(fields, field) 1936 } 1937 if md.Unit != nil { 1938 field := fmt.Sprintf("unit: %s", md.Unit) 1939 fields = append(fields, field) 1940 } 1941 if md.TemplateParams != nil { 1942 field := fmt.Sprintf("templateParams: %s", md.TemplateParams) 1943 fields = append(fields, field) 1944 } 1945 if md.Declaration != nil { 1946 field := fmt.Sprintf("declaration: %s", md.Declaration) 1947 fields = append(fields, field) 1948 } 1949 if md.RetainedNodes != nil { 1950 field := fmt.Sprintf("retainedNodes: %s", md.RetainedNodes) 1951 fields = append(fields, field) 1952 } 1953 if md.ThrownTypes != nil { 1954 field := fmt.Sprintf("thrownTypes: %s", md.ThrownTypes) 1955 fields = append(fields, field) 1956 } 1957 if md.Annotations != nil { 1958 field := fmt.Sprintf("annotations: %s", md.Annotations) 1959 fields = append(fields, field) 1960 } 1961 fmt.Fprintf(buf, "!DISubprogram(%s)", strings.Join(fields, ", ")) 1962 return buf.String() 1963 } 1964 1965 // SetDistinct specifies whether the metadata definition is dinstict. 1966 func (md *DISubprogram) SetDistinct(distinct bool) { 1967 md.Distinct = distinct 1968 } 1969 1970 // ~~~ [ DISubrange ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1971 1972 // DISubrange is a specialized metadata node. 1973 type DISubrange struct { 1974 // Metadata ID associated with the specialized metadata node; -1 if not 1975 // present. 1976 MetadataID 1977 // (optional) Distinct. 1978 Distinct bool 1979 1980 Count FieldOrInt // optional 1981 LowerBound FieldOrInt // optional 1982 UpperBound FieldOrInt // optional 1983 Stride FieldOrInt // optional 1984 } 1985 1986 // String returns the LLVM syntax representation of the specialized metadata 1987 // node. 1988 func (md *DISubrange) String() string { 1989 return md.Ident() 1990 } 1991 1992 // Ident returns the identifier associated with the specialized metadata node. 1993 func (md *DISubrange) Ident() string { 1994 if md == nil { 1995 return "null" 1996 } 1997 if md.MetadataID != -1 { 1998 return md.MetadataID.Ident() 1999 } 2000 return md.LLString() 2001 } 2002 2003 // LLString returns the LLVM syntax representation of the specialized metadata 2004 // node. 2005 // 2006 // '!DISubrange' '(' Fields=(DISubrangeField separator ',')* ')' 2007 func (md *DISubrange) LLString() string { 2008 buf := &strings.Builder{} 2009 if md.Distinct { 2010 buf.WriteString("distinct ") 2011 } 2012 var fields []string 2013 if md.Count != nil { 2014 field := fmt.Sprintf("count: %s", md.Count) 2015 fields = append(fields, field) 2016 } 2017 if md.LowerBound != nil { 2018 field := fmt.Sprintf("lowerBound: %s", md.LowerBound) 2019 fields = append(fields, field) 2020 } 2021 if md.UpperBound != nil { 2022 field := fmt.Sprintf("upperBound: %s", md.UpperBound) 2023 fields = append(fields, field) 2024 } 2025 if md.Stride != nil { 2026 field := fmt.Sprintf("stride: %s", md.Stride) 2027 fields = append(fields, field) 2028 } 2029 fmt.Fprintf(buf, "!DISubrange(%s)", strings.Join(fields, ", ")) 2030 return buf.String() 2031 } 2032 2033 // SetDistinct specifies whether the metadata definition is dinstict. 2034 func (md *DISubrange) SetDistinct(distinct bool) { 2035 md.Distinct = distinct 2036 } 2037 2038 // ~~~ [ DISubroutineType ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2039 2040 // DISubroutineType is a specialized metadata node. 2041 type DISubroutineType struct { 2042 // Metadata ID associated with the specialized metadata node; -1 if not 2043 // present. 2044 MetadataID 2045 // (optional) Distinct. 2046 Distinct bool 2047 2048 Flags enum.DIFlag // optional. 2049 CC enum.DwarfCC // optional; zero value if not present. 2050 Types *Tuple // required. 2051 } 2052 2053 // String returns the LLVM syntax representation of the specialized metadata 2054 // node. 2055 func (md *DISubroutineType) String() string { 2056 return md.Ident() 2057 } 2058 2059 // Ident returns the identifier associated with the specialized metadata node. 2060 func (md *DISubroutineType) Ident() string { 2061 if md == nil { 2062 return "null" 2063 } 2064 if md.MetadataID != -1 { 2065 return md.MetadataID.Ident() 2066 } 2067 return md.LLString() 2068 } 2069 2070 // LLString returns the LLVM syntax representation of the specialized metadata 2071 // node. 2072 // 2073 // '!DISubroutineType' '(' Fields=(DISubroutineTypeField separator ',')* ')' 2074 func (md *DISubroutineType) LLString() string { 2075 buf := &strings.Builder{} 2076 if md.Distinct { 2077 buf.WriteString("distinct ") 2078 } 2079 var fields []string 2080 if md.Flags != 0 { 2081 field := fmt.Sprintf("flags: %s", diFlagsString(md.Flags)) 2082 fields = append(fields, field) 2083 } 2084 if md.CC != 0 { 2085 field := fmt.Sprintf("cc: %s", md.CC) 2086 fields = append(fields, field) 2087 } 2088 field := fmt.Sprintf("types: %s", md.Types) 2089 fields = append(fields, field) 2090 fmt.Fprintf(buf, "!DISubroutineType(%s)", strings.Join(fields, ", ")) 2091 return buf.String() 2092 } 2093 2094 // SetDistinct specifies whether the metadata definition is dinstict. 2095 func (md *DISubroutineType) SetDistinct(distinct bool) { 2096 md.Distinct = distinct 2097 } 2098 2099 // ~~~ [ DITemplateTypeParameter ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2100 2101 // DITemplateTypeParameter is a specialized metadata node. 2102 type DITemplateTypeParameter struct { 2103 // Metadata ID associated with the specialized metadata node; -1 if not 2104 // present. 2105 MetadataID 2106 // (optional) Distinct. 2107 Distinct bool 2108 2109 Name string // optional; empty if not present. 2110 Type Field // required. 2111 Defaulted bool // optional; zero value if not present. 2112 } 2113 2114 // String returns the LLVM syntax representation of the specialized metadata 2115 // node. 2116 func (md *DITemplateTypeParameter) String() string { 2117 return md.Ident() 2118 } 2119 2120 // Ident returns the identifier associated with the specialized metadata node. 2121 func (md *DITemplateTypeParameter) Ident() string { 2122 if md == nil { 2123 return "null" 2124 } 2125 if md.MetadataID != -1 { 2126 return md.MetadataID.Ident() 2127 } 2128 return md.LLString() 2129 } 2130 2131 // LLString returns the LLVM syntax representation of the specialized metadata 2132 // node. 2133 // 2134 // '!DITemplateTypeParameter' '(' Fields=(DITemplateTypeParameterField separator ',')* ')' 2135 func (md *DITemplateTypeParameter) LLString() string { 2136 buf := &strings.Builder{} 2137 if md.Distinct { 2138 buf.WriteString("distinct ") 2139 } 2140 var fields []string 2141 if len(md.Name) > 0 { 2142 field := fmt.Sprintf("name: %s", quote(md.Name)) 2143 fields = append(fields, field) 2144 } 2145 field := fmt.Sprintf("type: %s", md.Type) 2146 if md.Defaulted { 2147 field := fmt.Sprintf("defaulted: %v", md.Defaulted) 2148 fields = append(fields, field) 2149 } 2150 fields = append(fields, field) 2151 fmt.Fprintf(buf, "!DITemplateTypeParameter(%s)", strings.Join(fields, ", ")) 2152 return buf.String() 2153 } 2154 2155 // SetDistinct specifies whether the metadata definition is dinstict. 2156 func (md *DITemplateTypeParameter) SetDistinct(distinct bool) { 2157 md.Distinct = distinct 2158 } 2159 2160 // ~~~ [ DITemplateValueParameter ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2161 2162 // DITemplateValueParameter is a specialized metadata node. 2163 type DITemplateValueParameter struct { 2164 // Metadata ID associated with the specialized metadata node; -1 if not 2165 // present. 2166 MetadataID 2167 // (optional) Distinct. 2168 Distinct bool 2169 2170 Tag enum.DwarfTag // optional; zero value if not present. 2171 Name string // optional; empty if not present. 2172 Type Field // optional; nil if not present. 2173 Value Field // required. 2174 Defaulted bool // optional; zero value if not present. 2175 } 2176 2177 // String returns the LLVM syntax representation of the specialized metadata 2178 // node. 2179 func (md *DITemplateValueParameter) String() string { 2180 return md.Ident() 2181 } 2182 2183 // Ident returns the identifier associated with the specialized metadata node. 2184 func (md *DITemplateValueParameter) Ident() string { 2185 if md == nil { 2186 return "null" 2187 } 2188 if md.MetadataID != -1 { 2189 return md.MetadataID.Ident() 2190 } 2191 return md.LLString() 2192 } 2193 2194 // LLString returns the LLVM syntax representation of the specialized metadata 2195 // node. 2196 // 2197 // '!DITemplateValueParameter' '(' Fields=(DITemplateValueParameterField separator ',')* ')' 2198 func (md *DITemplateValueParameter) LLString() string { 2199 buf := &strings.Builder{} 2200 if md.Distinct { 2201 buf.WriteString("distinct ") 2202 } 2203 var fields []string 2204 if md.Tag != 0 { 2205 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 2206 fields = append(fields, field) 2207 } 2208 if len(md.Name) > 0 { 2209 field := fmt.Sprintf("name: %s", quote(md.Name)) 2210 fields = append(fields, field) 2211 } 2212 if md.Type != nil { 2213 field := fmt.Sprintf("type: %s", md.Type) 2214 fields = append(fields, field) 2215 } 2216 field := fmt.Sprintf("value: %s", md.Value) 2217 if md.Defaulted { 2218 field := fmt.Sprintf("defaulted: %v", md.Defaulted) 2219 fields = append(fields, field) 2220 } 2221 fields = append(fields, field) 2222 fmt.Fprintf(buf, "!DITemplateValueParameter(%s)", strings.Join(fields, ", ")) 2223 return buf.String() 2224 } 2225 2226 // SetDistinct specifies whether the metadata definition is dinstict. 2227 func (md *DITemplateValueParameter) SetDistinct(distinct bool) { 2228 md.Distinct = distinct 2229 } 2230 2231 // ~~~ [ GenericDINode ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2232 2233 // GenericDINode is a specialized GenericDINode metadata node. 2234 type GenericDINode struct { 2235 // Metadata ID associated with the specialized metadata node; -1 if not 2236 // present. 2237 MetadataID 2238 // (optional) Distinct. 2239 Distinct bool 2240 2241 Tag enum.DwarfTag // required 2242 Header string // optional; empty if not present 2243 Operands []Field // optional 2244 } 2245 2246 // String returns the LLVM syntax representation of the specialized metadata 2247 // node. 2248 func (md *GenericDINode) String() string { 2249 return md.Ident() 2250 } 2251 2252 // Ident returns the identifier associated with the specialized metadata node. 2253 func (md *GenericDINode) Ident() string { 2254 if md == nil { 2255 return "null" 2256 } 2257 if md.MetadataID != -1 { 2258 return md.MetadataID.Ident() 2259 } 2260 return md.LLString() 2261 } 2262 2263 // LLString returns the LLVM syntax representation of the specialized metadata 2264 // node. 2265 // 2266 // '!GenericDINode' '(' Fields=(GenericDINodeField separator ',')* ')' 2267 func (md *GenericDINode) LLString() string { 2268 buf := &strings.Builder{} 2269 if md.Distinct { 2270 buf.WriteString("distinct ") 2271 } 2272 var fields []string 2273 field := fmt.Sprintf("tag: %s", dwarfTagString(md.Tag)) 2274 fields = append(fields, field) 2275 if len(md.Header) > 0 { 2276 field := fmt.Sprintf("header: %s", quote(md.Header)) 2277 fields = append(fields, field) 2278 } 2279 if len(md.Operands) > 0 { 2280 // TODO: figure out what operands output should look like. 2281 buf := &strings.Builder{} 2282 buf.WriteString("{") 2283 for i, o := range md.Operands { 2284 if i != 0 { 2285 buf.WriteString(", ") 2286 } 2287 buf.WriteString(o.String()) 2288 } 2289 buf.WriteString("}") 2290 field = fmt.Sprintf("operands: %s", buf) 2291 fields = append(fields, field) 2292 } 2293 fmt.Fprintf(buf, "!GenericDINode(%s)", strings.Join(fields, ", ")) 2294 return buf.String() 2295 } 2296 2297 // SetDistinct specifies whether the metadata definition is dinstict. 2298 func (md *GenericDINode) SetDistinct(distinct bool) { 2299 md.Distinct = distinct 2300 }