summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-03 17:56:04 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-03 17:56:04 -0800
commit687a7c439987b8cc5ee7d298f14b948a8c98350c (patch)
tree77a90b86476e958ea796b8412ad66d03f9e756b0 /src
parentf9ccaa4157bacd3a4690497bc8b5fa2e49ef739c (diff)
downloadbinaryen-687a7c439987b8cc5ee7d298f14b948a8c98350c.tar.gz
binaryen-687a7c439987b8cc5ee7d298f14b948a8c98350c.tar.bz2
binaryen-687a7c439987b8cc5ee7d298f14b948a8c98350c.zip
sexpression debugging
Diffstat (limited to 'src')
-rw-r--r--src/wasm-sexpr-parser.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wasm-sexpr-parser.h b/src/wasm-sexpr-parser.h
index 9729d6b1f..6264f6af4 100644
--- a/src/wasm-sexpr-parser.h
+++ b/src/wasm-sexpr-parser.h
@@ -62,6 +62,17 @@ public:
return this;
}
+ // printing
+
+ friend std::ostream& operator<<(std::ostream& o, Element& e) {
+ if (e.isList) {
+ o << '(';
+ for (auto item : e.list_) o << ' ' << *item << ' ';
+ o << ')';
+ } else {
+ o << e.str_.str;
+ }
+ }
};
//
@@ -122,7 +133,11 @@ private:
Element* parseString() {
char *start = input;
while (input[0] && !isspace(input[0]) && input[0] != ')') input++;
- return allocator.alloc<Element>()->setString(IString(start, false)); // TODO: reuse the string here, carefully
+ char temp = input[0];
+ input[0] = 0;
+ auto ret = allocator.alloc<Element>()->setString(IString(start, false)); // TODO: reuse the string here, carefully
+ input[0] = temp;
+ return ret;
}
};
@@ -140,6 +155,7 @@ public:
// Assumes control of and modifies the input.
SExpressionWasmBuilder(Module& wasm, char* input) : wasm(wasm), parser(input) {
Element* root = parser.parseEverything();
+ if (debug) std::cout << *root << '\n';
assert(root);
assert((*root)[0]->str() == MODULE);
for (unsigned i = 1; i < root->size(); i++) {