summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-14 15:27:37 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-14 15:27:37 -0800
commit07e236b06dfb8d223b93c893ffe92a2b1d64bc9d (patch)
tree51e8dd52c1def4d29874d7cd90b3f6389fc046f8
parent91c353b3c9f1f4121992bd3bd04eed84907ddeb4 (diff)
downloadbinaryen-07e236b06dfb8d223b93c893ffe92a2b1d64bc9d.tar.gz
binaryen-07e236b06dfb8d223b93c893ffe92a2b1d64bc9d.tar.bz2
binaryen-07e236b06dfb8d223b93c893ffe92a2b1d64bc9d.zip
update experimental tests and handle new call syntax
-rw-r--r--src/s2wasm.h111
m---------test/experimental0
2 files changed, 48 insertions, 63 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 8e75c6b89..62a4a77f8 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -37,8 +37,6 @@ private:
typedef std::pair<Const*, Name> Addressing;
std::vector<Addressing> addressings; // we fix these up
- std::map<Name, WasmType> functionResults; // function name => result type. we scan this early, then use it during processing.
-
// utilities
void skipWhitespace() {
@@ -225,24 +223,6 @@ private:
// processors
void scan() {
- while (*s) {
- s = strstr(s, "\n .type ");
- if (!s) break;
- mustMatch("\n .type ");
- Name name = getCommaSeparated();
- skipComma();
- if (!match("@function")) continue;
- mustMatch(name.str);
- mustMatch(":");
- while (1) {
- skipWhitespace();
- if (match(".param")) s = strchr(s, '\n');
- else if (match(".result")) {
- functionResults[name] = getType();
- break;
- } else break;
- }
- }
}
void process() {
@@ -448,6 +428,49 @@ private:
curr->type = type;
setOutput(curr, assign);
};
+ auto makeCall = [&](WasmType type) {
+ CallBase* curr;
+ if (match("_import")) {
+ curr = allocator.alloc<CallImport>();
+ } else if (match("_indirect")) {
+ curr = allocator.alloc<CallIndirect>();
+ } else {
+ curr = allocator.alloc<Call>();
+ }
+ Name assign = getAssign();
+ if (curr->is<Call>()) {
+ Name name = curr->dyn_cast<Call>()->target = getCommaSeparated();
+ curr->type = type;
+ } else if (curr->is<CallImport>()) {
+ Name name = curr->dyn_cast<CallImport>()->target = getCommaSeparated();
+ // XXX import definitions would help here, but still undecided in .s format
+ } else {
+ curr->dyn_cast<CallIndirect>()->target = getInput();
+ // XXX no way to know return type, https://github.com/WebAssembly/experimental/issues/53
+ }
+ while (1) {
+ if (!skipComma()) break;
+ curr->operands.push_back(getInput());
+ }
+ std::reverse(curr->operands.begin(), curr->operands.end());
+ setOutput(curr, assign);
+ if (curr->is<CallIndirect>()) {
+ auto call = curr->dyn_cast<CallIndirect>();
+ auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(call)).c_str(), false);
+ if (wasm.functionTypesMap.count(typeName) == 0) {
+ auto type = allocator.alloc<FunctionType>();
+ type->name = typeName;
+ // TODO type->result
+ for (auto operand : call->operands) {
+ type->params.push_back(operand->type);
+ }
+ wasm.addFunctionType(type);
+ call->fullType = type;
+ } else {
+ call->fullType = wasm.functionTypesMap[typeName];
+ }
+ }
+ };
auto handleTyped = [&](WasmType type) {
switch (*s) {
case 'a': {
@@ -472,7 +495,9 @@ private:
// constant
setOutput(parseConst(str, type, allocator), assign);
}
- } else if (match("convert_s/i32")) makeUnary(UnaryOp::ConvertSInt32, type);
+ }
+ else if (match("call")) makeCall(type);
+ else if (match("convert_s/i32")) makeUnary(UnaryOp::ConvertSInt32, type);
else if (match("convert_u/i32")) makeUnary(UnaryOp::ConvertUInt32, type);
else if (match("convert_s/i64")) makeUnary(UnaryOp::ConvertSInt64, type);
else if (match("convert_u/i64")) makeUnary(UnaryOp::ConvertUInt64, type);
@@ -605,48 +630,6 @@ private:
handleTyped(f32);
} else if (match("f64.")) {
handleTyped(f64);
- } else if (match("call")) {
- CallBase* curr;
- if (match("_import")) {
- curr = allocator.alloc<CallImport>();
- } else if (match("_indirect")) {
- curr = allocator.alloc<CallIndirect>();
- } else {
- curr = allocator.alloc<Call>();
- }
- Name assign = getAssign();
- if (curr->is<Call>()) {
- Name name = curr->dyn_cast<Call>()->target = getCommaSeparated();
- curr->type = functionResults[name];
- } else if (curr->is<CallImport>()) {
- Name name = curr->dyn_cast<CallImport>()->target = getCommaSeparated();
- // XXX import definitions would help here, but still undecided in .s format
- } else {
- curr->dyn_cast<CallIndirect>()->target = getInput();
- // XXX no way to know return type, https://github.com/WebAssembly/experimental/issues/53
- }
- while (1) {
- if (!skipComma()) break;
- curr->operands.push_back(getInput());
- }
- std::reverse(curr->operands.begin(), curr->operands.end());
- setOutput(curr, assign);
- if (curr->is<CallIndirect>()) {
- auto call = curr->dyn_cast<CallIndirect>();
- auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(call)).c_str(), false);
- if (wasm.functionTypesMap.count(typeName) == 0) {
- auto type = allocator.alloc<FunctionType>();
- type->name = typeName;
- // TODO type->result
- for (auto operand : call->operands) {
- type->params.push_back(operand->type);
- }
- wasm.addFunctionType(type);
- call->fullType = type;
- } else {
- call->fullType = wasm.functionTypesMap[typeName];
- }
- }
} else if (match("block")) {
auto curr = allocator.alloc<Block>();
curr->name = getStr();
@@ -693,6 +676,8 @@ private:
}
curr->name = getStr();
bstack.back()->list.push_back(curr);
+ } else if (match("call")) {
+ makeCall(none);
} else if (match("copy_local")) {
Name assign = getAssign();
skipComma();
diff --git a/test/experimental b/test/experimental
-Subproject 371e3d7f1ad6175ce24962a4bccf1de87b8a8dd
+Subproject c3f29d2082cefee02ce43d5768f1860513aa6fb