Skip to content

Commit

Permalink
Merge branch 'master' into rename_crates
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb authored Mar 15, 2023
2 parents feb79e4 + f8c0910 commit 21b0bb6
Show file tree
Hide file tree
Showing 26 changed files with 606 additions and 614 deletions.
12 changes: 8 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ js-sys = "0.3.51"
#web-sys = { version = "0.3.51", features = [ "console" ] }
wasmer-derive = { path = "../derive", version = "=3.2.0-alpha.1" }
# - Optional dependencies for `js`.
wasmparser = { version = "0.83", default-features = false, optional = true }
wasmparser = { version = "0.95", default-features = false, optional = true }
hashbrown = { version = "0.11", optional = true }
serde-wasm-bindgen = { version = "0.4.5" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
113 changes: 55 additions & 58 deletions lib/api/src/js/module_info_polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use wasmer_types::{
};

use wasmparser::{
self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FuncType as WPFunctionType,
FunctionSectionReader, GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionEntryType,
ImportSectionReader, MemorySectionReader, MemoryType as WPMemoryType, NameSectionReader,
Parser, Payload, TableSectionReader, TypeDef, TypeSectionReader,
self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionReader, MemorySectionReader,
MemoryType as WPMemoryType, NameSectionReader, Parser, Payload, TableSectionReader, TypeRef,
TypeSectionReader,
};

pub type WasmResult<T> = Result<T, String>;
Expand Down Expand Up @@ -283,15 +283,17 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult<ModuleInfoPolyfi
parse_export_section(exports, &mut module_info)?;
}

Payload::CustomSection {
name: "name",
data,
data_offset,
..
} => parse_name_section(
NameSectionReader::new(data, data_offset).map_err(transform_err)?,
&mut module_info,
)?,
Payload::CustomSection(sectionreader) => {
// We still add the custom section data, but also read it as name section reader
let name = sectionreader.name();
if name == "name" {
parse_name_section(
NameSectionReader::new(sectionreader.data(), sectionreader.data_offset())
.map_err(transform_err)?,
&mut module_info,
)?;
}
}

_ => {}
}
Expand All @@ -301,16 +303,15 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult<ModuleInfoPolyfi
}

