Skip to content

Commit 2bd30ed

Browse files
committed
[sil-printer] Refactor out the printing logic for printing of a SILLocation into its own method. NFC.
1 parent 727b6c0 commit 2bd30ed

File tree

1 file changed

+85
-74
lines changed

1 file changed

+85
-74
lines changed

lib/SIL/SILPrinter.cpp

Lines changed: 85 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -549,99 +549,110 @@ class SILPrinter : public SILVisitor<SILPrinter> {
549549
return true;
550550
}
551551

552+
void printSILLocation(SILLocation L, SILModule &M, const SILDebugScope *DS,
553+
bool printedSlashes) {
554+
if (!L.isNull()) {
555+
if (!printedSlashes) {
556+
PrintState.OS.PadToColumn(50);
557+
*this << "//";
558+
}
559+
*this << " ";
560+
561+
// To minimize output, only print the line and column number for
562+
// everything but the first instruction.
563+
L.getSourceLoc().printLineAndColumn(PrintState.OS,
564+
M.getASTContext().SourceMgr);
565+
566+
// Print the type of location.
567+
switch (L.getKind()) {
568+
case SILLocation::NoneKind:
569+
assert(L.isAutoGenerated() && "This kind shouldn't be printed.");
570+
break;
571+
case SILLocation::RegularKind:
572+
break;
573+
case SILLocation::ReturnKind:
574+
*this << ":return";
575+
break;
576+
case SILLocation::ImplicitReturnKind:
577+
*this << ":imp_return";
578+
break;
579+
case SILLocation::InlinedKind:
580+
*this << ":inlined";
581+
break;
582+
case SILLocation::MandatoryInlinedKind:
583+
*this << ":minlined";
584+
break;
585+
case SILLocation::CleanupKind:
586+
*this << ":cleanup";
587+
break;
588+
case SILLocation::ArtificialUnreachableKind:
589+
*this << ":art_unreach";
590+
break;
591+
case SILLocation::SILFileKind:
592+
*this << ":sil";
593+
break;
594+
}
595+
if (L.isAutoGenerated())
596+
*this << ":auto_gen";
597+
if (L.isInPrologue())
598+
*this << ":in_prologue";
599+
}
600+
if (L.isNull()) {
601+
if (!printedSlashes) {
602+
PrintState.OS.PadToColumn(50);
603+
*this << "//";
604+
}
605+
if (L.isInTopLevel())
606+
*this << " top_level";
607+
else if (L.isAutoGenerated())
608+
*this << " auto_gen";
609+
else
610+
*this << " no_loc";
611+
if (L.isInPrologue())
612+
*this << ":in_prologue";
613+
}
614+
615+
// Print inlined-at location, if any.
616+
if (DS) {
617+
while (DS->InlinedCallSite) {
618+
*this << ": perf_inlined_at ";
619+
auto CallSite = DS->InlinedCallSite->Loc;
620+
if (!CallSite.isNull())
621+
CallSite.getSourceLoc().print(
622+
PrintState.OS, M.getASTContext().SourceMgr, LastBufferID);
623+
else
624+
*this << "?";
625+
DS = DS->InlinedCallSite;
626+
}
627+
}
628+
}
629+
552630
void print(SILValue V) {
553631
if (auto *FRI = dyn_cast<FunctionRefInst>(V))
554632
*this << " // function_ref "
555-
<< demangleSymbolAsString(FRI->getReferencedFunction()->getName())
556-
<< "\n";
633+
<< demangleSymbolAsString(FRI->getReferencedFunction()->getName())
634+
<< "\n";
557635

558636
*this << " ";
559637

560638
// Print result.
561639
if (V->hasValue()) {
562640
ID Name = getID(V);
563-
Name.ResultNumber = -1; // Don't print subresult number.
641+
Name.ResultNumber = -1; // Don't print subresult number.
564642
*this << Name << " = ";
565643
}
566644

567645
// Print the value.
568646
visit(V);
569647

570-
// Print users, or id for valueless instructions. Return true if we emitted
571-
// any output.
648+
// Print users, or id for valueless instructions.
572649
bool printedSlashes = printUsersOfSILValue(V);
573650

574651
// Print SIL location.
575652
if (Verbose) {
576-
if (SILInstruction *I = dyn_cast<SILInstruction>(V)) {
577-
SILLocation L = I->getLoc();
578-
SILModule &M = I->getModule();
579-
if (!L.isNull()) {
580-
if (!printedSlashes) {
581-
PrintState.OS.PadToColumn(50);
582-
*this << "//";
583-
}
584-
*this << " ";
585-
586-
// To minimize output, only print the line and column number for
587-
// everything but the first instruction.
588-
L.getSourceLoc().printLineAndColumn(PrintState.OS,
589-
M.getASTContext().SourceMgr);
590-
591-
// Print the type of location.
592-
switch (L.getKind()) {
593-
case SILLocation::NoneKind :
594-
assert(L.isAutoGenerated() && "This kind shouldn't be printed.");
595-
break;
596-
case SILLocation::RegularKind :
597-
break;
598-
case SILLocation::ReturnKind :
599-
*this << ":return"; break;
600-
case SILLocation::ImplicitReturnKind :
601-
*this << ":imp_return"; break;
602-
case SILLocation::InlinedKind :
603-
*this << ":inlined"; break;
604-
case SILLocation::MandatoryInlinedKind :
605-
*this << ":minlined"; break;
606-
case SILLocation::CleanupKind :
607-
*this << ":cleanup"; break;
608-
case SILLocation::ArtificialUnreachableKind :
609-
*this << ":art_unreach"; break;
610-
case SILLocation::SILFileKind :
611-
*this << ":sil"; break;
612-
}
613-
if (L.isAutoGenerated())
614-
*this << ":auto_gen";
615-
if (L.isInPrologue())
616-
*this << ":in_prologue";
617-
}
618-
if (L.isNull()) {
619-
if (!printedSlashes) {
620-
PrintState.OS.PadToColumn(50);
621-
*this << "//";
622-
}
623-
if (L.isInTopLevel())
624-
*this << " top_level";
625-
else if (L.isAutoGenerated())
626-
*this << " auto_gen";
627-
else
628-
*this << " no_loc";
629-
if (L.isInPrologue())
630-
*this << ":in_prologue";
631-
}
632-
633-
// Print inlined-at location, if any.
634-
if (auto DS = I->getDebugScope())
635-
while (DS->InlinedCallSite) {
636-
*this << ": perf_inlined_at ";
637-
auto CallSite = DS->InlinedCallSite->Loc;
638-
if (!CallSite.isNull())
639-
CallSite.getSourceLoc().
640-
print(PrintState.OS, M.getASTContext().SourceMgr, LastBufferID);
641-
else
642-
*this << "?";
643-
DS = DS->InlinedCallSite;
644-
}
653+
if (auto *I = dyn_cast<SILInstruction>(V)) {
654+
printSILLocation(I->getLoc(), I->getModule(), I->getDebugScope(),
655+
printedSlashes);
645656
}
646657
}
647658

0 commit comments

Comments
 (0)