Browse Source

cranelift-wasm: Retain both the Wasm and Cranelift types of tables

pull/1901/head
Nick Fitzgerald 4 years ago
parent
commit
c6f32f666d
  1. 2
      cranelift/wasm/src/sections_translator.rs
  2. 6
      cranelift/wasm/src/translation_utils.rs
  3. 5
      crates/jit/src/imports.rs

2
cranelift/wasm/src/sections_translator.rs

@ -108,6 +108,7 @@ pub fn parse_import_section<'data>(
ImportSectionEntryType::Table(ref tab) => {
environ.declare_table_import(
Table {
wasm_ty: tab.element_type,
ty: match tabletype_to_type(tab.element_type, environ)? {
Some(t) => TableElementType::Val(t),
None => TableElementType::Func,
@ -157,6 +158,7 @@ pub fn parse_table_section(
for entry in tables {
let table = entry?;
environ.declare_table(Table {
wasm_ty: table.element_type,
ty: match tabletype_to_type(table.element_type, environ)? {
Some(t) => TableElementType::Val(t),
None => TableElementType::Func,

6
cranelift/wasm/src/translation_utils.rs

@ -1,5 +1,5 @@
//! Helper functions and structures for the translation.
use crate::environ::{TargetEnvironment, WasmResult};
use crate::environ::{TargetEnvironment, WasmResult, WasmType};
use crate::state::ModuleTranslationState;
use crate::wasm_unsupported;
use core::u32;
@ -104,7 +104,9 @@ pub enum GlobalInit {
/// WebAssembly table.
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub struct Table {
/// The type of data stored in elements of the table.
/// The table elements' Wasm type.
pub wasm_ty: WasmType,
/// The table elements' Cranelift type.
pub ty: TableElementType,
/// The minimum number of elements in the table.
pub minimum: u32,

5
crates/jit/src/imports.rs

@ -201,6 +201,7 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool {
let TablePlan {
table:
Table {
wasm_ty: exported_wasm_ty,
ty: exported_ty,
minimum: exported_minimum,
maximum: exported_maximum,
@ -210,6 +211,7 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool {
let TablePlan {
table:
Table {
wasm_ty: imported_wasm_ty,
ty: imported_ty,
minimum: imported_minimum,
maximum: imported_maximum,
@ -217,7 +219,8 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool {
style: _imported_style,
} = imported;
is_table_element_type_compatible(*exported_ty, *imported_ty)
exported_wasm_ty == imported_wasm_ty
&& is_table_element_type_compatible(*exported_ty, *imported_ty)
&& imported_minimum <= exported_minimum
&& (imported_maximum.is_none()
|| (!exported_maximum.is_none()

Loading…
Cancel
Save