forked from OSchip/llvm-project
COFF: Handle /machine option in a similar manner for other options. NFC.
llvm-svn: 241701
This commit is contained in:
parent
0a3f5f634a
commit
e16a75d5a1
|
@ -20,6 +20,7 @@
|
|||
namespace lld {
|
||||
namespace coff {
|
||||
|
||||
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
using llvm::COFF::WindowsSubsystem;
|
||||
using llvm::StringRef;
|
||||
class Undefined;
|
||||
|
@ -45,7 +46,7 @@ struct Export {
|
|||
struct Configuration {
|
||||
enum ManifestKind { SideBySide, Embed, No };
|
||||
|
||||
llvm::COFF::MachineTypes MachineType = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
|
||||
llvm::COFF::MachineTypes MachineType = IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
bool Verbose = false;
|
||||
WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
|
||||
Undefined *Entry = nullptr;
|
||||
|
|
|
@ -322,12 +322,12 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
|||
}
|
||||
|
||||
// Handle /machine
|
||||
auto MTOrErr = getMachineType(&Args);
|
||||
if (auto EC = MTOrErr.getError()) {
|
||||
llvm::errs() << EC.message() << "\n";
|
||||
return false;
|
||||
if (auto *Arg = Args.getLastArg(OPT_machine)) {
|
||||
ErrorOr<MachineTypes> MTOrErr = getMachineType(Arg->getValue());
|
||||
if (MTOrErr.getError())
|
||||
return false;
|
||||
Config->MachineType = MTOrErr.get();
|
||||
}
|
||||
Config->MachineType = MTOrErr.get();
|
||||
|
||||
// Handle /nodefaultlib:<filename>
|
||||
for (auto *Arg : Args.filtered(OPT_nodefaultlib))
|
||||
|
|
|
@ -117,7 +117,7 @@ std::error_code writeImportLibrary();
|
|||
void printHelp(const char *Argv0);
|
||||
|
||||
// For /machine option.
|
||||
ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
|
||||
ErrorOr<MachineTypes> getMachineType(StringRef Arg);
|
||||
StringRef machineTypeToStr(MachineTypes MT);
|
||||
|
||||
// Parses a string in the form of "<integer>[,<integer>]".
|
||||
|
|
|
@ -79,21 +79,16 @@ private:
|
|||
} // anonymous namespace
|
||||
|
||||
// Returns /machine's value.
|
||||
ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args) {
|
||||
if (auto *Arg = Args->getLastArg(OPT_machine)) {
|
||||
StringRef S(Arg->getValue());
|
||||
MachineTypes MT = StringSwitch<MachineTypes>(S.lower())
|
||||
.Case("arm", IMAGE_FILE_MACHINE_ARMNT)
|
||||
.Case("x64", IMAGE_FILE_MACHINE_AMD64)
|
||||
.Case("x86", IMAGE_FILE_MACHINE_I386)
|
||||
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
|
||||
if (MT == IMAGE_FILE_MACHINE_UNKNOWN) {
|
||||
llvm::errs() << "unknown /machine argument" << S << "\n";
|
||||
return make_error_code(LLDError::InvalidOption);
|
||||
}
|
||||
ErrorOr<MachineTypes> getMachineType(StringRef S) {
|
||||
MachineTypes MT = StringSwitch<MachineTypes>(S.lower())
|
||||
.Case("arm", IMAGE_FILE_MACHINE_ARMNT)
|
||||
.Case("x64", IMAGE_FILE_MACHINE_AMD64)
|
||||
.Case("x86", IMAGE_FILE_MACHINE_I386)
|
||||
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
|
||||
if (MT != IMAGE_FILE_MACHINE_UNKNOWN)
|
||||
return MT;
|
||||
}
|
||||
return IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
llvm::errs() << "unknown /machine argument" << S << "\n";
|
||||
return make_error_code(LLDError::InvalidOption);
|
||||
}
|
||||
|
||||
StringRef machineTypeToStr(MachineTypes MT) {
|
||||
|
|
Loading…
Reference in New Issue