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
20using namespace llvm;
21
22// Returns /machine's value.
23COFF::MachineTypes llvm::getMachineType(StringRef S) {
24 return StringSwitch<COFF::MachineTypes>(S.lower())
25 .Cases(S0: "x64", S1: "amd64", Value: COFF::IMAGE_FILE_MACHINE_AMD64)
26 .Cases(S0: "x86", S1: "i386", Value: COFF::IMAGE_FILE_MACHINE_I386)
27 .Case(S: "arm", Value: COFF::IMAGE_FILE_MACHINE_ARMNT)
28 .Case(S: "arm64", Value: COFF::IMAGE_FILE_MACHINE_ARM64)
29 .Case(S: "arm64ec", Value: COFF::IMAGE_FILE_MACHINE_ARM64EC)
30 .Case(S: "arm64x", Value: COFF::IMAGE_FILE_MACHINE_ARM64X)
31 .Default(Value: COFF::IMAGE_FILE_MACHINE_UNKNOWN);
32}
33
34StringRef 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