mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-28 08:51:05 +00:00
global optimization happy path
This commit is contained in:
parent
67ec3b6e2d
commit
2a7e93a764
@ -365,10 +365,10 @@ pub fn type_section<'a>(module: &'a mut elements::Module) -> Option<&'a mut elem
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use parity_wasm::builder;
|
use parity_wasm::{builder, elements};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// @spec
|
/// @spec 0
|
||||||
/// Optimizer presumes that export section exists and contains
|
/// Optimizer presumes that export section exists and contains
|
||||||
/// all symbols passed as a second parameter. Since empty module
|
/// all symbols passed as a second parameter. Since empty module
|
||||||
/// obviously contains no export section, optimizer should return
|
/// obviously contains no export section, optimizer should return
|
||||||
@ -381,6 +381,11 @@ mod tests {
|
|||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @spec 1
|
||||||
|
/// Imagine the unoptimized module has two own functions, `_call` and `_random`
|
||||||
|
/// and exports both of them in the export section. During optimization, the `_random`
|
||||||
|
/// function should vanish completely, given we pass `_call` as the only function to stay
|
||||||
|
/// in the module.
|
||||||
#[test]
|
#[test]
|
||||||
fn minimal() {
|
fn minimal() {
|
||||||
let mut module = builder::module()
|
let mut module = builder::module()
|
||||||
@ -389,7 +394,10 @@ mod tests {
|
|||||||
.body().build()
|
.body().build()
|
||||||
.build()
|
.build()
|
||||||
.function()
|
.function()
|
||||||
.signature().param().i32().param().i32().build()
|
.signature()
|
||||||
|
.param().i32()
|
||||||
|
.param().i32()
|
||||||
|
.build()
|
||||||
.body().build()
|
.body().build()
|
||||||
.build()
|
.build()
|
||||||
.export()
|
.export()
|
||||||
@ -409,4 +417,39 @@ mod tests {
|
|||||||
"There should only 1 (one) export entry in the optimized module"
|
"There should only 1 (one) export entry in the optimized module"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @spec 2
|
||||||
|
/// Imagine there is one exported function in unoptimized module, `_call`, that we specify as the one
|
||||||
|
/// to stay during the optimization. The code of this function uses global during the execution.
|
||||||
|
/// This sayed global should survive the optimization.
|
||||||
|
#[test]
|
||||||
|
fn globals() {
|
||||||
|
let mut module = builder::module()
|
||||||
|
.global()
|
||||||
|
.value_type().i32()
|
||||||
|
.build()
|
||||||
|
.function()
|
||||||
|
.signature().param().i32().build()
|
||||||
|
.body()
|
||||||
|
.with_opcodes(elements::Opcodes::new(
|
||||||
|
vec![
|
||||||
|
elements::Opcode::GetGlobal(0),
|
||||||
|
elements::Opcode::End
|
||||||
|
]
|
||||||
|
))
|
||||||
|
.build()
|
||||||
|
.build()
|
||||||
|
.export()
|
||||||
|
.field("_call")
|
||||||
|
.internal().func(0).build()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
optimize(&mut module, vec!["_call"]).expect("optimizer to succeed");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
1,
|
||||||
|
module.global_section().expect("global section to be generated").entries().len(),
|
||||||
|
"There should 1 (one) global entry in the optimized module, since _call function uses it"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user