cranelift-wasm: support multi-value Wasm (#1049)

This commit introduces initial support for multi-value Wasm. Wasm blocks and
calls can now take and return an arbitrary number of values.

The encoding for multi-value blocks means that we need to keep the contents of
the "Types" section around when translating function bodies. To do this, we
introduce a `WasmTypesMap` type that maps the type indices to their parameters
and returns, construct it when parsing the "Types" section, and shepherd it
through a bunch of functions and methods when translating function bodies.
This commit is contained in:
Nick Fitzgerald
2019-10-02 12:40:35 -07:00
committed by GitHub
parent f9d802fb1d
commit 10be3e4ba8
30 changed files with 610 additions and 138 deletions

View File

@@ -1,6 +1,6 @@
//! Translation skeleton that traverses the whole WebAssembly module and call helper functions
//! to deal with each part of it.
use crate::environ::{ModuleEnvironment, WasmError, WasmResult};
use crate::environ::{ModuleEnvironment, WasmError, WasmResult, WasmTypesMap};
use crate::sections_translator::{
parse_code_section, parse_data_section, parse_element_section, parse_export_section,
parse_function_section, parse_global_section, parse_import_section, parse_memory_section,
@@ -17,12 +17,13 @@ pub fn translate_module<'data>(
) -> WasmResult<()> {
let _tt = timing::wasm_translate_module();
let mut reader = ModuleReader::new(data)?;
let mut wasm_types = WasmTypesMap::new();
while !reader.eof() {
let section = reader.read()?;
match section.content()? {
SectionContent::Type(types) => {
parse_type_section(types, environ)?;
parse_type_section(types, &mut wasm_types, environ)?;
}
SectionContent::Import(imports) => {
@@ -58,7 +59,7 @@ pub fn translate_module<'data>(
}
SectionContent::Code(code) => {
parse_code_section(code, environ)?;
parse_code_section(code, &wasm_types, environ)?;
}
SectionContent::Data(data) => {