Skip to content

[llvm] Use XMACROS for MachO platforms. #69262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple &TT) {
case llvm::Triple::DriverKit:
return llvm::MachO::PLATFORM_DRIVERKIT;
default:
return /*Unknown platform*/ 0;
return llvm::MachO::PLATFORM_UNKNOWN;
}
}

Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/BinaryFormat/MachO.def
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)

#endif

#ifdef PLATFORM
// PLATFORM(platform, id, name, build_name, target, tapi_target, marketing)
PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown, unknown)
PLATFORM(MACOS, 1, macos, macos, macos, macos, macOS)
PLATFORM(IOS, 2, ios, ios, ios, ios, iOS)
PLATFORM(TVOS, 3, tvos, tvos, tvos, tvos, tvOS)
PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchos, watchOS)
PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeos, bridgeOS)
PLATFORM(MACCATALYST, 6, macCatalyst, macCatalyst, ios-macabi, maccatalyst, macCatalyst)
PLATFORM(IOSSIMULATOR, 7, iossimulator, iossimulator, ios-simulator, ios-simulator, iOS Simulator)
PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvossimulator, tvos-simulator, tvos-simulator, tvOS Simulator)
PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchossimulator, watchos-simulator, watchos-simulator, watchOS Simulator)
PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, driverkit, DriverKit)
#endif

#undef HANDLE_LOAD_COMMAND
#undef LOAD_COMMAND_STRUCT
#undef PLATFORM
15 changes: 4 additions & 11 deletions llvm/include/llvm/BinaryFormat/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,10 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, VM_PROT_EXECUTE = 0x4 };

// Values for platform field in build_version_command.
enum PlatformType {
PLATFORM_UNKNOWN = 0,
PLATFORM_MACOS = 1,
PLATFORM_IOS = 2,
PLATFORM_TVOS = 3,
PLATFORM_WATCHOS = 4,
PLATFORM_BRIDGEOS = 5,
PLATFORM_MACCATALYST = 6,
PLATFORM_IOSSIMULATOR = 7,
PLATFORM_TVOSSIMULATOR = 8,
PLATFORM_WATCHOSSIMULATOR = 9,
PLATFORM_DRIVERKIT = 10,
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
PLATFORM_##platform = id,
#include "MachO.def"
};

