diff options
author | Ben Smith <binjimin@gmail.com> | 2016-08-04 20:15:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-04 20:15:18 -0700 |
commit | 2d375e8d502327e814d62a08f22da9d9b6b675dc (patch) | |
tree | fbac644d0498c0fdf368935593f4894d3817ab2d /src/wasm-binary-reader-ast.c | |
parent | 31dcad7ff987455bae219b31e4d6c76d78634315 (diff) | |
download | wabt-2d375e8d502327e814d62a08f22da9d9b6b675dc.tar.gz wabt-2d375e8d502327e814d62a08f22da9d9b6b675dc.tar.bz2 wabt-2d375e8d502327e814d62a08f22da9d9b6b675dc.zip |
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.
Diffstat (limited to 'src/wasm-binary-reader-ast.c')
-rw-r--r-- | src/wasm-binary-reader-ast.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/wasm-binary-reader-ast.c b/src/wasm-binary-reader-ast.c index a3dc6d37..91a79dcd 100644 --- a/src/wasm-binary-reader-ast.c +++ b/src/wasm-binary-reader-ast.c @@ -51,7 +51,6 @@ #define CHECK_LOCAL(local_index) \ do { \ - assert(wasm_decl_has_func_type(&ctx->current_func->decl)); \ uint32_t max_local_index = \ wasm_get_num_params_and_locals(ctx->module, ctx->current_func); \ if ((local_index) >= max_local_index) { \ @@ -351,20 +350,23 @@ static WasmResult on_import(uint32_t index, WasmStringSlice function_name, void* user_data) { Context* ctx = user_data; + assert(index < ctx->module->imports.capacity); + assert(sig_index < ctx->module->func_types.size); + WasmModuleField* field = wasm_append_module_field(ctx->allocator, ctx->module); field->type = WASM_MODULE_FIELD_TYPE_IMPORT; WasmImport* import = &field->import; WASM_ZERO_MEMORY(*import); - import->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; import->module_name = wasm_dup_string_slice(ctx->allocator, module_name); import->func_name = wasm_dup_string_slice(ctx->allocator, function_name); + import->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE | + WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; import->decl.type_var.type = WASM_VAR_TYPE_INDEX; - assert(sig_index < ctx->module->func_types.size); import->decl.type_var.index = sig_index; + import->decl.sig = ctx->module->func_types.data[sig_index]->sig; - assert(index < ctx->module->imports.capacity); WasmImportPtr* import_ptr = wasm_append_import_ptr(ctx->allocator, &ctx->module->imports); *import_ptr = import; @@ -382,6 +384,9 @@ static WasmResult on_function_signature(uint32_t index, uint32_t sig_index, void* user_data) { Context* ctx = user_data; + assert(index < ctx->module->funcs.capacity); + assert(sig_index < ctx->module->func_types.size); + WasmModuleField* field = wasm_append_module_field(ctx->allocator, ctx->module); field->type = WASM_MODULE_FIELD_TYPE_FUNC; @@ -389,21 +394,11 @@ static WasmResult on_function_signature(uint32_t index, WasmFunc* func = &field->func; WASM_ZERO_MEMORY(*func); func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE | - WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; func->decl.type_var.type = WASM_VAR_TYPE_INDEX; - assert(sig_index < ctx->module->func_types.size); func->decl.type_var.index = sig_index; + func->decl.sig = ctx->module->func_types.data[sig_index]->sig; - /* copy the signature from the function type */ - WasmFuncSignature* sig = &ctx->module->func_types.data[sig_index]->sig; - size_t i; - for (i = 0; i < sig->param_types.size; ++i) { - wasm_append_type_value(ctx->allocator, &func->decl.sig.param_types, - &sig->param_types.data[i]); - } - func->decl.sig.result_type = sig->result_type; - - assert(index < ctx->module->funcs.capacity); WasmFuncPtr* func_ptr = wasm_append_func_ptr(ctx->allocator, &ctx->module->funcs); *func_ptr = func; |