Skip to content

Commit b58b6cc

Browse files
authored
Merge pull request #82548 from meg-gupta/printast
[NFC] Add a flag to print a function's ast before SILGen
2 parents 4ea6c23 + f19adca commit b58b6cc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
using namespace swift;
5252
using namespace Lowering;
5353

54+
llvm::cl::list<std::string> PrintFunctionAST(
55+
"print-function-ast", llvm::cl::CommaSeparated,
56+
llvm::cl::desc("Only print out the ast for this function"));
57+
5458
//===----------------------------------------------------------------------===//
5559
// SILGenModule Class implementation
5660
//===----------------------------------------------------------------------===//
@@ -879,6 +883,22 @@ void SILGenModule::visit(Decl *D) {
879883
ASTVisitor::visit(D);
880884
}
881885

886+
static bool isInPrintFunctionList(AbstractFunctionDecl *fd) {
887+
if (PrintFunctionAST.empty()) {
888+
return false;
889+
}
890+
auto fnName = SILDeclRef(fd).mangle();
891+
for (const std::string &printFnName : PrintFunctionAST) {
892+
if (printFnName == fnName)
893+
return true;
894+
if (!printFnName.empty() && printFnName[0] != '$' && !fnName.empty() &&
895+
fnName[0] == '$' && printFnName == fnName.substr(1)) {
896+
return true;
897+
}
898+
}
899+
return false;
900+
}
901+
882902
void SILGenModule::visitFuncDecl(FuncDecl *fd) { emitFunction(fd); }
883903

884904
void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
@@ -1477,6 +1497,11 @@ void SILGenModule::emitDifferentiabilityWitness(
14771497
}
14781498

14791499
void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
1500+
if (isInPrintFunctionList(AFD)) {
1501+
auto &out = llvm::errs();
1502+
AFD->dump(out);
1503+
}
1504+
14801505
// Emit default arguments and property wrapper initializers.
14811506
emitArgumentGenerators(AFD, AFD->getParameters());
14821507

0 commit comments

Comments
 (0)