@@ -212,3 +212,217 @@ index a5dc3ccb845..30667ae51f9 100644
212
212
DESTINATION "bin"
213
213
COMPONENT editor-integration)
214
214
-
215
+ diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake
216
+ index 6d93e52f1d5..9ab79aeb9d6 100644
217
+ --- a/cmake/modules/AddSwift.cmake
218
+ +++ b/cmake/modules/AddSwift.cmake
219
+ @@ -715,6 +715,7 @@ function(add_swift_host_tool executable)
220
+
221
+ # Include the abi stable system stdlib in our rpath.
222
+ list(APPEND RPATH_LIST "/usr/lib/swift")
223
+ + list(APPEND RPATH_LIST "${SWIFTLIB_DIR}")
224
+
225
+ elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE-WITH-HOSTLIBS")
226
+
227
+ @@ -731,6 +732,7 @@ function(add_swift_host_tool executable)
228
+
229
+ # Include the abi stable system stdlib in our rpath.
230
+ list(APPEND RPATH_LIST "/usr/lib/swift")
231
+ + list(APPEND RPATH_LIST "@executable_path/../lib")
232
+
233
+ elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
234
+ # Add the SDK directory for the host platform.
235
+ @@ -798,7 +800,7 @@ function(add_swift_host_tool executable)
236
+ if(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
237
+ set_target_properties(${executable} PROPERTIES
238
+ BUILD_WITH_INSTALL_RPATH YES
239
+ - INSTALL_RPATH "${host_lib_dir}")
240
+ + INSTALL_RPATH "${host_lib_dir};$ORIGIN/../lib")
241
+ else()
242
+ set_target_properties(${executable} PROPERTIES
243
+ BUILD_WITH_INSTALL_RPATH YES
244
+ diff --git a/include/swift/DriverTool/FrontendObserver.h b/include/swift/DriverTool/FrontendObserver.h
245
+ new file mode 100644
246
+ index 00000000000..4ac9b299a13
247
+ --- /dev/null
248
+ +++ b/include/swift/DriverTool/FrontendObserver.h
249
+ @@ -0,0 +1,10 @@
250
+ + #pragma once
251
+ +
252
+ + #include "llvm/ADT/ArrayRef.h"
253
+ + #include "swift/FrontendTool/FrontendTool.h"
254
+ +
255
+ + namespace swift {
256
+ +
257
+ + FrontendObserver* getFrontendObserver(llvm::ArrayRef<const char*> argv);
258
+ +
259
+ + } // namespace swift
260
+ diff --git a/include/swift/FrontendTool/FrontendTool.h b/include/swift/FrontendTool/FrontendTool.h
261
+ index 184e6196918..ef5c3eafe69 100644
262
+ --- a/include/swift/FrontendTool/FrontendTool.h
263
+ +++ b/include/swift/FrontendTool/FrontendTool.h
264
+ @@ -53,6 +53,9 @@ public:
265
+ /// The frontend has executed the SIL optimization and diagnostics pipelines.
266
+ virtual void performedSILProcessing(SILModule &module);
267
+
268
+ + /// The frontend has finished executing with the given return value
269
+ + virtual void finished(int status);
270
+ +
271
+ // TODO: maybe enhance this interface to hear about IRGen and LLVM
272
+ // progress.
273
+ };
274
+ diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt
275
+ index ec3fa2c853b..c4afddc4940 100644
276
+ --- a/lib/AST/CMakeLists.txt
277
+ +++ b/lib/AST/CMakeLists.txt
278
+ @@ -58,7 +58,6 @@ add_swift_host_library(swiftAST STATIC
279
+ GenericParamList.cpp
280
+ GenericSignature.cpp
281
+ GenericSignatureBuilder.cpp
282
+ - Identifier.cpp
283
+ ImportCache.cpp
284
+ IndexSubset.cpp
285
+ InlinableText.cpp
286
+ @@ -122,6 +121,14 @@ add_swift_host_library(swiftAST STATIC
287
+ ${SWIFTAST_LLVM_LINK_COMPONENTS}
288
+ )
289
+
290
+ + add_swift_host_library(swiftIdentifier SHARED
291
+ + Identifier.cpp
292
+ + )
293
+ +
294
+ + if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
295
+ + target_link_options(swiftIdentifier PRIVATE "-undefined dynamic_lookup")
296
+ + endif()
297
+ +
298
+ if(SWIFT_FORCE_OPTIMIZED_TYPECHECKER)
299
+ if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL MSVC)
300
+ target_compile_options(swiftAST PRIVATE /O2 /Ob2)
301
+ @@ -152,7 +159,7 @@ if(NOT SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
302
+ endif()
303
+
304
+ target_link_libraries(swiftAST
305
+ - PUBLIC swiftBasic
306
+ + PUBLIC swiftBasic swiftIdentifier
307
+ PRIVATE swiftSyntax)
308
+ if(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
309
+ # Remove dependencies from clangBasic to avoid bringing along some llvm
310
+ diff --git a/lib/DriverTool/CMakeLists.txt b/lib/DriverTool/CMakeLists.txt
311
+ index 869c00fece9..21610d8eb95 100644
312
+ --- a/lib/DriverTool/CMakeLists.txt
313
+ +++ b/lib/DriverTool/CMakeLists.txt
314
+ @@ -14,16 +14,24 @@ set(driver_common_libs
315
+ swiftSymbolGraphGen
316
+ LLVMBitstreamReader)
317
+
318
+ + add_swift_host_library(swiftFrontendObserver SHARED
319
+ + swift_frontend_observer.cpp)
320
+ + target_link_libraries(swiftFrontendObserver
321
+ + PUBLIC
322
+ + swiftFrontendTool)
323
+ +
324
+ add_swift_host_library(swiftDriverTool STATIC
325
+ ${driver_sources_and_options}
326
+ )
327
+ target_link_libraries(swiftDriverTool
328
+ PUBLIC
329
+ - ${driver_common_libs})
330
+ + ${driver_common_libs}
331
+ + swiftFrontendObserver)
332
+
333
+ # If building as part of clang, make sure the headers are installed.
334
+ if(NOT SWIFT_BUILT_STANDALONE)
335
+ add_dependencies(swiftDriverTool clang-resource-headers)
336
+ endif()
337
+
338
+ + set_swift_llvm_is_available(swiftFrontendObserver)
339
+ set_swift_llvm_is_available(swiftDriverTool)
340
+ diff --git a/lib/DriverTool/driver.cpp b/lib/DriverTool/driver.cpp
341
+ index f71e2de9eae..a500e30827f 100644
342
+ --- a/lib/DriverTool/driver.cpp
343
+ +++ b/lib/DriverTool/driver.cpp
344
+ @@ -31,6 +31,7 @@
345
+ #include "swift/Frontend/PrintingDiagnosticConsumer.h"
346
+ #include "swift/FrontendTool/FrontendTool.h"
347
+ #include "swift/DriverTool/DriverTool.h"
348
+ + #include "swift/DriverTool/FrontendObserver.h"
349
+ #include "llvm/ADT/SmallVector.h"
350
+ #include "llvm/Support/CommandLine.h"
351
+ #include "llvm/Support/ConvertUTF.h"
352
+ @@ -197,7 +198,8 @@ static int run_driver(StringRef ExecName,
353
+ if (FirstArg == "-frontend") {
354
+ return performFrontend(llvm::makeArrayRef(argv.data()+2,
355
+ argv.data()+argv.size()),
356
+ - argv[0], (void *)(intptr_t)getExecutablePath);
357
+ + argv[0], (void *)(intptr_t)getExecutablePath,
358
+ + getFrontendObserver(argv));
359
+ }
360
+ if (FirstArg == "-modulewrap") {
361
+ return modulewrap_main(llvm::makeArrayRef(argv.data()+2,
362
+ @@ -211,7 +213,8 @@ static int run_driver(StringRef ExecName,
363
+ && ExecName == "swift-frontend") {
364
+ return performFrontend(llvm::makeArrayRef(argv.data()+1,
365
+ argv.data()+argv.size()),
366
+ - argv[0], (void *)(intptr_t)getExecutablePath);
367
+ + argv[0], (void *)(intptr_t)getExecutablePath,
368
+ + getFrontendObserver(argv));
369
+ }
370
+
371
+ if (FirstArg == "repl") {
372
+ diff --git a/lib/DriverTool/swift_frontend_observer.cpp b/lib/DriverTool/swift_frontend_observer.cpp
373
+ new file mode 100644
374
+ index 00000000000..e16b2f970cd
375
+ --- /dev/null
376
+ +++ b/lib/DriverTool/swift_frontend_observer.cpp
377
+ @@ -0,0 +1,9 @@
378
+ + #include "swift/DriverTool/FrontendObserver.h"
379
+ +
380
+ + namespace swift {
381
+ +
382
+ + FrontendObserver* getFrontendObserver(llvm::ArrayRef<const char*>) {
383
+ + return nullptr;
384
+ + }
385
+ +
386
+ + } // namespace swift
387
+ diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp
388
+ index 811fb912f8a..afa2034aa71 100644
389
+ --- a/lib/FrontendTool/FrontendTool.cpp
390
+ +++ b/lib/FrontendTool/FrontendTool.cpp
391
+ @@ -1924,7 +1924,7 @@ public:
392
+ };
393
+ };
394
+
395
+ - int swift::performFrontend(ArrayRef<const char *> Args,
396
+ + static int performFrontendImpl(ArrayRef<const char *> Args,
397
+ const char *Argv0, void *MainAddr,
398
+ FrontendObserver *observer) {
399
+ INITIALIZE_LLVM();
400
+ @@ -2263,8 +2263,19 @@ int swift::performFrontend(ArrayRef<const char *> Args,
401
+ return r;
402
+ }
403
+
404
+ + int swift::performFrontend(ArrayRef<const char *> Args,
405
+ + const char *Argv0, void *MainAddr,
406
+ + FrontendObserver *observer) {
407
+ + auto ret = performFrontendImpl(Args, Argv0, MainAddr, observer);
408
+ + if (observer) {
409
+ + observer->finished(ret);
410
+ + }
411
+ + return ret;
412
+ + }
413
+ +
414
+ void FrontendObserver::parsedArgs(CompilerInvocation &invocation) {}
415
+ void FrontendObserver::configuredCompiler(CompilerInstance &instance) {}
416
+ void FrontendObserver::performedSemanticAnalysis(CompilerInstance &instance) {}
417
+ void FrontendObserver::performedSILGeneration(SILModule &module) {}
418
+ void FrontendObserver::performedSILProcessing(SILModule &module) {}
419
+ + void FrontendObserver::finished(int status) {}
420
+ diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt
421
+ index a5dc3ccb845..30667ae51f9 100644
422
+ --- a/tools/driver/CMakeLists.txt
423
+ +++ b/tools/driver/CMakeLists.txt
424
+ @@ -123,4 +123,3 @@ add_dependencies(editor-integration swift-frontend)
425
+ swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
426
+ DESTINATION "bin"
427
+ COMPONENT editor-integration)
428
+ -
0 commit comments