Mercurial > hg > CbC > CbC_llvm
comparison lib/Object/ELFYAML.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #include "llvm/Object/ELFYAML.h" | 14 #include "llvm/Object/ELFYAML.h" |
15 #include "llvm/Support/Casting.h" | 15 #include "llvm/Support/Casting.h" |
16 #include "llvm/Support/MipsABIFlags.h" | |
16 | 17 |
17 namespace llvm { | 18 namespace llvm { |
18 | 19 |
19 ELFYAML::Section::~Section() {} | 20 ELFYAML::Section::~Section() {} |
20 | 21 |
41 ECase(EM_M32) | 42 ECase(EM_M32) |
42 ECase(EM_SPARC) | 43 ECase(EM_SPARC) |
43 ECase(EM_386) | 44 ECase(EM_386) |
44 ECase(EM_68K) | 45 ECase(EM_68K) |
45 ECase(EM_88K) | 46 ECase(EM_88K) |
46 ECase(EM_486) | 47 ECase(EM_IAMCU) |
47 ECase(EM_860) | 48 ECase(EM_860) |
48 ECase(EM_MIPS) | 49 ECase(EM_MIPS) |
49 ECase(EM_S370) | 50 ECase(EM_S370) |
50 ECase(EM_MIPS_RS3_LE) | 51 ECase(EM_MIPS_RS3_LE) |
51 ECase(EM_PARISC) | 52 ECase(EM_PARISC) |
190 ECase(EM_OPEN8) | 191 ECase(EM_OPEN8) |
191 ECase(EM_RL78) | 192 ECase(EM_RL78) |
192 ECase(EM_VIDEOCORE5) | 193 ECase(EM_VIDEOCORE5) |
193 ECase(EM_78KOR) | 194 ECase(EM_78KOR) |
194 ECase(EM_56800EX) | 195 ECase(EM_56800EX) |
196 ECase(EM_AMDGPU) | |
195 #undef ECase | 197 #undef ECase |
196 } | 198 } |
197 | 199 |
198 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration( | 200 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration( |
199 IO &IO, ELFYAML::ELF_ELFCLASS &Value) { | 201 IO &IO, ELFYAML::ELF_ELFCLASS &Value) { |
233 ECase(ELFOSABI_OPENBSD) | 235 ECase(ELFOSABI_OPENBSD) |
234 ECase(ELFOSABI_OPENVMS) | 236 ECase(ELFOSABI_OPENVMS) |
235 ECase(ELFOSABI_NSK) | 237 ECase(ELFOSABI_NSK) |
236 ECase(ELFOSABI_AROS) | 238 ECase(ELFOSABI_AROS) |
237 ECase(ELFOSABI_FENIXOS) | 239 ECase(ELFOSABI_FENIXOS) |
240 ECase(ELFOSABI_CLOUDABI) | |
238 ECase(ELFOSABI_C6000_ELFABI) | 241 ECase(ELFOSABI_C6000_ELFABI) |
239 ECase(ELFOSABI_C6000_LINUX) | 242 ECase(ELFOSABI_C6000_LINUX) |
240 ECase(ELFOSABI_ARM) | 243 ECase(ELFOSABI_ARM) |
241 ECase(ELFOSABI_STANDALONE) | 244 ECase(ELFOSABI_STANDALONE) |
242 #undef ECase | 245 #undef ECase |
263 BCase(EF_MIPS_NOREORDER) | 266 BCase(EF_MIPS_NOREORDER) |
264 BCase(EF_MIPS_PIC) | 267 BCase(EF_MIPS_PIC) |
265 BCase(EF_MIPS_CPIC) | 268 BCase(EF_MIPS_CPIC) |
266 BCase(EF_MIPS_ABI2) | 269 BCase(EF_MIPS_ABI2) |
267 BCase(EF_MIPS_32BITMODE) | 270 BCase(EF_MIPS_32BITMODE) |
271 BCase(EF_MIPS_FP64) | |
268 BCase(EF_MIPS_NAN2008) | 272 BCase(EF_MIPS_NAN2008) |
269 BCase(EF_MIPS_ABI_O32) | |
270 BCase(EF_MIPS_MICROMIPS) | 273 BCase(EF_MIPS_MICROMIPS) |
271 BCase(EF_MIPS_ARCH_ASE_M16) | 274 BCase(EF_MIPS_ARCH_ASE_M16) |
275 BCase(EF_MIPS_ARCH_ASE_MDMX) | |
276 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI) | |
277 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI) | |
278 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI) | |
279 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI) | |
280 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH) | |
281 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH) | |
282 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH) | |
283 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH) | |
284 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH) | |
285 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH) | |
286 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH) | |
287 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH) | |
288 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH) | |
289 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH) | |
290 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH) | |
291 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH) | |
292 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH) | |
293 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH) | |
294 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH) | |
295 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH) | |
296 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH) | |
297 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH) | |
272 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH) | 298 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH) |
273 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH) | 299 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH) |
274 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH) | 300 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH) |
275 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH) | 301 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH) |
276 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH) | 302 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH) |
453 llvm_unreachable("Unsupported architecture"); | 479 llvm_unreachable("Unsupported architecture"); |
454 } | 480 } |
455 #undef ELF_RELOC | 481 #undef ELF_RELOC |
456 } | 482 } |
457 | 483 |
484 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration( | |
485 IO &IO, ELFYAML::MIPS_AFL_REG &Value) { | |
486 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X); | |
487 ECase(REG_NONE) | |
488 ECase(REG_32) | |
489 ECase(REG_64) | |
490 ECase(REG_128) | |
491 #undef ECase | |
492 } | |
493 | |
494 void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration( | |
495 IO &IO, ELFYAML::MIPS_ABI_FP &Value) { | |
496 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X); | |
497 ECase(FP_ANY) | |
498 ECase(FP_DOUBLE) | |
499 ECase(FP_SINGLE) | |
500 ECase(FP_SOFT) | |
501 ECase(FP_OLD_64) | |
502 ECase(FP_XX) | |
503 ECase(FP_64) | |
504 ECase(FP_64A) | |
505 #undef ECase | |
506 } | |
507 | |
508 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration( | |
509 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) { | |
510 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X); | |
511 ECase(EXT_NONE) | |
512 ECase(EXT_XLR) | |
513 ECase(EXT_OCTEON2) | |
514 ECase(EXT_OCTEONP) | |
515 ECase(EXT_LOONGSON_3A) | |
516 ECase(EXT_OCTEON) | |
517 ECase(EXT_5900) | |
518 ECase(EXT_4650) | |
519 ECase(EXT_4010) | |
520 ECase(EXT_4100) | |
521 ECase(EXT_3900) | |
522 ECase(EXT_10000) | |
523 ECase(EXT_SB1) | |
524 ECase(EXT_4111) | |
525 ECase(EXT_4120) | |
526 ECase(EXT_5400) | |
527 ECase(EXT_5500) | |
528 ECase(EXT_LOONGSON_2E) | |
529 ECase(EXT_LOONGSON_2F) | |
530 ECase(EXT_OCTEON3) | |
531 #undef ECase | |
532 } | |
533 | |
534 void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration( | |
535 IO &IO, ELFYAML::MIPS_ISA &Value) { | |
536 IO.enumCase(Value, "MIPS1", 1); | |
537 IO.enumCase(Value, "MIPS2", 2); | |
538 IO.enumCase(Value, "MIPS3", 3); | |
539 IO.enumCase(Value, "MIPS4", 4); | |
540 IO.enumCase(Value, "MIPS5", 5); | |
541 IO.enumCase(Value, "MIPS32", 32); | |
542 IO.enumCase(Value, "MIPS64", 64); | |
543 } | |
544 | |
545 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset( | |
546 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) { | |
547 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X); | |
548 BCase(DSP) | |
549 BCase(DSPR2) | |
550 BCase(EVA) | |
551 BCase(MCU) | |
552 BCase(MDMX) | |
553 BCase(MIPS3D) | |
554 BCase(MT) | |
555 BCase(SMARTMIPS) | |
556 BCase(VIRT) | |
557 BCase(MSA) | |
558 BCase(MIPS16) | |
559 BCase(MICROMIPS) | |
560 BCase(XPA) | |
561 #undef BCase | |
562 } | |
563 | |
564 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset( | |
565 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) { | |
566 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X); | |
567 BCase(ODDSPREG) | |
568 #undef BCase | |
569 } | |
570 | |
458 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, | 571 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, |
459 ELFYAML::FileHeader &FileHdr) { | 572 ELFYAML::FileHeader &FileHdr) { |
460 IO.mapRequired("Class", FileHdr.Class); | 573 IO.mapRequired("Class", FileHdr.Class); |
461 IO.mapRequired("Data", FileHdr.Data); | 574 IO.mapRequired("Data", FileHdr.Data); |
462 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); | 575 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); |
504 IO.mapRequired("Type", Section.Type); | 617 IO.mapRequired("Type", Section.Type); |
505 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0)); | 618 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0)); |
506 IO.mapOptional("Address", Section.Address, Hex64(0)); | 619 IO.mapOptional("Address", Section.Address, Hex64(0)); |
507 IO.mapOptional("Link", Section.Link, StringRef()); | 620 IO.mapOptional("Link", Section.Link, StringRef()); |
508 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); | 621 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); |
622 IO.mapOptional("Info", Section.Info, StringRef()); | |
509 } | 623 } |
510 | 624 |
511 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { | 625 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { |
512 commonSectionMapping(IO, Section); | 626 commonSectionMapping(IO, Section); |
513 IO.mapOptional("Content", Section.Content); | 627 IO.mapOptional("Content", Section.Content); |
514 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size())); | 628 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size())); |
515 } | 629 } |
516 | 630 |
631 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { | |
632 commonSectionMapping(IO, Section); | |
633 IO.mapOptional("Size", Section.Size, Hex64(0)); | |
634 } | |
635 | |
517 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { | 636 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { |
518 commonSectionMapping(IO, Section); | 637 commonSectionMapping(IO, Section); |
519 IO.mapOptional("Info", Section.Info, StringRef()); | |
520 IO.mapOptional("Relocations", Section.Relocations); | 638 IO.mapOptional("Relocations", Section.Relocations); |
639 } | |
640 | |
641 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) { | |
642 commonSectionMapping(IO, group); | |
643 IO.mapRequired("Members", group.Members); | |
644 } | |
645 | |
646 void MappingTraits<ELFYAML::SectionOrType>::mapping( | |
647 IO &IO, ELFYAML::SectionOrType §ionOrType) { | |
648 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType); | |
649 } | |
650 | |
651 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) { | |
652 commonSectionMapping(IO, Section); | |
653 IO.mapOptional("Version", Section.Version, Hex16(0)); | |
654 IO.mapRequired("ISA", Section.ISALevel); | |
655 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0)); | |
656 IO.mapOptional("ISAExtension", Section.ISAExtension, | |
657 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE)); | |
658 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0)); | |
659 IO.mapOptional("FpABI", Section.FpABI, | |
660 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY)); | |
661 IO.mapOptional("GPRSize", Section.GPRSize, | |
662 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); | |
663 IO.mapOptional("CPR1Size", Section.CPR1Size, | |
664 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); | |
665 IO.mapOptional("CPR2Size", Section.CPR2Size, | |
666 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); | |
667 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0)); | |
668 IO.mapOptional("Flags2", Section.Flags2, Hex32(0)); | |
521 } | 669 } |
522 | 670 |
523 void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping( | 671 void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping( |
524 IO &IO, std::unique_ptr<ELFYAML::Section> &Section) { | 672 IO &IO, std::unique_ptr<ELFYAML::Section> &Section) { |
525 ELFYAML::ELF_SHT sectionType; | 673 ELFYAML::ELF_SHT sectionType; |
532 case ELF::SHT_REL: | 680 case ELF::SHT_REL: |
533 case ELF::SHT_RELA: | 681 case ELF::SHT_RELA: |
534 if (!IO.outputting()) | 682 if (!IO.outputting()) |
535 Section.reset(new ELFYAML::RelocationSection()); | 683 Section.reset(new ELFYAML::RelocationSection()); |
536 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); | 684 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); |
685 break; | |
686 case ELF::SHT_GROUP: | |
687 if (!IO.outputting()) | |
688 Section.reset(new ELFYAML::Group()); | |
689 groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get())); | |
690 break; | |
691 case ELF::SHT_NOBITS: | |
692 if (!IO.outputting()) | |
693 Section.reset(new ELFYAML::NoBitsSection()); | |
694 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get())); | |
695 break; | |
696 case ELF::SHT_MIPS_ABIFLAGS: | |
697 if (!IO.outputting()) | |
698 Section.reset(new ELFYAML::MipsABIFlags()); | |
699 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get())); | |
537 break; | 700 break; |
538 default: | 701 default: |
539 if (!IO.outputting()) | 702 if (!IO.outputting()) |
540 Section.reset(new ELFYAML::RawContentSection()); | 703 Section.reset(new ELFYAML::RawContentSection()); |
541 sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get())); | 704 sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get())); |
602 IO.mapOptional("Sections", Object.Sections); | 765 IO.mapOptional("Sections", Object.Sections); |
603 IO.mapOptional("Symbols", Object.Symbols); | 766 IO.mapOptional("Symbols", Object.Symbols); |
604 IO.setContext(nullptr); | 767 IO.setContext(nullptr); |
605 } | 768 } |
606 | 769 |
770 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) | |
771 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) | |
772 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) | |
773 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) | |
774 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) | |
775 | |
607 } // end namespace yaml | 776 } // end namespace yaml |
608 } // end namespace llvm | 777 } // end namespace llvm |