xref: /freebsd/contrib/llvm-project/llvm/lib/Object/WindowsMachineFlag.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric //===- WindowsMachineFlag.cpp ---------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // Functions for implementing the /machine: flag.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "llvm/Object/WindowsMachineFlag.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
160b57cec5SDimitry Andric #include "llvm/ADT/StringSwitch.h"
170b57cec5SDimitry Andric #include "llvm/BinaryFormat/COFF.h"
18bdd1243dSDimitry Andric #include "llvm/Support/ErrorHandling.h"
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric using namespace llvm;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric // Returns /machine's value.
getMachineType(StringRef S)230b57cec5SDimitry Andric COFF::MachineTypes llvm::getMachineType(StringRef S) {
240b57cec5SDimitry Andric   return StringSwitch<COFF::MachineTypes>(S.lower())
250b57cec5SDimitry Andric       .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
260b57cec5SDimitry Andric       .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
270b57cec5SDimitry Andric       .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
280b57cec5SDimitry Andric       .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
29bdd1243dSDimitry Andric       .Case("arm64ec", COFF::IMAGE_FILE_MACHINE_ARM64EC)
30*06c3fb27SDimitry Andric       .Case("arm64x", COFF::IMAGE_FILE_MACHINE_ARM64X)
310b57cec5SDimitry Andric       .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
320b57cec5SDimitry Andric }
330b57cec5SDimitry Andric 
machineToStr(COFF::MachineTypes MT)340b57cec5SDimitry Andric StringRef llvm::machineToStr(COFF::MachineTypes MT) {
350b57cec5SDimitry Andric   switch (MT) {
360b57cec5SDimitry Andric   case COFF::IMAGE_FILE_MACHINE_ARMNT:
370b57cec5SDimitry Andric     return "arm";
380b57cec5SDimitry Andric   case COFF::IMAGE_FILE_MACHINE_ARM64:
390b57cec5SDimitry Andric     return "arm64";
40bdd1243dSDimitry Andric   case COFF::IMAGE_FILE_MACHINE_ARM64EC:
41bdd1243dSDimitry Andric     return "arm64ec";
42*06c3fb27SDimitry Andric   case COFF::IMAGE_FILE_MACHINE_ARM64X:
43*06c3fb27SDimitry Andric     return "arm64x";
440b57cec5SDimitry Andric   case COFF::IMAGE_FILE_MACHINE_AMD64:
450b57cec5SDimitry Andric     return "x64";
460b57cec5SDimitry Andric   case COFF::IMAGE_FILE_MACHINE_I386:
470b57cec5SDimitry Andric     return "x86";
480b57cec5SDimitry Andric   default:
490b57cec5SDimitry Andric     llvm_unreachable("unknown machine type");
500b57cec5SDimitry Andric   }
510b57cec5SDimitry Andric }
52