/// Parses the optional name section, which provides human-friendly names
/// of functions and locals as a debugging aid, and saves to an in-memory
/// HashMap.
Parses the optional name section, which provides human-friendly names
of functions and locals as a debugging aid, and saves to an in-memory
HashMap.
Parses the optional name section which provides human - friendly names of functions and locals as a debugging aid and saves to an in - memory HashMap .
fn process_name_section(&mut self, data: &[u8]) -> Result<(), Box<dyn Error>> {
        let reader = NameSectionReader::new(data, 0)?;
        for name in reader {
            match name? {
                Name::Function(nm) => {
                    let mut map = nm.get_map()?;
                    for _ in 0..map.get_count() {
                        let Naming { name, index } = map.read()?;
                        // The function names in a WebAssembly Name Section are not
                        // guaranteed to be unique. Duplicates occur when compiling
                        // from languages with function overloading. In order to
                        // guarantee unique symbols, we append a unique suffix.
                        let mut suffix = 0;
                        let mut unique_name = name.to_string();
                        while self.function_names.contains(&unique_name) {
                            suffix = suffix + 1;
                            unique_name = format!("{}_{}", name, suffix);
                        }
                        self.function_names.insert(unique_name.clone());
                        self.function_name_maps.insert(
                            index,
                            FunctionNameMap {
                                name: unique_name,
                                locals: HashMap::new(),
                            },
                        );
                    }
                }
                Name::Local(nm) => {
                    let mut fn_reader = nm.get_function_local_reader()?;
                    for _ in 0..fn_reader.get_count() {
                        let fn_locals = fn_reader.read()?;
                        let mut fn_locals_map = fn_locals.get_map()?;
                        for _ in 0..fn_locals_map.get_count() {
                            let local = fn_locals_map.read()?;
                            if let Some(function_name_map) =
                                self.function_name_maps.get_mut(&fn_locals.func_index)
                            {
                                function_name_map
                                    .locals
                                    .insert(local.index, String::from(local.name));
                            }
                        }
                    }
                }
                Name::Module(module_name) => {
                    // This is not derived from a file name.
                    // Extracts the optional label from the module instruction
                    // (module $moduleName).
                    if let Ok(name) = module_name.get_name() {
                        info!("Module Name: {}", name);
                    }
                }
            }
        }
        Ok(())
    }
fn process_name_section ( & mut self , data : & [ u8 ] ) -> Result < ( ) , Box < dyn Error > > { let reader = NameSectionReader :: new ( data , 0 ) ? ; for name in reader { match name ? { Name :: Function ( nm ) => { let mut map = nm . get_map ( ) ? ; for _ in 0 .. map . get_count ( ) { let Naming { name , index } = map . read ( ) ? ; // The function names in a WebAssembly Name Section are not // guaranteed to be unique. Duplicates occur when compiling // from languages with function overloading. In order to // guarantee unique symbols, we append a unique suffix. let mut suffix = 0 ; let mut unique_name = name . to_string ( ) ; while self . function_names . contains ( & unique_name ) { suffix = suffix + 1 ; unique_name = format ! ( " " name suffix ) ; } self . function_names . insert ( unique_name . clone ( ) ) ; self . function_name_maps . insert ( index , FunctionNameMap { name : unique_name , locals : HashMap :: new ( ) , } , ) ; } } Name :: Local ( nm ) => { let mut fn_reader = nm . get_function_local_reader ( ) ? ; for _ in 0 .. fn_reader . get_count ( ) { let fn_locals = fn_reader . read ( ) ? ; let mut fn_locals_map = fn_locals . get_map ( ) ? ; for _ in 0 .. fn_locals_map . get_count ( ) { let local = fn_locals_map . read ( ) ? ; if let Some ( function_name_map ) = self . function_name_maps . get_mut ( & fn_locals . func_index ) { function_name_map . locals . insert ( local . index , String :: from ( local . name ) ) ; } } } } Name :: Module ( module_name ) => { // This is not derived from a file name. // Extracts the optional label from the module instruction // (module $moduleName). if let Ok ( name ) = module_name . get_name ( ) { info ! ( " " name ) ; } } } } Ok ( ( ) ) }
Parses the optional name section, which provides human-friendly names
of functions and locals as a debugging aid, and saves to an in-memory
HashMap.
Parses the optional name section which provides human - friendly names of functions and locals as a debugging aid and saves to an in - memory HashMap .
&mut self
data
&[u8]