basic::jmp now implements InstTargetFmt.

This commit is contained in:
2021-01-12 02:28:22 +00:00
parent eb00824fbf
commit dbfdc01a2e
2 changed files with 18 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
use crate::{
exe::inst::{
basic::{Decodable, Encodable},
InstFmt,
InstTarget, InstTargetFmt,
},
Pos,
};
@@ -51,12 +51,6 @@ pub struct Inst {
}
impl Inst {
/// Returns the target of this instruction
#[must_use]
pub fn target(self, pos: Pos) -> Pos {
Self::target_of(self.imm, pos)
}
/// Returns the target using an immediate
#[must_use]
pub fn target_of(imm: u32, pos: Pos) -> Pos {
@@ -90,10 +84,15 @@ impl Encodable for Inst {
}
}
impl InstFmt for Inst {
fn fmt(&self, pos: Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl InstTarget for Inst {
fn target(&self, pos: Pos) -> Pos {
Self::target_of(self.imm, pos)
}
}
impl InstTargetFmt for Inst {
fn fmt(&self, _pos: Pos, target: impl std::fmt::Display, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mnemonic = self.kind.mnemonic();
let target = self.target(pos);
write!(f, "{mnemonic} {target}")
}