forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share /machine: handling code with llvm-cvtres too
r363016 let lld-link and llvm-lib share the /machine: parsing code. This lets llvm-cvtres share it as well. Making llvm-cvtres depend on llvm-lib seemed a bit strange (it doesn't need llvm-lib's dependencies on BinaryFormat and BitReader) and I couldn't find a good place to put this code. Since it's just a few lines, put it in lib/Object for now. Differential Revision: https://reviews.llvm.org/D63120 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363144 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
7 changed files
with
91 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===- WindowsMachineFlag.h -------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Functions for implementing the /machine: flag. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TOOLDRIVERS_MACHINEFLAG_MACHINEFLAG_H | ||
#define LLVM_TOOLDRIVERS_MACHINEFLAG_MACHINEFLAG_H | ||
|
||
namespace llvm { | ||
|
||
class StringRef; | ||
namespace COFF { | ||
enum MachineTypes : unsigned; | ||
} | ||
|
||
// Returns a user-readable string for ARMNT, ARM64, AMD64, I386. | ||
// Other MachineTypes values must not be passed in. | ||
StringRef machineToStr(COFF::MachineTypes MT); | ||
|
||
// Maps /machine: arguments to a MachineTypes value. | ||
// Only returns ARMNT, ARM64, AMD64, I386, or IMAGE_FILE_MACHINE_UNKNOWN. | ||
COFF::MachineTypes getMachineType(StringRef S); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===- WindowsMachineFlag.cpp ---------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Functions for implementing the /machine: flag. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Object/WindowsMachineFlag.h" | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ADT/StringSwitch.h" | ||
#include "llvm/BinaryFormat/COFF.h" | ||
|
||
using namespace llvm; | ||
|
||
// Returns /machine's value. | ||
COFF::MachineTypes llvm::getMachineType(StringRef S) { | ||
return StringSwitch<COFF::MachineTypes>(S.lower()) | ||
.Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64) | ||
.Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386) | ||
.Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT) | ||
.Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64) | ||
.Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN); | ||
} | ||
|
||
StringRef llvm::machineToStr(COFF::MachineTypes MT) { | ||
switch (MT) { | ||
case COFF::IMAGE_FILE_MACHINE_ARMNT: | ||
return "arm"; | ||
case COFF::IMAGE_FILE_MACHINE_ARM64: | ||
return "arm64"; | ||
case COFF::IMAGE_FILE_MACHINE_AMD64: | ||
return "x64"; | ||
case COFF::IMAGE_FILE_MACHINE_I386: | ||
return "x86"; | ||
default: | ||
llvm_unreachable("unknown machine type"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters