@ -10,9 +10,9 @@
use crate ::environ ::{ Alias , ModuleEnvironment , WasmError , WasmResult } ;
use crate ::state ::ModuleTranslationState ;
use crate ::translation_utils ::{
tabletype_to_type , type_to_type , DataIndex , ElemIndex , EntityIndex , EntityType , Event ,
EventIndex , FuncIndex , Global , GlobalIndex , GlobalInit , InstanceIndex , Memory , MemoryIndex ,
ModuleIndex , Table , TableElementType , Table Index , TypeIndex ,
tabletype_to_type , type_to_type , DataIndex , ElemIndex , EntityIndex , EntityType , FuncIndex ,
Global , GlobalIndex , GlobalInit , InstanceIndex , Memory , MemoryIndex , ModuleIndex , Table ,
TableElementType , TableIndex , Tag , Tag Index , TypeIndex ,
} ;
use crate ::wasm_unsupported ;
use core ::convert ::TryFrom ;
@ -24,10 +24,10 @@ use std::boxed::Box;
use std ::vec ::Vec ;
use wasmparser ::{
self , Data , DataKind , DataSectionReader , Element , ElementItem , ElementItems , ElementKind ,
ElementSectionReader , EventSectionReader , EventType , E xport , ExportSectionReader , ExternalKind ,
FunctionSectionReader , GlobalSectionReader , GlobalType , ImportSectionEntryType ,
ImportSectionReader , MemorySectionReader , MemoryType , NameSectionReader , Naming , Operator ,
TableSectionReader , Table Type , TypeDef , TypeSectionReader ,
ElementSectionReader , Export , ExportSectionReader , ExternalKind , FunctionSectionReader ,
GlobalSectionReader , GlobalType , ImportSectionEntryType , ImportSectionReader ,
MemorySectionReader , MemoryType , NameSectionReader , Naming , Operator , TableSectionReader ,
TableType , Tag SectionReader , Tag Type , TypeDef , TypeSectionReader ,
} ;
fn entity_type (
@ -45,7 +45,7 @@ fn entity_type(
EntityType ::Instance ( environ . type_to_instance_type ( TypeIndex ::from_u32 ( sig ) ) ? )
}
ImportSectionEntryType ::Memory ( ty ) = > EntityType ::Memory ( memory ( ty ) ) ,
ImportSectionEntryType ::Event ( ev t) = > EntityType ::Event ( event ( ev t) ) ,
ImportSectionEntryType ::Tag ( t ) = > EntityType ::Tag ( tag ( t ) ) ,
ImportSectionEntryType ::Global ( ty ) = > {
EntityType ::Global ( global ( ty , environ , GlobalInit ::Import ) ? )
}
@ -54,19 +54,16 @@ fn entity_type(
}
fn memory ( ty : MemoryType ) -> Memory {
match ty {
MemoryType ::M32 { limits , shared } = > Memory {
minimum : limits . initial ,
maximum : limits . maximum ,
shared : shared ,
} ,
// FIXME(#2361)
MemoryType ::M64 { . . } = > unimplemented ! ( ) ,
assert ! ( ! ty . memory64 ) ;
Memory {
minimum : ty . initial . try_into ( ) . unwrap ( ) ,
maximum : ty . maximum . map ( | i | i . try_into ( ) . unwrap ( ) ) ,
shared : ty . shared ,
}
}
fn even t( e : EventType ) -> Event {
Event {
fn tag ( e : TagType ) -> Tag {
Tag {
ty : TypeIndex ::from_u32 ( e . type_index ) ,
}
}
@ -78,8 +75,8 @@ fn table(ty: TableType, environ: &mut dyn ModuleEnvironment<'_>) -> WasmResult<T
Some ( t ) = > TableElementType ::Val ( t ) ,
None = > TableElementType ::Func ,
} ,
minimum : ty . limits . initial ,
maximum : ty . limits . maximum ,
minimum : ty . initial ,
maximum : ty . maximum ,
} )
}
@ -174,8 +171,8 @@ pub fn parse_import_section<'data>(
ImportSectionEntryType ::Memory ( ty ) = > {
environ . declare_memory_import ( memory ( ty ) , import . module , import . field ) ? ;
}
ImportSectionEntryType ::Event ( e ) = > {
environ . declare_even t_import ( even t( e ) , import . module , import . field ) ? ;
ImportSectionEntryType ::Tag ( e ) = > {
environ . declare_tag _import ( tag ( e ) , import . module , import . field ) ? ;
}
ImportSectionEntryType ::Global ( ty ) = > {
let ty = global ( ty , environ , GlobalInit ::Import ) ? ;
@ -243,16 +240,16 @@ pub fn parse_memory_section(
Ok ( ( ) )
}
/// Parses the Event section of the wasm module.
pub fn parse_even t_section (
events : Event SectionReader,
/// Parses the Tag section of the wasm module.
pub fn parse_tag _section (
tags : Tag SectionReader,
environ : & mut dyn ModuleEnvironment ,
) -> WasmResult < ( ) > {
environ . reserve_even ts ( even ts. get_count ( ) ) ? ;
environ . reserve_tag s ( tag s . get_count ( ) ) ? ;
for entry in even ts {
let even t = even t( entry ? ) ;
environ . declare_even t ( even t) ? ;
for entry in tag s {
let tag = tag ( entry ? ) ;
environ . declare_tag ( tag ) ? ;
}
Ok ( ( ) )
@ -321,7 +318,7 @@ pub fn parse_export_section<'data>(
ExternalKind ::Memory = > {
environ . declare_memory_export ( MemoryIndex ::new ( index ) , field ) ?
}
ExternalKind ::Event = > environ . declare_even t_export ( Event Index ::new ( index ) , field ) ? ,
ExternalKind ::Tag = > environ . declare_tag _export ( Tag Index ::new ( index ) , field ) ? ,
ExternalKind ::Global = > {
environ . declare_global_export ( GlobalIndex ::new ( index ) , field ) ?
}
@ -473,20 +470,31 @@ pub fn parse_name_section<'data>(
environ . declare_module_name ( name ) ;
}
wasmparser ::Name ::Local ( l ) = > {
let mut reader = l . get_function_local_reader ( ) ? ;
for _ in 0 . . reader . get_count ( ) {
let mut reader = l . get_indirect_map ( ) ? ;
for _ in 0 . . reader . get_indirect_ count ( ) {
let f = reader . read ( ) ? ;
if f . func _index = = u32 ::max_value ( ) {
if f . indirect _index = = u32 ::max_value ( ) {
continue ;
}
let mut map = f . get_map ( ) ? ;
for _ in 0 . . map . get_count ( ) {
let Naming { index , name } = map . read ( ) ? ;
environ . declare_local_name ( FuncIndex ::from_u32 ( f . func_index ) , index , name )
environ . declare_local_name (
FuncIndex ::from_u32 ( f . indirect_index ) ,
index ,
name ,
)
}
}
}
wasmparser ::Name ::Unknown { . . } = > { }
wasmparser ::Name ::Label ( _ )
| wasmparser ::Name ::Type ( _ )
| wasmparser ::Name ::Table ( _ )
| wasmparser ::Name ::Global ( _ )
| wasmparser ::Name ::Memory ( _ )
| wasmparser ::Name ::Element ( _ )
| wasmparser ::Name ::Data ( _ )
| wasmparser ::Name ::Unknown { . . } = > { }
}
}
Ok ( ( ) )
@ -516,7 +524,7 @@ pub fn parse_instance_section<'data>(
ExternalKind ::Instance = > {
EntityIndex ::Instance ( InstanceIndex ::from_u32 ( arg . index ) )
}
ExternalKind ::Event = > unimplemented ! ( ) ,
ExternalKind ::Tag = > unimplemented ! ( ) ,
// this won't pass validation
ExternalKind ::Type = > unreachable ! ( ) ,