Skip to content

Commit

Permalink
Address reviewer comments. Don't create a CommonUtils file, but move …
Browse files Browse the repository at this point in the history
…the code

to CommonArgs instead. That code has been put in the clang::driver namespace.
  • Loading branch information
Tarun Prabhu committed Sep 16, 2024
1 parent fffcf99 commit 367519d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 123 deletions.
1 change: 0 additions & 1 deletion clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ add_clang_library(clangDriver
ToolChains/BareMetal.cpp
ToolChains/Clang.cpp
ToolChains/CommonArgs.cpp
ToolChains/CommonUtils.cpp
ToolChains/CrossWindows.cpp
ToolChains/CSKYToolChain.cpp
ToolChains/Cuda.cpp
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "Arch/VE.h"
#include "Arch/X86.h"
#include "CommonArgs.h"
#include "CommonUtils.h"
#include "Hexagon.h"
#include "MSP430.h"
#include "PS4CPU.h"
Expand Down
59 changes: 59 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,3 +2976,62 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
}
}
}

void driver::EscapeSpacesAndBackslashes(const char *Arg,
llvm::SmallVectorImpl<char> &Res) {
for (; *Arg; ++Arg) {
switch (*Arg) {
default:
break;
case ' ':
case '\\':
Res.push_back('\\');
break;
}
Res.push_back(*Arg);
}
}

const char *driver::RenderEscapedCommandLine(const ToolChain &TC,
const llvm::opt::ArgList &Args) {
const Driver &D = TC.getDriver();
const char *Exec = D.getClangProgramPath();

llvm::opt::ArgStringList OriginalArgs;
for (const auto &Arg : Args)
Arg->render(Args, OriginalArgs);

llvm::SmallString<256> Flags;
EscapeSpacesAndBackslashes(Exec, Flags);
for (const char *OriginalArg : OriginalArgs) {
llvm::SmallString<128> EscapedArg;
EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
Flags += " ";
Flags += EscapedArg;
}

return Args.MakeArgString(Flags);
}

bool driver::ShouldRecordCommandLine(const ToolChain &TC,
const llvm::opt::ArgList &Args,
bool &FRecordCommandLine,
bool &GRecordCommandLine) {
const Driver &D = TC.getDriver();
const llvm::Triple &Triple = TC.getEffectiveTriple();
const std::string &TripleStr = Triple.getTriple();

FRecordCommandLine =
Args.hasFlag(options::OPT_frecord_command_line,
options::OPT_fno_record_command_line, false);
GRecordCommandLine =
Args.hasFlag(options::OPT_grecord_command_line,
options::OPT_gno_record_command_line, false);
if (FRecordCommandLine && !Triple.isOSBinFormatELF() &&
!Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
<< TripleStr;

return FRecordCommandLine || TC.UseDwarfDebugFlags() || GRecordCommandLine;
}
26 changes: 26 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,32 @@ void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);

} // end namespace tools

/// Add backslashes to escape spaces and other backslashes.
/// This is used for the space-separated argument list specified with
/// the -dwarf-debug-flags option.
void EscapeSpacesAndBackslashes(const char *Arg,
llvm::SmallVectorImpl<char> &Res);

/// Join the args in the given ArgList, escape spaces and backslashes and
/// return the joined string. This is used when saving the command line as a
/// result of using either the -frecord-command-line or -grecord-command-line
/// options. The lifetime of the returned c-string will match that of the Args
/// argument.
const char *RenderEscapedCommandLine(const ToolChain &TC,
const llvm::opt::ArgList &Args);

/// Check if the command line should be recorded in the object file. This is
/// done if either -frecord-command-line or -grecord-command-line options have
/// been passed. This also does some error checking since -frecord-command-line
/// is currently only supported on ELF platforms. The last two boolean
/// arguments are out parameters and will be set depending on the command
/// line options that were passed.
bool ShouldRecordCommandLine(const ToolChain &TC,
const llvm::opt::ArgList &Args,
bool &FRecordCommandLine,
bool &GRecordCommandLine);

} // end namespace driver
} // end namespace clang

Expand Down
76 changes: 0 additions & 76 deletions clang/lib/Driver/ToolChains/CommonUtils.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions clang/lib/Driver/ToolChains/CommonUtils.h

This file was deleted.

1 change: 0 additions & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Flang.h"
#include "Arch/RISCV.h"
#include "CommonArgs.h"
#include "CommonUtils.h"

#include "clang/Basic/CodeGenOptions.h"
#include "clang/Driver/Options.h"
Expand Down

0 comments on commit 367519d

Please sign in to comment.