From 72c5e955d27436d9a6dae4191f6cc6a52676438e Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 18 Mar 2016 12:40:10 -0700 Subject: Make --debug a boolean As discussed in #248. --- src/asm2wasm.h | 18 +++++++----------- src/support/command-line.cpp | 8 +++----- src/support/command-line.h | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index c4f73b57a..eb1471382 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -150,7 +150,7 @@ class Asm2WasmBuilder { std::map callIndirects; // track these, as we need to fix them after we know the functionTableStarts. this maps call => its function table bool memoryGrowth; - int debug; + bool debug; public: std::map mappedGlobals; @@ -254,7 +254,7 @@ private: } public: - Asm2WasmBuilder(AllocatingModule& wasm, bool memoryGrowth, int debug) + Asm2WasmBuilder(AllocatingModule& wasm, bool memoryGrowth, bool debug) : wasm(wasm), allocator(wasm.allocator), nextGlobal(8), @@ -729,10 +729,8 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { if (debug) { std::cout << "\nfunc: " << ast[1]->getIString().str << '\n'; - if (debug >= 2) { - ast->stringify(std::cout); - std::cout << '\n'; - } + ast->stringify(std::cout); + std::cout << '\n'; } auto function = allocator.alloc(); @@ -802,11 +800,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { std::function process = [&](Ref ast) -> Expression* { AstStackHelper astStackHelper(ast); // TODO: only create one when we need it? - if (debug >= 2) { - std::cout << "at: "; - ast->stringify(std::cout); - std::cout << '\n'; - } + std::cout << "at: "; + ast->stringify(std::cout); + std::cout << '\n'; IString what = ast[0]->getIString(); if (what == STAT) { return process(ast[1]); // and drop return value, if any diff --git a/src/support/command-line.cpp b/src/support/command-line.cpp index b4f8a4d62..f3aa4dc08 100644 --- a/src/support/command-line.cpp +++ b/src/support/command-line.cpp @@ -19,7 +19,7 @@ using namespace wasm; Options::Options(const std::string &command, const std::string &description) - : debug(0), positional(Arguments::Zero) { + : debug(false), positional(Arguments::Zero) { add("--help", "-h", "Show this help message and exit", Arguments::Zero, [this, command, description](Options *o, const std::string &) { std::cerr << command; @@ -41,10 +41,8 @@ Options::Options(const std::string &command, const std::string &description) std::cerr << '\n'; exit(EXIT_SUCCESS); }); - add("--debug", "-d", "Print debug information to stderr", Arguments::Optional, - [](Options *o, const std::string &arguments) { - o->debug = arguments.size() ? std::stoi(arguments) : 1; - }); + add("--debug", "-d", "Print debug information to stderr", Arguments::Zero, + [](Options *o, const std::string &arguments) {}); } Options::~Options() {} diff --git a/src/support/command-line.h b/src/support/command-line.h index 6e0af846e..7c3ae528f 100644 --- a/src/support/command-line.h +++ b/src/support/command-line.h @@ -37,7 +37,7 @@ class Options { typedef std::function Action; enum class Arguments { Zero, One, N, Optional }; - int debug; + bool debug; std::map extra; Options(const std::string &command, const std::string &description); -- cgit v1.2.3 From ac74a808876a27f44a0eb66cef7cb441be1c2017 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 18 Mar 2016 13:55:23 -0700 Subject: Check for debug --- src/asm2wasm.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index eb1471382..2d024665e 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -800,9 +800,11 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { std::function process = [&](Ref ast) -> Expression* { AstStackHelper astStackHelper(ast); // TODO: only create one when we need it? - std::cout << "at: "; - ast->stringify(std::cout); - std::cout << '\n'; + if (debug) { + std::cout << "at: "; + ast->stringify(std::cout); + std::cout << '\n'; + } IString what = ast[0]->getIString(); if (what == STAT) { return process(ast[1]); // and drop return value, if any -- cgit v1.2.3