@@ -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 ' ;
@@ -84,7 +87,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
84
87
}
85
88
86
89
void visit (Expression *curr) {
87
- if (curr->debugInfo .labelIndex != lastLabelId) {
90
+ if (debugInfoComments && curr->debugInfo .labelIndex != lastLabelId) {
88
91
lastLabelId = curr->debugInfo .labelIndex ;
89
92
if (functionLabels) { // no labels -- skipping
90
93
const Name& labelName = (*functionLabels)[lastLabelId];
@@ -93,7 +96,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
93
96
!minify && doIndent (o, indent);
94
97
}
95
98
}
96
- if (curr->debugInfo .locationIndex != lastDebugLocationId) {
99
+ if (debugInfoComments && curr->debugInfo .locationIndex != lastDebugLocationId) {
97
100
lastDebugLocationId = curr->debugInfo .locationIndex ;
98
101
// skipping location id 0 or debug information is absent
99
102
if (functionDebugLocations && lastDebugLocationId) {
@@ -561,7 +564,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
561
564
printMinorOpening (o, " local " ) << printableLocal (i) << ' ' << printWasmType (curr->getLocalType (i)) << " )" ;
562
565
o << maybeNewLine;
563
566
}
564
- if (functionLabels) { // no labels -- skipping
567
+ if (debugInfoComments && functionLabels) { // no labels -- skipping
565
568
const Name& labelName = (*functionLabels)[0 ]; // first label is normally a function name
566
569
doIndent (o, indent);
567
570
o << " (;!bookmark " << labelName.str << " ;)" ;
@@ -587,6 +590,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
587
590
o << ' )' ;
588
591
}
589
592
void printDebugSections (Module *curr) {
593
+ if (!debugInfoComments)
594
+ return ;
595
+
590
596
bool hasSequences = false ;
591
597
for (auto & child : curr->functions ) {
592
598
if (child->labels .size () > 0 ) {
@@ -676,12 +682,14 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
676
682
visitTable (&curr->table );
677
683
o << maybeNewLine;
678
684
}
679
- for (auto const &item : curr->debugFileMap ) {
680
- doIndent (o, indent);
681
- o << " (;!file " << item.first << " " ;
682
- printText (o, item.second .str );
683
- o << " ;)" ;
684
- o << maybeNewLine;
685
+ if (debugInfoComments) {
686
+ for (auto const &item : curr->debugFileMap ) {
687
+ doIndent (o, indent);
688
+ o << " (;!file " << item.first << " " ;
689
+ printText (o, item.second .str );
690
+ o << " ;)" ;
691
+ o << maybeNewLine;
692
+ }
685
693
}
686
694
for (auto & child : curr->functions ) {
687
695
doIndent (o, indent);
@@ -695,7 +703,10 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
695
703
};
696
704
697
705
void Printer::run (PassRunner* runner, Module* module ) {
698
- PrintSExpression print (o);
706
+ PrintSExpression print (args.o );
707
+ print.setMinify (args.minify );
708
+ print.setFullAST (args.fullAST );
709
+ print.setDebugInfoComments (args.debugInfo );
699
710
print.visitModule (module );
700
711
}
701
712
@@ -705,14 +716,8 @@ static RegisterPass<Printer> registerPass("print", "print in s-expression format
705
716
706
717
class MinifiedPrinter : public Printer {
707
718
public:
708
- MinifiedPrinter () : Printer() {}
709
- MinifiedPrinter (std::ostream& o) : Printer(o) {}
710
-
711
- void run (PassRunner* runner, Module* module ) override {
712
- PrintSExpression print (o);
713
- print.setMinify (true );
714
- print.visitModule (module );
715
- }
719
+ MinifiedPrinter () : Printer(PrinterArgs(std::cout, true , false , false )) {}
720
+ MinifiedPrinter (std::ostream& o) : Printer(PrinterArgs(o, true , false , false )) {}
716
721
};
717
722
718
723
static RegisterPass<MinifiedPrinter> registerMinifyPass (" print-minified" , " print in minified s-expression format" );
@@ -721,18 +726,21 @@ static RegisterPass<MinifiedPrinter> registerMinifyPass("print-minified", "print
721
726
722
727
class FullPrinter : public Printer {
723
728
public:
724
- FullPrinter () : Printer() {}
725
- FullPrinter (std::ostream& o) : Printer(o) {}
726
-
727
- void run (PassRunner* runner, Module* module ) override {
728
- PrintSExpression print (o);
729
- print.setFullAST (true );
730
- print.visitModule (module );
731
- }
729
+ FullPrinter () : Printer(PrinterArgs(std::cout, false , true , false )) {}
730
+ FullPrinter (std::ostream& o) : Printer(PrinterArgs(o, false , true , false )) {}
732
731
};
733
732
734
733
static RegisterPass<FullPrinter> registerFullASTPass (" print-full" , " print in full s-expression format" );
735
734
735
+ // Prints out full ast module with additional debug info comments
736
+ class DebugInfoCommentsPrinter : public Printer {
737
+ public:
738
+ DebugInfoCommentsPrinter () : Printer(PrinterArgs(std::cout, false , true , true )) {}
739
+ DebugInfoCommentsPrinter (std::ostream& o) : Printer(PrinterArgs(o, false , true , true )) {}
740
+ };
741
+
742
+ static RegisterPass<DebugInfoCommentsPrinter> registerDebugInfoCommentsPass (" print-debug-info" , " print in full s-expression format with debug info comments" );
743
+
736
744
// Print individual expressions
737
745
738
746
std::ostream& WasmPrinter::printExpression (Expression* expression, std::ostream& o, bool minify) {
0 commit comments