This commit is contained in:
Graham Kelly 2024-08-10 15:02:05 -04:00
parent 8db8a02347
commit 8fff4913c0
4 changed files with 28 additions and 7 deletions

View file

@ -1145,7 +1145,8 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
.map(|elts| elts.len() as u64) .map(|elts| elts.len() as u64)
.unwrap_or(table.initial), .unwrap_or(table.initial),
maximum: table.max, maximum: table.max,
table64: false, table64: table.table64,
}) })
} }
&ImportKind::Global(global) => { &ImportKind::Global(global) => {
@ -1198,7 +1199,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
.map(|elt| elt.len()) .map(|elt| elt.len())
.unwrap_or(0) as u64, .unwrap_or(0) as u64,
maximum: table_data.max, maximum: table_data.max,
table64: false, table64: table_data.table64,
}); });
} }
into_mod.section(&tables); into_mod.section(&tables);

View file

@ -135,6 +135,7 @@ fn handle_payload<'a>(
ty.element_type.into(), ty.element_type.into(),
ty.initial, ty.initial,
ty.maximum, ty.maximum,
ty.table64,
); );
ImportKind::Table(table) ImportKind::Table(table)
} }
@ -182,6 +183,7 @@ fn handle_payload<'a>(
table.ty.element_type.into(), table.ty.element_type.into(),
table.ty.initial, table.ty.initial,
table.ty.maximum, table.ty.maximum,
table.ty.table64,
); );
} }
} }

View file

@ -47,6 +47,7 @@ pub struct MemorySegment {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
pub struct TableData { pub struct TableData {
pub ty: Type, pub ty: Type,
pub table64: bool,
pub initial: u64, pub initial: u64,
pub max: Option<u64>, pub max: Option<u64>,
pub func_elements: Option<Vec<Func>>, pub func_elements: Option<Vec<Func>>,
@ -177,13 +178,14 @@ impl<'a> Module<'a> {
} }
impl<'a> Module<'a> { impl<'a> Module<'a> {
pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option<u64>) -> Table { pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option<u64>, table64: bool) -> Table {
let func_elements = Some(vec![]); let func_elements = Some(vec![]);
self.tables.push(TableData { self.tables.push(TableData {
ty, ty,
func_elements, func_elements,
initial, initial,
max, max,
table64
}) })
} }

View file

@ -257,12 +257,24 @@ pub fn op_inputs(
Operator::F64ReinterpretI64 => Ok(Cow::Borrowed(&[Type::I64])), Operator::F64ReinterpretI64 => Ok(Cow::Borrowed(&[Type::I64])),
Operator::I32ReinterpretF32 => Ok(Cow::Borrowed(&[Type::F32])), Operator::I32ReinterpretF32 => Ok(Cow::Borrowed(&[Type::F32])),
Operator::I64ReinterpretF64 => Ok(Cow::Borrowed(&[Type::F64])), 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 } => { 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 } => { 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::TableSize { .. } => Ok(Cow::Borrowed(&[])),
Operator::MemorySize { .. } => 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::TableGet { table_index } => Ok(vec![module.tables[*table_index].ty].into()),
Operator::TableSet { .. } => Ok(Cow::Borrowed(&[])), Operator::TableSet { .. } => Ok(Cow::Borrowed(&[])),
Operator::TableGrow { .. } => 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 { Operator::MemorySize { mem } => Ok(if module.memories[*mem].memory64 {
Cow::Borrowed(&[Type::I64]) Cow::Borrowed(&[Type::I64])
} else { } else {