[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / BinaryFormat / Dwarf.cpp
blobcb92f80318ec39fbfca704cb0827f76e5d02564e
1 //===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- C++-*-===//
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 contains support for generic dwarf information.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/BinaryFormat/Dwarf.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/ErrorHandling.h"
18 using namespace llvm;
19 using namespace dwarf;
21 StringRef llvm::dwarf::TagString(unsigned Tag) {
22 switch (Tag) {
23 default:
24 return StringRef();
25 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
26 case DW_TAG_##NAME: \
27 return "DW_TAG_" #NAME;
28 #include "llvm/BinaryFormat/Dwarf.def"
32 unsigned llvm::dwarf::getTag(StringRef TagString) {
33 return StringSwitch<unsigned>(TagString)
34 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
35 .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
36 #include "llvm/BinaryFormat/Dwarf.def"
37 .Default(DW_TAG_invalid);
40 unsigned llvm::dwarf::TagVersion(dwarf::Tag Tag) {
41 switch (Tag) {
42 default:
43 return 0;
44 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
45 case DW_TAG_##NAME: \
46 return VERSION;
47 #include "llvm/BinaryFormat/Dwarf.def"
51 unsigned llvm::dwarf::TagVendor(dwarf::Tag Tag) {
52 switch (Tag) {
53 default:
54 return 0;
55 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
56 case DW_TAG_##NAME: \
57 return DWARF_VENDOR_##VENDOR;
58 #include "llvm/BinaryFormat/Dwarf.def"
62 StringRef llvm::dwarf::ChildrenString(unsigned Children) {
63 switch (Children) {
64 case DW_CHILDREN_no:
65 return "DW_CHILDREN_no";
66 case DW_CHILDREN_yes:
67 return "DW_CHILDREN_yes";
69 return StringRef();
72 StringRef llvm::dwarf::AttributeString(unsigned Attribute) {
73 switch (Attribute) {
74 default:
75 return StringRef();
76 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
77 case DW_AT_##NAME: \
78 return "DW_AT_" #NAME;
79 #include "llvm/BinaryFormat/Dwarf.def"
83 unsigned llvm::dwarf::AttributeVersion(dwarf::Attribute Attribute) {
84 switch (Attribute) {
85 default:
86 return 0;
87 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
88 case DW_AT_##NAME: \
89 return VERSION;
90 #include "llvm/BinaryFormat/Dwarf.def"
94 unsigned llvm::dwarf::AttributeVendor(dwarf::Attribute Attribute) {
95 switch (Attribute) {
96 default:
97 return 0;
98 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
99 case DW_AT_##NAME: \
100 return DWARF_VENDOR_##VENDOR;
101 #include "llvm/BinaryFormat/Dwarf.def"
105 StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) {
106 switch (Encoding) {
107 default:
108 return StringRef();
109 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
110 case DW_FORM_##NAME: \
111 return "DW_FORM_" #NAME;
112 #include "llvm/BinaryFormat/Dwarf.def"
116 unsigned llvm::dwarf::FormVersion(dwarf::Form Form) {
117 switch (Form) {
118 default:
119 return 0;
120 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
121 case DW_FORM_##NAME: \
122 return VERSION;
123 #include "llvm/BinaryFormat/Dwarf.def"
127 unsigned llvm::dwarf::FormVendor(dwarf::Form Form) {
128 switch (Form) {
129 default:
130 return 0;
131 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
132 case DW_FORM_##NAME: \
133 return DWARF_VENDOR_##VENDOR;
134 #include "llvm/BinaryFormat/Dwarf.def"
138 StringRef llvm::dwarf::OperationEncodingString(unsigned Encoding) {
139 switch (Encoding) {
140 default:
141 return StringRef();
142 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
143 case DW_OP_##NAME: \
144 return "DW_OP_" #NAME;
145 #include "llvm/BinaryFormat/Dwarf.def"
146 case DW_OP_LLVM_convert:
147 return "DW_OP_LLVM_convert";
148 case DW_OP_LLVM_fragment:
149 return "DW_OP_LLVM_fragment";
150 case DW_OP_LLVM_tag_offset:
151 return "DW_OP_LLVM_tag_offset";
155 unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) {
156 return StringSwitch<unsigned>(OperationEncodingString)
157 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
158 .Case("DW_OP_" #NAME, DW_OP_##NAME)
159 #include "llvm/BinaryFormat/Dwarf.def"
160 .Case("DW_OP_LLVM_convert", DW_OP_LLVM_convert)
161 .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment)
162 .Case("DW_OP_LLVM_tag_offset", DW_OP_LLVM_tag_offset)
163 .Default(0);
166 unsigned llvm::dwarf::OperationVersion(dwarf::LocationAtom Op) {
167 switch (Op) {
168 default:
169 return 0;
170 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
171 case DW_OP_##NAME: \
172 return VERSION;
173 #include "llvm/BinaryFormat/Dwarf.def"
177 unsigned llvm::dwarf::OperationVendor(dwarf::LocationAtom Op) {
178 switch (Op) {
179 default:
180 return 0;
181 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
182 case DW_OP_##NAME: \
183 return DWARF_VENDOR_##VENDOR;
184 #include "llvm/BinaryFormat/Dwarf.def"
188 StringRef llvm::dwarf::AttributeEncodingString(unsigned Encoding) {
189 switch (Encoding) {
190 default:
191 return StringRef();
192 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
193 case DW_ATE_##NAME: \
194 return "DW_ATE_" #NAME;
195 #include "llvm/BinaryFormat/Dwarf.def"
199 unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) {
200 return StringSwitch<unsigned>(EncodingString)
201 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
202 .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
203 #include "llvm/BinaryFormat/Dwarf.def"
204 .Default(0);
207 unsigned llvm::dwarf::AttributeEncodingVersion(dwarf::TypeKind ATE) {
208 switch (ATE) {
209 default:
210 return 0;
211 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
212 case DW_ATE_##NAME: \
213 return VERSION;
214 #include "llvm/BinaryFormat/Dwarf.def"
218 unsigned llvm::dwarf::AttributeEncodingVendor(dwarf::TypeKind ATE) {
219 switch (ATE) {
220 default:
221 return 0;
222 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
223 case DW_ATE_##NAME: \
224 return DWARF_VENDOR_##VENDOR;
225 #include "llvm/BinaryFormat/Dwarf.def"
229 StringRef llvm::dwarf::DecimalSignString(unsigned Sign) {
230 switch (Sign) {
231 case DW_DS_unsigned:
232 return "DW_DS_unsigned";
233 case DW_DS_leading_overpunch:
234 return "DW_DS_leading_overpunch";
235 case DW_DS_trailing_overpunch:
236 return "DW_DS_trailing_overpunch";
237 case DW_DS_leading_separate:
238 return "DW_DS_leading_separate";
239 case DW_DS_trailing_separate:
240 return "DW_DS_trailing_separate";
242 return StringRef();
245 StringRef llvm::dwarf::EndianityString(unsigned Endian) {
246 switch (Endian) {
247 case DW_END_default:
248 return "DW_END_default";
249 case DW_END_big:
250 return "DW_END_big";
251 case DW_END_little:
252 return "DW_END_little";
253 case DW_END_lo_user:
254 return "DW_END_lo_user";
255 case DW_END_hi_user:
256 return "DW_END_hi_user";
258 return StringRef();
261 StringRef llvm::dwarf::AccessibilityString(unsigned Access) {
262 switch (Access) {
263 // Accessibility codes
264 case DW_ACCESS_public:
265 return "DW_ACCESS_public";
266 case DW_ACCESS_protected:
267 return "DW_ACCESS_protected";
268 case DW_ACCESS_private:
269 return "DW_ACCESS_private";
271 return StringRef();
274 StringRef llvm::dwarf::VisibilityString(unsigned Visibility) {
275 switch (Visibility) {
276 case DW_VIS_local:
277 return "DW_VIS_local";
278 case DW_VIS_exported:
279 return "DW_VIS_exported";
280 case DW_VIS_qualified:
281 return "DW_VIS_qualified";
283 return StringRef();
286 StringRef llvm::dwarf::VirtualityString(unsigned Virtuality) {
287 switch (Virtuality) {
288 default:
289 return StringRef();
290 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
291 case DW_VIRTUALITY_##NAME: \
292 return "DW_VIRTUALITY_" #NAME;
293 #include "llvm/BinaryFormat/Dwarf.def"
297 unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) {
298 return StringSwitch<unsigned>(VirtualityString)
299 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
300 .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
301 #include "llvm/BinaryFormat/Dwarf.def"
302 .Default(DW_VIRTUALITY_invalid);
305 StringRef llvm::dwarf::LanguageString(unsigned Language) {
306 switch (Language) {
307 default:
308 return StringRef();
309 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
310 case DW_LANG_##NAME: \
311 return "DW_LANG_" #NAME;
312 #include "llvm/BinaryFormat/Dwarf.def"
316 unsigned llvm::dwarf::getLanguage(StringRef LanguageString) {
317 return StringSwitch<unsigned>(LanguageString)
318 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
319 .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
320 #include "llvm/BinaryFormat/Dwarf.def"
321 .Default(0);
324 unsigned llvm::dwarf::LanguageVersion(dwarf::SourceLanguage Lang) {
325 switch (Lang) {
326 default:
327 return 0;
328 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
329 case DW_LANG_##NAME: \
330 return VERSION;
331 #include "llvm/BinaryFormat/Dwarf.def"
335 unsigned llvm::dwarf::LanguageVendor(dwarf::SourceLanguage Lang) {
336 switch (Lang) {
337 default:
338 return 0;
339 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
340 case DW_LANG_##NAME: \
341 return DWARF_VENDOR_##VENDOR;
342 #include "llvm/BinaryFormat/Dwarf.def"
346 Optional<unsigned> llvm::dwarf::LanguageLowerBound(dwarf::SourceLanguage Lang) {
347 switch (Lang) {
348 default:
349 return None;
350 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
351 case DW_LANG_##NAME: \
352 return LOWER_BOUND;
353 #include "llvm/BinaryFormat/Dwarf.def"
357 StringRef llvm::dwarf::CaseString(unsigned Case) {
358 switch (Case) {
359 case DW_ID_case_sensitive:
360 return "DW_ID_case_sensitive";
361 case DW_ID_up_case:
362 return "DW_ID_up_case";
363 case DW_ID_down_case:
364 return "DW_ID_down_case";
365 case DW_ID_case_insensitive:
366 return "DW_ID_case_insensitive";
368 return StringRef();
371 StringRef llvm::dwarf::ConventionString(unsigned CC) {
372 switch (CC) {
373 default:
374 return StringRef();
375 #define HANDLE_DW_CC(ID, NAME) \
376 case DW_CC_##NAME: \
377 return "DW_CC_" #NAME;
378 #include "llvm/BinaryFormat/Dwarf.def"
382 unsigned llvm::dwarf::getCallingConvention(StringRef CCString) {
383 return StringSwitch<unsigned>(CCString)
384 #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
385 #include "llvm/BinaryFormat/Dwarf.def"
386 .Default(0);
389 StringRef llvm::dwarf::InlineCodeString(unsigned Code) {
390 switch (Code) {
391 case DW_INL_not_inlined:
392 return "DW_INL_not_inlined";
393 case DW_INL_inlined:
394 return "DW_INL_inlined";
395 case DW_INL_declared_not_inlined:
396 return "DW_INL_declared_not_inlined";
397 case DW_INL_declared_inlined:
398 return "DW_INL_declared_inlined";
400 return StringRef();
403 StringRef llvm::dwarf::ArrayOrderString(unsigned Order) {
404 switch (Order) {
405 case DW_ORD_row_major:
406 return "DW_ORD_row_major";
407 case DW_ORD_col_major:
408 return "DW_ORD_col_major";
410 return StringRef();
413 StringRef llvm::dwarf::LNStandardString(unsigned Standard) {
414 switch (Standard) {
415 default:
416 return StringRef();
417 #define HANDLE_DW_LNS(ID, NAME) \
418 case DW_LNS_##NAME: \
419 return "DW_LNS_" #NAME;
420 #include "llvm/BinaryFormat/Dwarf.def"
424 StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) {
425 switch (Encoding) {
426 default:
427 return StringRef();
428 #define HANDLE_DW_LNE(ID, NAME) \
429 case DW_LNE_##NAME: \
430 return "DW_LNE_" #NAME;
431 #include "llvm/BinaryFormat/Dwarf.def"
435 StringRef llvm::dwarf::MacinfoString(unsigned Encoding) {
436 switch (Encoding) {
437 // Macinfo Type Encodings
438 case DW_MACINFO_define:
439 return "DW_MACINFO_define";
440 case DW_MACINFO_undef:
441 return "DW_MACINFO_undef";
442 case DW_MACINFO_start_file:
443 return "DW_MACINFO_start_file";
444 case DW_MACINFO_end_file:
445 return "DW_MACINFO_end_file";
446 case DW_MACINFO_vendor_ext:
447 return "DW_MACINFO_vendor_ext";
448 case DW_MACINFO_invalid:
449 return "DW_MACINFO_invalid";
451 return StringRef();
454 unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) {
455 return StringSwitch<unsigned>(MacinfoString)
456 .Case("DW_MACINFO_define", DW_MACINFO_define)
457 .Case("DW_MACINFO_undef", DW_MACINFO_undef)
458 .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
459 .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
460 .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
461 .Default(DW_MACINFO_invalid);
464 StringRef llvm::dwarf::RangeListEncodingString(unsigned Encoding) {
465 switch (Encoding) {
466 default:
467 return StringRef();
468 #define HANDLE_DW_RLE(ID, NAME) \
469 case DW_RLE_##NAME: \
470 return "DW_RLE_" #NAME;
471 #include "llvm/BinaryFormat/Dwarf.def"
475 StringRef llvm::dwarf::LocListEncodingString(unsigned Encoding) {
476 switch (Encoding) {
477 default:
478 return StringRef();
479 #define HANDLE_DW_LLE(ID, NAME) \
480 case DW_LLE_##NAME: \
481 return "DW_LLE_" #NAME;
482 #include "llvm/BinaryFormat/Dwarf.def"
486 StringRef llvm::dwarf::CallFrameString(unsigned Encoding,
487 Triple::ArchType Arch) {
488 assert(Arch != llvm::Triple::ArchType::UnknownArch);
489 #define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64)
490 #define SELECT_MIPS64 Arch == llvm::Triple::mips64
491 #define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9)
492 #define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
493 #define HANDLE_DW_CFA(ID, NAME)
494 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \
495 if (ID == Encoding && PRED) \
496 return "DW_CFA_" #NAME;
497 #include "llvm/BinaryFormat/Dwarf.def"
499 switch (Encoding) {
500 default:
501 return StringRef();
502 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
503 #define HANDLE_DW_CFA(ID, NAME) \
504 case DW_CFA_##NAME: \
505 return "DW_CFA_" #NAME;
506 #include "llvm/BinaryFormat/Dwarf.def"
508 #undef SELECT_X86
509 #undef SELECT_SPARC
510 #undef SELECT_MIPS64
511 #undef SELECT_AARCH64
515 StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) {
516 switch (Prop) {
517 default:
518 return StringRef();
519 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
520 case DW_APPLE_PROPERTY_##NAME: \
521 return "DW_APPLE_PROPERTY_" #NAME;
522 #include "llvm/BinaryFormat/Dwarf.def"
526 StringRef llvm::dwarf::UnitTypeString(unsigned UT) {
527 switch (UT) {
528 default:
529 return StringRef();
530 #define HANDLE_DW_UT(ID, NAME) \
531 case DW_UT_##NAME: \
532 return "DW_UT_" #NAME;
533 #include "llvm/BinaryFormat/Dwarf.def"
537 StringRef llvm::dwarf::AtomTypeString(unsigned AT) {
538 switch (AT) {
539 case dwarf::DW_ATOM_null:
540 return "DW_ATOM_null";
541 case dwarf::DW_ATOM_die_offset:
542 return "DW_ATOM_die_offset";
543 case DW_ATOM_cu_offset:
544 return "DW_ATOM_cu_offset";
545 case DW_ATOM_die_tag:
546 return "DW_ATOM_die_tag";
547 case DW_ATOM_type_flags:
548 case DW_ATOM_type_type_flags:
549 return "DW_ATOM_type_flags";
550 case DW_ATOM_qual_name_hash:
551 return "DW_ATOM_qual_name_hash";
553 return StringRef();
556 StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) {
557 switch (Kind) {
558 case GIEK_NONE:
559 return "NONE";
560 case GIEK_TYPE:
561 return "TYPE";
562 case GIEK_VARIABLE:
563 return "VARIABLE";
564 case GIEK_FUNCTION:
565 return "FUNCTION";
566 case GIEK_OTHER:
567 return "OTHER";
568 case GIEK_UNUSED5:
569 return "UNUSED5";
570 case GIEK_UNUSED6:
571 return "UNUSED6";
572 case GIEK_UNUSED7:
573 return "UNUSED7";
575 llvm_unreachable("Unknown GDBIndexEntryKind value");
578 StringRef
579 llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
580 switch (Linkage) {
581 case GIEL_EXTERNAL:
582 return "EXTERNAL";
583 case GIEL_STATIC:
584 return "STATIC";
586 llvm_unreachable("Unknown GDBIndexEntryLinkage value");
589 StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
590 switch (Attr) {
591 case DW_AT_accessibility:
592 return AccessibilityString(Val);
593 case DW_AT_virtuality:
594 return VirtualityString(Val);
595 case DW_AT_language:
596 return LanguageString(Val);
597 case DW_AT_encoding:
598 return AttributeEncodingString(Val);
599 case DW_AT_decimal_sign:
600 return DecimalSignString(Val);
601 case DW_AT_endianity:
602 return EndianityString(Val);
603 case DW_AT_visibility:
604 return VisibilityString(Val);
605 case DW_AT_identifier_case:
606 return CaseString(Val);
607 case DW_AT_calling_convention:
608 return ConventionString(Val);
609 case DW_AT_inline:
610 return InlineCodeString(Val);
611 case DW_AT_ordering:
612 return ArrayOrderString(Val);
613 case DW_AT_APPLE_runtime_class:
614 return LanguageString(Val);
617 return StringRef();
620 StringRef llvm::dwarf::AtomValueString(uint16_t Atom, unsigned Val) {
621 switch (Atom) {
622 case DW_ATOM_null:
623 return "NULL";
624 case DW_ATOM_die_tag:
625 return TagString(Val);
628 return StringRef();
631 StringRef llvm::dwarf::IndexString(unsigned Idx) {
632 switch (Idx) {
633 default:
634 return StringRef();
635 #define HANDLE_DW_IDX(ID, NAME) \
636 case DW_IDX_##NAME: \
637 return "DW_IDX_" #NAME;
638 #include "llvm/BinaryFormat/Dwarf.def"
642 Optional<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form,
643 FormParams Params) {
644 switch (Form) {
645 case DW_FORM_addr:
646 if (Params)
647 return Params.AddrSize;
648 return None;
650 case DW_FORM_block: // ULEB128 length L followed by L bytes.
651 case DW_FORM_block1: // 1 byte length L followed by L bytes.
652 case DW_FORM_block2: // 2 byte length L followed by L bytes.
653 case DW_FORM_block4: // 4 byte length L followed by L bytes.
654 case DW_FORM_string: // C-string with null terminator.
655 case DW_FORM_sdata: // SLEB128.
656 case DW_FORM_udata: // ULEB128.
657 case DW_FORM_ref_udata: // ULEB128.
658 case DW_FORM_indirect: // ULEB128.
659 case DW_FORM_exprloc: // ULEB128 length L followed by L bytes.
660 case DW_FORM_strx: // ULEB128.
661 case DW_FORM_addrx: // ULEB128.
662 case DW_FORM_loclistx: // ULEB128.
663 case DW_FORM_rnglistx: // ULEB128.
664 case DW_FORM_GNU_addr_index: // ULEB128.
665 case DW_FORM_GNU_str_index: // ULEB128.
666 return None;
668 case DW_FORM_ref_addr:
669 if (Params)
670 return Params.getRefAddrByteSize();
671 return None;
673 case DW_FORM_flag:
674 case DW_FORM_data1:
675 case DW_FORM_ref1:
676 case DW_FORM_strx1:
677 case DW_FORM_addrx1:
678 return 1;
680 case DW_FORM_data2:
681 case DW_FORM_ref2:
682 case DW_FORM_strx2:
683 case DW_FORM_addrx2:
684 return 2;
686 case DW_FORM_strx3:
687 return 3;
689 case DW_FORM_data4:
690 case DW_FORM_ref4:
691 case DW_FORM_ref_sup4:
692 case DW_FORM_strx4:
693 case DW_FORM_addrx4:
694 return 4;
696 case DW_FORM_strp:
697 case DW_FORM_GNU_ref_alt:
698 case DW_FORM_GNU_strp_alt:
699 case DW_FORM_line_strp:
700 case DW_FORM_sec_offset:
701 case DW_FORM_strp_sup:
702 if (Params)
703 return Params.getDwarfOffsetByteSize();
704 return None;
706 case DW_FORM_data8:
707 case DW_FORM_ref8:
708 case DW_FORM_ref_sig8:
709 case DW_FORM_ref_sup8:
710 return 8;
712 case DW_FORM_flag_present:
713 return 0;
715 case DW_FORM_data16:
716 return 16;
718 case DW_FORM_implicit_const:
719 // The implicit value is stored in the abbreviation as a SLEB128, and
720 // there no data in debug info.
721 return 0;
723 default:
724 break;
726 return None;
729 bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version,
730 bool ExtensionsOk) {
731 if (FormVendor(F) == DWARF_VENDOR_DWARF) {
732 unsigned FV = FormVersion(F);
733 return FV > 0 && FV <= Version;
735 return ExtensionsOk;
738 constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
739 constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
740 constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
741 constexpr char llvm::dwarf::EnumTraits<Tag>::Type[];