@@ -97,8 +97,7 @@ extern int swift_api_extract_main(ArrayRef<const char *> Args,
97
97
// / \returns True if running as a subcommand.
98
98
static bool shouldRunAsSubcommand (StringRef ExecName,
99
99
SmallString<256 > &SubcommandName,
100
- const ArrayRef<const char *> Args,
101
- bool &isRepl) {
100
+ const ArrayRef<const char *> Args) {
102
101
assert (!Args.empty ());
103
102
104
103
// If we are not run as 'swift', don't do anything special. This doesn't work
@@ -125,7 +124,6 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
125
124
// If the subcommand is the "built-in" 'repl', then use the
126
125
// normal driver.
127
126
if (Subcommand == " repl" ) {
128
- isRepl = true ;
129
127
return false ;
130
128
}
131
129
@@ -184,15 +182,18 @@ static bool appendSwiftDriverName(SmallString<256> &buffer) {
184
182
}
185
183
186
184
static int run_driver (StringRef ExecName,
187
- const ArrayRef<const char *> argv,
185
+ ArrayRef<const char *> argv,
188
186
const ArrayRef<const char *> originalArgv) {
189
187
// This is done here and not done in FrontendTool.cpp, because
190
188
// FrontendTool.cpp is linked to tools, which don't use swift modules.
191
189
initializeSwiftModules ();
192
190
191
+ bool isRepl = false ;
192
+
193
193
// Handle integrated tools.
194
194
if (argv.size () > 1 ) {
195
195
StringRef FirstArg (argv[1 ]);
196
+
196
197
if (FirstArg == " -frontend" ) {
197
198
return performFrontend (llvm::makeArrayRef (argv.data ()+2 ,
198
199
argv.data ()+argv.size ()),
@@ -212,6 +213,11 @@ static int run_driver(StringRef ExecName,
212
213
argv.data ()+argv.size ()),
213
214
argv[0 ], (void *)(intptr_t )getExecutablePath);
214
215
}
216
+
217
+ if (FirstArg == " repl" ) {
218
+ isRepl = true ;
219
+ argv = argv.drop_front ();
220
+ }
215
221
}
216
222
217
223
std::string Path = getExecutablePath (argv[0 ]);
@@ -245,8 +251,14 @@ static int run_driver(StringRef ExecName,
245
251
subCommandArgs.push_back (NewDriverPath.c_str ());
246
252
247
253
// Push on the source program arguments
248
- subCommandArgs.insert (subCommandArgs.end (),
249
- originalArgv.begin () + 1 , originalArgv.end ());
254
+ if (isRepl) {
255
+ subCommandArgs.push_back (" -repl" );
256
+ subCommandArgs.insert (subCommandArgs.end (),
257
+ originalArgv.begin () + 2 , originalArgv.end ());
258
+ } else {
259
+ subCommandArgs.insert (subCommandArgs.end (),
260
+ originalArgv.begin () + 1 , originalArgv.end ());
261
+ }
250
262
251
263
// Execute the subcommand.
252
264
subCommandArgs.push_back (nullptr );
@@ -361,8 +373,7 @@ int swift::mainEntry(int argc_, const char **argv_) {
361
373
// Check if this invocation should execute a subcommand.
362
374
StringRef ExecName = llvm::sys::path::stem (argv[0 ]);
363
375
SmallString<256 > SubcommandName;
364
- bool isRepl = false ;
365
- if (shouldRunAsSubcommand (ExecName, SubcommandName, argv, isRepl)) {
376
+ if (shouldRunAsSubcommand (ExecName, SubcommandName, argv)) {
366
377
// Preserve argv for the stack trace.
367
378
SmallVector<const char *, 256 > subCommandArgs (argv.begin (), argv.end ());
368
379
subCommandArgs.erase (&subCommandArgs[1 ]);
@@ -396,12 +407,5 @@ int swift::mainEntry(int argc_, const char **argv_) {
396
407
}
397
408
398
409
ArrayRef<const char *> originalArgv (argv_, &argv_[argc_]);
399
- if (isRepl) {
400
- // Preserve argv for the stack trace.
401
- SmallVector<const char *, 256 > replArgs (argv.begin (), argv.end ());
402
- replArgs.erase (&replArgs[1 ]);
403
- return run_driver (ExecName, replArgs, originalArgv);
404
- } else {
405
- return run_driver (ExecName, argv, originalArgv);
406
- }
410
+ return run_driver (ExecName, argv, originalArgv);
407
411
}
0 commit comments