mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-28 08:51:05 +00:00
minimal test and expects replace
This commit is contained in:
parent
9787b36b77
commit
67ec3b6e2d
@ -380,4 +380,33 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn minimal() {
|
||||||
|
let mut module = builder::module()
|
||||||
|
.function()
|
||||||
|
.signature().param().i32().build()
|
||||||
|
.body().build()
|
||||||
|
.build()
|
||||||
|
.function()
|
||||||
|
.signature().param().i32().param().i32().build()
|
||||||
|
.body().build()
|
||||||
|
.build()
|
||||||
|
.export()
|
||||||
|
.field("_call")
|
||||||
|
.internal().func(0).build()
|
||||||
|
.export()
|
||||||
|
.field("_random")
|
||||||
|
.internal().func(1).build()
|
||||||
|
.build();
|
||||||
|
assert_eq!(module.export_section().expect("export section to be generated").entries().len(), 2);
|
||||||
|
|
||||||
|
optimize(&mut module, vec!["_call"]).expect("optimizer to succeed");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
1,
|
||||||
|
module.export_section().expect("export section to be generated").entries().len(),
|
||||||
|
"There should only 1 (one) export entry in the optimized module"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,15 +12,17 @@ pub enum Symbol {
|
|||||||
|
|
||||||
pub fn resolve_function(module: &elements::Module, index: u32) -> Symbol {
|
pub fn resolve_function(module: &elements::Module, index: u32) -> Symbol {
|
||||||
let mut functions = 0;
|
let mut functions = 0;
|
||||||
for (item_index, item) in module.import_section().expect("Functions section to exist").entries().iter().enumerate() {
|
if let Some(import_section) = module.import_section() {
|
||||||
match item.external() {
|
for (item_index, item) in import_section.entries().iter().enumerate() {
|
||||||
&elements::External::Function(_) => {
|
match item.external() {
|
||||||
if functions == index {
|
&elements::External::Function(_) => {
|
||||||
return Symbol::Import(item_index as usize);
|
if functions == index {
|
||||||
}
|
return Symbol::Import(item_index as usize);
|
||||||
functions += 1;
|
}
|
||||||
},
|
functions += 1;
|
||||||
_ => {}
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,15 +31,17 @@ pub fn resolve_function(module: &elements::Module, index: u32) -> Symbol {
|
|||||||
|
|
||||||
pub fn resolve_global(module: &elements::Module, index: u32) -> Symbol {
|
pub fn resolve_global(module: &elements::Module, index: u32) -> Symbol {
|
||||||
let mut globals = 0;
|
let mut globals = 0;
|
||||||
for (item_index, item) in module.import_section().expect("Functions section to exist").entries().iter().enumerate() {
|
if let Some(import_section) = module.import_section() {
|
||||||
match item.external() {
|
for (item_index, item) in import_section.entries().iter().enumerate() {
|
||||||
&elements::External::Global(_) => {
|
match item.external() {
|
||||||
if globals == index {
|
&elements::External::Global(_) => {
|
||||||
return Symbol::Import(item_index as usize);
|
if globals == index {
|
||||||
}
|
return Symbol::Import(item_index as usize);
|
||||||
globals += 1;
|
}
|
||||||
},
|
globals += 1;
|
||||||
_ => {}
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user