summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-19 20:36:33 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-19 20:36:33 -0700
commite9e6b5aeee24f36e92c1e02de6eff31154ca4f07 (patch)
treebbfeb900b6a4b176bed8a7592fe5d4902b21aac0 /src
parentba0a6541885d324b9562a79a8977ed8733191b7f (diff)
downloadbinaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.tar.gz
binaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.tar.bz2
binaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.zip
import parsing fixes
Diffstat (limited to 'src')
-rw-r--r--src/asm_v_wasm.h10
-rw-r--r--src/wasm-s-parser.h24
2 files changed, 22 insertions, 12 deletions
diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h
index 7a4a0be31..53881861c 100644
--- a/src/asm_v_wasm.h
+++ b/src/asm_v_wasm.h
@@ -54,6 +54,16 @@ std::string getSig(WasmType result, const ListType& operands) {
return ret;
}
+template<typename ListType>
+std::string getSigFromStructs(WasmType result, const ListType& operands) {
+ std::string ret;
+ ret += getSig(result);
+ for (auto operand : operands) {
+ ret += getSig(operand.type);
+ }
+ return ret;
+}
+
WasmType sigToWasmType(char sig);
FunctionType* sigToFunctionType(std::string sig);
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 6280de7d3..592c84803 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -571,6 +571,18 @@ private:
}
}
}
+ // see https://github.com/WebAssembly/spec/pull/301
+ if (type.isNull()) {
+ // if no function type name provided, then we generated one
+ std::unique_ptr<FunctionType> functionType = std::unique_ptr<FunctionType>(sigToFunctionType(getSigFromStructs(result, params)));
+ for (auto& existing : wasm.functionTypes) {
+ if (existing->structuralComparison(*functionType)) {
+ type = existing->name;
+ break;
+ }
+ }
+ if (!type.is()) throw ParseException("no function type [internal error?]", s.line, s.col);
+ }
if (importModule.is()) {
// this is an import, actually
assert(preParseImport);
@@ -603,18 +615,6 @@ private:
body = allocator.alloc<Nop>();
}
if (currFunction->result != result) throw ParseException("bad func declaration", s.line, s.col);
- // see https://github.com/WebAssembly/spec/pull/301
- if (type.isNull()) {
- // if no function type name provided, then we generated one
- std::unique_ptr<FunctionType> functionType = std::unique_ptr<FunctionType>(sigToFunctionType(getSig(currFunction.get())));
- for (auto& existing : wasm.functionTypes) {
- if (existing->structuralComparison(*functionType)) {
- type = existing->name;
- break;
- }
- }
- if (!type.is()) throw ParseException("no function type [internal error?]", s.line, s.col);
- }
currFunction->body = body;
currFunction->type = type;