mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-08 11:28:44 +00:00
Added basic::co instructions (not finished yet).
Removed `InstFmt::mnemonic`.
This commit is contained in:
parent
9cc7d81e8e
commit
ec0d1bcf0c
@ -106,14 +106,6 @@ impl<'a> InstSize for Inst<'a> {
|
||||
}
|
||||
|
||||
impl<'a> InstFmt for Inst<'a> {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Basic(inst) => inst.mnemonic(),
|
||||
Self::Pseudo(inst) => inst.mnemonic(),
|
||||
Self::Directive(directive) => directive.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Basic(inst) => inst.fmt(pos, f),
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
// Modules
|
||||
pub mod alu;
|
||||
pub mod co;
|
||||
pub mod cond;
|
||||
pub mod jmp;
|
||||
pub mod load;
|
||||
@ -48,6 +49,9 @@ pub enum Raw {
|
||||
|
||||
/// Syscall
|
||||
Sys(sys::Raw),
|
||||
|
||||
/// Co-processor
|
||||
Co(u32),
|
||||
}
|
||||
|
||||
impl Raw {
|
||||
@ -57,8 +61,7 @@ impl Raw {
|
||||
#[allow(clippy::many_single_char_names)] // `bitmatch` can only output single character names.
|
||||
pub fn from_u32(raw: u32) -> Option<Self> {
|
||||
#[rustfmt::skip]
|
||||
let raw = #[bitmatch]
|
||||
match raw {
|
||||
let raw = #[bitmatch] match raw {
|
||||
"000000_?????_ttttt_ddddd_iiiii_0000ff" => Self::Shift(shift::Raw::Imm(shift::imm::Raw { t, d, i, f })),
|
||||
"000000_sssss_ttttt_ddddd_?????_0001ff" => Self::Shift(shift::Raw::Reg(shift::reg::Raw { s, t, d, f })),
|
||||
"000000_sssss_?????_ddddd_?????_00100f" => Self::Jmp (jmp ::Raw::Reg(jmp ::reg::Raw { s, d, f })),
|
||||
@ -71,18 +74,7 @@ impl Raw {
|
||||
"001ppp_sssss_ttttt_iiiii_iiiii_iiiiii" => Self::Alu (alu ::Raw::Imm(alu ::imm::Raw { p, s, t, i })),
|
||||
"100ppp_sssss_ttttt_iiiii_iiiii_iiiiii" => Self::Load ( load :: Raw { p, s, t, i } ),
|
||||
"101ppp_sssss_ttttt_iiiii_iiiii_iiiiii" => Self::Store( store:: Raw { p, s, t, i } ),
|
||||
|
||||
/*
|
||||
"0100nn_1iiii_iiiii_iiiii_iiiii_iiiiii" => CopN { n: n.truncate(), imm: i},
|
||||
"0100nn_00000_ttttt_ddddd_?????_000000" => MfcN { n: n.truncate(), rt: reg(t)?, rd: reg(d)? },
|
||||
"0100nn_00010_ttttt_ddddd_?????_000000" => CfcN { n: n.truncate(), rt: reg(t)?, rd: reg(d)? },
|
||||
"0100nn_00100_ttttt_ddddd_?????_000000" => MtcN { n: n.truncate(), rt: reg(t)?, rd: reg(d)? },
|
||||
"0100nn_00110_ttttt_ddddd_?????_000000" => CtcN { n: n.truncate(), rt: reg(t)?, rd: reg(d)? },
|
||||
"0100nn_01000_00000_iiiii_iiiii_iiiiii" => BcNf { n: n.truncate(), target: i.truncate() },
|
||||
"0100nn_01000_00001_iiiii_iiiii_iiiiii" => BcNt { n: n.truncate(), target: i.truncate() },
|
||||
"1100nn_sssss_ttttt_iiiii_iiiii_iiiiii" => LwcN { n: n.truncate(), rs: reg(s)?, rt: reg(t)?, imm: i.truncate() },
|
||||
"1110nn_sssss_ttttt_iiiii_iiiii_iiiiii" => SwcN { n: n.truncate(), rs: reg(s)?, rt: reg(t)?, imm: i.truncate() },
|
||||
*/
|
||||
"?1????_?????_?????_?????_?????_??????" => Self::Co (raw),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
@ -107,6 +99,7 @@ impl Raw {
|
||||
Self::Alu (alu ::Raw::Imm(alu ::imm::Raw { p, s, t, i })) => bitpack!("001ppp_sssss_ttttt_iiiii_iiiii_iiiiii"),
|
||||
Self::Load ( load :: Raw { p, s, t, i } ) => bitpack!("100ppp_sssss_ttttt_iiiii_iiiii_iiiiii"),
|
||||
Self::Store( store:: Raw { p, s, t, i } ) => bitpack!("101ppp_sssss_ttttt_iiiii_iiiii_iiiiii"),
|
||||
Self::Co (raw) => raw,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,6 +135,9 @@ pub enum Inst {
|
||||
|
||||
/// Syscall
|
||||
Sys(sys::Inst),
|
||||
|
||||
/// Co-processor
|
||||
Co(co::Inst),
|
||||
}
|
||||
|
||||
|
||||
@ -161,6 +157,7 @@ impl Decodable for Inst {
|
||||
Raw::Shift(raw) => Self::Shift(shift::Inst::decode(raw)?),
|
||||
Raw::Store(raw) => Self::Store(store::Inst::decode(raw)?),
|
||||
Raw::Sys (raw) => Self::Sys (sys ::Inst::decode(raw)?),
|
||||
Raw::Co (raw) => Self::Co (co ::Inst::decode(raw)?),
|
||||
};
|
||||
|
||||
Some(inst)
|
||||
@ -180,6 +177,7 @@ impl Encodable for Inst {
|
||||
Self::Shift(inst) => Raw::Shift(inst.encode()),
|
||||
Self::Store(inst) => Raw::Store(inst.encode()),
|
||||
Self::Sys (inst) => Raw::Sys (inst.encode()),
|
||||
Self::Co (inst) => Raw::Co (inst.encode()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,21 +190,6 @@ impl<T: Decodable> InstSize for T {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
#[rustfmt::skip]
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Alu (inst) => inst.mnemonic(),
|
||||
Self::Cond (inst) => inst.mnemonic(),
|
||||
Self::Jmp (inst) => inst.mnemonic(),
|
||||
Self::Load (inst) => inst.mnemonic(),
|
||||
Self::Lui (inst) => inst.mnemonic(),
|
||||
Self::Mult (inst) => inst.mnemonic(),
|
||||
Self::Shift(inst) => inst.mnemonic(),
|
||||
Self::Store(inst) => inst.mnemonic(),
|
||||
Self::Sys (inst) => inst.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
@ -219,6 +202,7 @@ impl InstFmt for Inst {
|
||||
Self::Shift(inst) => inst.fmt(pos, f),
|
||||
Self::Store(inst) => inst.fmt(pos, f),
|
||||
Self::Sys (inst) => inst.fmt(pos, f),
|
||||
Self::Co (inst) => inst.fmt(pos, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,13 +53,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.mnemonic(),
|
||||
Self::Reg(inst) => inst.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.fmt(pos, f),
|
||||
|
||||
@ -134,10 +134,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, lhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -141,13 +141,10 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
write!(f, "{} {dst}, {lhs}, {rhs}", kind.mnemonic())
|
||||
write!(f, "{mnemonic} {dst}, {lhs}, {rhs}")
|
||||
}
|
||||
}
|
||||
|
||||
138
dcb-exe/src/exe/inst/basic/co.rs
Normal file
138
dcb-exe/src/exe/inst/basic/co.rs
Normal file
@ -0,0 +1,138 @@
|
||||
//! Co-processor instructions
|
||||
|
||||
// Modules
|
||||
//pub mod exec;
|
||||
//pub mod move_reg;
|
||||
//pub mod cond;
|
||||
//pub mod load;
|
||||
//pub mod store;
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
use int_conv::{Signed, Truncated};
|
||||
|
||||
/// Co-processor instruction kind
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub enum Kind {
|
||||
/// Execute
|
||||
CopN {
|
||||
/// Command to execute
|
||||
imm: u32,
|
||||
},
|
||||
|
||||
/// Move data register from co-processor
|
||||
MfcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
},
|
||||
|
||||
/// Move control register from co-processor
|
||||
CfcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
},
|
||||
/// Move data register to co-processor
|
||||
MtcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
},
|
||||
/// Move control register to co-processor
|
||||
CtcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
},
|
||||
/// Branch if true
|
||||
BcNf {
|
||||
/// Offset
|
||||
offset: i16,
|
||||
},
|
||||
|
||||
/// Branch if false
|
||||
BcNt {
|
||||
/// Offset
|
||||
offset: i16,
|
||||
},
|
||||
|
||||
/// Load co-processor
|
||||
LwcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
|
||||
/// offset
|
||||
offset: i16,
|
||||
},
|
||||
|
||||
/// Store co-processor
|
||||
SwcN {
|
||||
/// Destination
|
||||
dst: Register,
|
||||
|
||||
/// Source
|
||||
src: Register,
|
||||
|
||||
/// offset
|
||||
offset: i16,
|
||||
},
|
||||
}
|
||||
|
||||
/// Store instructions
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct Inst {
|
||||
/// Co-processor number
|
||||
pub n: u32,
|
||||
|
||||
/// Kind
|
||||
pub kind: Kind,
|
||||
}
|
||||
|
||||
impl Decodable for Inst {
|
||||
type Raw = u32;
|
||||
|
||||
#[bitmatch::bitmatch]
|
||||
fn decode(raw: Self::Raw) -> Option<Self> {
|
||||
#[rustfmt::skip]
|
||||
let (n, kind) = #[bitmatch] match raw {
|
||||
"0100nn_1iiii_iiiii_iiiii_iiiii_iiiiii" => (n, Kind::CopN { imm: i }),
|
||||
"0100nn_00000_ttttt_ddddd_?????_000000" => (n, Kind::MfcN { dst: Register::new(t)?, src: Register::new(d)? }),
|
||||
"0100nn_00010_ttttt_ddddd_?????_000000" => (n, Kind::CfcN { dst: Register::new(t)?, src: Register::new(d)? }),
|
||||
"0100nn_00100_ttttt_ddddd_?????_000000" => (n, Kind::MtcN { dst: Register::new(d)?, src: Register::new(t)? }),
|
||||
"0100nn_00110_ttttt_ddddd_?????_000000" => (n, Kind::CtcN { dst: Register::new(d)?, src: Register::new(t)? }),
|
||||
"0100nn_01000_00000_iiiii_iiiii_iiiiii" => (n, Kind::BcNf { offset: i.truncated::<u16>().as_signed() }),
|
||||
"0100nn_01000_00001_iiiii_iiiii_iiiiii" => (n, Kind::BcNt { offset: i.truncated::<u16>().as_signed() }),
|
||||
"1100nn_sssss_ttttt_iiiii_iiiii_iiiiii" => (n, Kind::LwcN { dst: Register::new(t)?, src: Register::new(s)?, offset: i.truncated::<u16>().as_signed() }),
|
||||
"1110nn_sssss_ttttt_iiiii_iiiii_iiiiii" => (n, Kind::SwcN { dst: Register::new(s)?, src: Register::new(t)?, offset: i.truncated::<u16>().as_signed() }),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(Self { n, kind })
|
||||
}
|
||||
}
|
||||
impl Encodable for Inst {
|
||||
fn encode(&self) -> Self::Raw {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, _pos: crate::Pos, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
0
dcb-exe/src/exe/inst/basic/co/cond.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/cond.rs
Normal file
50
dcb-exe/src/exe/inst/basic/co/exec.rs
Normal file
50
dcb-exe/src/exe/inst/basic/co/exec.rs
Normal file
@ -0,0 +1,50 @@
|
||||
//! Co-processor exec instructions
|
||||
|
||||
//! Lui instruction
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
use int_conv::{Truncated, ZeroExtended};
|
||||
|
||||
/// Raw representation
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct Raw {
|
||||
/// Immediate
|
||||
pub i: u32,
|
||||
}
|
||||
|
||||
/// Exec co-processor.
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct Inst {
|
||||
/// Value
|
||||
pub value: u32,
|
||||
}
|
||||
|
||||
impl Decodable for Inst {
|
||||
type Raw = Raw;
|
||||
|
||||
fn decode(raw: Self::Raw) -> Option<Self> {
|
||||
Some(Self { value: raw.i })
|
||||
}
|
||||
}
|
||||
impl Encodable for Inst {
|
||||
fn encode(&self) -> Self::Raw {
|
||||
Raw { i: self.value }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
"cop"
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, value } = self;
|
||||
|
||||
write!(f, "lui {dst}, {value:#x}")
|
||||
}
|
||||
}
|
||||
0
dcb-exe/src/exe/inst/basic/co/load.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/load.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/move_reg.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/move_reg.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/store.rs
Normal file
0
dcb-exe/src/exe/inst/basic/co/store.rs
Normal file
@ -148,10 +148,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: Pos, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Self { kind, arg, .. } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -53,13 +53,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.mnemonic(),
|
||||
Self::Reg(inst) => inst.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.fmt(pos, f),
|
||||
|
||||
@ -91,10 +91,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let mnemonic = self.kind.mnemonic();
|
||||
let target = self.target(pos);
|
||||
|
||||
@ -78,10 +78,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { target, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -125,10 +125,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, src, offset, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -48,10 +48,6 @@ impl Encodable for Inst {
|
||||
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
"lui"
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, value } = self;
|
||||
|
||||
|
||||
@ -89,6 +89,30 @@ pub enum Inst {
|
||||
},
|
||||
}
|
||||
|
||||
impl Inst {
|
||||
/// Returns this instruction's mnemonic
|
||||
#[must_use]
|
||||
const fn mnemonic(self) -> &'static str {
|
||||
match self {
|
||||
#[rustfmt::skip]
|
||||
Self::Mult { kind, mode, .. } => match (kind, mode) {
|
||||
(MultKind::Mult, MultMode:: Signed) => "mult",
|
||||
(MultKind::Mult, MultMode::Unsigned) => "multu",
|
||||
(MultKind::Div , MultMode:: Signed) => "div",
|
||||
(MultKind::Div , MultMode::Unsigned) => "diu",
|
||||
},
|
||||
Self::MoveFrom { src, .. } => match src {
|
||||
MultReg::Hi => "mfhi",
|
||||
MultReg::Lo => "mflo",
|
||||
},
|
||||
Self::MoveTo { dst, .. } => match dst {
|
||||
MultReg::Hi => "mthi",
|
||||
MultReg::Lo => "mtlo",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Inst {
|
||||
type Raw = Raw;
|
||||
|
||||
@ -152,30 +176,9 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
#[rustfmt::skip]
|
||||
Self::Mult { kind, mode, .. } => match (kind, mode) {
|
||||
(MultKind::Mult, MultMode:: Signed) => "mult",
|
||||
(MultKind::Mult, MultMode::Unsigned) => "multu",
|
||||
(MultKind::Div , MultMode:: Signed) => "div",
|
||||
(MultKind::Div , MultMode::Unsigned) => "diu",
|
||||
},
|
||||
Self::MoveFrom { src, .. } => match src {
|
||||
MultReg::Hi => "mfhi",
|
||||
MultReg::Lo => "mflo",
|
||||
},
|
||||
Self::MoveTo { dst, .. } => match dst {
|
||||
MultReg::Hi => "mthi",
|
||||
MultReg::Lo => "mtlo",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let mnemonic = self.mnemonic();
|
||||
match self {
|
||||
#[rustfmt::skip]
|
||||
Self::Mult { lhs, rhs, .. } => write!(f, "{mnemonic} {lhs}, {rhs}"),
|
||||
Self::MoveFrom { dst: arg, .. } | Self::MoveTo { src: arg, .. } => write!(f, "{mnemonic} {arg}"),
|
||||
}
|
||||
|
||||
@ -54,13 +54,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.mnemonic(),
|
||||
Self::Reg(inst) => inst.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Imm(inst) => inst.fmt(pos, f),
|
||||
|
||||
@ -100,10 +100,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -99,10 +99,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -112,10 +112,6 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, src, offset, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -75,10 +75,6 @@ impl Encodable for Inst {
|
||||
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { comment, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -153,22 +153,12 @@ impl<'a> InstSize for Directive<'a> {
|
||||
}
|
||||
|
||||
impl<'a> InstFmt for Directive<'a> {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Dw(_) => "dw",
|
||||
Self::Dh(_) => "dh",
|
||||
Self::Db(_) => "db",
|
||||
Self::Ascii { .. } => ".ascii",
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let mnemonic = self.mnemonic();
|
||||
match self {
|
||||
Self::Dw(value) => write!(f, "{mnemonic} {value:#x}"),
|
||||
Self::Dh(value) => write!(f, "{mnemonic} {value:#x}"),
|
||||
Self::Db(value) => write!(f, "{mnemonic} {value:#x}"),
|
||||
Self::Ascii(string) => write!(f, "{mnemonic} \"{}\"", string.as_str().escape_debug()),
|
||||
Self::Dw(value) => write!(f, "dw {value:#x}"),
|
||||
Self::Dh(value) => write!(f, "dh {value:#x}"),
|
||||
Self::Db(value) => write!(f, "db {value:#x}"),
|
||||
Self::Ascii(string) => write!(f, ".ascii \"{}\"", string.as_str().escape_debug()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,9 +13,6 @@ use std::fmt;
|
||||
/// branching instructions), as well as the byte array containing the entire
|
||||
/// executable.
|
||||
pub trait InstFmt {
|
||||
/// Returns this instruction's mnemonic
|
||||
fn mnemonic(&self) -> &'static str;
|
||||
|
||||
/// Formats this instruction
|
||||
fn fmt(&self, pos: Pos, f: &mut fmt::Formatter) -> fmt::Result;
|
||||
|
||||
|
||||
@ -76,19 +76,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::AluAssign(inst) => inst.mnemonic(),
|
||||
Self::ShiftAssign(inst) => inst.mnemonic(),
|
||||
Self::LoadImm(inst) => inst.mnemonic(),
|
||||
Self::Nop(inst) => inst.mnemonic(),
|
||||
Self::MoveReg(inst) => inst.mnemonic(),
|
||||
Self::Jmp(inst) => inst.mnemonic(),
|
||||
Self::Load(inst) => inst.mnemonic(),
|
||||
Self::Store(inst) => inst.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::AluAssign(inst) => inst.fmt(pos, f),
|
||||
|
||||
@ -85,10 +85,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -77,22 +77,12 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
match self {
|
||||
Self::JalrRa { .. } => "jalr",
|
||||
Self::Beqz { .. } => "beqz",
|
||||
Self::Bnez { .. } => "bnez",
|
||||
Self::B { .. } => "b",
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let mnemonic = self.mnemonic();
|
||||
|
||||
match *self {
|
||||
Self::JalrRa { target } => write!(f, "{mnemonic} {target}"),
|
||||
Self::Beqz { arg, offset } | Self::Bnez { arg, offset } => write!(f, "{mnemonic} {arg}, {}", basic::cond::Inst::target_of(offset, pos)),
|
||||
Self::B { offset } => write!(f, "{mnemonic} {}", basic::cond::Inst::target_of(offset, pos)),
|
||||
Self::JalrRa { target } => write!(f, "jalr {target}"),
|
||||
Self::Beqz { arg, offset } => write!(f, "beqz {arg}, {}", basic::cond::Inst::target_of(offset, pos)),
|
||||
Self::Bnez { arg, offset } => write!(f, "bnez {arg}, {}", basic::cond::Inst::target_of(offset, pos)),
|
||||
Self::B { offset } => write!(f, "b {}", basic::cond::Inst::target_of(offset, pos)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,10 +53,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind, target } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -112,10 +112,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -43,14 +43,9 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
"move"
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, src } = self;
|
||||
let mnemonic = self.mnemonic();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {src}")
|
||||
write!(f, "move {dst}, {src}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,16 +44,10 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
"nop"
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let mnemonic = self.mnemonic();
|
||||
|
||||
match self.len {
|
||||
1 => write!(f, "{mnemonic}"),
|
||||
len => write!(f, "{mnemonic} {}", len),
|
||||
1 => write!(f, "nop"),
|
||||
len => write!(f, "nop {}", len),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,10 +88,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
@ -53,10 +53,6 @@ impl InstSize for Inst {
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn mnemonic(&self) -> &'static str {
|
||||
self.kind.mnemonic()
|
||||
}
|
||||
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind, target } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user