forked from OSchip/llvm-project
[WinLink] Add -subsystem and -out command line option parsing.
The code to actually consume these flags will be added soon. llvm-svn: 182824
This commit is contained in:
parent
ecf63c6833
commit
81247063bf
|
@ -14,13 +14,14 @@
|
|||
#include "lld/ReaderWriter/Reader.h"
|
||||
#include "lld/ReaderWriter/Writer.h"
|
||||
|
||||
#include "llvm/Support/COFF.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
namespace lld {
|
||||
|
||||
class PECOFFTargetInfo : public TargetInfo {
|
||||
public:
|
||||
PECOFFTargetInfo() {}
|
||||
PECOFFTargetInfo() : _subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN) {}
|
||||
|
||||
virtual error_code parseFile(
|
||||
std::unique_ptr<MemoryBuffer> &mb,
|
||||
|
@ -31,10 +32,20 @@ public:
|
|||
|
||||
virtual void addPasses(PassManager &pm) const {}
|
||||
|
||||
void setSubsystem(llvm::COFF::WindowsSubsystem subsystem) {
|
||||
_subsystem = subsystem;
|
||||
}
|
||||
|
||||
llvm::COFF::WindowsSubsystem getSubsystem() {
|
||||
return _subsystem;
|
||||
}
|
||||
|
||||
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
|
||||
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
|
||||
|
||||
private:
|
||||
llvm::COFF::WindowsSubsystem _subsystem;
|
||||
|
||||
mutable std::unique_ptr<Reader> _reader;
|
||||
mutable std::unique_ptr<Writer> _writer;
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
|
||||
|
@ -62,6 +63,15 @@ int findDoubleDash(int argc, const char *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Parses -subsystem command line option.
|
||||
llvm::COFF::WindowsSubsystem strToWinSubsystem(std::string str) {
|
||||
std::string arg(StringRef(str).lower());
|
||||
return llvm::StringSwitch<llvm::COFF::WindowsSubsystem>(arg)
|
||||
.Case("windows", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
||||
.Case("console", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
||||
.Default(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
@ -101,6 +111,13 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
|
|||
return true;
|
||||
}
|
||||
|
||||
// Show warning for unknown arguments
|
||||
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
|
||||
ie = parsedArgs->filtered_end(); it != ie; ++it) {
|
||||
diagnostics << "warning: ignoring unknown argument: "
|
||||
<< (*it)->getAsString(*parsedArgs) << "\n";
|
||||
}
|
||||
|
||||
// Copy -mllvm
|
||||
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_mllvm),
|
||||
ie = parsedArgs->filtered_end();
|
||||
|
@ -108,6 +125,21 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
|
|||
info.appendLLVMOption((*it)->getValue());
|
||||
}
|
||||
|
||||
// Handle -subsystem
|
||||
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem)) {
|
||||
llvm::COFF::WindowsSubsystem subsystem = strToWinSubsystem(arg->getValue());
|
||||
if (subsystem == llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN) {
|
||||
diagnostics << "error: unknown subsystem name: "
|
||||
<< arg->getValue() << "\n";
|
||||
return true;
|
||||
}
|
||||
info.setSubsystem(subsystem);
|
||||
}
|
||||
|
||||
// Hanlde -out
|
||||
if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out))
|
||||
info.setOutputPath(outpath->getValue());
|
||||
|
||||
// Add input files
|
||||
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT),
|
||||
ie = parsedArgs->filtered_end();
|
||||
|
|
|
@ -5,5 +5,13 @@ include "llvm/Option/OptParser.td"
|
|||
def mllvm : Separate<["-", "/"], "mllvm">,
|
||||
HelpText<"Options to pass to LLVM">;
|
||||
|
||||
def out : Separate<["-", "/"], "out">,
|
||||
HelpText<"Path to file to write output">;
|
||||
def out_c : Joined<["-", "/"], "out:">, Alias<out>;
|
||||
|
||||
def subsystem : Separate<["-", "/"], "subsystem">,
|
||||
HelpText<"Specify subsystem">;
|
||||
def subsystem_c: Joined<["-", "/"], "subsystem:">, Alias<subsystem>;
|
||||
|
||||
def help : Flag<["-", "/"], "help">;
|
||||
def help_q : Flag<["-", "/"], "?">, Alias<help>;
|
||||
|
|
Loading…
Reference in New Issue