// Values for tools enum in build_tool_version.
Expand Down
15 changes: 5 additions & 10 deletions llvm/include/llvm/Object/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,11 @@ class MachOObjectFile : public ObjectFile {

static std::string getBuildPlatform(uint32_t platform) {
switch (platform) {
case MachO::PLATFORM_MACOS: return "macos";
case MachO::PLATFORM_IOS: return "ios";
case MachO::PLATFORM_TVOS: return "tvos";
case MachO::PLATFORM_WATCHOS: return "watchos";
case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
case MachO::PLATFORM_DRIVERKIT: return "driverkit";
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
case MachO::PLATFORM_##platform: \
return #name;
#include "llvm/BinaryFormat/MachO.def"
default:
std::string ret;
raw_string_ostream ss(ret);
Expand Down
17 changes: 5 additions & 12 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,18 +629,11 @@ void MCAsmStreamer::emitVersionMin(MCVersionMinType Type, unsigned Major,

static const char *getPlatformName(MachO::PlatformType Type) {
switch (Type) {
case MachO::PLATFORM_UNKNOWN: /* silence warning*/
break;
case MachO::PLATFORM_MACOS: return "macos";
case MachO::PLATFORM_IOS: return "ios";
case MachO::PLATFORM_TVOS: return "tvos";
case MachO::PLATFORM_WATCHOS: return "watchos";
case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
case MachO::PLATFORM_DRIVERKIT: return "driverkit";
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
case MachO::PLATFORM_##platform: \
return #build_name;
#include "llvm/BinaryFormat/MachO.def"
}
llvm_unreachable("Invalid Mach-O platform type");
}
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/MC/MCParser/DarwinAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,13 @@ bool DarwinAsmParser::parseBuildVersion(StringRef Directive, SMLoc Loc) {
return TokError("platform name expected");

unsigned Platform = StringSwitch<unsigned>(PlatformName)
.Case("macos", MachO::PLATFORM_MACOS)
.Case("ios", MachO::PLATFORM_IOS)
.Case("tvos", MachO::PLATFORM_TVOS)
.Case("watchos", MachO::PLATFORM_WATCHOS)
.Case("macCatalyst", MachO::PLATFORM_MACCATALYST)
.Case("driverkit", MachO::PLATFORM_DRIVERKIT)
.Default(0);
if (Platform == 0)
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
.Case(#build_name, MachO::PLATFORM_##platform)
#include "llvm/BinaryFormat/MachO.def"
.Default(MachO::PLATFORM_UNKNOWN);

if (Platform == MachO::PLATFORM_UNKNOWN)
return Error(PlatformLoc, "unknown platform name");

if (getLexer().isNot(AsmToken::Comma))
Expand Down
41 changes: 9 additions & 32 deletions llvm/lib/TextAPI/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,45 +62,22 @@ PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets) {

StringRef getPlatformName(PlatformType Platform) {
switch (Platform) {
case PLATFORM_UNKNOWN:
return "unknown";
case PLATFORM_MACOS:
return "macOS";
case PLATFORM_IOS:
return "iOS";
case PLATFORM_TVOS:
return "tvOS";
case PLATFORM_WATCHOS:
return "watchOS";
case PLATFORM_BRIDGEOS:
return "bridgeOS";
case PLATFORM_MACCATALYST:
return "macCatalyst";
case PLATFORM_IOSSIMULATOR:
return "iOS Simulator";
case PLATFORM_TVOSSIMULATOR:
return "tvOS Simulator";
case PLATFORM_WATCHOSSIMULATOR:
return "watchOS Simulator";
case PLATFORM_DRIVERKIT:
return "DriverKit";
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
case PLATFORM_##platform: \
return #marketing;
#include "llvm/BinaryFormat/MachO.def"
}
llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
}

PlatformType getPlatformFromName(StringRef Name) {
return StringSwitch<PlatformType>(Name)
.Case("osx", PLATFORM_MACOS)
.Case("macos", PLATFORM_MACOS)
.Case("ios", PLATFORM_IOS)
.Case("tvos", PLATFORM_TVOS)
.Case("watchos", PLATFORM_WATCHOS)
.Case("bridgeos", PLATFORM_BRIDGEOS)
.Case("ios-macabi", PLATFORM_MACCATALYST)
.Case("ios-simulator", PLATFORM_IOSSIMULATOR)
.Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
.Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
.Case("driverkit", PLATFORM_DRIVERKIT)
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
.Case(#tapi_target, PLATFORM_##platform)
#include "llvm/BinaryFormat/MachO.def"
.Default(PLATFORM_UNKNOWN);
}

Expand Down
14 changes: 4 additions & 10 deletions llvm/lib/TextAPI/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ Expected<Target> Target::create(StringRef TargetValue) {
auto PlatformStr = Result.second;
PlatformType Platform;
Platform = StringSwitch<PlatformType>(PlatformStr)
.Case("macos", PLATFORM_MACOS)
.Case("ios", PLATFORM_IOS)
.Case("tvos", PLATFORM_TVOS)
.Case("watchos", PLATFORM_WATCHOS)
.Case("bridgeos", PLATFORM_BRIDGEOS)
.Case("maccatalyst", PLATFORM_MACCATALYST)
.Case("ios-simulator", PLATFORM_IOSSIMULATOR)
.Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
.Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
.Case("driverkit", PLATFORM_DRIVERKIT)
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
.Case(#tapi_target, PLATFORM_##platform)
#include "llvm/BinaryFormat/MachO.def"
.Default(PLATFORM_UNKNOWN);

if (Platform == PLATFORM_UNKNOWN) {
Expand Down
39 changes: 6 additions & 33 deletions llvm/lib/TextAPI/TextStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,39 +367,12 @@ template <> struct ScalarTraits<Target> {
static void output(const Target &Value, void *, raw_ostream &OS) {
OS << Value.Arch << "-";
switch (Value.Platform) {
default:
OS << "unknown";
break;
case PLATFORM_MACOS:
OS << "macos";
break;
case PLATFORM_IOS:
OS << "ios";
break;
case PLATFORM_TVOS:
OS << "tvos";
break;
case PLATFORM_WATCHOS:
OS << "watchos";
break;
case PLATFORM_BRIDGEOS:
OS << "bridgeos";
break;
case PLATFORM_MACCATALYST:
OS << "maccatalyst";
break;
case PLATFORM_IOSSIMULATOR:
OS << "ios-simulator";
break;
case PLATFORM_TVOSSIMULATOR:
OS << "tvos-simulator";
break;
case PLATFORM_WATCHOSSIMULATOR:
OS << "watchos-simulator";
break;
case PLATFORM_DRIVERKIT:
OS << "driverkit";
break;
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
case PLATFORM_##platform: \
OS << #tapi_target; \
break;
#include "llvm/BinaryFormat/MachO.def"
}
}

Expand Down