Compare commits
2 Commits
renovate/c
...
trunk
Author | SHA1 | Date | |
---|---|---|---|
49f93b7975 | |||
5b0f87f02b |
@ -1,4 +1,5 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"codegen/luajit",
|
||||
"codegen/luau",
|
||||
|
@ -4,7 +4,7 @@ version = "0.12.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
wasmparser = "0.107.0"
|
||||
wasmparser = "0.206.0"
|
||||
|
||||
[dependencies.wasm-ast]
|
||||
path = "../../wasm-ast"
|
||||
|
@ -41,14 +41,16 @@ fn reader_to_code(reader: OperatorsReader) -> Vec<Operator> {
|
||||
}
|
||||
|
||||
fn write_named_array(name: &str, len: usize, w: &mut dyn Write) -> Result<()> {
|
||||
let Some(len) = len.checked_sub(1) else { return Ok(()) };
|
||||
let Some(len) = len.checked_sub(1) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
writeln!(w, "local {name} = table_new({len}, 1)")
|
||||
}
|
||||
|
||||
fn write_constant(init: &ConstExpr, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||
let code = reader_to_code(init.get_operators_reader());
|
||||
let func = Factory::from_type_info(type_info).create_anonymous(&code);
|
||||
let func = Factory::from_type_info(type_info).create_anonymous(code.as_slice());
|
||||
|
||||
if let Some(Statement::SetTemporary(stat)) = func.code().code().last() {
|
||||
stat.value().write(&mut Manager::empty(), w)
|
||||
@ -151,7 +153,11 @@ fn write_global_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) ->
|
||||
|
||||
fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
|
||||
for element in list {
|
||||
let ElementKind::Active { table_index: index, offset_expr: init } = element.kind else {
|
||||
let ElementKind::Active {
|
||||
table_index: index,
|
||||
offset_expr: init,
|
||||
} = element.kind
|
||||
else {
|
||||
unimplemented!("passive elements not supported")
|
||||
};
|
||||
|
||||
@ -173,7 +179,7 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write)
|
||||
write!(w, "FUNC_LIST[{index}],")?;
|
||||
}
|
||||
}
|
||||
ElementItems::Expressions(expressions) => {
|
||||
ElementItems::Expressions(_, expressions) => {
|
||||
for init in expressions {
|
||||
let init = init.unwrap();
|
||||
write_constant(&init, type_info, w)?;
|
||||
|
@ -4,7 +4,7 @@ version = "0.12.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
wasmparser = "0.107.0"
|
||||
wasmparser = "0.206.0"
|
||||
|
||||
[dependencies.wasm-ast]
|
||||
path = "../../wasm-ast"
|
||||
|
@ -180,7 +180,7 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write)
|
||||
write!(w, "FUNC_LIST[{index}],")?;
|
||||
}
|
||||
}
|
||||
ElementItems::Expressions(expressions) => {
|
||||
ElementItems::Expressions(_, expressions) => {
|
||||
for init in expressions {
|
||||
let init = init.unwrap();
|
||||
write_constant(&init, type_info, w)?;
|
||||
|
@ -8,15 +8,15 @@ publish = false
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4.6"
|
||||
wasm-smith = "0.12.10"
|
||||
libfuzzer-sys = "0.4.7"
|
||||
wasm-smith = "0.206.0"
|
||||
wasm-ast = { path = "../wasm-ast" }
|
||||
codegen-luajit = { path = "../codegen/luajit" }
|
||||
codegen-luau = { path = "../codegen/luau" }
|
||||
|
||||
[dev-dependencies]
|
||||
test-generator = "0.3.1"
|
||||
wast = "60.0.0"
|
||||
wast = "206.0.0"
|
||||
|
||||
[[bin]]
|
||||
name = "luajit_translate"
|
||||
|
@ -74,7 +74,7 @@ impl Target for LuaJIT {
|
||||
Self::write_call_of("assert_trap", data, w)?;
|
||||
writeln!(w)
|
||||
}
|
||||
WastExecute::Get { module, global } => {
|
||||
WastExecute::Get { module, global, .. } => {
|
||||
let name = get_name_from_id(*module);
|
||||
|
||||
write!(w, "assert_neq(")?;
|
||||
@ -114,7 +114,7 @@ impl Target for LuaJIT {
|
||||
|
||||
writeln!(w, "}})")
|
||||
}
|
||||
WastExecute::Get { module, global } => {
|
||||
WastExecute::Get { module, global, .. } => {
|
||||
let name = get_name_from_id(*module);
|
||||
|
||||
write!(w, "assert_eq(")?;
|
||||
|
@ -88,7 +88,7 @@ impl Target for Luau {
|
||||
Self::write_call_of("assert_trap", data, w)?;
|
||||
writeln!(w)
|
||||
}
|
||||
WastExecute::Get { module, global } => {
|
||||
WastExecute::Get { module, global, .. } => {
|
||||
let name = get_name_from_id(*module);
|
||||
|
||||
write!(w, "assert_neq(")?;
|
||||
@ -128,7 +128,7 @@ impl Target for Luau {
|
||||
|
||||
writeln!(w, "}})")
|
||||
}
|
||||
WastExecute::Get { module, global } => {
|
||||
WastExecute::Get { module, global, .. } => {
|
||||
let name = get_name_from_id(*module);
|
||||
|
||||
write!(w, "assert_eq(")?;
|
||||
|
@ -41,8 +41,8 @@ macro_rules! impl_write_number_nan {
|
||||
};
|
||||
}
|
||||
|
||||
impl_write_number_nan!(write_f32, write_f32_nan, f32, wast::token::Float32);
|
||||
impl_write_number_nan!(write_f64, write_f64_nan, f64, wast::token::Float64);
|
||||
impl_write_number_nan!(write_f32, write_f32_nan, f32, wast::token::F32);
|
||||
impl_write_number_nan!(write_f64, write_f64_nan, f64, wast::token::F64);
|
||||
|
||||
#[allow(clippy::missing_const_for_fn)]
|
||||
fn try_into_ast_module(data: QuoteWat) -> Option<WaModule> {
|
||||
|
@ -4,4 +4,4 @@ version = "0.12.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
wasmparser = "0.107.0"
|
||||
wasmparser = "0.206.0"
|
||||
|
@ -2,7 +2,8 @@ use std::collections::HashMap;
|
||||
|
||||
use wasmparser::{
|
||||
BlockType, Data, Element, Export, ExternalKind, FunctionBody, Global, Import, LocalsReader,
|
||||
MemoryType, Name, NameSectionReader, Parser, Payload, Result, Table, Type, TypeRef, ValType,
|
||||
MemoryType, Name, NameSectionReader, Parser, Payload, RecGroup as Type, Result, Table, TypeRef,
|
||||
ValType,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
@ -255,10 +256,11 @@ impl<'a> TypeInfo<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn by_type_index(&self, index: usize) -> (usize, usize) {
|
||||
let Type::Func(ty) = &self.type_list[index] else {
|
||||
unreachable!("type at func index must be a func type");
|
||||
};
|
||||
// let Type::Func(ty) = &self.type_list[index] else {
|
||||
// unreachable!("type at func index must be a func type");
|
||||
// };
|
||||
|
||||
let ty = self.type_list[index].types().next().unwrap().unwrap_func();
|
||||
(ty.params().len(), ty.results().len())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user