diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-03 10:18:14 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-03 10:18:14 -0800 |
commit | aa122695e53bb2c39175e2d04f626b2cd6c2e911 (patch) | |
tree | 50b7d08231582457793a9285a578a9e1745e6662 /src/pretty_printing.h | |
parent | 3b0fc2374d042ba81e16ee09f57cdef9891be065 (diff) | |
download | binaryen-aa122695e53bb2c39175e2d04f626b2cd6c2e911.tar.gz binaryen-aa122695e53bb2c39175e2d04f626b2cd6c2e911.tar.bz2 binaryen-aa122695e53bb2c39175e2d04f626b2cd6c2e911.zip |
refactor pretty printing code
Diffstat (limited to 'src/pretty_printing.h')
-rw-r--r-- | src/pretty_printing.h | 70 |
1 files changed, 70 insertions, 0 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; +} + |