/// Helper function translating wasmparser types to Wasm Type.
pub fn wptype_to_type(ty: wasmparser::Type) -> WasmResult<Type> {
pub fn wptype_to_type(ty: wasmparser::ValType) -> WasmResult<Type> {
match ty {
wasmparser::Type::I32 => Ok(Type::I32),
wasmparser::Type::I64 => Ok(Type::I64),
wasmparser::Type::F32 => Ok(Type::F32),
wasmparser::Type::F64 => Ok(Type::F64),
wasmparser::Type::V128 => Ok(Type::V128),
wasmparser::Type::ExternRef => Ok(Type::ExternRef),
wasmparser::Type::FuncRef => Ok(Type::FuncRef),
ty => Err(format!("wptype_to_type: wasmparser type {:?}", ty)),
wasmparser::ValType::I32 => Ok(Type::I32),
wasmparser::ValType::I64 => Ok(Type::I64),
wasmparser::ValType::F32 => Ok(Type::F32),
wasmparser::ValType::F64 => Ok(Type::F64),
wasmparser::ValType::V128 => Ok(Type::V128),
wasmparser::ValType::ExternRef => Ok(Type::ExternRef),
wasmparser::ValType::FuncRef => Ok(Type::FuncRef),
}
}

Expand All @@ -323,7 +324,9 @@ pub fn parse_type_section(
module_info.reserve_signatures(count)?;

for entry in types {
if let Ok(TypeDef::Func(WPFunctionType { params, returns })) = entry {
if let Ok(wasmparser::Type::Func(functype)) = entry {
let params = functype.params();
let returns = functype.results();
let sig_params: Vec<Type> = params
.iter()
.map(|ty| {
Expand Down Expand Up @@ -358,23 +361,20 @@ pub fn parse_import_section<'data>(
for entry in imports {
let import = entry.map_err(transform_err)?;
let module_name = import.module;
let field_name = import.field;
let field_name = import.name;

match import.ty {
ImportSectionEntryType::Function(sig) => {
TypeRef::Func(sig) => {
module_info.declare_func_import(
SignatureIndex::from_u32(sig),
module_name,
field_name.unwrap_or_default(),
field_name,
)?;
}
ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => {
unimplemented!("module linking not implemented yet")
}
ImportSectionEntryType::Tag(_) => {
TypeRef::Tag(_) => {
unimplemented!("exception handling not implemented yet")
}
ImportSectionEntryType::Memory(WPMemoryType {
TypeRef::Memory(WPMemoryType {
shared,
memory64,
initial,
Expand All @@ -390,28 +390,28 @@ pub fn parse_import_section<'data>(
shared,
},
module_name,
field_name.unwrap_or_default(),
field_name,
)?;
}
ImportSectionEntryType::Global(ref ty) => {
TypeRef::Global(ref ty) => {
module_info.declare_global_import(
GlobalType {
ty: wptype_to_type(ty.content_type).unwrap(),
mutability: ty.mutable.into(),
},
module_name,
field_name.unwrap_or_default(),
field_name,
)?;
}
ImportSectionEntryType::Table(ref tab) => {
TypeRef::Table(ref tab) => {
module_info.declare_table_import(
TableType {
ty: wptype_to_type(tab.element_type).unwrap(),
minimum: tab.initial,
maximum: tab.maximum,
},
module_name,
field_name.unwrap_or_default(),
field_name,
)?;
}
}
Expand Down Expand Up @@ -512,7 +512,7 @@ pub fn parse_export_section<'data>(

for entry in exports {
let Export {
field,
name,
ref kind,
index,
} = entry.map_err(transform_err)?;
Expand All @@ -522,20 +522,17 @@ pub fn parse_export_section<'data>(
// becomes a concern here.
let index = index as usize;
match *kind {
ExternalKind::Function => {
module_info.declare_func_export(FunctionIndex::new(index), field)?
ExternalKind::Func => {
module_info.declare_func_export(FunctionIndex::new(index), name)?
}
ExternalKind::Table => {
module_info.declare_table_export(TableIndex::new(index), field)?
module_info.declare_table_export(TableIndex::new(index), name)?
}
ExternalKind::Memory => {
module_info.declare_memory_export(MemoryIndex::new(index), field)?
module_info.declare_memory_export(MemoryIndex::new(index), name)?
}
ExternalKind::Global => {
module_info.declare_global_export(GlobalIndex::new(index), field)?
}
ExternalKind::Type | ExternalKind::Module | ExternalKind::Instance => {
unimplemented!("module linking not implemented yet")
module_info.declare_global_export(GlobalIndex::new(index), name)?
}
ExternalKind::Tag => {
unimplemented!("exception handling not implemented yet")
Expand All @@ -559,20 +556,20 @@ pub fn parse_name_section<'data>(
while let Ok(subsection) = names.read() {
match subsection {
wasmparser::Name::Function(_function_subsection) => {
// if let Some(function_names) = function_subsection
// .get_map()
// .ok()
// .and_then(parse_function_name_subsection)
// {
// for (index, name) in function_names {
// module_info.declare_function_name(index, name)?;
// }
// }
//for naming in function_subsection.into_iter().flatten() {
// if naming.index != std::u32::MAX {
// environ.declare_function_name(
// FunctionIndex::from_u32(naming.index),
// naming.name,
// )?;
// }
//}
}
wasmparser::Name::Module(module) => {
if let Ok(name) = module.get_name() {
module_info.declare_module_name(name)?;
}
wasmparser::Name::Module {
name,
name_range: _,
} => {
module_info.declare_module_name(name)?;
}
wasmparser::Name::Local(_) => {}
wasmparser::Name::Label(_)
Expand Down
28 changes: 18 additions & 10 deletions lib/c-api/src/wasm_c_api/unstable/parser/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ pub enum wasmer_parser_operator_t {
F32x4RelaxedMax,
F64x2RelaxedMin,
F64x2RelaxedMax,
I16x8RelaxedQ15mulrS,
I16x8DotI8x16I7x16S,
I32x4DotI8x16I7x16AddS,
F32x4RelaxedDotBf16x8AddF32x4,
}

impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
Expand Down Expand Up @@ -1044,8 +1048,8 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::V128Store16Lane { .. } => Self::V128Store16Lane,
O::V128Store32Lane { .. } => Self::V128Store32Lane,
O::V128Store64Lane { .. } => Self::V128Store64Lane,
O::I8x16RoundingAverageU => Self::I8x16RoundingAverageU,
O::I16x8RoundingAverageU => Self::I16x8RoundingAverageU,
O::I8x16AvgrU => Self::I8x16RoundingAverageU,
O::I16x8AvgrU => Self::I16x8RoundingAverageU,
O::I16x8Q15MulrSatS => Self::I16x8Q15MulrSatS,
O::F32x4DemoteF64x2Zero => Self::F32x4DemoteF64x2Zero,
O::F64x2PromoteLowF32x4 => Self::F64x2PromoteLowF32x4,
Expand All @@ -1058,18 +1062,22 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
O::F32x4Fma => Self::F32x4Fma,
O::F32x4Fms => Self::F32x4Fms,
O::F64x2Fma => Self::F64x2Fma,
O::F64x2Fms => Self::F64x2Fms,
O::I8x16LaneSelect => Self::I8x16LaneSelect,
O::I16x8LaneSelect => Self::I16x8LaneSelect,
O::I32x4LaneSelect => Self::I32x4LaneSelect,
O::I64x2LaneSelect => Self::I64x2LaneSelect,
O::F32x4RelaxedFma => Self::F32x4Fma,
O::F32x4RelaxedFnma => Self::F32x4Fms,
O::F64x2RelaxedFma => Self::F64x2Fma,
O::F64x2RelaxedFnma => Self::F64x2Fms,
O::I8x16RelaxedLaneselect => Self::I8x16LaneSelect,
O::I16x8RelaxedLaneselect => Self::I16x8LaneSelect,
O::I32x4RelaxedLaneselect => Self::I32x4LaneSelect,
O::I64x2RelaxedLaneselect => Self::I64x2LaneSelect,
O::F32x4RelaxedMin => Self::F32x4RelaxedMin,
O::F32x4RelaxedMax => Self::F32x4RelaxedMax,
O::F64x2RelaxedMin => Self::F64x2RelaxedMin,
O::F64x2RelaxedMax => Self::F64x2RelaxedMax,
O::I16x8RelaxedQ15mulrS => Self::I16x8RelaxedQ15mulrS,
O::I16x8DotI8x16I7x16S => Self::I16x8DotI8x16I7x16S,
O::I32x4DotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS,
O::F32x4RelaxedDotBf16x8AddF32x4 => Self::F32x4RelaxedDotBf16x8AddF32x4,
}
}
}
4 changes: 2 additions & 2 deletions lib/compiler-cranelift/src/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

use cranelift_codegen::Context;
use cranelift_codegen::MachSrcLoc;
use wasmer_compiler::wasmparser::Range;
use std::ops::Range;
use wasmer_types::{FunctionAddressMap, InstructionAddressMap, SourceLoc};

pub fn get_function_address_map(
context: &Context,
range: Range,
range: Range<usize>,
body_len: usize,
) -> FunctionAddressMap {
let mut instructions = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions lib/compiler-cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Function, InstBuilder, Si
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use std::convert::TryFrom;
use wasmer_compiler::wasmparser::Type;
use wasmer_compiler::wasmparser::ValType;
use wasmer_types::entity::EntityRef;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::VMBuiltinFunctionIndex;
Expand Down Expand Up @@ -999,11 +999,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
fn translate_ref_null(
&mut self,
mut pos: cranelift_codegen::cursor::FuncCursor,
ty: Type,
ty: ValType,
) -> WasmResult<ir::Value> {
Ok(match ty {
Type::FuncRef => pos.ins().null(self.reference_type()),
Type::ExternRef => pos.ins().null(self.reference_type()),
ValType::FuncRef => pos.ins().null(self.reference_type()),
ValType::ExternRef => pos.ins().null(self.reference_type()),
_ => {
return Err(WasmError::Unsupported(
"`ref.null T` that is not a `funcref` or an `externref`".into(),
Expand Down
Loading

0 comments on commit 21b0bb6

Please sign in to comment.