Frontend: teach final module emitting jobs to dump a placeholder file for module semantic info

This additional supplement output should capture semantic info the compiler has
captured while building a Swift module. Similar to the source info file, the content of
the semantic info file should only be consumed by local tooling written in Swift.
This commit is contained in:
Xi Ge
2021-10-11 12:44:01 -07:00
parent c2fd49cebb
commit 2d43a9259e
11 changed files with 100 additions and 1 deletions

View File

@@ -80,6 +80,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/FileSystem.h"
#if __has_include(<unistd.h>)
#include <unistd.h>
@@ -660,6 +661,22 @@ static void emitSwiftdepsForAllPrimaryInputsIfNeeded(
}
}
static bool writeModuleSemanticInfoIfNeeded(CompilerInstance &Instance) {
const auto &Invocation = Instance.getInvocation();
const auto &frontendOpts = Invocation.getFrontendOptions();
if (!frontendOpts.InputsAndOutputs.hasModuleSemanticInfoOutputPath())
return false;
std::error_code EC;
assert(frontendOpts.InputsAndOutputs.isWholeModule() &&
"TBDPath only makes sense when the whole module can be seen");
auto ModuleSemanticPath = frontendOpts.InputsAndOutputs
.getPrimarySpecificPathsForAtMostOnePrimary().SupplementaryOutputs
.ModuleSemanticInfoOutputPath;
llvm::raw_fd_ostream OS(ModuleSemanticPath, EC, llvm::sys::fs::OF_None);
OS << "{}\n";
return false;
}
static bool writeTBDIfNeeded(CompilerInstance &Instance) {
const auto &Invocation = Instance.getInvocation();
const auto &frontendOpts = Invocation.getFrontendOptions();
@@ -842,6 +859,9 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
hadAnyError |= writeTBDIfNeeded(Instance);
}
{
hadAnyError |= writeModuleSemanticInfoIfNeeded(Instance);
}
return hadAnyError;
}