summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h22
-rw-r--r--test/dot_s/basics.wast2
2 files changed, 20 insertions, 4 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 9766471f7..e1e913836 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -25,6 +25,10 @@ public:
}
private:
+ // state
+
+ size_t nextStatic = 0; // location of next static allocation, i.e., the data segment
+
// utilities
void skipWhitespace() {
@@ -84,7 +88,7 @@ private:
}
Name getStr() {
- std::string str;
+ std::string str; // TODO: optimize this and the other get* methods
while (*s && !isspace(*s)) {
str += *s;
s++;
@@ -141,6 +145,7 @@ private:
str += *s;
s++;
}
+ s++;
skipWhitespace();
return cashew::IString(str.c_str(), false);
}
@@ -175,7 +180,10 @@ private:
s++;
if (match("file")) parseFile();
else if (match("globl")) parseGlobl();
- else break;
+ else {
+ s--;
+ break;
+ }
}
}
@@ -432,7 +440,9 @@ private:
void parseType() {
Name name = getStrToComma();
+ skipComma();
mustMatch("@object");
+ mustMatch(".data");
mustMatch(name.str);
mustMatch(":");
mustMatch(".asciz");
@@ -440,7 +450,13 @@ private:
mustMatch(".size");
mustMatch(name.str);
mustMatch(",");
- Name size = getStr();
+ size_t size = atoi(getStr().str); // TODO: optimize
+ assert(strlen(buffer.str) == size);
+ const int ALIGN = 16;
+ if (nextStatic == 0) nextStatic = ALIGN;
+ wasm.memory.segments.emplace_back(nextStatic, buffer.str, size);
+ nextStatic += size;
+ nextStatic = (nextStatic + ALIGN - 1) & -ALIGN;
}
};
diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast
index 29001914b..e7efb9202 100644
--- a/test/dot_s/basics.wast
+++ b/test/dot_s/basics.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295)
+ (memory 0 4294967295 (segment 16 "hello, world!\n"))
(func $0 (param $$0 i32) (param $$1 i32) (result i32)
(block $fake_return_waka123
(block