]>
Witch of Git - jade-rose/blob - toolchain/src/inst/format.rs
1 use super::{AddImm
, AluI
as OpI
, Data
, Inst
, Op1
, OpI3
, OpR
, Reg
, Special
, Target
, 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 Trap
=> write
!(fmt
, "TRAP"),
31 Jump(Target
::Abs
) => write
!(fmt
, "JABS"),
32 Call(Target
::Abs
) => write
!(fmt
, "CABS"),
33 Jump(Target
::Off
) => write
!(fmt
, "JOFF"),
34 Call(Target
::Off
) => write
!(fmt
, "COFF"),
35 Swap(r
) => write
!(fmt
, "SWAP {}", r
),
36 GetR(r
) => write
!(fmt
, "GETR {}", r
),
37 SetR(r
) => write
!(fmt
, "SETR {}", r
),
38 Get(s
) => write
!(fmt
, "GET{}", special(s
)),
39 Set(s
) => write
!(fmt
, "SET{}", special(s
)),
40 Alu1(Op1
::Zero
) => write
!(fmt
, "ZERO"),
41 Alu1(Op1
::Lsl1
) => write
!(fmt
, "LSL1"),
42 Alu1(Op1
::Lsr1
) => write
!(fmt
, "LSR1"),
43 Alu1(Op1
::Asr1
) => write
!(fmt
, "ASR1"),
44 Alu1(Op1
::Incr
) => write
!(fmt
, "INCR"),
45 Alu1(Op1
::Decr
) => write
!(fmt
, "DECR"),
46 Alu1(Op1
::Comp
) => write
!(fmt
, "COMP"),
47 Alu1(Op1
::Negt
) => write
!(fmt
, "NEGT"),
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 LdD(d
, r
, i
) => write
!(fmt
, "LD{}U {}{}", data(d
), r
, flag(i
)),
58 StD(d
, r
, i
) => write
!(fmt
, "ST{}U {}{}", data(d
), r
, flag(i
)),
59 AluI(OpI
::And(i
)) => write
!(fmt
, "ANDI #x{:02X}", i
),
60 AluI(OpI
::Ior(i
)) => write
!(fmt
, "IORI #x{:02X}", i
),
61 AluI(OpI
::Xor(i
)) => write
!(fmt
, "XORI #x{: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
::Set
=> write
!(fmt
, "SETI #{}", i
),
70 OpI3
::Tog
=> write
!(fmt
, "TOGI #{}", i
),
71 OpI3
::Ext
=> write
!(fmt
, "EXTI #{}", i
),
73 BEzI(off
) => write
!(fmt
, "BEZI #{}", off
),
74 Jump(Target
::OffImm(i
)) => write
!(fmt
, "JOFI #{}", i
),
75 Call(Target
::OffImm(i
)) => write
!(fmt
, "COFI #{}", i
),
80 impl Display
for Reg
{
81 fn fmt(&self, fmt
: &mut Formatter
) -> fmt
::Result
{
82 write
!(fmt
, "r{}", self.0)
87 fn fmt(&self, fmt
: &mut Formatter
) -> fmt
::Result
{
88 write
!(fmt
, "{}", self.0)