[TextAPI] Prefix all architecture enums to fix the build on i386.

Summary: This changes the Architecture enum to use a prefix (AK_) to prevent the
preprocessor from replacing i386 with 1 when building llvm/clang for i386.

Reviewers: steven_wu, lhames, mstorsjo

Reviewed By: mstorsjo

Subscribers: hiraditya, jkorous, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60241

llvm-svn: 357733
This commit is contained in:
Juergen Ributzka 2019-04-04 22:56:50 +00:00
parent b250403590
commit 875565e559
7 changed files with 37 additions and 43 deletions

View File

@ -20,11 +20,11 @@ namespace llvm {
namespace MachO { namespace MachO {
/// Defines the architecture slices that are supported by Text-based Stub files. /// Defines the architecture slices that are supported by Text-based Stub files.
enum class Architecture : uint8_t { enum Architecture : uint8_t {
#define ARCHINFO(Arch, Type, SubType) Arch, #define ARCHINFO(Arch, Type, SubType) AK_##Arch,
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
unknown, // this has to go last. AK_unknown, // this has to go last.
}; };
/// Convert a CPU Type and Subtype pair to an architecture slice. /// Convert a CPU Type and Subtype pair to an architecture slice.

View File

@ -38,7 +38,7 @@ public:
ArchitectureSet(const std::vector<Architecture> &Archs); ArchitectureSet(const std::vector<Architecture> &Archs);
void set(Architecture Arch) { void set(Architecture Arch) {
if (Arch == Architecture::unknown) if (Arch == AK_unknown)
return; return;
ArchSet |= 1U << static_cast<int>(Arch); ArchSet |= 1U << static_cast<int>(Arch);
} }

View File

@ -21,29 +21,29 @@ Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) {
#define ARCHINFO(Arch, Type, Subtype) \ #define ARCHINFO(Arch, Type, Subtype) \
if (CPUType == (Type) && \ if (CPUType == (Type) && \
(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \ (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
return Architecture::Arch; return AK_##Arch;
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
return Architecture::unknown; return AK_unknown;
} }
Architecture getArchitectureFromName(StringRef Name) { Architecture getArchitectureFromName(StringRef Name) {
return StringSwitch<Architecture>(Name) return StringSwitch<Architecture>(Name)
#define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, Architecture::Arch) #define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, AK_##Arch)
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
.Default(Architecture::unknown); .Default(AK_unknown);
} }
StringRef getArchitectureName(Architecture Arch) { StringRef getArchitectureName(Architecture Arch) {
switch (Arch) { switch (Arch) {
#define ARCHINFO(Arch, Type, Subtype) \ #define ARCHINFO(Arch, Type, Subtype) \
case Architecture::Arch: \ case AK_##Arch: \
return #Arch; return #Arch;
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
case Architecture::unknown: case AK_unknown:
return "unknown"; return "unknown";
} }
@ -55,11 +55,11 @@ StringRef getArchitectureName(Architecture Arch) {
std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) { std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
switch (Arch) { switch (Arch) {
#define ARCHINFO(Arch, Type, Subtype) \ #define ARCHINFO(Arch, Type, Subtype) \
case Architecture::Arch: \ case AK_##Arch: \
return std::make_pair(Type, Subtype); return std::make_pair(Type, Subtype);
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
case Architecture::unknown: case AK_unknown:
return std::make_pair(0, 0); return std::make_pair(0, 0);
} }

View File

@ -18,7 +18,7 @@ namespace MachO {
ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs) ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
: ArchitectureSet() { : ArchitectureSet() {
for (auto Arch : Archs) { for (auto Arch : Archs) {
if (Arch == Architecture::unknown) if (Arch == AK_unknown)
continue; continue;
set(Arch); set(Arch);
} }
@ -51,7 +51,7 @@ ArchitectureSet::operator std::string() const {
ArchitectureSet::operator std::vector<Architecture>() const { ArchitectureSet::operator std::vector<Architecture>() const {
std::vector<Architecture> archs; std::vector<Architecture> archs;
for (auto arch : *this) { for (auto arch : *this) {
if (arch == Architecture::unknown) if (arch == AK_unknown)
continue; continue;
archs.emplace_back(arch); archs.emplace_back(arch);
} }

View File

@ -85,7 +85,7 @@ QuotingType ScalarTraits<PlatformKind>::mustQuote(StringRef) {
void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO, void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO,
ArchitectureSet &Archs) { ArchitectureSet &Archs) {
#define ARCHINFO(arch, type, subtype) \ #define ARCHINFO(arch, type, subtype) \
IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(Architecture::arch)); IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch));
#include "llvm/TextAPI/MachO/Architecture.def" #include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO #undef ARCHINFO
} }

View File

@ -87,8 +87,7 @@ TEST(TBDv1, ReadFile) {
EXPECT_TRUE(!!Result); EXPECT_TRUE(!!Result);
auto File = std::move(Result.get()); auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType()); EXPECT_EQ(FileType::TBD_V1, File->getFileType());
auto Archs = Architecture::armv7 | Architecture::armv7s | auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures()); EXPECT_EQ(Archs, File->getArchitectures());
EXPECT_EQ(PlatformKind::iOS, File->getPlatform()); EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName()); EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
@ -133,8 +132,7 @@ TEST(TBDv1, ReadFile2) {
EXPECT_TRUE(!!Result); EXPECT_TRUE(!!Result);
auto File = std::move(Result.get()); auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType()); EXPECT_EQ(FileType::TBD_V1, File->getFileType());
auto Archs = Architecture::armv7 | Architecture::armv7s | auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures()); EXPECT_EQ(Archs, File->getArchitectures());
EXPECT_EQ(PlatformKind::iOS, File->getPlatform()); EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName()); EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
@ -178,23 +176,22 @@ TEST(TBDv1, WriteFile) {
File.setPath("libfoo.dylib"); File.setPath("libfoo.dylib");
File.setInstallName("/usr/lib/libfoo.dylib"); File.setInstallName("/usr/lib/libfoo.dylib");
File.setFileType(FileType::TBD_V1); File.setFileType(FileType::TBD_V1);
File.setArchitectures(Architecture::i386 | Architecture::x86_64); File.setArchitectures(AK_i386 | AK_x86_64);
File.setPlatform(PlatformKind::macOS); File.setPlatform(PlatformKind::macOS);
File.setCurrentVersion(PackedVersion(1, 2, 3)); File.setCurrentVersion(PackedVersion(1, 2, 3));
File.setSwiftABIVersion(5); File.setSwiftABIVersion(5);
File.setObjCConstraint(ObjCConstraintType::Retain_Release); File.setObjCConstraint(ObjCConstraintType::Retain_Release);
File.addAllowableClient("clientA", Architecture::x86_64); File.addAllowableClient("clientA", AK_x86_64);
File.addReexportedLibrary("/usr/lib/libfoo.dylib", Architecture::x86_64); File.addReexportedLibrary("/usr/lib/libfoo.dylib", AK_x86_64);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", Architecture::i386); File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", AK_i386);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", Architecture::i386, File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", AK_i386,
SymbolFlags::WeakDefined); SymbolFlags::WeakDefined);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", Architecture::i386, File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", AK_i386,
SymbolFlags::ThreadLocalValue); SymbolFlags::ThreadLocalValue);
File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", Architecture::x86_64); File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", AK_x86_64);
File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", AK_x86_64);
Architecture::x86_64);
File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1", File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
Architecture::x86_64); AK_x86_64);
SmallString<4096> Buffer; SmallString<4096> Buffer;
raw_svector_ostream OS(Buffer); raw_svector_ostream OS(Buffer);

