From 8fff4913c0dcd18db52a6d6aad3728c114d5d9a2 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Sat, 10 Aug 2024 15:02:05 -0400 Subject: [PATCH] table64 --- src/backend/mod.rs | 5 +++-- src/frontend.rs | 2 ++ src/ir/module.rs | 4 +++- src/op_traits.rs | 24 ++++++++++++++++++++---- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index c27e837..ea2b865 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1145,7 +1145,8 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { .map(|elts| elts.len() as u64) .unwrap_or(table.initial), maximum: table.max, - table64: false, + table64: table.table64, + }) } &ImportKind::Global(global) => { @@ -1198,7 +1199,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { .map(|elt| elt.len()) .unwrap_or(0) as u64, maximum: table_data.max, - table64: false, + table64: table_data.table64, }); } into_mod.section(&tables); diff --git a/src/frontend.rs b/src/frontend.rs index a1c2673..e7645b8 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -135,6 +135,7 @@ fn handle_payload<'a>( ty.element_type.into(), ty.initial, ty.maximum, + ty.table64, ); ImportKind::Table(table) } @@ -182,6 +183,7 @@ fn handle_payload<'a>( table.ty.element_type.into(), table.ty.initial, table.ty.maximum, + table.ty.table64, ); } } diff --git a/src/ir/module.rs b/src/ir/module.rs index 6af9fe1..8d88c83 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -47,6 +47,7 @@ pub struct MemorySegment { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)] pub struct TableData { pub ty: Type, + pub table64: bool, pub initial: u64, pub max: Option, pub func_elements: Option>, @@ -177,13 +178,14 @@ impl<'a> Module<'a> { } impl<'a> Module<'a> { - pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option) -> Table { + pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option, table64: bool) -> Table { let func_elements = Some(vec![]); self.tables.push(TableData { ty, func_elements, initial, max, + table64 }) } diff --git a/src/op_traits.rs b/src/op_traits.rs index 9532584..b3c9c04 100644 --- a/src/op_traits.rs +++ b/src/op_traits.rs @@ -257,12 +257,24 @@ pub fn op_inputs( Operator::F64ReinterpretI64 => Ok(Cow::Borrowed(&[Type::I64])), Operator::I32ReinterpretF32 => Ok(Cow::Borrowed(&[Type::F32])), Operator::I64ReinterpretF64 => Ok(Cow::Borrowed(&[Type::F64])), - Operator::TableGet { .. } => Ok(Cow::Borrowed(&[Type::I32])), + Operator::TableGet { table_index } => if module.tables[*table_index].table64{ + Ok(Cow::Borrowed(&[Type::I64])) + }else{ + Ok(Cow::Borrowed(&[Type::I32])) + }, Operator::TableSet { table_index } => { - Ok(vec![Type::I32, module.tables[*table_index].ty].into()) + Ok(vec![if module.tables[*table_index].table64{ + Type::I64 + }else{ + Type::I32 + }, module.tables[*table_index].ty].into()) } Operator::TableGrow { table_index } => { - Ok(vec![Type::I32, module.tables[*table_index].ty].into()) + Ok(vec![if module.tables[*table_index].table64{ + Type::I64 + }else{ + Type::I32 + }, module.tables[*table_index].ty].into()) } Operator::TableSize { .. } => Ok(Cow::Borrowed(&[])), Operator::MemorySize { .. } => Ok(Cow::Borrowed(&[])), @@ -1302,7 +1314,11 @@ pub fn op_outputs( Operator::TableGet { table_index } => Ok(vec![module.tables[*table_index].ty].into()), Operator::TableSet { .. } => Ok(Cow::Borrowed(&[])), Operator::TableGrow { .. } => Ok(Cow::Borrowed(&[])), - Operator::TableSize { .. } => Ok(Cow::Borrowed(&[Type::I32])), + Operator::TableSize { table_index } => Ok(Cow::Borrowed(if module.tables[*table_index].table64{ + &[Type::I64] + }else{ + &[Type::I32] + })), Operator::MemorySize { mem } => Ok(if module.memories[*mem].memory64 { Cow::Borrowed(&[Type::I64]) } else {