diff options
-rw-r--r-- | src/pretty_printing.h | 70 | ||||
-rw-r--r-- | src/wasm.h | 67 |
2 files changed, 71 insertions, 66 deletions
diff --git a/src/pretty_printing.h b/src/pretty_printing.h new file mode 100644 index 000000000..71a729625 --- /dev/null +++ b/src/pretty_printing.h @@ -0,0 +1,70 @@ + +#include <ostream> + +#include "colors.h" + +std::ostream &doIndent(std::ostream &o, unsigned indent) { + for (unsigned i = 0; i < indent; i++) { + o << " "; + } + return o; +} + +std::ostream &incIndent(std::ostream &o, unsigned& indent) { + o << '\n'; + indent++; + return o; +} + +std::ostream &decIndent(std::ostream &o, unsigned& indent) { + indent--; + doIndent(o, indent); + return o << ')'; +} + +std::ostream &prepareMajorColor(std::ostream &o) { + Colors::red(o); + Colors::bold(o); + return o; +} + +std::ostream &prepareColor(std::ostream &o) { + Colors::magenta(o); + Colors::bold(o); + return o; +} + +std::ostream &prepareMinorColor(std::ostream &o) { + Colors::orange(o); + return o; +} + +std::ostream &restoreNormalColor(std::ostream &o) { + Colors::normal(o); + return o; +} + +std::ostream& printText(std::ostream &o, const char *str) { + o << '"'; + Colors::green(o); + o << str; + Colors::normal(o); + return o << '"'; +} + +std::ostream& printOpening(std::ostream &o, const char *str, bool major=false) { + o << '('; + major ? prepareMajorColor(o) : prepareColor(o); + o << str; + restoreNormalColor(o); + return o; +} + +std::ostream& printMinorOpening(std::ostream &o, const char *str) { + o << '('; + prepareMinorColor(o); + o << str; + restoreNormalColor(o); + return o; +} + diff --git a/src/wasm.h b/src/wasm.h index 1fce6692b..d4ecabca3 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -12,29 +12,10 @@ #include <vector> #include "simple_ast.h" -#include "colors.h" +#include "pretty_printing.h" namespace wasm { -// Utilities - -std::ostream &doIndent(std::ostream &o, unsigned indent) { - for (unsigned i = 0; i < indent; i++) { - o << " "; - } - return o; -} -std::ostream &incIndent(std::ostream &o, unsigned& indent) { - o << '\n'; - indent++; - return o; -} -std::ostream &decIndent(std::ostream &o, unsigned& indent) { - indent--; - doIndent(o, indent); - return o << ')'; -} - // Basics struct Name : public cashew::IString { @@ -93,36 +74,6 @@ WasmType getWasmType(unsigned size, bool float_) { abort(); } -std::ostream &prepareMajorColor(std::ostream &o) { - Colors::red(o); - Colors::bold(o); - return o; -} - -std::ostream &prepareColor(std::ostream &o) { - Colors::magenta(o); - Colors::bold(o); - return o; -} - -std::ostream &prepareMinorColor(std::ostream &o) { - Colors::orange(o); - return o; -} - -std::ostream &restoreNormalColor(std::ostream &o) { - Colors::normal(o); - return o; -} - -std::ostream& printText(std::ostream &o, const char *str) { - o << '"'; - Colors::green(o); - o << str; - Colors::normal(o); - return o << '"'; -} - struct Literal { WasmType type; union { @@ -251,22 +202,6 @@ std::ostream& printFullLine(std::ostream &o, unsigned indent, Expression *expres return o << '\n'; } -std::ostream& printOpening(std::ostream &o, const char *str, bool major=false) { - o << '('; - major ? prepareMajorColor(o) : prepareColor(o); - o << str; - restoreNormalColor(o); - return o; -} - -std::ostream& printMinorOpening(std::ostream &o, const char *str) { - o << '('; - prepareMinorColor(o); - o << str; - restoreNormalColor(o); - return o; -} - typedef std::vector<Expression*> ExpressionList; // TODO: optimize class Nop : public Expression { |