Unverified Commit bde2e698 authored by Juergen Ributzka's avatar Juergen Ributzka Committed by GitHub
Browse files

[llvm] Use XMACROS for MachO platforms. (#69262)

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.
parent 7fc3d32d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
  }
}

+16 −0
Original line number Diff line number Diff line
@@ -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
+4 −11
Original line number Diff line number Diff line
@@ -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.
+5 −10
Original line number Diff line number Diff line
@@ -789,16 +789,11 @@ public:

  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);
+5 −12
Original line number Diff line number Diff line
@@ -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");
}
Loading