View File

@ -89,8 +89,7 @@ TEST(TBDv2, ReadFile) {
EXPECT_TRUE(!!Result); EXPECT_TRUE(!!Result);
auto File = std::move(Result.get()); auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType()); EXPECT_EQ(FileType::TBD_V2, File->getFileType());
auto Archs = Architecture::armv7 | Architecture::armv7s | auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures()); EXPECT_EQ(Archs, File->getArchitectures());
EXPECT_EQ(PlatformKind::iOS, File->getPlatform()); EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName()); EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
@ -157,8 +156,7 @@ TEST(TBDv2, ReadFile2) {
EXPECT_TRUE(!!Result); EXPECT_TRUE(!!Result);
auto File = std::move(Result.get()); auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType()); EXPECT_EQ(FileType::TBD_V2, File->getFileType());
auto Archs = Architecture::armv7 | Architecture::armv7s | auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures()); EXPECT_EQ(Archs, File->getArchitectures());
EXPECT_EQ(PlatformKind::iOS, File->getPlatform()); EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName()); EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
@ -201,25 +199,24 @@ TEST(TBDv2, WriteFile) {
File.setPath("libfoo.dylib"); File.setPath("libfoo.dylib");
File.setInstallName("/usr/lib/libfoo.dylib"); File.setInstallName("/usr/lib/libfoo.dylib");
File.setFileType(FileType::TBD_V2); File.setFileType(FileType::TBD_V2);
File.setArchitectures(Architecture::i386 | Architecture::x86_64); File.setArchitectures(AK_i386 | AK_x86_64);
File.setPlatform(PlatformKind::macOS); File.setPlatform(PlatformKind::macOS);
File.setCurrentVersion(PackedVersion(1, 2, 3)); File.setCurrentVersion(PackedVersion(1, 2, 3));
File.setTwoLevelNamespace(); File.setTwoLevelNamespace();
File.setApplicationExtensionSafe(); File.setApplicationExtensionSafe();
File.setSwiftABIVersion(5); File.setSwiftABIVersion(5);
File.setObjCConstraint(ObjCConstraintType::Retain_Release); File.setObjCConstraint(ObjCConstraintType::Retain_Release);
File.addAllowableClient("clientA", Architecture::x86_64); File.addAllowableClient("clientA", AK_x86_64);
File.addReexportedLibrary("/usr/lib/libfoo.dylib", Architecture::x86_64); File.addReexportedLibrary("/usr/lib/libfoo.dylib", AK_x86_64);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", Architecture::i386); File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", AK_i386);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", Architecture::i386, File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", AK_i386,
SymbolFlags::WeakDefined); SymbolFlags::WeakDefined);
File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", Architecture::i386, File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", AK_i386,
SymbolFlags::ThreadLocalValue); SymbolFlags::ThreadLocalValue);
File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", Architecture::x86_64); File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", AK_x86_64);
File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", AK_x86_64);
Architecture::x86_64);
File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1", File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
Architecture::x86_64); AK_x86_64);
SmallString<4096> Buffer; SmallString<4096> Buffer;
raw_svector_ostream OS(Buffer); raw_svector_ostream OS(Buffer);