summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-12 11:01:18 -0500
committerAlon Zakai <alonzakai@gmail.com>2015-12-12 11:01:18 -0500
commit30b612178e4059b4f5012a25bc1d961da932470a (patch)
tree4c223d910e24e90da622622d03f86de0f75fbbea /src
parent187394be5d5f8ac230b61170161466791c589567 (diff)
downloadbinaryen-30b612178e4059b4f5012a25bc1d961da932470a.tar.gz
binaryen-30b612178e4059b4f5012a25bc1d961da932470a.tar.bz2
binaryen-30b612178e4059b4f5012a25bc1d961da932470a.zip
more load and store
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h54
1 files changed, 16 insertions, 38 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index fea9296e3..3f5efc803 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -52,6 +52,11 @@ private:
return true;
}
+ #define abort_on(why) { \
+ dump(why ":"); \
+ abort(); \
+ }
+
// match and skip the pattern, if matched
bool match(const char *pattern) {
size_t size = strlen(pattern);
@@ -65,7 +70,10 @@ private:
void mustMatch(const char *pattern) {
bool matched = match(pattern);
- assert(matched);
+ if (!matched) {
+ std::cerr << "<< " << pattern << " >>\n";
+ abort_on("bad mustMatch");
+ }
}
void dump(const char *text) {
@@ -77,11 +85,6 @@ private:
std::cerr << "\n==========\n";
}
- #define abort_on(why) { \
- dump(why ":"); \
- abort(); \
- }
-
void unget(Name str) {
s -= strlen(str.str);
}
@@ -320,26 +323,13 @@ private:
setOutput(curr, assign);
};
auto makeLoad = [&](WasmType type) {
- Name assign = getAssign();
skipComma();
auto curr = allocator.alloc<Load>();
curr->type = type;
- switch (type) {
- case i32: {
- curr->bytes = 4;
- curr->signed_ = false; // XXX
- }
- case i64: {
- curr->bytes = 8;
- curr->signed_ = false; // XXX
- }
- case f32: {
- curr->bytes = 4;
- }
- case f64: {
- curr->bytes = 8;
- }
- }
+ int32_t bytes = getInt();
+ curr->bytes = bytes > 0 ? bytes : getWasmTypeSize(type);
+ curr->signed_ = match("_u");
+ Name assign = getAssign();
curr->offset = getInt();
curr->align = curr->bytes; // XXX
mustMatch("(");
@@ -348,24 +338,12 @@ private:
setOutput(curr, assign);
};
auto makeStore = [&](WasmType type) {
- Name assign = getAssign();
skipComma();
auto curr = allocator.alloc<Store>();
curr->type = type;
- switch (type) {
- case i32: {
- curr->bytes = 4;
- }
- case i64: {
- curr->bytes = 8;
- }
- case f32: {
- curr->bytes = 4;
- }
- case f64: {
- curr->bytes = 8;
- }
- }
+ int32_t bytes = getInt();
+ curr->bytes = bytes > 0 ? bytes : getWasmTypeSize(type);
+ Name assign = getAssign();
curr->offset = getInt();
curr->align = curr->bytes; // XXX
mustMatch("(");