@@ -28,6 +28,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
28
28
std::ostream& o;
29
29
unsigned indent = 0 ;
30
30
31
+ bool debugInfoComments = false ;
31
32
size_t lastDebugLocationId = 0 ;
32
33
std::vector<DebugLocation>* functionDebugLocations = nullptr ;
33
34
size_t lastLabelId = 0 ;
@@ -54,6 +55,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
54
55
55
56
void setFullAST (bool fullAST_) { fullAST = fullAST_; }
56
57
58
+ void setDebugInfoComments (bool debugInfoComments_) { debugInfoComments = debugInfoComments_; }
59
+
57
60
void incIndent () {
58
61
if (minify) return ;
59
62
o << ' \n ' ;
@@ -81,7 +84,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
81
84
}
82
85
83
86
void visit (Expression *curr) {
84
- if (curr->debugInfo .labelIndex != lastLabelId) {
87
+ if (debugInfoComments && curr->debugInfo .labelIndex != lastLabelId) {
85
88
lastLabelId = curr->debugInfo .labelIndex ;
86
89
if (functionLabels) { // no labels -- skipping
87
90
const Name& labelName = (*functionLabels)[lastLabelId];
@@ -90,7 +93,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
90
93
!minify && doIndent (o, indent);
91
94
}
92
95
}
93
- if (curr->debugInfo .locationIndex != lastDebugLocationId) {
96
+ if (debugInfoComments && curr->debugInfo .locationIndex != lastDebugLocationId) {
94
97
lastDebugLocationId = curr->debugInfo .locationIndex ;
95
98
// skipping location id 0 or debug information is absent
96
99
if (functionDebugLocations && lastDebugLocationId) {
@@ -491,7 +494,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
491
494
printMinorOpening (o, " local " ) << printableLocal (i) << ' ' << printWasmType (curr->getLocalType (i)) << " )" ;
492
495
o << maybeNewLine;
493
496
}
494
- if (functionLabels) { // no labels -- skipping
497
+ if (debugInfoComments && functionLabels) { // no labels -- skipping
495
498
const Name& labelName = (*functionLabels)[0 ]; // first label is normally a function name
496
499
doIndent (o, indent);
497
500
o << " (;!bookmark " << labelName.str << " ;)" ;
@@ -517,6 +520,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
517
520
o << ' )' ;
518
521
}
519
522
void printDebugSections (Module *curr) {
523
+ if (!debugInfoComments)
524
+ return ;
525
+
520
526
bool hasSequences = false ;
521
527
for (auto & child : curr->functions ) {
522
528
if (child->labels .size () > 0 ) {
@@ -606,12 +612,14 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
606
612
visitTable (&curr->table );
607
613
o << maybeNewLine;
608
614
}
609
- for (auto const &item : curr->debugFileMap ) {
610
- doIndent (o, indent);
611
- o << " (;!file " << item.first << " " ;
612
- printText (o, item.second .str );
613
- o << " ;)" ;
614
- o << maybeNewLine;
615
+ if (debugInfoComments) {
616
+ for (auto const &item : curr->debugFileMap ) {
617
+ doIndent (o, indent);
618
+ o << " (;!file " << item.first << " " ;
619
+ printText (o, item.second .str );
620
+ o << " ;)" ;
621
+ o << maybeNewLine;
622
+ }
615
623
}
616
624
for (auto & child : curr->functions ) {
617
625
doIndent (o, indent);
@@ -625,7 +633,10 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
625
633
};
626
634
627
635
void Printer::run (PassRunner* runner, Module* module ) {
628
- PrintSExpression print (o);
636
+ PrintSExpression print (args.o );
637
+ print.setMinify (args.minify );
638
+ print.setFullAST (args.fullAST );
639
+ print.setDebugInfoComments (args.debugInfo );
629
640
print.visitModule (module );
630
641
}
631
642
@@ -635,14 +646,8 @@ static RegisterPass<Printer> registerPass("print", "print in s-expression format
635
646
636
647
class MinifiedPrinter : public Printer {
637
648
public:
638
- MinifiedPrinter () : Printer() {}
639
- MinifiedPrinter (std::ostream& o) : Printer(o) {}
640
-
641
- void run (PassRunner* runner, Module* module ) override {
642
- PrintSExpression print (o);
643
- print.setMinify (true );
644
- print.visitModule (module );
645
- }
649
+ MinifiedPrinter () : Printer(PrinterArgs(std::cout, true , false , false )) {}
650
+ MinifiedPrinter (std::ostream& o) : Printer(PrinterArgs(o, true , false , false )) {}
646
651
};
647
652
648
653
static RegisterPass<MinifiedPrinter> registerMinifyPass (" print-minified" , " print in minified s-expression format" );
@@ -651,18 +656,21 @@ static RegisterPass<MinifiedPrinter> registerMinifyPass("print-minified", "print
651
656
652
657
class FullPrinter : public Printer {
653
658
public:
654
- FullPrinter () : Printer() {}
655
- FullPrinter (std::ostream& o) : Printer(o) {}
656
-
657
- void run (PassRunner* runner, Module* module ) override {
658
- PrintSExpression print (o);
659
- print.setFullAST (true );
660
- print.visitModule (module );
661
- }
659
+ FullPrinter () : Printer(PrinterArgs(std::cout, false , true , false )) {}
660
+ FullPrinter (std::ostream& o) : Printer(PrinterArgs(o, false , true , false )) {}
662
661
};
663
662
664
663
static RegisterPass<FullPrinter> registerFullASTPass (" print-full" , " print in full s-expression format" );
665
664
665
+ // Prints out full ast module with additional debug info comments
666
+ class DebugInfoCommentsPrinter : public Printer {
667
+ public:
668
+ DebugInfoCommentsPrinter () : Printer(PrinterArgs(std::cout, false , true , true )) {}
669
+ DebugInfoCommentsPrinter (std::ostream& o) : Printer(PrinterArgs(o, false , true , true )) {}
670
+ };
671
+
672
+ static RegisterPass<DebugInfoCommentsPrinter> registerDebugInfoCommentsPass (" print-debug-info" , " print in full s-expression format with debug info comments" );
673
+
666
674
// Print individual expressions
667
675
668
676
std::ostream& WasmPrinter::printExpression (Expression* expression, std::ostream& o, bool minify) {
0 commit comments