Skip to content

Commit adb0e6e

Browse files
authored
Merge pull request swiftlang#27277 from nkcsgexi/add-source-info-to-driver
Frontend: set up output file .swiftsourceinfo
2 parents 88bc5b8 + 7013725 commit adb0e6e

28 files changed

+233
-33
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,13 @@ function(_compile_swift_files
310310
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
311311
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
312312
set(specific_module_dir "${module_base}.swiftmodule")
313+
set(specific_module_private_dir "${specific_module_dir}/Private")
314+
set(source_info_file "${specific_module_private_dir}/${SWIFTFILE_ARCHITECTURE}.swiftsourceinfo")
313315
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
314316
else()
315317
set(specific_module_dir)
318+
set(specific_module_private_dir)
319+
set(source_info_file "${module_base}.swiftsourceinfo")
316320
endif()
317321
set(module_file "${module_base}.swiftmodule")
318322
set(module_doc_file "${module_base}.swiftdoc")
@@ -322,6 +326,8 @@ function(_compile_swift_files
322326
set(sib_file "${module_base}.Onone.sib")
323327
set(sibopt_file "${module_base}.O.sib")
324328
set(sibgen_file "${module_base}.sibgen")
329+
list(APPEND swift_module_flags
330+
"-emit-module-source-info-path" "${source_info_file}")
325331

326332
if(SWIFT_ENABLE_MODULE_INTERFACES)
327333
set(interface_file "${module_base}.swiftinterface")
@@ -349,7 +355,8 @@ function(_compile_swift_files
349355
swift_install_in_component(DIRECTORY "${specific_module_dir}"
350356
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
351357
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}"
352-
OPTIONAL)
358+
OPTIONAL
359+
PATTERN "Private" EXCLUDE)
353360
else()
354361
swift_install_in_component(FILES ${module_outputs}
355362
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
@@ -490,6 +497,7 @@ function(_compile_swift_files
490497
COMMAND
491498
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
492499
${specific_module_dir}
500+
${specific_module_private_dir}
493501
COMMAND
494502
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
495503
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ ERROR(error_mode_cannot_emit_module,none,
124124
"this mode does not support emitting modules", ())
125125
ERROR(error_mode_cannot_emit_module_doc,none,
126126
"this mode does not support emitting module documentation files", ())
127+
ERROR(error_mode_cannot_emit_module_source_info,none,
128+
"this mode does not support emitting module source info files", ())
127129
ERROR(error_mode_cannot_emit_interface,none,
128130
"this mode does not support emitting module interface files", ())
129131

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TYPE("autolink", AutolinkFile, "autolink", "")
5050
TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
5151
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
5252
TYPE("swiftinterface", SwiftModuleInterfaceFile, "swiftinterface", "")
53+
TYPE("swiftsourceinfo", SwiftSourceInfoFile, "swiftsourceinfo", "")
5354
TYPE("assembly", Assembly, "s", "")
5455
TYPE("raw-sil", RawSIL, "sil", "")
5556
TYPE("raw-sib", RawSIB, "sib", "")

include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ struct SupplementaryOutputPaths {
4141
/// \sa swift::serialize
4242
std::string ModuleOutputPath;
4343

44+
/// The path to which we should emit a module source information file.
45+
/// It is valid whenever there are any inputs.
46+
///
47+
/// This binary format stores source locations and other information about the
48+
/// declarations in a module.
49+
///
50+
/// \sa swift::serialize
51+
std::string ModuleSourceInfoOutputPath;
52+
4453
/// The path to which we should emit a module documentation file.
4554
/// It is valid whenever there are any inputs.
4655
///
@@ -132,7 +141,8 @@ struct SupplementaryOutputPaths {
132141
ModuleDocOutputPath.empty() && DependenciesFilePath.empty() &&
133142
ReferenceDependenciesFilePath.empty() &&
134143
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
135-
TBDPath.empty() && ModuleInterfaceOutputPath.empty();
144+
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&
145+
ModuleSourceInfoOutputPath.empty();
136146
}
137147
};
138148
} // namespace swift

include/swift/Driver/Driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ class Driver {
354354
StringRef workingDirectory,
355355
CommandOutput *Output) const;
356356

357+
void chooseSwiftSourceInfoOutputPath(Compilation &C,
358+
const TypeToPathMap *OutputMap,
359+
StringRef workingDirectory,
360+
CommandOutput *Output) const;
361+
357362
void chooseModuleInterfacePath(Compilation &C, const JobAction *JA,
358363
StringRef workingDirectory,
359364
llvm::SmallString<128> &buffer,

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class FrontendInputsAndOutputs {
235235
bool hasLoadedModuleTracePath() const;
236236
bool hasModuleOutputPath() const;
237237
bool hasModuleDocOutputPath() const;
238+
bool hasModuleSourceInfoOutputPath() const;
238239
bool hasModuleInterfaceOutputPath() const;
239240
bool hasTBDPath() const;
240241

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def emit_module_doc_path
3838
: Separate<["-"], "emit-module-doc-path">, MetaVarName<"<path>">,
3939
HelpText<"Output module documentation file <path>">;
4040

41+
def emit_module_source_info : Flag<["-"], "emit-module-source-info">,
42+
HelpText<"Output module source info file">;
43+
4144
def merge_modules
4245
: Flag<["-"], "merge-modules">, ModeOpt,
4346
HelpText<"Merge the input modules without otherwise processing them">;

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ def emit_module_interface_path :
364364
ArgumentIsPath]>,
365365
MetaVarName<"<path>">, HelpText<"Output module interface file to <path>">;
366366

367+
def emit_module_source_info_path :
368+
Separate<["-"], "emit-module-source-info-path">,
369+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
370+
ArgumentIsPath]>,
371+
MetaVarName<"<path>">, HelpText<"Output module source info file to <path>">;
372+
367373
def emit_parseable_module_interface :
368374
Flag<["-"], "emit-parseable-module-interface">,
369375
Alias<emit_module_interface>,

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace swift {
2929

3030
const char *OutputPath = nullptr;
3131
const char *DocOutputPath = nullptr;
32+
const char *SourceInfoOutputPath = nullptr;
3233

3334
StringRef GroupInfoPath;
3435
StringRef ImportedHeader;

include/swift/Subsystems.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ namespace swift {
282282
const SerializationOptions &opts,
283283
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
284284
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
285+
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
285286
const SILModule *M = nullptr);
286287

287288
/// Get the CPU, subtarget feature options, and triple to use when emitting code.

0 commit comments

Comments
 (0)