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 .Case("arm64x", COFF::IMAGE_FILE_MACHINE_ARM64X) 31 .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN); 32 } 33 34 StringRef llvm::machineToStr(COFF::MachineTypes MT) { 35 switch (MT) { 36 case COFF::IMAGE_FILE_MACHINE_ARMNT: 37 return "arm"; 38 case COFF::IMAGE_FILE_MACHINE_ARM64: 39 return "arm64"; 40 case COFF::IMAGE_FILE_MACHINE_ARM64EC: 41 return "arm64ec"; 42 case COFF::IMAGE_FILE_MACHINE_ARM64X: 43 return "arm64x"; 44 case COFF::IMAGE_FILE_MACHINE_AMD64: 45 return "x64"; 46 case COFF::IMAGE_FILE_MACHINE_I386: 47 return "x86"; 48 default: 49 llvm_unreachable("unknown machine type"); 50 } 51 } 52