summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
authorDan Gohman <sunfish@mozilla.com>2016-05-19 11:34:31 -0700
committerDan Gohman <sunfish@mozilla.com>2016-05-19 11:34:31 -0700
commit63c7898825c50fbfce9a0ec54113ab2274c7a077 (patch)
tree948e2b23e46df7387d40831c2b7e96fff77e2760 /src/s2wasm.h
parentd541e4fdaff224d61c9ff0036d707d423de76ed8 (diff)
downloadbinaryen-63c7898825c50fbfce9a0ec54113ab2274c7a077.tar.gz
binaryen-63c7898825c50fbfce9a0ec54113ab2274c7a077.tar.bz2
binaryen-63c7898825c50fbfce9a0ec54113ab2274c7a077.zip
Avoid double dollarsigns in s2wasm local names. (#527)
* Avoid double dollarsigns in s2wasm local names. Recognize '$' as part of the .s syntax for register names, and exclude it when forming the wasm local name. This changes names like "$$0" to "$0". * Fix a comment.
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 082cbed1a..67ec557ef 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -285,8 +285,9 @@ class S2WasmBuilder {
Name getAssign() {
skipWhitespace();
if (*s != '$') return Name();
- std::string str;
const char *before = s;
+ s++;
+ std::string str;
while (*s && *s != '=' && *s != '\n' && *s != ',') {
str += *s;
s++;
@@ -486,7 +487,7 @@ class S2WasmBuilder {
unsigned nextId = 0;
auto getNextId = [&nextId]() {
- return cashew::IString(('$' + std::to_string(nextId++)).c_str(), false);
+ return cashew::IString(std::to_string(nextId++).c_str(), false);
};
wasm::Builder builder(*wasm);
std::vector<NameType> params;
@@ -564,11 +565,14 @@ class S2WasmBuilder {
if (match("$pop")) {
skipToSep();
inputs[i] = nullptr;
- } else {
+ } else if (*s == '$') {
+ s++;
auto curr = allocator->alloc<GetLocal>();
curr->index = func->getLocalIndex(getStrToSep());
curr->type = func->getLocalType(curr->index);
inputs[i] = curr;
+ } else {
+ abort_on("bad input register");
}
if (*s == ')') s++; // tolerate 0(argument) syntax, where we started at the 'a'
if (*s == ':') { // tolerate :attribute=value syntax (see getAttributes)
@@ -586,9 +590,9 @@ class S2WasmBuilder {
return getInputs(1)[0];
};
auto setOutput = [&](Expression* curr, Name assign) {
- if (assign.isNull() || assign.str[1] == 'd') { // discard
+ if (assign.isNull() || assign.str[0] == 'd') { // drop
addToBlock(curr);
- } else if (assign.str[1] == 'p') { // push
+ } else if (assign.str[0] == 'p') { // push
push(curr);
} else { // set to a local
auto set = allocator->alloc<SetLocal>();