diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-19 20:36:33 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-19 20:36:33 -0700 |
commit | e9e6b5aeee24f36e92c1e02de6eff31154ca4f07 (patch) | |
tree | bbfeb900b6a4b176bed8a7592fe5d4902b21aac0 /src | |
parent | ba0a6541885d324b9562a79a8977ed8733191b7f (diff) | |
download | binaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.tar.gz binaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.tar.bz2 binaryen-e9e6b5aeee24f36e92c1e02de6eff31154ca4f07.zip |
import parsing fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/asm_v_wasm.h | 10 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 24 |
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; |