only function imports should be excluded from function_index

This commit is contained in:
fro 2017-07-17 16:59:40 +03:00
parent 1b8ecf11a5
commit bd0c0f70e7

View File

@ -3,7 +3,8 @@ extern crate parity_wasm;
use std::env::args;
use parity_wasm::{interpreter, ModuleInstanceInterface, RuntimeValue};
use parity_wasm::elements::{Internal, Type, FunctionType, ValueType};
use parity_wasm::elements::{Internal, External, Type, FunctionType, ValueType};
fn main() {
let args: Vec<_> = args().collect();
@ -37,9 +38,14 @@ fn main() {
_ => panic!("Founded export is not a function"),
};
let import_section_len: usize = match module.import_section() {
Some(import) => import.entries().len(),
Some(import) =>
import.entries().iter().filter(|entry| match entry.external() {
&External::Function(_) => true,
_ => false,
}).collect::<Vec<_>>().len(),
None => 0,
};
println!("{:?}", import_section_len);
let function_index_in_section = function_index - import_section_len;
let func_type_ref: usize = function_section.entries()[function_index_in_section].type_ref() as usize;