Skip to content

Commit

Permalink
[clang][cli] NFC: Promote ParseLangArgs and ParseCodeGenArgs to members
Browse files Browse the repository at this point in the history
This patch promotes `ParseLangArgs` and `ParseCodeGenArgs` to members of `CompilerInvocation`. That will be useful in the following patch D94682, where we need to access protected members of `LangOptions` and `CodeGenOptions`. Both of those classes already have `friend CompilerInvocation`.

This is cleaner than keeping those functions freestanding and having to specify the exact signature of both in extra `friend` declarations.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94681
  • Loading branch information
jansvoboda11 committed Jan 15, 2021
1 parent a7dcd3a commit 1744f4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 12 additions & 0 deletions clang/include/clang/Frontend/CompilerInvocation.h
Expand Up @@ -247,6 +247,18 @@ class CompilerInvocation : public CompilerInvocationBase {
/// \returns - True if parsing was successful, false otherwise
bool parseSimpleArgs(const llvm::opt::ArgList &Args,
DiagnosticsEngine &Diags);

/// Parse command line options that map to LangOptions.
static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
InputKind IK, const llvm::Triple &T,
std::vector<std::string> &Includes,
DiagnosticsEngine &Diags);

/// Parse command line options that map to CodeGenOptions.
static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args,
InputKind IK, DiagnosticsEngine &Diags,
const llvm::Triple &T,
const std::string &OutputFile);
};

IntrusiveRefCntPtr<llvm::vfs::FileSystem>
Expand Down
16 changes: 9 additions & 7 deletions clang/lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -907,9 +907,11 @@ static void setPGOUseInstrumentor(CodeGenOptions &Opts,
Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
}

static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
DiagnosticsEngine &Diags, const llvm::Triple &T,
const std::string &OutputFile) {
bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
InputKind IK,
DiagnosticsEngine &Diags,
const llvm::Triple &T,
const std::string &OutputFile) {
bool Success = true;

unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
Expand Down Expand Up @@ -2151,10 +2153,10 @@ static void GenerateLangArgs(const LangOptions &Opts,
Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins)));
}

static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
const llvm::Triple &T,
std::vector<std::string> &Includes,
DiagnosticsEngine &Diags) {
void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
InputKind IK, const llvm::Triple &T,
std::vector<std::string> &Includes,
DiagnosticsEngine &Diags) {
// FIXME: Cleanup per-file based stuff.
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
Expand Down

0 comments on commit 1744f4c

Please sign in to comment.