mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-17 22:54:48 +00:00
Relaxed requirements of implementing InstTargetFmt to allow semi-targetable instructions.
`pseudo::load_imm` now implements `InstTargetFmt`.
This commit is contained in:
@@ -19,12 +19,12 @@ pub trait InstFmt {
|
||||
}
|
||||
|
||||
/// A formattable instruction that supports overloading it's target.
|
||||
pub trait InstTargetFmt: InstTarget {
|
||||
pub trait InstTargetFmt {
|
||||
/// Formats this instruction
|
||||
fn fmt(&self, pos: Pos, target: impl fmt::Display, f: &mut fmt::Formatter) -> fmt::Result;
|
||||
}
|
||||
|
||||
impl<T: InstTargetFmt> InstFmt for T {
|
||||
impl<T: InstTarget + InstTargetFmt> InstFmt for T {
|
||||
fn fmt(&self, pos: Pos, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let target = self.target(pos);
|
||||
self.fmt(pos, target, f)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Imports
|
||||
use super::Decodable;
|
||||
use crate::{
|
||||
exe::inst::{basic, InstFmt, InstSize, Register},
|
||||
exe::inst::{basic, InstFmt, InstSize, InstTargetFmt, Register},
|
||||
Pos,
|
||||
};
|
||||
use dcb_util::SignedHex;
|
||||
@@ -114,12 +114,17 @@ impl InstSize for Inst {
|
||||
}
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl InstTargetFmt for Inst {
|
||||
fn fmt(&self, _pos: crate::Pos, target: impl std::fmt::Display, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
let value = kind.value_fmt();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {value}")
|
||||
write!(f, "{mnemonic} {dst}, {target}")
|
||||
}
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
<Self as InstTargetFmt>::fmt(self, pos, self.kind.value_fmt(), f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user