WindowsMachineFlag.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- WindowsMachineFlag.cpp ---------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Functions for implementing the /machine: flag.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/Object/WindowsMachineFlag.h"
  13. #include "llvm/ADT/StringRef.h"
  14. #include "llvm/ADT/StringSwitch.h"
  15. #include "llvm/BinaryFormat/COFF.h"
  16. #include "llvm/Support/ErrorHandling.h"
  17. using namespace llvm;
  18. // Returns /machine's value.
  19. COFF::MachineTypes llvm::getMachineType(StringRef S) {
  20. return StringSwitch<COFF::MachineTypes>(S.lower())
  21. .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
  22. .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
  23. .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
  24. .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
  25. .Case("arm64ec", COFF::IMAGE_FILE_MACHINE_ARM64EC)
  26. .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
  27. }
  28. StringRef llvm::machineToStr(COFF::MachineTypes MT) {
  29. switch (MT) {
  30. case COFF::IMAGE_FILE_MACHINE_ARMNT:
  31. return "arm";
  32. case COFF::IMAGE_FILE_MACHINE_ARM64:
  33. return "arm64";
  34. case COFF::IMAGE_FILE_MACHINE_ARM64EC:
  35. return "arm64ec";
  36. case COFF::IMAGE_FILE_MACHINE_AMD64:
  37. return "x64";
  38. case COFF::IMAGE_FILE_MACHINE_I386:
  39. return "x86";
  40. default:
  41. llvm_unreachable("unknown machine type");
  42. }
  43. }