Frontend: set up output file .swiftsourceinfo

This patch will focus on teaching driver and frontend to emit this file.
The actual content and de-serialization parts will come later.

More details: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation/28794
This commit is contained in:
Xi Ge
2019-09-18 13:17:11 -07:00
parent 4e476ff243
commit 3103b5cec1
21 changed files with 146 additions and 8 deletions

View File

@@ -4738,6 +4738,7 @@ void swift::serializeToBuffers(
ModuleOrSourceFile DC, const SerializationOptions &options,
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
const SILModule *M) {
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
@@ -4774,6 +4775,22 @@ void swift::serializeToBuffers(
*moduleDocBuffer = llvm::make_unique<llvm::SmallVectorMemoryBuffer>(
std::move(buf), options.DocOutputPath);
}
if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
SharedTimer timer("Serialization, swiftsourceinfo, to buffer");
llvm::SmallString<1024> buf;
llvm::raw_svector_ostream stream(buf);
writeSourceInfoToStream(stream, DC);
(void)withOutputFile(getContext(DC).Diags,
options.SourceInfoOutputPath,
[&](raw_ostream &out) {
out << stream.str();
return false;
});
if (moduleSourceInfoBuffer)
*moduleSourceInfoBuffer = llvm::make_unique<llvm::SmallVectorMemoryBuffer>(
std::move(buf), options.SourceInfoOutputPath);
}
}
void swift::serialize(ModuleOrSourceFile DC,
@@ -4807,4 +4824,14 @@ void swift::serialize(ModuleOrSourceFile DC,
return false;
});
}
if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
(void)withOutputFile(getContext(DC).Diags,
options.SourceInfoOutputPath,
[&](raw_ostream &out) {
SharedTimer timer("Serialization, swiftsourceinfo");
writeSourceInfoToStream(out, DC);
return false;
});
}
}