summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-14 19:24:08 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-14 19:24:08 -0800
commit119896a6688ff3ae78bdd0b0cc47328c3383ac2a (patch)
tree4eedeca9baa93949f02df219a7b8ce5351298cf0
parent3fe9c430f321a5cdf948a903509367ba872e37a6 (diff)
downloadbinaryen-119896a6688ff3ae78bdd0b0cc47328c3383ac2a.tar.gz
binaryen-119896a6688ff3ae78bdd0b0cc47328c3383ac2a.tar.bz2
binaryen-119896a6688ff3ae78bdd0b0cc47328c3383ac2a.zip
emit asm const ids
-rw-r--r--src/s2wasm.h8
-rw-r--r--test/dot_s/asm_const.wast2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 5fccef19b..6d821dc83 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -873,6 +873,7 @@ public:
std::ostream& o;
std::map<std::string, std::set<std::string>> sigsForCode;
+ std::map<std::string, size_t> ids;
AsmConstWalker(S2WasmBuilder* parent) : parent(parent), o(o) {}
@@ -881,6 +882,10 @@ public:
auto arg = curr->operands[0]->cast<Const>();
size_t segmentIndex = parent->addressSegments[arg->value.geti32()];
std::string code = escape(parent->wasm.memory.segments[segmentIndex].data);
+ if (ids.count(code) == 0) {
+ size_t id = ids.size();
+ ids[code] = id;
+ }
std::string sig = getSig(curr);
sigsForCode[code].insert(sig);
}
@@ -917,8 +922,9 @@ public:
auto& sigs = pair.second;
if (first) first = false;
else o << ",";
- o << '"' << code << '"' << ":";
+ o << '"' << walker.ids[code] << "\": [\"" << code << "\", ";
printSet(o, sigs);
+ o << "]";
}
o << "}";
diff --git a/test/dot_s/asm_const.wast b/test/dot_s/asm_const.wast
index 37ff45061..620606a58 100644
--- a/test/dot_s/asm_const.wast
+++ b/test/dot_s/asm_const.wast
@@ -15,4 +15,4 @@
)
)
)
-; METADATA: { "asmConsts": {"{ Module.print(\"hello, world!\"); }":["vi"]} } \ No newline at end of file
+; METADATA: { "asmConsts": {"0": ["{ Module.print(\"hello, world!\"); }", ["vi"]]} } \ No newline at end of file