diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 10 | ||||
-rw-r--r-- | src/dataflow/utils.h | 3 | ||||
-rw-r--r-- | src/ir/LocalGraph.cpp | 1 | ||||
-rw-r--r-- | src/parsing.h | 2 | ||||
-rw-r--r-- | src/passes/PostAssemblyScript.cpp | 21 | ||||
-rw-r--r-- | src/passes/Print.cpp | 82 | ||||
-rw-r--r-- | src/passes/ReReloop.cpp | 4 | ||||
-rw-r--r-- | src/passes/Souperify.cpp | 3 | ||||
-rw-r--r-- | src/passes/TrapMode.cpp | 1 | ||||
-rw-r--r-- | src/passes/pass.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 2 | ||||
-rw-r--r-- | src/tools/wasm-dis.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 7 | ||||
-rw-r--r-- | src/tools/wasm-metadce.cpp | 2 | ||||
-rw-r--r-- | src/tools/wasm-opt.cpp | 5 | ||||
-rw-r--r-- | src/tools/wasm-shell.cpp | 3 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 2 | ||||
-rw-r--r-- | src/wasm-printing.h | 70 | ||||
-rw-r--r-- | src/wasm-validator.h | 1 | ||||
-rw-r--r-- | src/wasm.h | 7 | ||||
-rw-r--r-- | src/wasm/wasm-io.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 7 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 8 | ||||
-rw-r--r-- | src/wasm2js.h | 2 |
24 files changed, 96 insertions, 159 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 7365a3863..29724ec10 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -29,7 +29,6 @@ #include "wasm-binary.h" #include "wasm-builder.h" #include "wasm-interpreter.h" -#include "wasm-printing.h" #include "wasm-s-parser.h" #include "wasm-validator.h" #include "wasm.h" @@ -1276,8 +1275,7 @@ void BinaryenExpressionSetType(BinaryenExpressionRef expr, BinaryenType type) { ((Expression*)expr)->type = Type(type); } void BinaryenExpressionPrint(BinaryenExpressionRef expr) { - WasmPrinter::printExpression((Expression*)expr, std::cout); - std::cout << '\n'; + std::cout << *(Expression*)expr << '\n'; } void BinaryenExpressionFinalize(BinaryenExpressionRef expr) { ReFinalizeNode().visit((Expression*)expr); @@ -3382,7 +3380,7 @@ BinaryenModuleRef BinaryenModuleParse(const char* text) { } void BinaryenModulePrint(BinaryenModuleRef module) { - WasmPrinter::printModule((Module*)module); + std::cout << *(Module*)module; } void BinaryenModulePrintAsmjs(BinaryenModuleRef module) { @@ -3546,7 +3544,7 @@ size_t BinaryenModuleWriteText(BinaryenModuleRef module, // use a stringstream as an std::ostream. Extract the std::string // representation, and then store in the output. std::stringstream ss; - WasmPrinter::printModule((Module*)module, ss); + ss << *(Module*)module; const auto temp = ss.str(); const auto ctemp = temp.c_str(); @@ -3591,7 +3589,7 @@ BinaryenModuleAllocateAndWrite(BinaryenModuleRef module, char* BinaryenModuleAllocateAndWriteText(BinaryenModuleRef module) { std::stringstream ss; - WasmPrinter::printModule((Module*)module, ss); + ss << *(Module*)module; const std::string out = ss.str(); const int len = out.length() + 1; diff --git a/src/dataflow/utils.h b/src/dataflow/utils.h index 436ccc4d8..02625212e 100644 --- a/src/dataflow/utils.h +++ b/src/dataflow/utils.h @@ -26,7 +26,6 @@ #define wasm_dataflow_utils_h #include "dataflow/node.h" -#include "wasm-printing.h" #include "wasm.h" namespace wasm { @@ -47,7 +46,7 @@ inline std::ostream& dump(Node* node, std::ostream& o, size_t indent = 0) { break; case Node::Type::Expr: { o << "expr "; - WasmPrinter::printExpression(node->expr, o, true); + o << *node->expr << '\n'; break; } case Node::Type::Phi: diff --git a/src/ir/LocalGraph.cpp b/src/ir/LocalGraph.cpp index dd7046351..bf1f7e576 100644 --- a/src/ir/LocalGraph.cpp +++ b/src/ir/LocalGraph.cpp @@ -20,7 +20,6 @@ #include <ir/find_all.h> #include <ir/local-graph.h> #include <wasm-builder.h> -#include <wasm-printing.h> namespace wasm { diff --git a/src/parsing.h b/src/parsing.h index 680f2f5cc..22d45de07 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -26,7 +26,7 @@ #include "shared-constants.h" #include "support/colors.h" #include "support/utilities.h" -#include "wasm-printing.h" +#include "wasm-traversal.h" #include "wasm.h" namespace wasm { diff --git a/src/passes/PostAssemblyScript.cpp b/src/passes/PostAssemblyScript.cpp index eeb077ce9..aa9c5cc40 100644 --- a/src/passes/PostAssemblyScript.cpp +++ b/src/passes/PostAssemblyScript.cpp @@ -28,7 +28,6 @@ #include <unordered_map> #include <unordered_set> #ifdef POST_ASSEMBLYSCRIPT_DEBUG -#include "wasm-printing.h" #include <iostream> #endif @@ -468,14 +467,14 @@ struct OptimizeARC : public WalkerPass<PostWalker<OptimizeARC>> { if (allBalanced) { #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " eliminating "; - WasmPrinter::printExpression(retain, std::cerr, true); + std::cerr << *retain << '\n'; std::cerr << " reaching\n"; #endif redundantRetains.insert(retainLocation); for (auto** getLocation : releaseLocations) { #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " "; - WasmPrinter::printExpression(*getLocation, std::cerr, true); + std::cerr << **getLocation << '\n'; std::cerr << "\n"; #endif redundantReleases.insert(getLocation); @@ -483,28 +482,28 @@ struct OptimizeARC : public WalkerPass<PostWalker<OptimizeARC>> { #ifdef POST_ASSEMBLYSCRIPT_DEBUG } else { std::cerr << " cannot eliminate "; - WasmPrinter::printExpression(retain, std::cerr, true); + std::cerr << *retain << '\n'; std::cerr << " - unbalanced\n"; #endif } #ifdef POST_ASSEMBLYSCRIPT_DEBUG } else { std::cerr << " cannot eliminate "; - WasmPrinter::printExpression(retain, std::cerr, true); + std::cerr << *retain << '\n'; std::cerr << " - zero releases\n"; #endif } #ifdef POST_ASSEMBLYSCRIPT_DEBUG } else { std::cerr << " cannot eliminate "; - WasmPrinter::printExpression(retain, std::cerr, true); + std::cerr << *retain << '\n'; std::cerr << " - retains allocation\n"; #endif } #ifdef POST_ASSEMBLYSCRIPT_DEBUG } else { std::cerr << " cannot eliminate "; - WasmPrinter::printExpression(retain, std::cerr, true); + std::cerr << *retain << '\n'; std::cerr << " - reaches return\n"; #endif } @@ -560,7 +559,7 @@ struct FinalizeARC : public WalkerPass<PostWalker<FinalizeARC>> { // __release(__retain(__alloc(...))) - unnecessary allocation #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " finalizing "; - WasmPrinter::printExpression(curr, std::cerr, true); + std::cerr << *curr << '\n'; std::cerr << " - unnecessary allocation\n"; #endif Builder builder(*getModule()); @@ -574,7 +573,7 @@ struct FinalizeARC : public WalkerPass<PostWalker<FinalizeARC>> { // __release(__retain(...)) - unnecessary pair #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " finalizing "; - WasmPrinter::printExpression(curr, std::cerr, true); + std::cerr << *curr << '\n'; std::cerr << " - unnecessary pair\n"; #endif Builder builder(*getModule()); @@ -586,7 +585,7 @@ struct FinalizeARC : public WalkerPass<PostWalker<FinalizeARC>> { // __release(42) - unnecessary static release #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " finalizing "; - WasmPrinter::printExpression(curr, std::cerr, true); + std::cerr << *curr << '\n'; std::cerr << " - static release\n"; #endif Builder builder(*getModule()); @@ -598,7 +597,7 @@ struct FinalizeARC : public WalkerPass<PostWalker<FinalizeARC>> { // __retain(42) - unnecessary static retain #ifdef POST_ASSEMBLYSCRIPT_DEBUG std::cerr << " finalizing "; - WasmPrinter::printExpression(curr, std::cerr, true); + std::cerr << *curr << '\n'; std::cerr << " - static retain\n"; #endif replaceCurrent(retainedConst); diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index b61a72720..c0e940d04 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -21,12 +21,22 @@ #include <ir/module-utils.h> #include <pass.h> #include <pretty_printing.h> -#include <wasm-printing.h> #include <wasm-stack.h> #include <wasm.h> namespace wasm { +static std::ostream& printExpression(Expression* expression, + std::ostream& o, + bool minify = false, + bool full = false); + +static std::ostream& +printStackInst(StackInst* inst, std::ostream& o, Function* func = nullptr); + +static std::ostream& +printStackIR(StackIR* ir, std::ostream& o, Function* func = nullptr); + namespace { bool isFullForced() { @@ -1814,9 +1824,9 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { bool full = false; // whether to not elide nodes in output when possible // (like implicit blocks) and to emit types - bool printStackIR = false; // whether to print stack IR if it is present - // (if false, and Stack IR is there, we just - // note it exists) + bool stackIR = false; // whether to print stack IR if it is present + // (if false, and Stack IR is there, we just + // note it exists) Module* currModule = nullptr; Function* currFunction = nullptr; @@ -1876,7 +1886,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { void setFull(bool full_) { full = full_; } - void setPrintStackIR(bool printStackIR_) { printStackIR = printStackIR_; } + void setStackIR(bool stackIR_) { stackIR = stackIR_; } void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; } @@ -2680,7 +2690,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { o << '('; printMajor(o, "func "); printName(curr->name, o); - if (!printStackIR && curr->stackIR && !minify) { + if (!stackIR && curr->stackIR && !minify) { o << " (; has Stack IR ;)"; } if (curr->sig.params.size() > 0) { @@ -2708,7 +2718,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { o << maybeNewLine; } // Print the body. - if (!printStackIR || !curr->stackIR) { + if (!stackIR || !curr->stackIR) { // It is ok to emit a block here, as a function can directly contain a // list, even if our ast avoids that for simplicity. We can just do that // optimization here.. @@ -2723,7 +2733,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { } } else { // Print the stack IR. - WasmPrinter::printStackIR(curr->stackIR.get(), o, curr); + printStackIR(curr->stackIR.get(), o, curr); } if (currFunction->epilogLocation.size() && lastPrintedLocation != *currFunction->epilogLocation.begin()) { @@ -3061,29 +3071,17 @@ public: void run(PassRunner* runner, Module* module) override { PrintSExpression print(o); print.setDebugInfo(runner->options.debugInfo); - print.setPrintStackIR(true); + print.setStackIR(true); print.visitModule(module); } }; Pass* createPrintStackIRPass() { return new PrintStackIR(); } -// Print individual expressions - -std::ostream& WasmPrinter::printModule(Module* module, std::ostream& o) { - PassRunner runner(module); - Printer(&o).run(&runner, module); - return o; -} - -std::ostream& WasmPrinter::printModule(Module* module) { - return printModule(module, std::cout); -} - -std::ostream& WasmPrinter::printExpression(Expression* expression, - std::ostream& o, - bool minify, - bool full) { +static std::ostream& printExpression(Expression* expression, + std::ostream& o, + bool minify, + bool full) { if (!expression) { o << "(null expression)"; return o; @@ -3098,8 +3096,8 @@ std::ostream& WasmPrinter::printExpression(Expression* expression, return o; } -std::ostream& -WasmPrinter::printStackInst(StackInst* inst, std::ostream& o, Function* func) { +static std::ostream& +printStackInst(StackInst* inst, std::ostream& o, Function* func) { switch (inst->op) { case StackInst::Basic: { PrintExpressionContents(func, o).visit(inst->origin); @@ -3133,8 +3131,8 @@ WasmPrinter::printStackInst(StackInst* inst, std::ostream& o, Function* func) { return o; } -std::ostream& -WasmPrinter::printStackIR(StackIR* ir, std::ostream& o, Function* func) { +static std::ostream& +printStackIR(StackIR* ir, std::ostream& o, Function* func) { size_t indent = func ? 2 : 0; auto doIndent = [&indent, &o]() { for (size_t j = 0; j < indent; j++) { @@ -3198,3 +3196,29 @@ WasmPrinter::printStackIR(StackIR* ir, std::ostream& o, Function* func) { } } // namespace wasm + +namespace std { + +std::ostream& operator<<(std::ostream& o, wasm::Module& module) { + wasm::PassRunner runner(&module); + wasm::Printer(&o).run(&runner, &module); + return o; +} + +std::ostream& operator<<(std::ostream& o, wasm::Expression& expression) { + return wasm::printExpression(&expression, o); +} + +std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) { + return wasm::printExpression(expression, o); +} + +std::ostream& operator<<(std::ostream& o, wasm::StackInst& inst) { + return wasm::printStackInst(&inst, o); +} + +std::ostream& operator<<(std::ostream& o, wasm::StackIR& ir) { + return wasm::printStackIR(&ir, o); +} + +} // namespace std diff --git a/src/passes/ReReloop.cpp b/src/passes/ReReloop.cpp index 30cd55f44..374a54bb8 100644 --- a/src/passes/ReReloop.cpp +++ b/src/passes/ReReloop.cpp @@ -31,10 +31,6 @@ #include "wasm-traversal.h" #include "wasm.h" -#ifdef RERELOOP_DEBUG -#include <wasm-printing.h> -#endif - namespace wasm { struct ReReloop final : public Pass { diff --git a/src/passes/Souperify.cpp b/src/passes/Souperify.cpp index fb0a9d7b9..90fd64777 100644 --- a/src/passes/Souperify.cpp +++ b/src/passes/Souperify.cpp @@ -464,8 +464,7 @@ struct Printer { case Node::Type::Expr: { if (debug()) { std::cout << "; "; - WasmPrinter::printExpression(node->expr, std::cout, true); - std::cout << '\n'; + std::cout << *node->expr << '\n'; } std::cout << "%" << indexing[node] << " = "; printExpression(node); diff --git a/src/passes/TrapMode.cpp b/src/passes/TrapMode.cpp index 528357d4a..9c9dee9ca 100644 --- a/src/passes/TrapMode.cpp +++ b/src/passes/TrapMode.cpp @@ -26,7 +26,6 @@ #include "pass.h" #include "support/name.h" #include "wasm-builder.h" -#include "wasm-printing.h" #include "wasm-type.h" #include "wasm.h" diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 58083c43b..64e48680e 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -561,7 +561,7 @@ void PassRunner::run() { // pass breaks it, so we can print the before and after std::stringstream moduleBefore; if (passDebug == 2 && !isNested) { - WasmPrinter::printModule(wasm, moduleBefore); + moduleBefore << *wasm << '\n'; } // prepare to run std::cerr << "[PassRunner] running pass: " << pass->name << "... "; @@ -584,7 +584,7 @@ void PassRunner::run() { // validate, ignoring the time std::cerr << "[PassRunner] (validating)\n"; if (!WasmValidator().validate(*wasm, validationFlags)) { - WasmPrinter::printModule(wasm); + std::cout << *wasm << '\n'; if (passDebug >= 2) { Fatal() << "Last pass (" << pass->name << ") broke validation. Here is the module before: \n" @@ -606,7 +606,7 @@ void PassRunner::run() { if (options.validate && !isNested) { std::cerr << "[PassRunner] (final validation)\n"; if (!WasmValidator().validate(*wasm, validationFlags)) { - WasmPrinter::printModule(wasm); + std::cout << *wasm << '\n'; Fatal() << "final module does not validate\n"; } } diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 941e7961d..9e78cfb7a 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -466,7 +466,7 @@ int main(int argc, const char* argv[]) { options.applyFeatures(wasm); if (!WasmValidator().validate(wasm)) { - WasmPrinter::printModule(&wasm); + std::cout << wasm << '\n'; Fatal() << "error in validating input"; } diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index 89925b9cc..8220e96cd 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -22,7 +22,6 @@ #include "support/command-line.h" #include "support/file.h" #include "wasm-io.h" -#include "wasm-printing.h" using namespace cashew; using namespace wasm; @@ -76,8 +75,7 @@ int main(int argc, const char* argv[]) { std::cerr << "Printing..." << std::endl; } Output output(options.extra["output"], Flags::Text); - WasmPrinter::printModule(&wasm, output.getStream()); - output << '\n'; + output.getStream() << wasm << '\n'; if (options.debug) { std::cerr << "Done." << std::endl; diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 844dfbb60..d12594274 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -30,7 +30,6 @@ #include "wasm-binary.h" #include "wasm-emscripten.h" #include "wasm-io.h" -#include "wasm-printing.h" #include "wasm-validator.h" #define DEBUG_TYPE "emscripten" @@ -222,8 +221,7 @@ int main(int argc, const char* argv[]) { options.applyFeatures(wasm); BYN_TRACE_WITH_TYPE("emscripten-dump", "Module before:\n"); - BYN_DEBUG_WITH_TYPE("emscripten-dump", - WasmPrinter::printModule(&wasm, std::cerr)); + BYN_DEBUG_WITH_TYPE("emscripten-dump", std::cerr << &wasm); EmscriptenGlueGenerator generator(wasm); generator.standalone = standaloneWasm; @@ -315,8 +313,7 @@ int main(int argc, const char* argv[]) { } BYN_TRACE_WITH_TYPE("emscripten-dump", "Module after:\n"); - BYN_DEBUG_WITH_TYPE("emscripten-dump", - WasmPrinter::printModule(&wasm, std::cerr)); + BYN_DEBUG_WITH_TYPE("emscripten-dump", std::cerr << wasm << '\n'); // Write the modified wasm if the user asked us to, either by specifying an // output file, or requesting text output (which goes to stdout by default). diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp index 3b889b984..87bb293b6 100644 --- a/src/tools/wasm-metadce.cpp +++ b/src/tools/wasm-metadce.cpp @@ -511,7 +511,7 @@ int main(int argc, const char* argv[]) { if (options.passOptions.validate) { if (!WasmValidator().validate(wasm)) { - WasmPrinter::printModule(&wasm); + std::cout << wasm << '\n'; Fatal() << "error in validating input"; } } diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp index 56a26ccfb..8884619fe 100644 --- a/src/tools/wasm-opt.cpp +++ b/src/tools/wasm-opt.cpp @@ -34,7 +34,6 @@ #include "wasm-binary.h" #include "wasm-interpreter.h" #include "wasm-io.h" -#include "wasm-printing.h" #include "wasm-s-parser.h" #include "wasm-validator.h" #include "wasm2c-wrapper.h" @@ -227,7 +226,7 @@ int main(int argc, const char* argv[]) { // to print would not be reached). if (std::find(options.passes.begin(), options.passes.end(), "print") != options.passes.end()) { - WasmPrinter::printModule(&wasm); + std::cout << wasm << '\n'; } Fatal() << message; }; @@ -279,7 +278,7 @@ int main(int argc, const char* argv[]) { reader.build(); if (options.passOptions.validate) { if (!WasmValidator().validate(wasm)) { - WasmPrinter::printModule(&wasm); + std::cout << wasm << '\n'; Fatal() << "error after translate-to-fuzz"; } } diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index c0d02ee15..08c76ac9c 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -28,7 +28,6 @@ #include "support/command-line.h" #include "support/file.h" #include "wasm-interpreter.h" -#include "wasm-printing.h" #include "wasm-s-parser.h" #include "wasm-validator.h" @@ -311,7 +310,7 @@ int main(int argc, const char* argv[]) { modules[moduleName]->features = FeatureSet::All; bool valid = WasmValidator().validate(*modules[moduleName]); if (!valid) { - WasmPrinter::printModule(modules[moduleName].get()); + std::cout << *modules[moduleName] << '\n'; Fatal() << "module failed to validate, see above"; } run_asserts(moduleName, diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 348fc6c10..1464f48f8 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -984,7 +984,7 @@ int main(int argc, const char* argv[]) { if (options.passOptions.validate) { if (!WasmValidator().validate(wasm)) { - WasmPrinter::printModule(&wasm); + std::cout << wasm << '\n'; Fatal() << "error in validating input"; } } diff --git a/src/wasm-printing.h b/src/wasm-printing.h deleted file mode 100644 index 276a387ae..000000000 --- a/src/wasm-printing.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2016 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef wasm_wasm_printing_h -#define wasm_wasm_printing_h - -#include <ostream> - -#include "pass.h" -#include "wasm.h" - -namespace wasm { - -struct WasmPrinter { - static std::ostream& printModule(Module* module, std::ostream& o); - - static std::ostream& printModule(Module* module); - - static std::ostream& printExpression(Expression* expression, - std::ostream& o, - bool minify = false, - bool full = false); - - static std::ostream& - printStackInst(StackInst* inst, std::ostream& o, Function* func = nullptr); - - static std::ostream& - printStackIR(StackIR* ir, std::ostream& o, Function* func = nullptr); -}; - -} // namespace wasm - -namespace std { - -inline std::ostream& operator<<(std::ostream& o, wasm::Module& module) { - return wasm::WasmPrinter::printModule(&module, o); -} - -inline std::ostream& operator<<(std::ostream& o, wasm::Expression& expression) { - return wasm::WasmPrinter::printExpression(&expression, o); -} - -inline std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) { - return wasm::WasmPrinter::printExpression(expression, o); -} - -inline std::ostream& operator<<(std::ostream& o, wasm::StackInst& inst) { - return wasm::WasmPrinter::printStackInst(&inst, o); -} - -inline std::ostream& operator<<(std::ostream& o, wasm::StackIR& ir) { - return wasm::WasmPrinter::printStackIR(&ir, o); -} - -} // namespace std - -#endif // wasm_wasm_printing_h diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 496109a4c..b7f17c19c 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -43,7 +43,6 @@ #include <sstream> #include <unordered_set> -#include "wasm-printing.h" #include "wasm.h" namespace wasm { diff --git a/src/wasm.h b/src/wasm.h index 37c12ffc6..8cada039f 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -28,6 +28,7 @@ #include <array> #include <cassert> #include <map> +#include <ostream> #include <string> #include <vector> @@ -1842,6 +1843,12 @@ template<> struct hash<wasm::Address> { return std::hash<wasm::Address::address64_t>()(a.addr); } }; + +std::ostream& operator<<(std::ostream& o, wasm::Module& module); +std::ostream& operator<<(std::ostream& o, wasm::Expression& expression); +std::ostream& operator<<(std::ostream& o, wasm::StackInst& inst); +std::ostream& operator<<(std::ostream& o, wasm::StackIR& ir); + } // namespace std #endif // wasm_wasm_h diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp index 79687d469..2fb4af838 100644 --- a/src/wasm/wasm-io.cpp +++ b/src/wasm/wasm-io.cpp @@ -121,7 +121,7 @@ void ModuleReader::readStdin(Module& wasm, std::string sourceMapFilename) { #define DEBUG_TYPE "writer" void ModuleWriter::writeText(Module& wasm, Output& output) { - WasmPrinter::printModule(&wasm, output.getStream()); + output.getStream() << wasm; } void ModuleWriter::writeText(Module& wasm, std::string filename) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index b294c953c..f110faf56 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -25,7 +25,6 @@ #include "ir/stack-utils.h" #include "ir/utils.h" #include "support/colors.h" -#include "wasm-printing.h" #include "wasm-validator.h" #include "wasm.h" @@ -41,10 +40,12 @@ inline std::ostream& printModuleComponent(T curr, std::ostream& stream) { return stream; } -// Extra overload for Expressions, to print type info too +// Extra overload for Expressions, to print their contents. inline std::ostream& printModuleComponent(Expression* curr, std::ostream& stream) { - WasmPrinter::printExpression(curr, stream, false, true) << std::endl; + if (curr) { + stream << *curr << '\n'; + } return stream; } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index d9ca03185..90120233d 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -16,7 +16,6 @@ #include "wasm.h" #include "ir/branch-utils.h" -#include "wasm-printing.h" #include "wasm-traversal.h" namespace wasm { @@ -99,12 +98,7 @@ Name ATTR("attr"); // Expressions -void Expression::dump() { - WasmPrinter::printExpression(this, - std::cerr, - /*minify=*/false, - /*full=*/true); -} +void Expression::dump() { std::cout << *this << '\n'; } const char* getExpressionName(Expression* curr) { switch (curr->_id) { diff --git a/src/wasm2js.h b/src/wasm2js.h index ddc3d7313..5257e3456 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -404,7 +404,7 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { #ifndef NDEBUG if (!WasmValidator().validate(*wasm)) { - WasmPrinter::printModule(wasm); + std::cout << *wasm << '\n'; Fatal() << "error in validating wasm2js output"; } #endif |