From 34ed08f02b63de1fa031cea76ca8462fbab15232 Mon Sep 17 00:00:00 2001 From: MilkeeyCat Date: Sun, 20 Oct 2024 17:22:28 +0300 Subject: [PATCH] refactor(archs/amd64): use existing functions to generate `not` --- src/archs/amd64/amd64.rs | 9 --------- src/archs/arch.rs | 1 - src/codegen/codegen.rs | 7 +++++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/archs/amd64/amd64.rs b/src/archs/amd64/amd64.rs index 8106a33..1ca6c80 100644 --- a/src/archs/amd64/amd64.rs +++ b/src/archs/amd64/amd64.rs @@ -235,15 +235,6 @@ impl Architecture for Amd64 { )); } - fn not(&mut self, dest: &Destination, dest2: &Destination) { - self.buf.push_str(&formatdoc!( - " - \tcmp {dest}, 0 - \tsete {dest2} - ", - )); - } - fn add( &mut self, lhs: &Source, diff --git a/src/archs/arch.rs b/src/archs/arch.rs index 0fe6139..353d4dc 100644 --- a/src/archs/arch.rs +++ b/src/archs/arch.rs @@ -59,7 +59,6 @@ pub trait Architecture: ArchitectureClone { fn declare(&mut self, name: &str, size: usize); fn mov(&mut self, src: &Source, dest: &Destination, signed: bool) -> Result<(), ArchError>; fn negate(&mut self, dest: &Destination); - fn not(&mut self, dest: &Destination, dest2: &Destination); fn add( &mut self, lhs: &Source, diff --git a/src/codegen/codegen.rs b/src/codegen/codegen.rs index e30d90f..11b518c 100644 --- a/src/codegen/codegen.rs +++ b/src/codegen/codegen.rs @@ -747,8 +747,11 @@ impl CodeGen { Some(&r.dest(self.arch.size(&type_, &self.scope))), state, )?; - self.arch - .not(&r.dest(self.arch.size(&type_, &self.scope)), dest); + self.arch.cmp( + &r.dest(self.arch.size(&type_, &self.scope)), + &Source::Immediate(Immediate::UInt(0)), + ); + self.arch.setcc(dest, CmpOp::Equal); self.arch.free(r)?; } UnOp::Address => {