Skip to content

Commit

Permalink
fix(codegen): operands order
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkeeyCat committed Jul 16, 2024
1 parent db965e3 commit e708116
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/archs/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ pub trait Architecture {
fn declare(&mut self, var: StmtVarDecl);
fn mov(&mut self, src: MoveSource, dest: MoveDestination, scope: &Scope);
fn negate(&mut self, r: &Register);
fn not(&mut self, r1: &Register, r2: &Register);
fn add(&mut self, r1: &Register, r2: &Register);
fn sub(&mut self, r1: &Register, r2: &Register);
fn mul(&mut self, r1: &Register, r2: &Register);
fn div(&mut self, r1: &Register, r2: &Register);
fn cmp(&mut self, r1: &Register, r2: &Register, cmp: CmpOp);
fn not(&mut self, dest: &Register, src: &Register);
fn add(&mut self, dest: &Register, src: &Register);
fn sub(&mut self, dest: &Register, src: &Register);
fn mul(&mut self, dest: &Register, src: &Register);
fn div(&mut self, dest: &Register, src: &Register);
fn cmp(&mut self, dest: &Register, src: &Register, cmp: CmpOp);
fn fn_preamble(&mut self, name: &str, stackframe: usize);
fn fn_postamble(&mut self, name: &str, stackframe: usize);
fn ret(&mut self, r: Register, type_: Type);
Expand Down
10 changes: 5 additions & 5 deletions src/codegen/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<Arch: Architecture> CodeGen<Arch> {
let r = self.arch.alloc()?;
self.expr(*expr.right, (&r).into())?;

self.arch.add(&r, dest.register().unwrap());
self.arch.add(dest.register().unwrap(), &r);
self.arch.free(r)?;
}
BinOp::Sub => {
Expand All @@ -215,7 +215,7 @@ impl<Arch: Architecture> CodeGen<Arch> {
let r = self.arch.alloc()?;
self.expr(*expr.right, (&r).into())?;

self.arch.sub(&r, dest.register().unwrap());
self.arch.sub(dest.register().unwrap(), &r);
self.arch.free(r)?;
}
BinOp::Mul => {
Expand All @@ -224,7 +224,7 @@ impl<Arch: Architecture> CodeGen<Arch> {
let r = self.arch.alloc()?;
self.expr(*expr.right, (&r).into())?;

self.arch.mul(&r, dest.register().unwrap());
self.arch.mul(dest.register().unwrap(), &r);
self.arch.free(r)?;
}
BinOp::Div => {
Expand All @@ -233,7 +233,7 @@ impl<Arch: Architecture> CodeGen<Arch> {
let r = self.arch.alloc()?;
self.expr(*expr.right, (&r).into())?;

self.arch.div(&r, dest.register().unwrap());
self.arch.div(dest.register().unwrap(), &r);
self.arch.free(r)?;
}
BinOp::LessThan
Expand All @@ -248,7 +248,7 @@ impl<Arch: Architecture> CodeGen<Arch> {
self.expr(*expr.right, (&r).into())?;

self.arch
.cmp(&r, dest.register().unwrap(), CmpOp::try_from(&expr.op)?);
.cmp(dest.register().unwrap(), &r, CmpOp::try_from(&expr.op)?);
self.arch.free(r)?;
}
};
Expand Down

0 comments on commit e708116

Please sign in to comment.