Skip to content

Commit 0ec620b

Browse files
author
Tarun Prabhu
committed
Address reviewer comments. Don't create a CommonUtils file, but move the code
to CommonArgs instead. That code has been put in the clang::driver namespace.
1 parent 93ab47b commit 0ec620b

File tree

7 files changed

+85
-123
lines changed

7 files changed

+85
-123
lines changed

clang/lib/Driver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ add_clang_library(clangDriver
4848
ToolChains/BareMetal.cpp
4949
ToolChains/Clang.cpp
5050
ToolChains/CommonArgs.cpp
51-
ToolChains/CommonUtils.cpp
5251
ToolChains/CrossWindows.cpp
5352
ToolChains/CSKYToolChain.cpp
5453
ToolChains/Cuda.cpp

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "Arch/VE.h"
2222
#include "Arch/X86.h"
2323
#include "CommonArgs.h"
24-
#include "CommonUtils.h"
2524
#include "Hexagon.h"
2625
#include "MSP430.h"
2726
#include "PS4CPU.h"

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,3 +2960,62 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
29602960
}
29612961
}
29622962
}
2963+
2964+
void driver::EscapeSpacesAndBackslashes(const char *Arg,
2965+
llvm::SmallVectorImpl<char> &Res) {
2966+
for (; *Arg; ++Arg) {
2967+
switch (*Arg) {
2968+
default:
2969+
break;
2970+
case ' ':
2971+
case '\\':
2972+
Res.push_back('\\');
2973+
break;
2974+
}
2975+
Res.push_back(*Arg);
2976+
}
2977+
}
2978+
2979+
const char *driver::RenderEscapedCommandLine(const ToolChain &TC,
2980+
const llvm::opt::ArgList &Args) {
2981+
const Driver &D = TC.getDriver();
2982+
const char *Exec = D.getClangProgramPath();
2983+
2984+
llvm::opt::ArgStringList OriginalArgs;
2985+
for (const auto &Arg : Args)
2986+
Arg->render(Args, OriginalArgs);
2987+
2988+
llvm::SmallString<256> Flags;
2989+
EscapeSpacesAndBackslashes(Exec, Flags);
2990+
for (const char *OriginalArg : OriginalArgs) {
2991+
llvm::SmallString<128> EscapedArg;
2992+
EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
2993+
Flags += " ";
2994+
Flags += EscapedArg;
2995+
}
2996+
2997+
return Args.MakeArgString(Flags);
2998+
}
2999+
3000+
bool driver::ShouldRecordCommandLine(const ToolChain &TC,
3001+
const llvm::opt::ArgList &Args,
3002+
bool &FRecordCommandLine,
3003+
bool &GRecordCommandLine) {
3004+
const Driver &D = TC.getDriver();
3005+
const llvm::Triple &Triple = TC.getEffectiveTriple();
3006+
const std::string &TripleStr = Triple.getTriple();
3007+
3008+
FRecordCommandLine =
3009+
Args.hasFlag(options::OPT_frecord_command_line,
3010+
options::OPT_fno_record_command_line, false);
3011+
GRecordCommandLine =
3012+
Args.hasFlag(options::OPT_grecord_command_line,
3013+
options::OPT_gno_record_command_line, false);
3014+
if (FRecordCommandLine && !Triple.isOSBinFormatELF() &&
3015+
!Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
3016+
D.Diag(diag::err_drv_unsupported_opt_for_target)
3017+
<< Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
3018+
<< TripleStr;
3019+
3020+
return FRecordCommandLine || TC.UseDwarfDebugFlags() || GRecordCommandLine;
3021+
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,32 @@ void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
234234
llvm::opt::ArgStringList &CmdArgs);
235235

236236
} // end namespace tools
237+
238+
/// Add backslashes to escape spaces and other backslashes.
239+
/// This is used for the space-separated argument list specified with
240+
/// the -dwarf-debug-flags option.
241+
void EscapeSpacesAndBackslashes(const char *Arg,
242+
llvm::SmallVectorImpl<char> &Res);
243+
244+
/// Join the args in the given ArgList, escape spaces and backslashes and
245+
/// return the joined string. This is used when saving the command line as a
246+
/// result of using either the -frecord-command-line or -grecord-command-line
247+
/// options. The lifetime of the returned c-string will match that of the Args
248+
/// argument.
249+
const char *RenderEscapedCommandLine(const ToolChain &TC,
250+
const llvm::opt::ArgList &Args);
251+
252+
/// Check if the command line should be recorded in the object file. This is
253+
/// done if either -frecord-command-line or -grecord-command-line options have
254+
/// been passed. This also does some error checking since -frecord-command-line
255+
/// is currently only supported on ELF platforms. The last two boolean
256+
/// arguments are out parameters and will be set depending on the command
257+
/// line options that were passed.
258+
bool ShouldRecordCommandLine(const ToolChain &TC,
259+
const llvm::opt::ArgList &Args,
260+
bool &FRecordCommandLine,
261+
bool &GRecordCommandLine);
262+
237263
} // end namespace driver
238264
} // end namespace clang
239265

clang/lib/Driver/ToolChains/CommonUtils.cpp

Lines changed: 0 additions & 76 deletions
This file was deleted.

clang/lib/Driver/ToolChains/CommonUtils.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "Flang.h"
1010
#include "Arch/RISCV.h"
1111
#include "CommonArgs.h"
12-
#include "CommonUtils.h"
1312

1413
#include "clang/Basic/CodeGenOptions.h"
1514
#include "clang/Driver/Options.h"

0 commit comments

Comments
 (0)