summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-12 12:22:58 -0500
committerAlon Zakai <alonzakai@gmail.com>2015-12-12 12:22:58 -0500
commit611652074f94d8878cf6ee695b54d2f711dc3803 (patch)
tree553d955ab62bf5af2afbc1ead1ee3f045499f3f2
parent5b97dfbf7cd4ecffbde111020f992b2c7a9bd03a (diff)
downloadbinaryen-611652074f94d8878cf6ee695b54d2f711dc3803.tar.gz
binaryen-611652074f94d8878cf6ee695b54d2f711dc3803.tar.bz2
binaryen-611652074f94d8878cf6ee695b54d2f711dc3803.zip
quoting and data fixes
-rw-r--r--src/s2wasm.h27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index d39ed3b71..403909cd0 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -182,6 +182,10 @@ private:
s++;
std::string str;
while (*s && *s != '\"') {
+ if (s[0] == '\\' && s[1] == '"') {
+ str += '"';
+ s += 2;
+ }
str += *s;
s++;
}
@@ -209,6 +213,7 @@ private:
if (match("text")) parseText();
else if (match("type")) parseType();
else if (match("imports")) skipImports();
+ else if (match("data")) {}
else abort_on("process");
}
}
@@ -715,34 +720,40 @@ private:
mustMatch(":");
const char* data;
size_t expectedSize;
+ size_t realSize; // including null terminator if any
if (match(".asciz")) {
Name buffer = getQuoted();
data = buffer.str;
expectedSize = strlen(data);
+ realSize = expectedSize + 1;
+ } else if (match(".ascii")) {
+ Name buffer = getQuoted();
+ data = buffer.str;
+ realSize = expectedSize = strlen(data);
} else if (match(".zero")) {
int32_t size = getInt();
data = (const char*)calloc(size, 1);
- expectedSize = size;
+ realSize = expectedSize = size;
} else if (match(".int32")) {
auto i = new int32_t(getInt());
data = (const char*)i;
- expectedSize = 4;
+ realSize = expectedSize = 4;
} else if (match(".int64")) {
auto i = new int64_t(getInt64());
data = (const char*)i;
- expectedSize = 8;
- } else abort_on("data");
+ realSize = expectedSize = 8;
+ } else abort_on("data form");
skipWhitespace();
mustMatch(".size");
mustMatch(name.str);
mustMatch(",");
- size_t size = atoi(getStr().str); // TODO: optimize
- assert(size == expectedSize);
+ size_t seenSize = atoi(getStr().str); // TODO: optimize
+ assert(seenSize == expectedSize);
while (nextStatic % align) nextStatic++;
// assign the address, add to memory
staticAddresses[name] = nextStatic;
- wasm.memory.segments.emplace_back(nextStatic, data, size);
- nextStatic += size;
+ wasm.memory.segments.emplace_back(nextStatic, data, realSize);
+ nextStatic += realSize;
}
void skipImports() {