]>
Witch of Git - jade-rose/blob - toolchain/src/inst/format.rs
1 use super::{AddImm
, AluI
as OpI
, Data
, Inst
, LdSt
, Op1
, OpI3
, OpR
, Reg
, Special
, U3
};
2 use std
::fmt
::{self, Display
, Formatter
};
4 fn data(d
: Data
) -> &'
static str {
11 fn special(s
: Special
) -> &'
static str {
13 Special
::Data(d
) => data(d
),
18 fn flag(x
: bool
) -> &'
static str {
26 impl Display
for Inst
{
27 fn fmt(&self, fmt
: &mut Formatter
) -> fmt
::Result
{
30 Stop
=> write
!(fmt
, "STOP"),
31 Nope
=> write
!(fmt
, "NOPE"),
32 Prnt
=> write
!(fmt
, "PRNT"),
33 CAbA
=> write
!(fmt
, "CABA"),
34 COfA
=> write
!(fmt
, "COFA"),
35 Alu1(Op1
::Zero
) => write
!(fmt
, "ZERO"),
36 Alu1(Op1
::Lsl1
) => write
!(fmt
, "LSL1"),
37 Alu1(Op1
::Lsr1
) => write
!(fmt
, "LSR1"),
38 Alu1(Op1
::Asr1
) => write
!(fmt
, "ASR1"),
39 Alu1(Op1
::Incr
) => write
!(fmt
, "INCR"),
40 Alu1(Op1
::Decr
) => write
!(fmt
, "DECR"),
41 Alu1(Op1
::Comp
) => write
!(fmt
, "COMP"),
42 Alu1(Op1
::Negt
) => write
!(fmt
, "NEGT"),
43 Get(s
) => write
!(fmt
, "GET{}", special(s
)),
44 Set(s
) => write
!(fmt
, "SET{}", special(s
)),
45 GetR(r
) => write
!(fmt
, "GETR {}", r
),
46 SetR(r
) => write
!(fmt
, "SETR {}", r
),
47 Swap(r
) => write
!(fmt
, "SWAP {}", r
),
48 IsLt(r
) => write
!(fmt
, "ISLT {}", r
),
49 AluR(OpR
::Add
, r
) => write
!(fmt
, "ADDR {}", r
),
50 AluR(OpR
::Sub
, r
) => write
!(fmt
, "SUBR {}", r
),
51 AluR(OpR
::And
, r
) => write
!(fmt
, "ANDR {}", r
),
52 AluR(OpR
::Ior
, r
) => write
!(fmt
, "IORR {}", r
),
53 AluR(OpR
::Xor
, r
) => write
!(fmt
, "XORR {}", r
),
54 AluR(OpR
::Lsl
, r
) => write
!(fmt
, "LSLR {}", r
),
55 AluR(OpR
::Lsr
, r
) => write
!(fmt
, "LSRR {}", r
),
56 AluR(OpR
::Asr
, r
) => write
!(fmt
, "ASRR {}", r
),
57 Mem(LdSt
::Ld
, d
, r
, i
) => write
!(fmt
, "LD{}U {}{}", data(d
), r
, flag(i
)),
58 Mem(LdSt
::St
, d
, r
, i
) => write
!(fmt
, "ST{}U {}{}", data(d
), r
, flag(i
)),
59 AluI(OpI
::And(i
)) => write
!(fmt
, "ANDI 0x{:02X}", i
),
60 AluI(OpI
::Ior(i
)) => write
!(fmt
, "IORI 0x{:02X}", i
),
61 AluI(OpI
::Xor(i
)) => write
!(fmt
, "XORI 0x{:02X}", i
),
62 AluI(OpI
::Add(AddImm(i
))) => write
!(fmt
, "ADDI {}", i
),
63 AluI(OpI
::Compact(op
, i
)) => match op
{
64 OpI3
::Rol
=> write
!(fmt
, "ROLI {}", i
),
65 OpI3
::Lsl
=> write
!(fmt
, "LSLI {}", i
),
66 OpI3
::Lsr
=> write
!(fmt
, "LSRI {}", i
),
67 OpI3
::Asr
=> write
!(fmt
, "ASRI {}", i
),
68 OpI3
::Clr
=> write
!(fmt
, "CLRI {}", i
),
69 OpI3
::Ins
=> write
!(fmt
, "INSI {}", i
),
70 OpI3
::Tog
=> write
!(fmt
, "TOGI {}", i
),
71 OpI3
::Ext
=> write
!(fmt
, "EXTI {}", i
),
73 BEzI(off
) => write
!(fmt
, "BEZI {}", off
),
74 JOfI(i
) => write
!(fmt
, "JOFI {}", i
),
75 CAbI(i
) => write
!(fmt
, "CABI {}", i
),
76 COfI(i
) => write
!(fmt
, "COFI {}", i
),
77 GetI(i
) => write
!(fmt
, "GETI {}", i
),
82 impl Display
for Reg
{
83 fn fmt(&self, fmt
: &mut Formatter
) -> fmt
::Result
{
84 write
!(fmt
, "r{}", self.0)
89 fn fmt(&self, fmt
: &mut Formatter
) -> fmt
::Result
{
90 write
!(fmt
, "{}", self.0)