@@ -1224,9 +1224,12 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
1224
1224
return hadAnyError;
1225
1225
}
1226
1226
1227
- // / Returns true if an error occurred.
1228
- static bool dumpAPI (ModuleDecl *Mod, StringRef OutDir) {
1227
+ static void dumpAPIIfNeeded (const CompilerInstance &Instance) {
1229
1228
using namespace llvm ::sys;
1229
+ const auto &Invocation = Instance.getInvocation ();
1230
+ StringRef OutDir = Invocation.getFrontendOptions ().DumpAPIPath ;
1231
+ if (OutDir.empty ())
1232
+ return ;
1230
1233
1231
1234
auto getOutPath = [&](SourceFile *SF) -> std::string {
1232
1235
SmallString<256 > Path = OutDir;
@@ -1274,16 +1277,14 @@ static bool dumpAPI(ModuleDecl *Mod, StringRef OutDir) {
1274
1277
if (EC) {
1275
1278
llvm::errs () << " error creating directory '" << OutDir << " ': "
1276
1279
<< EC.message () << ' \n ' ;
1277
- return true ;
1280
+ return ;
1278
1281
}
1279
1282
1280
- for (auto *FU : Mod ->getFiles ()) {
1283
+ for (auto *FU : Instance. getMainModule () ->getFiles ()) {
1281
1284
if (auto *SF = dyn_cast<SourceFile>(FU))
1282
1285
if (dumpFile (SF))
1283
- return true ;
1286
+ return ;
1284
1287
}
1285
-
1286
- return false ;
1287
1288
}
1288
1289
1289
1290
// / Perform any actions that must have access to the ASTContext, and need to be
@@ -1330,6 +1331,8 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
1330
1331
Instance.getMainModule (), Instance.getDependencyTracker (), opts);
1331
1332
1332
1333
emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance);
1334
+
1335
+ dumpAPIIfNeeded (Instance);
1333
1336
}
1334
1337
1335
1338
// Verify reference dependencies of the current compilation job. Note this
@@ -1623,12 +1626,7 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
1623
1626
return ;
1624
1627
}
1625
1628
1626
- // If we're going to dump the API of the module, we cannot tear down
1627
- // the ASTContext, as that would cause the module to be freed prematurely.
1628
1629
const auto &opts = Instance.getInvocation ().getFrontendOptions ();
1629
- if (!opts.DumpAPIPath .empty ()) {
1630
- return ;
1631
- }
1632
1630
1633
1631
// If there are multiple primary inputs it is too soon to free
1634
1632
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
@@ -2230,10 +2228,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2230
2228
2231
2229
int ReturnValue = 0 ;
2232
2230
bool HadError = performCompile (*Instance, Args, ReturnValue, observer);
2233
- if (!HadError && !Invocation.getFrontendOptions ().DumpAPIPath .empty ()) {
2234
- HadError = dumpAPI (Instance->getMainModule (),
2235
- Invocation.getFrontendOptions ().DumpAPIPath );
2236
- }
2237
2231
2238
2232
if (verifierEnabled) {
2239
2233
DiagnosticEngine &diags = Instance->getDiags ();
0 commit comments