WindowsMachineFlag.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. using namespace llvm;
  17. // Returns /machine's value.
  18. COFF::MachineTypes llvm::getMachineType(StringRef S) {
  19. return StringSwitch<COFF::MachineTypes>(S.lower())
  20. .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
  21. .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
  22. .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
  23. .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
  24. .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
  25. }
  26. StringRef llvm::machineToStr(COFF::MachineTypes MT) {
  27. switch (MT) {
  28. case COFF::IMAGE_FILE_MACHINE_ARMNT:
  29. return "arm";
  30. case COFF::IMAGE_FILE_MACHINE_ARM64:
  31. return "arm64";
  32. case COFF::IMAGE_FILE_MACHINE_AMD64:
  33. return "x64";
  34. case COFF::IMAGE_FILE_MACHINE_I386:
  35. return "x86";
  36. default:
  37. llvm_unreachable("unknown machine type");
  38. }
  39. }