From 899263882c48dba8e34717af1e28005f8888dca7 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 24 May 2019 16:39:52 -0700 Subject: Refactor type and function parsing (#2143) - Refactored & fixed typeuse parsing rules so now the rules more closely follow the spec. There have been multiple parsing rules that were different in subtle ways, which are supposed to be the same according to the spec. - Duplicate types, i.e., types with the same signature, in the type section are allowed as long as they don't have the same given name. If a name is given, we use it; if type name is not given, we generate one in the form of `$FUNCSIG$` + signature string. If the same generated name already exists in the type section, we append `_` at the end. This causes most of the changes in the autogenerated type names in test outputs. - A typeuse has to be in the order of (type) -> (param) -> (result), if more than one of them exist. In case of function definitions, (local) has to be after all of these. Fixed some test cases that violate this rule. - When only (param)/(result) are given, its type will be the type with the smallest existing type index whose parameter and result are the same. If there's no such type, a new type will be created and inserted. - Added a test case `duplicate_types.wast` to test type namings for duplicate types. - Refactored `parseFunction` function. - Add more overrides to helper functions: `getSig` and `ensureFunctionType`. --- src/wasm/wasm.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/wasm/wasm.cpp') diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index c72103ebe..c32ead836 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -406,14 +406,19 @@ void CallIndirect::finalize() { } bool FunctionType::structuralComparison(FunctionType& b) { - if (result != b.result) { + return structuralComparison(b.params, b.result); +} + +bool FunctionType::structuralComparison(const std::vector& otherParams, + Type otherResult) { + if (result != otherResult) { return false; } - if (params.size() != b.params.size()) { + if (params.size() != otherParams.size()) { return false; } for (size_t i = 0; i < params.size(); i++) { - if (params[i] != b.params[i]) { + if (params[i] != otherParams[i]) { return false; } } -- cgit v1.2.3