Index: include/llvm/Support/YAMLTraits.h =================================================================== --- include/llvm/Support/YAMLTraits.h +++ include/llvm/Support/YAMLTraits.h @@ -473,16 +473,22 @@ } template - void bitSetCase(T &Val, const char* Str, const T ConstVal) { - if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) { + void bitSetCase(T &Val, const char *Str, const T ConstVal, + const T EnumMask = T(0)) { + bool Match = (EnumMask && (Val & EnumMask) == ConstVal) || + (!EnumMask && (Val & ConstVal) == ConstVal); + if (bitSetMatch(Str, outputting() && Match)) { Val = Val | ConstVal; } } // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF template - void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) { - if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) { + void bitSetCase(T &Val, const char *Str, const uint32_t ConstVal, + const uint32_t EnumMask = 0) { + bool Match = (EnumMask && (Val & EnumMask) == ConstVal) || + (!EnumMask && (Val & ConstVal) == ConstVal); + if (bitSetMatch(Str, outputting() && Match)) { Val = Val | ConstVal; } } Index: lib/Object/ELFYAML.cpp =================================================================== --- lib/Object/ELFYAML.cpp +++ lib/Object/ELFYAML.cpp @@ -246,16 +246,17 @@ const auto *Object = static_cast(IO.getContext()); assert(Object && "The IO context is not initialized"); #define BCase(X) IO.bitSetCase(Value, #X, ELF::X); +#define BCaseMask(X, M) IO.bitSetCase(Value, #X, ELF::X, ELF::M); switch (Object->Header.Machine) { case ELF::EM_ARM: BCase(EF_ARM_SOFT_FLOAT) BCase(EF_ARM_VFP_FLOAT) - BCase(EF_ARM_EABI_UNKNOWN) - BCase(EF_ARM_EABI_VER1) - BCase(EF_ARM_EABI_VER2) - BCase(EF_ARM_EABI_VER3) - BCase(EF_ARM_EABI_VER4) - BCase(EF_ARM_EABI_VER5) + BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK) + BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK) + BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK) + BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK) + BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK) + BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK) break; case ELF::EM_MIPS: BCase(EF_MIPS_NOREORDER) @@ -266,17 +267,17 @@ BCase(EF_MIPS_ABI_O32) BCase(EF_MIPS_MICROMIPS) BCase(EF_MIPS_ARCH_ASE_M16) - BCase(EF_MIPS_ARCH_1) - BCase(EF_MIPS_ARCH_2) - BCase(EF_MIPS_ARCH_3) - BCase(EF_MIPS_ARCH_4) - BCase(EF_MIPS_ARCH_5) - BCase(EF_MIPS_ARCH_32) - BCase(EF_MIPS_ARCH_64) - BCase(EF_MIPS_ARCH_32R2) - BCase(EF_MIPS_ARCH_64R2) - BCase(EF_MIPS_ARCH_32R6) - BCase(EF_MIPS_ARCH_64R6) + BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH) + BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH) break; case ELF::EM_HEXAGON: BCase(EF_HEXAGON_MACH_V2) @@ -292,6 +293,7 @@ llvm_unreachable("Unsupported architecture"); } #undef BCase +#undef BCaseMask } void ScalarEnumerationTraits::enumeration( Index: test/Object/obj2yaml.test =================================================================== --- test/Object/obj2yaml.test +++ test/Object/obj2yaml.test @@ -191,7 +191,7 @@ ELF-MIPSEL-NEXT: Data: ELFDATA2LSB ELF-MIPSEL-NEXT: Type: ET_REL ELF-MIPSEL-NEXT: Machine: EM_MIPS -ELF-MIPSEL-NEXT: Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_1, EF_MIPS_ARCH_2, EF_MIPS_ARCH_5, EF_MIPS_ARCH_32 ] +ELF-MIPSEL-NEXT: Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] ELF-MIPSEL-NEXT: Sections: ELF-MIPSEL-NEXT: - Name: .text ELF-MIPSEL-NEXT: Type: SHT_PROGBITS @@ -285,7 +285,7 @@ ELF-MIPS64EL-NEXT: Data: ELFDATA2LSB ELF-MIPS64EL-NEXT: Type: ET_REL ELF-MIPS64EL-NEXT: Machine: EM_MIPS -ELF-MIPS64EL-NEXT: Flags: [ EF_MIPS_ARCH_1, EF_MIPS_ARCH_3 ] +ELF-MIPS64EL-NEXT: Flags: [ EF_MIPS_ARCH_3 ] ELF-MIPS64EL-NEXT: Sections: ELF-MIPS64EL-NEXT: - Name: .text ELF-MIPS64EL-NEXT: Type: SHT_PROGBITS