[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 1fd81231ce
commit e1ce3bb6dc
7 changed files with 37 additions and 43 deletions

View File

@ -20,11 +20,11 @@ namespace llvm {
namespace MachO {
/// Defines the architecture slices that are supported by Text-based Stub files.
enum class Architecture : uint8_t {
#define ARCHINFO(Arch, Type, SubType) Arch,
enum Architecture : uint8_t {
#define ARCHINFO(Arch, Type, SubType) AK_##Arch,
#include "llvm/TextAPI/MachO/Architecture.def"
#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.

View File

@ -38,7 +38,7 @@ public:
ArchitectureSet(const std::vector<Architecture> &Archs);
void set(Architecture Arch) {
if (Arch == Architecture::unknown)
if (Arch == AK_unknown)
return;
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) \
if (CPUType == (Type) && \
(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
return Architecture::Arch;
return AK_##Arch;
#include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO
return Architecture::unknown;
return AK_unknown;
}
Architecture getArchitectureFromName(StringRef 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"
#undef ARCHINFO
.Default(Architecture::unknown);
.Default(AK_unknown);
}
StringRef getArchitectureName(Architecture Arch) {
switch (Arch) {
#define ARCHINFO(Arch, Type, Subtype) \
case Architecture::Arch: \
case AK_##Arch: \
return #Arch;
#include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO
case Architecture::unknown:
case AK_unknown:
return "unknown";
}
@ -55,11 +55,11 @@ StringRef getArchitectureName(Architecture Arch) {
std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
switch (Arch) {
#define ARCHINFO(Arch, Type, Subtype) \
case Architecture::Arch: \
case AK_##Arch: \
return std::make_pair(Type, Subtype);
#include "llvm/TextAPI/MachO/Architecture.def"
#undef ARCHINFO
case Architecture::unknown:
case AK_unknown:
return std::make_pair(0, 0);
}

View File

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

View File

@ -85,7 +85,7 @@ QuotingType ScalarTraits<PlatformKind>::mustQuote(StringRef) {
void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO,
ArchitectureSet &Archs) {
#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"
#undef ARCHINFO
}

View File

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

View File

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