[llvm] r363144 - Share /machine: handling code with llvm-cvtres too
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 04:32:43 PDT 2019
Author: nico
Date: Wed Jun 12 04:32:43 2019
New Revision: 363144
URL: http://llvm.org/viewvc/llvm-project?rev=363144&view=rev
Log:
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
Added:
llvm/trunk/include/llvm/Object/WindowsMachineFlag.h
llvm/trunk/lib/Object/WindowsMachineFlag.cpp
Modified:
llvm/trunk/include/llvm/ToolDrivers/llvm-lib/LibDriver.h
llvm/trunk/lib/Object/CMakeLists.txt
llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn
Added: llvm/trunk/include/llvm/Object/WindowsMachineFlag.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/WindowsMachineFlag.h?rev=363144&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Object/WindowsMachineFlag.h (added)
+++ llvm/trunk/include/llvm/Object/WindowsMachineFlag.h Wed Jun 12 04:32:43 2019
@@ -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
Modified: llvm/trunk/include/llvm/ToolDrivers/llvm-lib/LibDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ToolDrivers/llvm-lib/LibDriver.h?rev=363144&r1=363143&r2=363144&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ToolDrivers/llvm-lib/LibDriver.h (original)
+++ llvm/trunk/include/llvm/ToolDrivers/llvm-lib/LibDriver.h Wed Jun 12 04:32:43 2019
@@ -19,20 +19,6 @@ template <typename T> class ArrayRef;
int libDriverMain(ArrayRef<const char *> ARgs);
-
-class StringRef;
-namespace COFF {
-enum MachineTypes : unsigned;
-}
-
-// Returns a user-readable string for ARMNT, ARM64, AMD64, I386.
-// Other MachineTypes values must not be pased 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
Modified: llvm/trunk/lib/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/CMakeLists.txt?rev=363144&r1=363143&r2=363144&view=diff
==============================================================================
--- llvm/trunk/lib/Object/CMakeLists.txt (original)
+++ llvm/trunk/lib/Object/CMakeLists.txt Wed Jun 12 04:32:43 2019
@@ -22,6 +22,7 @@ add_llvm_library(LLVMObject
SymbolicFile.cpp
SymbolSize.cpp
WasmObjectFile.cpp
+ WindowsMachineFlag.cpp
WindowsResource.cpp
XCOFFObjectFile.cpp
Added: llvm/trunk/lib/Object/WindowsMachineFlag.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WindowsMachineFlag.cpp?rev=363144&view=auto
==============================================================================
--- llvm/trunk/lib/Object/WindowsMachineFlag.cpp (added)
+++ llvm/trunk/lib/Object/WindowsMachineFlag.cpp Wed Jun 12 04:32:43 2019
@@ -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");
+ }
+}
Modified: llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp?rev=363144&r1=363143&r2=363144&view=diff
==============================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp (original)
+++ llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp Wed Jun 12 04:32:43 2019
@@ -18,6 +18,7 @@
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Object/COFF.h"
+#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
@@ -140,31 +141,6 @@ static void doList(opt::InputArgList& Ar
fatalOpenError(std::move(Err), B->getBufferIdentifier());
}
-// 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");
- }
-}
-
int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
BumpPtrAllocator Alloc;
StringSaver Saver(Alloc);
Modified: llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp?rev=363144&r1=363143&r2=363144&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp (original)
+++ llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp Wed Jun 12 04:32:43 2019
@@ -13,6 +13,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Object/Binary.h"
+#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
@@ -118,16 +119,12 @@ int main(int Argc, const char **Argv) {
COFF::MachineTypes MachineType;
- if (InputArgs.hasArg(OPT_MACHINE)) {
- std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper();
- MachineType = StringSwitch<COFF::MachineTypes>(MachineString)
- .Case("ARM", COFF::IMAGE_FILE_MACHINE_ARMNT)
- .Case("ARM64", COFF::IMAGE_FILE_MACHINE_ARM64)
- .Case("X64", COFF::IMAGE_FILE_MACHINE_AMD64)
- .Case("X86", COFF::IMAGE_FILE_MACHINE_I386)
- .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
- if (MachineType == COFF::IMAGE_FILE_MACHINE_UNKNOWN)
- reportError("Unsupported machine architecture");
+ if (opt::Arg *Arg = InputArgs.getLastArg(OPT_MACHINE)) {
+ MachineType = getMachineType(Arg->getValue());
+ if (MachineType == COFF::IMAGE_FILE_MACHINE_UNKNOWN) {
+ reportError(Twine("Unsupported machine architecture ") + Arg->getValue() +
+ "\n");
+ }
} else {
if (Verbose)
outs() << "Machine architecture not specified; assumed X64.\n";
@@ -142,8 +139,8 @@ int main(int Argc, const char **Argv) {
SmallString<128> OutputFile;
- if (InputArgs.hasArg(OPT_OUT)) {
- OutputFile = InputArgs.getLastArgValue(OPT_OUT);
+ if (opt::Arg *Arg = InputArgs.getLastArg(OPT_OUT)) {
+ OutputFile = Arg->getValue();
} else {
OutputFile = sys::path::filename(StringRef(InputFiles[0]));
sys::path::replace_extension(OutputFile, ".obj");
@@ -159,22 +156,8 @@ int main(int Argc, const char **Argv) {
DateTimeStamp = getTime();
}
- if (Verbose) {
- outs() << "Machine: ";
- switch (MachineType) {
- case COFF::IMAGE_FILE_MACHINE_ARM64:
- outs() << "ARM64\n";
- break;
- case COFF::IMAGE_FILE_MACHINE_ARMNT:
- outs() << "ARM\n";
- break;
- case COFF::IMAGE_FILE_MACHINE_I386:
- outs() << "X86\n";
- break;
- default:
- outs() << "X64\n";
- }
- }
+ if (Verbose)
+ outs() << "Machine: " << machineToStr(MachineType) << '\n';
WindowsResourceParser Parser;
Modified: llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn?rev=363144&r1=363143&r2=363144&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn (original)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn Wed Jun 12 04:32:43 2019
@@ -35,6 +35,7 @@ static_library("Object") {
"SymbolSize.cpp",
"SymbolicFile.cpp",
"WasmObjectFile.cpp",
+ "WindowsMachineFlag.cpp",
"WindowsResource.cpp",
"XCOFFObjectFile.cpp",
]
More information about the llvm-commits
mailing list