• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 using namespace llvm;
20 
21 // Returns /machine's value.
getMachineType(StringRef S)22 COFF::MachineTypes llvm::getMachineType(StringRef S) {
23   return StringSwitch<COFF::MachineTypes>(S.lower())
24       .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
25       .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
26       .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
27       .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
28       .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
29 }
30 
machineToStr(COFF::MachineTypes MT)31 StringRef llvm::machineToStr(COFF::MachineTypes MT) {
32   switch (MT) {
33   case COFF::IMAGE_FILE_MACHINE_ARMNT:
34     return "arm";
35   case COFF::IMAGE_FILE_MACHINE_ARM64:
36     return "arm64";
37   case COFF::IMAGE_FILE_MACHINE_AMD64:
38     return "x64";
39   case COFF::IMAGE_FILE_MACHINE_I386:
40     return "x86";
41   default:
42     llvm_unreachable("unknown machine type");
43   }
44 }
45