From 2d375e8d502327e814d62a08f22da9d9b6b675dc Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 4 Aug 2016 20:15:18 -0700 Subject: update testsuite, handle implicit func types (#96) Change 7c482b1a of the spec repo now requires that implicit function types are created when creating a new func or import, but only when the type is not explicitly specified, and the have not been specified. For example: ``` (func (param i32)) (import "foo" "bar" (result i32) ``` This was previously done in sexpr-wasm when writing the binary, but now these types can be referenced by `call_import`, so it has to be handled earlier. Since all signatures are now defined in the module, I made it so the function signature is shared with the module function types. The tricky part here is when a function type and an explicit signature are both specified: ``` (func (type $t) (param f32) ...) ``` In this case, we need to keep the explicit signature around long enough to be checked against the function type, so it must be owned by the function. The WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE flag specifies this case. To simplify code that uses the AST, I reverted many of the changes introduced in 73e5bc7d. Now the function declaration's signature is always valid to access, and will have been resolved if it was specified with a func type instead of an explicit signature. Some other changes: * There was a bug in the interpreter's `f32.demote/f64` rounding when given a value that is very close to positive or negative F32_MAX * Added `update-spec-tests.py` to more easily update the spec tests in `test/interp/spec/*.txt` from the files in `third_party/testsuite/*.wast`. Previously I would just do it manually. --- src/wasm-binary-writer-spec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/wasm-binary-writer-spec.c') diff --git a/src/wasm-binary-writer-spec.c b/src/wasm-binary-writer-spec.c index b76529e6..1185c0d3 100644 --- a/src/wasm-binary-writer-spec.c +++ b/src/wasm-binary-writer-spec.c @@ -223,11 +223,27 @@ static WasmFunc* append_nullary_func(WasmAllocator* allocator, WasmModule* module, WasmType result_type, WasmStringSlice export_name) { + WasmFuncType* func_type; + WasmFuncSignature sig; + WASM_ZERO_MEMORY(sig); + sig.result_type = result_type; + int sig_index = wasm_get_func_type_index_by_sig(module, &sig); + if (sig_index == -1) { + WasmLocation loc; + WASM_ZERO_MEMORY(loc); + func_type = wasm_append_implicit_func_type(allocator, &loc, module, &sig); + sig_index = module->func_types.size - 1; + } else { + func_type = module->func_types.data[sig_index]; + } + WasmModuleField* func_field = append_module_field(allocator, module, WASM_MODULE_FIELD_TYPE_FUNC); WasmFunc* func = &func_field->func; - func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; - func->decl.sig.result_type = result_type; + func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + func->decl.type_var.type = WASM_VAR_TYPE_INDEX; + func->decl.type_var.index = sig_index; + func->decl.sig = func_type->sig; int func_index = module->funcs.size - 1; WasmModuleField* export_field = -- cgit v1.2.3