Skip to content

Commit

Permalink
A couple small Winch cleanups (bytecodealliance#6526)
Browse files Browse the repository at this point in the history
* Winch: remove tabs, use spaces

* Winch: remove unnecessary mutable references
  • Loading branch information
fitzgen authored Jun 6, 2023
1 parent bea4014 commit 81cd998
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
4 changes: 2 additions & 2 deletions winch/codegen/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> CodeGenContext<'a> {
}

/// Prepares arguments for emitting an i32 binary operation.
pub fn i32_binop<F, M>(&mut self, masm: &mut M, emit: &mut F)
pub fn i32_binop<F, M>(&mut self, masm: &mut M, mut emit: F)
where
F: FnMut(&mut M, RegImm, RegImm, OperandSize),
M: MacroAssembler,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<'a> CodeGenContext<'a> {
}

/// Prepares arguments for emitting an i64 binary operation.
pub fn i64_binop<F, M>(&mut self, masm: &mut M, emit: &mut F)
pub fn i64_binop<F, M>(&mut self, masm: &mut M, mut emit: F)
where
F: FnMut(&mut M, RegImm, RegImm, OperandSize),
M: MacroAssembler,
Expand Down
69 changes: 31 additions & 38 deletions winch/codegen/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use wasmtime_environ::{FuncIndex, WasmType};
macro_rules! def_unsupported {
($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident)*) => {
$(
def_unsupported!(
emit
$op

fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
$($(let _ = $arg;)*)?
todo!(stringify!($op))
}
);
def_unsupported!(
emit
$op

fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
$($(let _ = $arg;)*)?
todo!(stringify!($op))
}
);
)*
};

Expand Down Expand Up @@ -93,45 +93,39 @@ where
}

fn visit_i32_add(&mut self) {
self.context
.i32_binop(self.masm, &mut |masm, dst, src, size| {
masm.add(dst, dst, src, size);
});
self.context.i32_binop(self.masm, |masm, dst, src, size| {
masm.add(dst, dst, src, size);
});
}

fn visit_i64_add(&mut self) {
self.context
.i64_binop(self.masm, &mut |masm, dst, src, size| {
masm.add(dst, dst, src, size);
});
self.context.i64_binop(self.masm, |masm, dst, src, size| {
masm.add(dst, dst, src, size);
});
}

fn visit_i32_sub(&mut self) {
self.context
.i32_binop(self.masm, &mut |masm, dst, src, size| {
masm.sub(dst, dst, src, size);
});
self.context.i32_binop(self.masm, |masm, dst, src, size| {
masm.sub(dst, dst, src, size);
});
}

fn visit_i64_sub(&mut self) {
self.context
.i64_binop(self.masm, &mut |masm, dst, src, size| {
masm.sub(dst, dst, src, size);
});
self.context.i64_binop(self.masm, |masm, dst, src, size| {
masm.sub(dst, dst, src, size);
});
}

fn visit_i32_mul(&mut self) {
self.context
.i32_binop(self.masm, &mut |masm, dst, src, size| {
masm.mul(dst, dst, src, size);
});
self.context.i32_binop(self.masm, |masm, dst, src, size| {
masm.mul(dst, dst, src, size);
});
}

fn visit_i64_mul(&mut self) {
self.context
.i64_binop(self.masm, &mut |masm, dst, src, size| {
masm.mul(dst, dst, src, size);
});
self.context.i64_binop(self.masm, |masm, dst, src, size| {
masm.mul(dst, dst, src, size);
});
}

fn visit_i32_div_s(&mut self) {
Expand Down Expand Up @@ -328,15 +322,14 @@ where
M: MacroAssembler,
{
fn cmp_i32s(&mut self, kind: CmpKind) {
self.context
.i32_binop(self.masm, &mut |masm, dst, src, size| {
masm.cmp_with_set(src, dst, kind, size);
});
self.context.i32_binop(self.masm, |masm, dst, src, size| {
masm.cmp_with_set(src, dst, kind, size);
});
}

fn cmp_i64s(&mut self, kind: CmpKind) {
self.context
.i64_binop(self.masm, &mut move |masm, dst, src, size| {
.i64_binop(self.masm, move |masm, dst, src, size| {
masm.cmp_with_set(src, dst, kind, size);
});
}
Expand Down

0 comments on commit 81cd998

Please sign in to comment.