Skip to content

Commit

Permalink
Driver/Frontend: Add support for -mllvm, which forwards options to th…
Browse files Browse the repository at this point in the history
…e LLVM option parser.

 - Note that this is a behavior change, previously -mllvm at the driver level forwarded to clang -cc1. The driver does a little magic to make sure that '-mllvm -disable-llvm-optzns' works correctly, but other users will need to be updated to use -Xclang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101354 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Apr 15, 2010
1 parent 2df2569 commit 3f87fb0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/clang/Driver/CC1Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ def ftime_report : Flag<"-ftime-report">,
def fdump_record_layouts : Flag<"-fdump-record-layouts">,
HelpText<"Dump record layout information">;

// Generic forwarding to LLVM options. This should only be used for debugging
// and experimental features.
def mllvm : Separate<"-mllvm">,
HelpText<"Additional arguments to forward to LLVM's option processing">;

//===----------------------------------------------------------------------===//
// Language Options
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions include/clang/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class FrontendOptions {
/// \brief The list of AST files to merge.
std::vector<std::string> ASTMergeFiles;

/// \brief A list of arguments to forward to LLVM's option processing; this
/// should only be used for debugging and experimental features.
std::vector<std::string> LLVMArgs;

public:
FrontendOptions() {
DebugCodeCompletionPrinter = 1;
Expand Down
12 changes: 11 additions & 1 deletion lib/Driver/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_dM);
Args.AddLastArg(CmdArgs, options::OPT_dD);

// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
// parser.
Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
Args.AddAllArgValues(CmdArgs, options::OPT_mllvm);
for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm),
ie = Args.filtered_end(); it != ie; ++it) {
// We translate this by hand to the -cc1 argument, since nightly test uses
// it and developers have been trained to spell it with -mllvm.
if (llvm::StringRef(it->getValue(Args, 0)) == "-disable-llvm-optzns")
CmdArgs.push_back("-disable-llvm-optzns");
else
it->render(Args, CmdArgs);
}

if (Output.getType() == types::TY_Dependencies) {
// Handled with other dependency code.
Expand Down
5 changes: 5 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ static void FrontendOptsToArgs(const FrontendOptions &Opts,
Res.push_back("-ast-merge");
Res.push_back(Opts.ASTMergeFiles[i]);
}
for (unsigned i = 0, e = Opts.LLVMArgs.size(); i != e; ++i) {
Res.push_back("-mllvm");
Res.push_back(Opts.LLVMArgs[i]);
}
}

static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
Expand Down Expand Up @@ -955,6 +959,7 @@ ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Diagnostic &Diags) {
Opts.ShowVersion = Args.hasArg(OPT_version);
Opts.ViewClassInheritance = getLastArgValue(Args, OPT_cxx_inheritance_view);
Opts.ASTMergeFiles = getAllArgValues(Args, OPT_ast_merge);
Opts.LLVMArgs = getAllArgValues(Args, OPT_mllvm);

FrontendOptions::InputKind DashX = FrontendOptions::IK_None;
if (const Arg *A = Args.getLastArg(OPT_x)) {
Expand Down
13 changes: 13 additions & 0 deletions tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
return 0;
}

// Honor -mllvm.
//
// FIXME: Remove this, one day.
if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
const char **Args = new const char*[NumArgs + 2];
Args[0] = "clang (LLVM option parsing)";
for (unsigned i = 0; i != NumArgs; ++i)
Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
Args[NumArgs + 1] = 0;
llvm::cl::ParseCommandLineOptions(NumArgs + 1, (char**) Args);
}

// Create the actual diagnostics engine.
Clang->createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang->hasDiagnostics())
Expand Down

0 comments on commit 3f87fb0

Please sign in to comment.