xref: /freebsd/contrib/llvm-project/llvm/lib/Object/WindowsMachineFlag.cpp (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
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 
13 #include "llvm/Object/WindowsMachineFlag.h"
14 
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/BinaryFormat/COFF.h"
18 #include "llvm/Support/ErrorHandling.h"
19 
20 using namespace llvm;
21 
22 // Returns /machine's value.
23 COFF::MachineTypes llvm::getMachineType(StringRef S) {
24   return StringSwitch<COFF::MachineTypes>(S.lower())
25       .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
26       .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
27       .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
28       .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
29       .Case("arm64ec", COFF::IMAGE_FILE_MACHINE_ARM64EC)
30       .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
31 }
32 
33 StringRef llvm::machineToStr(COFF::MachineTypes MT) {
34   switch (MT) {
35   case COFF::IMAGE_FILE_MACHINE_ARMNT:
36     return "arm";
37   case COFF::IMAGE_FILE_MACHINE_ARM64:
38     return "arm64";
39   case COFF::IMAGE_FILE_MACHINE_ARM64EC:
40     return "arm64ec";
41   case COFF::IMAGE_FILE_MACHINE_AMD64:
42     return "x64";
43   case COFF::IMAGE_FILE_MACHINE_I386:
44     return "x86";
45   default:
46     llvm_unreachable("unknown machine type");
47   }
48 }
49