wasmonkey 0.1.18

WebAssembly object-file patcher for replacing exported functions with imports from a builtins library
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use parity_wasm::elements::{FunctionNameSubsection, IndexMap};

use crate::errors::*;

pub fn prepend_function_name(
    function_names_subsection: &mut FunctionNameSubsection,
    name: String,
) -> Result<(), WError> {
    let mut map_new = IndexMap::with_capacity(function_names_subsection.names().len() + 1_usize);
    for (idx, name) in function_names_subsection.names() {
        map_new.insert(idx + 1, name.clone());
    }
    map_new.insert(0, name);
    *function_names_subsection.names_mut() = map_new;
    Ok(())
}