llvm-project
51 строка · 1.7 Кб
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) {
24return 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
34StringRef llvm::machineToStr(COFF::MachineTypes MT) {
35switch (MT) {
36case COFF::IMAGE_FILE_MACHINE_ARMNT:
37return "arm";
38case COFF::IMAGE_FILE_MACHINE_ARM64:
39return "arm64";
40case COFF::IMAGE_FILE_MACHINE_ARM64EC:
41return "arm64ec";
42case COFF::IMAGE_FILE_MACHINE_ARM64X:
43return "arm64x";
44case COFF::IMAGE_FILE_MACHINE_AMD64:
45return "x64";
46case COFF::IMAGE_FILE_MACHINE_I386:
47return "x86";
48default:
49llvm_unreachable("unknown machine type");
50}
51}
52