Skip to content

Commit f6643af

Browse files
[Printer] Update printSIL to make sure LLDB doesn't break.
For more context, see: 1. swiftlang/swift#29239 - original PR which introduced the change, including an LLDB-side change. 2. The immediately preceding commit, which reverted this change. 3. swiftlang/swift#29350 which revealed some breakage caused by the changes in PR 29239 (unrelated to printing).
1 parent ae35884 commit f6643af

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

include/swift/SIL/SILModule.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ class SILModule {
166166
/// Functions, which are dead (and not in the functions list anymore),
167167
/// but kept alive for debug info generation.
168168
FunctionListType zombieFunctions;
169-
169+
170170
/// Stores the names of zombie functions.
171171
llvm::BumpPtrAllocator zombieFunctionNames;
172-
172+
173173
/// Lookup table for SIL vtables from class decls.
174174
llvm::DenseMap<const ClassDecl *, SILVTable *> VTableMap;
175175

@@ -211,7 +211,7 @@ class SILModule {
211211

212212
// The map of SILCoverageMaps in the module.
213213
CoverageMapCollectionType coverageMaps;
214-
214+
215215
// The list of SILProperties in the module.
216216
PropertyListType properties;
217217

@@ -502,7 +502,7 @@ class SILModule {
502502

503503
PropertyListType &getPropertyList() { return properties; }
504504
const PropertyListType &getPropertyList() const { return properties; }
505-
505+
506506
/// Look for a global variable by name.
507507
///
508508
/// \return null if this module has no such global variable
@@ -630,7 +630,7 @@ class SILModule {
630630

631631
/// Pretty-print the module.
632632
void dump(bool Verbose = false) const;
633-
633+
634634
/// Pretty-print the module to a file.
635635
/// Useful for dumping the module when running in a debugger.
636636
/// Warning: no error handling is done. Fails with an assert if the file
@@ -643,11 +643,14 @@ class SILModule {
643643
/// \param M If present, the types and declarations from this module will be
644644
/// printed. The module would usually contain the types and Decls that
645645
/// the SIL module depends on.
646+
/// \param Opts The SIL options, used to determine printing verbosity and
647+
/// and sorting.
646648
/// \param PrintASTDecls If set to true print AST decls.
647-
void print(raw_ostream &OS, bool Verbose = false,
648-
ModuleDecl *M = nullptr, bool ShouldSort = false,
649+
void print(raw_ostream& OS,
650+
ModuleDecl *M = nullptr,
651+
const SILOptions &Opts = SILOptions(),
649652
bool PrintASTDecls = true) const {
650-
SILPrintContext PrintCtx(OS, Verbose, ShouldSort);
653+
SILPrintContext PrintCtx(OS, Opts);
651654
print(PrintCtx, M, PrintASTDecls);
652655
}
653656

include/swift/SIL/SILPrintContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_PRINTCONTEXT_H
1414
#define SWIFT_SIL_PRINTCONTEXT_H
1515

16+
#include "swift/AST/SILOptions.h"
1617
#include "swift/SIL/SILDebugScope.h"
1718
#include "swift/SIL/SILValue.h"
1819
#include "llvm/ADT/DenseMap.h"
@@ -72,6 +73,11 @@ class SILPrintContext {
7273
SILPrintContext(llvm::raw_ostream &OS, bool Verbose = false,
7374
bool SortedSIL = false);
7475

76+
/// Constructor based on SILOptions.
77+
///
78+
/// DebugInfo will be set according to the -sil-print-debuginfo option.
79+
SILPrintContext(llvm::raw_ostream &OS, const SILOptions &Opts);
80+
7581
SILPrintContext(llvm::raw_ostream &OS, bool Verbose,
7682
bool SortedSIL, bool DebugInfo);
7783

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,20 +499,20 @@ static bool emitSyntax(SourceFile *SF, StringRef OutputFilename) {
499499
}
500500

501501
/// Writes SIL out to the given file.
502-
static bool writeSIL(SILModule &SM, ModuleDecl *M, bool EmitVerboseSIL,
503-
StringRef OutputFilename, bool SortSIL) {
502+
static bool writeSIL(SILModule &SM, ModuleDecl *M, const SILOptions &Opts,
503+
StringRef OutputFilename) {
504504
auto OS = getFileOutputStream(OutputFilename, M->getASTContext());
505505
if (!OS) return true;
506-
SM.print(*OS, EmitVerboseSIL, M, SortSIL);
506+
SM.print(*OS, M, Opts);
507507

508508
return M->getASTContext().hadError();
509509
}
510510

511511
static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs,
512512
const CompilerInstance &Instance,
513-
const SILOptions &opts) {
514-
return writeSIL(SM, Instance.getMainModule(), opts.EmitVerboseSIL,
515-
PSPs.OutputFilename, opts.EmitSortedSIL);
513+
const SILOptions &Opts) {
514+
return writeSIL(SM, Instance.getMainModule(), Opts,
515+
PSPs.OutputFilename);
516516
}
517517

518518
/// Prints the Objective-C "generated header" interface for \p M to \p

lib/SIL/SILPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,11 @@ SILPrintContext::SILPrintContext(llvm::raw_ostream &OS, bool Verbose,
31163116
OutStream(OS), Verbose(Verbose), SortedSIL(SortedSIL),
31173117
DebugInfo(SILPrintDebugInfo) { }
31183118

3119+
SILPrintContext::SILPrintContext(llvm::raw_ostream &OS,
3120+
const SILOptions &Opts) :
3121+
OutStream(OS), Verbose(Opts.EmitVerboseSIL), SortedSIL(Opts.EmitSortedSIL),
3122+
DebugInfo(SILPrintDebugInfo) {}
3123+
31193124
SILPrintContext::SILPrintContext(llvm::raw_ostream &OS, bool Verbose,
31203125
bool SortedSIL, bool DebugInfo) :
31213126
OutStream(OS), Verbose(Verbose), SortedSIL(SortedSIL),

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,13 @@ int main(int argc, char **argv) {
355355
const StringRef OutputFile =
356356
OutputFilename.size() ? StringRef(OutputFilename) : "-";
357357

358+
auto SILOpts = SILOptions();
359+
SILOpts.EmitVerboseSIL = EmitVerboseSIL;
360+
SILOpts.EmitSortedSIL = EnableSILSortOutput;
361+
358362
if (OutputFile == "-") {
359-
CI.getSILModule()->print(llvm::outs(), EmitVerboseSIL, CI.getMainModule(),
360-
EnableSILSortOutput, !DisableASTDump);
363+
CI.getSILModule()->print(llvm::outs(), CI.getMainModule(), SILOpts,
364+
!DisableASTDump);
361365
} else {
362366
std::error_code EC;
363367
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
@@ -366,8 +370,8 @@ int main(int argc, char **argv) {
366370
<< '\n';
367371
return 1;
368372
}
369-
CI.getSILModule()->print(OS, EmitVerboseSIL, CI.getMainModule(),
370-
EnableSILSortOutput, !DisableASTDump);
373+
CI.getSILModule()->print(OS, CI.getMainModule(), SILOpts,
374+
!DisableASTDump);
371375
}
372376
}
373377
}

tools/sil-opt/SILOpt.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ int main(int argc, char **argv) {
479479
} else {
480480
const StringRef OutputFile = OutputFilename.size() ?
481481
StringRef(OutputFilename) : "-";
482-
482+
auto SILOpts = SILOptions();
483+
SILOpts.EmitVerboseSIL = EmitVerboseSIL;
484+
SILOpts.EmitSortedSIL = EnableSILSortOutput;
483485
if (OutputFile == "-") {
484-
CI.getSILModule()->print(llvm::outs(), EmitVerboseSIL, CI.getMainModule(),
485-
EnableSILSortOutput, !DisableASTDump);
486+
CI.getSILModule()->print(llvm::outs(), CI.getMainModule(),
487+
SILOpts, !DisableASTDump);
486488
} else {
487489
std::error_code EC;
488490
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
@@ -491,8 +493,8 @@ int main(int argc, char **argv) {
491493
<< EC.message() << '\n';
492494
return 1;
493495
}
494-
CI.getSILModule()->print(OS, EmitVerboseSIL, CI.getMainModule(),
495-
EnableSILSortOutput, !DisableASTDump);
496+
CI.getSILModule()->print(OS, CI.getMainModule(), SILOpts,
497+
!DisableASTDump);
496498
}
497499
}
498500

0 commit comments

Comments
 (0)