mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-16 03:20:50 +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());
|
||||
}
|
||||
|
||||
#[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 {
|
||||
let mut functions = 0;
|
||||
for (item_index, item) in module.import_section().expect("Functions section to exist").entries().iter().enumerate() {
|
||||
match item.external() {
|
||||
&elements::External::Function(_) => {
|
||||
if functions == index {
|
||||
return Symbol::Import(item_index as usize);
|
||||
}
|
||||
functions += 1;
|
||||
},
|
||||
_ => {}
|
||||
if let Some(import_section) = module.import_section() {
|
||||
for (item_index, item) in import_section.entries().iter().enumerate() {
|
||||
match item.external() {
|
||||
&elements::External::Function(_) => {
|
||||
if functions == index {
|
||||
return Symbol::Import(item_index as usize);
|
||||
}
|
||||
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 {
|
||||
let mut globals = 0;
|
||||
for (item_index, item) in module.import_section().expect("Functions section to exist").entries().iter().enumerate() {
|
||||
match item.external() {
|
||||
&elements::External::Global(_) => {
|
||||
if globals == index {
|
||||
return Symbol::Import(item_index as usize);
|
||||
}
|
||||
globals += 1;
|
||||
},
|
||||
_ => {}
|
||||
if let Some(import_section) = module.import_section() {
|
||||
for (item_index, item) in import_section.entries().iter().enumerate() {
|
||||
match item.external() {
|
||||
&elements::External::Global(_) => {
|
||||
if globals == index {
|
||||
return Symbol::Import(item_index as usize);
|
||||
}
|
||||
globals += 1;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user