summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h33
-rw-r--r--src/wasm.h16
2 files changed, 34 insertions, 15 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 48e9dac10..6f209a436 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -181,19 +181,24 @@ private:
assert(*s == '"');
s++;
std::vector<char> str;
- auto ESCAPES = "nrtfb\\\"";
while (*s && *s != '\"') {
if (s[0] == '\\') {
- if (strchr(ESCAPES, s[1])) {
- str.push_back(s[1]);
- s += 2;
- continue;
- } else if (isdigit(s[1])) {
- int code = (s[1] - '0')*8*8 + (s[2] - '0')*8 + (s[3] - '0');
- str.push_back(char(code));
- s += 4;
- continue;
- } else abort_on("getQuoted-escape");
+ switch (s[1]) {
+ case 'n': str.push_back('\n'); s += 2; continue;
+ case 'r': str.push_back('\r'); s += 2; continue;
+ case 't': str.push_back('\t'); s += 2; continue;
+ case 'f': str.push_back('\f'); s += 2; continue;
+ case 'b': str.push_back('\b'); s += 2; continue;
+ case '\\': str.push_back('\\'); s += 2; continue;
+ default: {
+ if (isdigit(s[1])) {
+ int code = (s[1] - '0')*8*8 + (s[2] - '0')*8 + (s[3] - '0');
+ str.push_back(char(code));
+ s += 4;
+ continue;
+ } else abort_on("getQuoted-escape");
+ }
+ }
}
str.push_back(*s);
s++;
@@ -740,10 +745,10 @@ private:
}
} else if (match(".int32")) {
raw->resize(4);
- (*(int32_t*)(&raw[0])) = getInt();
+ (*(int32_t*)(&(*raw)[0])) = getInt();
} else if (match(".int64")) {
raw->resize(8);
- (*(int64_t*)(&raw[0])) = getInt();
+ (*(int64_t*)(&(*raw)[0])) = getInt();
} else abort_on("data form");
skipWhitespace();
mustMatch(".size");
@@ -754,7 +759,7 @@ private:
while (nextStatic % align) nextStatic++;
// assign the address, add to memory
staticAddresses[name] = nextStatic;
- wasm.memory.segments.emplace_back(nextStatic, (const char*)&raw[0], seenSize);
+ wasm.memory.segments.emplace_back(nextStatic, (const char*)&(*raw)[0], seenSize);
nextStatic += seenSize;
}
diff --git a/src/wasm.h b/src/wasm.h
index aea38f9b7..d53c4e629 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1035,7 +1035,21 @@ public:
printOpening(o, "memory") << " " << module.memory.initial;
if (module.memory.max) o << " " << module.memory.max;
for (auto segment : module.memory.segments) {
- o << " (segment " << segment.offset << " \"" << segment.data << "\")";
+ o << " (segment " << segment.offset << " \"";
+ for (size_t i = 0; i < segment.size; i++) {
+ char c = segment.data[i];
+ switch (c) {
+ case '\n': o << "\\n"; break;
+ case '\r': o << "\\r"; break;
+ case '\t': o << "\\t"; break;
+ case '\f': o << "\\f"; break;
+ case '\b': o << "\\b"; break;
+ case '\\': o << "\\\\"; break;
+ case 0: o << "\\0"; break;
+ default: o << c; // TODO: escaping
+ }
+ }
+ o << "\")";
}
o << ")\n";
for (auto& curr : module.functionTypes) {