Skip to content

Commit 8208b3a

Browse files
committed
[Macros] Add debug logs for macro expansions
These can be enabled with `-Xcc -mllvm -debug-only=macros`.
1 parent ce6664f commit 8208b3a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include "swift/Subsystems.h"
5353
#include "llvm/Config/config.h"
5454

55+
#define DEBUG_TYPE "macros"
56+
5557
using namespace swift;
5658

5759
/// Translate an argument provided as a string literal into an identifier,
@@ -1201,6 +1203,11 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion,
12011203

12021204
PrettyStackTraceFreestandingMacroExpansion debugStack(
12031205
"expanding freestanding macro", expansion);
1206+
LLVM_DEBUG(
1207+
llvm::dbgs() << "\nexpanding macro:\n";
1208+
macro->print(llvm::dbgs(), PrintOptions::printEverything());
1209+
llvm::dbgs() << "\n";
1210+
);
12041211

12051212
// Builtin macros are handled via ASTGen.
12061213
auto *astGenSourceFile = sourceFile->getExportedSourceFile();
@@ -1527,6 +1534,18 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
15271534
auto *astGenAttrSourceFile = attrSourceFile->getExportedSourceFile();
15281535
if (!astGenAttrSourceFile)
15291536
return nullptr;
1537+
LLVM_DEBUG(
1538+
StreamPrinter P(llvm::dbgs());
1539+
llvm::dbgs() << "\nexpanding macro:\n";
1540+
attr->print(P, PrintOptions::printEverything(), attachedTo);
1541+
llvm::dbgs() << "\nattached to:\n";
1542+
attachedTo->print(P, PrintOptions::printEverything());
1543+
if (parentDecl) {
1544+
llvm::dbgs() << "\nwith parent:\n";
1545+
parentDecl->print(P, PrintOptions::printEverything());
1546+
}
1547+
llvm::dbgs() << "\n";
1548+
);
15301549

15311550
auto *astGenDeclSourceFile = declSourceFile->getExportedSourceFile();
15321551
if (!astGenDeclSourceFile)
@@ -1677,6 +1696,14 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro,
16771696
#if SWIFT_BUILD_SWIFT_SYNTAX
16781697
PrettyStackTraceExpr debugStack(
16791698
ctx, "expanding attached macro", attachedTo);
1699+
LLVM_DEBUG(
1700+
StreamPrinter P(llvm::dbgs());
1701+
llvm::dbgs() << "\nexpanding macro:\n";
1702+
attr->print(P, PrintOptions::printEverything(), nullptr);
1703+
llvm::dbgs() << "\nattached to:\n";
1704+
attachedTo->print(P, PrintOptions::printEverything());
1705+
llvm::dbgs() << "\n";
1706+
);
16801707

16811708
auto *astGenAttrSourceFile = attrSourceFile->getExportedSourceFile();
16821709
if (!astGenAttrSourceFile)

0 commit comments

Comments
 (0)