@@ -223,7 +223,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
223
223
// / identifying the conditions under which the module was built.
224
224
std::string getModuleHash () const ;
225
225
226
- using StringAllocator = llvm::function_ref<const char *(const llvm:: Twine &)>;
226
+ using StringAllocator = llvm::function_ref<const char *(const Twine &)>;
227
227
// / Generate cc1-compatible command line arguments from this instance.
228
228
// /
229
229
// / \param [out] Args - The generated arguments. Note that the caller is
@@ -233,7 +233,21 @@ class CompilerInvocation : public CompilerInvocationRefBase,
233
233
// / command line argument and return a pointer to the newly allocated string.
234
234
// / The returned pointer is what gets appended to Args.
235
235
void generateCC1CommandLine (llvm::SmallVectorImpl<const char *> &Args,
236
- StringAllocator SA) const ;
236
+ StringAllocator SA) const {
237
+ generateCC1CommandLine ([&](const Twine &Arg) {
238
+ // No need to allocate static string literals.
239
+ Args.push_back (Arg.isSingleStringLiteral ()
240
+ ? Arg.getSingleStringRef ().data ()
241
+ : SA (Arg));
242
+ });
243
+ }
244
+
245
+ using ArgumentConsumer = llvm::function_ref<void (const Twine &)>;
246
+ // / Generate cc1-compatible command line arguments from this instance.
247
+ // /
248
+ // / \param Consumer - Callback that gets invoked for every single generated
249
+ // / command line argument.
250
+ void generateCC1CommandLine (ArgumentConsumer Consumer) const ;
237
251
238
252
// / Generate cc1-compatible command line arguments from this instance,
239
253
// / wrapping the result as a std::vector<std::string>.
@@ -267,8 +281,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,
267
281
268
282
// / Generate command line options from DiagnosticOptions.
269
283
static void GenerateDiagnosticArgs (const DiagnosticOptions &Opts,
270
- SmallVectorImpl< const char *> &Args ,
271
- StringAllocator SA, bool DefaultDiagColor);
284
+ ArgumentConsumer Consumer ,
285
+ bool DefaultDiagColor);
272
286
273
287
// / Parse command line options that map to LangOptions.
274
288
static bool ParseLangArgs (LangOptions &Opts, llvm::opt::ArgList &Args,
@@ -278,8 +292,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
278
292
279
293
// / Generate command line options from LangOptions.
280
294
static void GenerateLangArgs (const LangOptions &Opts,
281
- SmallVectorImpl<const char *> &Args,
282
- StringAllocator SA, const llvm::Triple &T,
295
+ ArgumentConsumer Consumer, const llvm::Triple &T,
283
296
InputKind IK);
284
297
285
298
// / Parse command line options that map to CodeGenOptions.
@@ -291,8 +304,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,
291
304
292
305
// Generate command line options from CodeGenOptions.
293
306
static void GenerateCodeGenArgs (const CodeGenOptions &Opts,
294
- SmallVectorImpl< const char *> &Args ,
295
- StringAllocator SA, const llvm::Triple &T,
307
+ ArgumentConsumer Consumer ,
308
+ const llvm::Triple &T,
296
309
const std::string &OutputFile,
297
310
const LangOptions *LangOpts);
298
311
};
0 commit comments