Skip to content

Commit 5c2576d

Browse files
axicpepyakin
andcommitted
Change optimize() to take in a mutable self (#42)
* Add smoke test for optimizer() * Change optimize() to take in a mutable self This is to singal that the underlying data is being changed, despite that this mutability specifier is not needed for the Rust part. Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
1 parent 27dd1af commit 5c2576d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/wasm_opt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() {
9696
process::exit(1);
9797
}
9898
};
99-
let module = read_module(&args.input_path);
99+
let mut module = read_module(&args.input_path);
100100
binaryen::set_global_codegen_config(&args.codegen_config);
101101
module.optimize();
102102

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Module {
9797
/// Returns `Err` if an invalid module is given.
9898
pub fn read(module: &[u8]) -> Result<Module, ()> {
9999
unsafe {
100-
let raw = ffi::BinaryenModuleSafeRead(module.as_ptr() as *mut c_char, module.len());
100+
let raw = ffi::BinaryenModuleSafeRead(module.as_ptr() as *const c_char, module.len());
101101
if raw.is_null() {
102102
return Err(())
103103
}
@@ -114,15 +114,15 @@ impl Module {
114114
/// Run the standard optimization passes on the module.
115115
///
116116
/// It will take into account code generation configuration set by `set_global_codegen_config`.
117-
pub fn optimize(&self) {
117+
pub fn optimize(&mut self) {
118118
unsafe { ffi::BinaryenModuleOptimize(self.inner.raw) }
119119
}
120120

121121
/// Run a specified set of optimization passes on the module.
122122
///
123123
/// This WILL NOT take into account code generation configuration set by `set_global_codegen_config`.
124124
pub fn run_optimization_passes<B: AsRef<str>, I: IntoIterator<Item = B>>(
125-
&self,
125+
&mut self,
126126
passes: I,
127127
) -> Result<(), ()> {
128128
let mut cstr_vec: Vec<_> = vec![];
@@ -213,7 +213,7 @@ mod tests {
213213
)
214214
)
215215
"#;
216-
let module = Module::read(&wat2wasm!(CODE)).unwrap();
216+
let mut module = Module::read(&wat2wasm!(CODE)).unwrap();
217217

218218
assert!(module.is_valid());
219219

@@ -224,7 +224,7 @@ mod tests {
224224

225225
#[test]
226226
fn test_invalid_optimization_passes() {
227-
let module = Module::new();
227+
let mut module = Module::new();
228228
assert!(module.run_optimization_passes(&["invalid"]).is_err());
229229
}
230230

@@ -241,7 +241,7 @@ mod tests {
241241
0x0a, 0x05, 0x01, 0x03, 0x00, 0x01, 0x0b,
242242
];
243243

244-
let module = Module::read(&input).unwrap();
244+
let mut module = Module::read(&input).unwrap();
245245
assert!(module.is_valid());
246246
module.optimize();
247247
assert!(module.is_valid());

0 commit comments

Comments
 (0)