Move parsing of LLVM options to parse() method.

We used to parse the LLVM options in Driver::link.  However, that is
after parse() where we load files.  By moving the LLVM option handling
earlier, we can add DEBUG() to code such as MachONormalizedFileToAtoms.cpp
and have it enabled correctly by '-mllvm --debug'.

llvm-svn: 255819
This commit is contained in:
Pete Cooper 2015-12-16 20:53:27 +00:00
parent 3e3edc91f9
commit 7bf3a85e2b
5 changed files with 18 additions and 2 deletions

View File

@ -46,6 +46,9 @@ protected:
static bool link(LinkingContext &context,
raw_ostream &diag = llvm::errs());
/// Parses the LLVM options from the context.
static void parseLLVMOptions(const LinkingContext &context);
private:
Driver() = delete;
};

View File

@ -159,6 +159,8 @@ bool CoreDriver::parse(llvm::ArrayRef<const char *> args,
}
}
parseLLVMOptions(ctx);
if (ctx.getNodes().empty()) {
diagnostics << "No input files\n";
return false;

View File

@ -822,6 +822,10 @@ bool DarwinLdDriver::parse(llvm::ArrayRef<const char *> args,
}
}
// Parse the LLVM options before we process files in case the file handling
// makes use of things like DEBUG().
parseLLVMOptions(ctx);
// Handle input files and sectcreate.
for (auto &arg : parsedArgs) {
bool upward;

View File

@ -64,8 +64,7 @@ FileVector loadFile(LinkingContext &ctx, StringRef path, bool wholeArchive) {
return files;
}
/// This is where the link is actually performed.
bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
void Driver::parseLLVMOptions(const LinkingContext &ctx) {
// Honor -mllvm
if (!ctx.llvmOptions().empty()) {
unsigned numArgs = ctx.llvmOptions().size();
@ -76,6 +75,10 @@ bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
args[numArgs + 1] = nullptr;
llvm::cl::ParseCommandLineOptions(numArgs + 1, args);
}
}
/// This is where the link is actually performed.
bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
if (ctx.getNodes().empty())
return false;

View File

@ -637,6 +637,10 @@ bool GnuLdDriver::parse(llvm::ArrayRef<const char *> args,
if (ctx->allowLinkWithDynamicLibraries())
ctx->registry().addSupportELFDynamicSharedObjects(*ctx);
// Parse the LLVM options before we process files in case the file handling
// makes use of things like DEBUG().
parseLLVMOptions(*ctx);
std::stack<int> groupStack;
int numfiles = 0;
bool asNeeded = false;