summaryrefslogtreecommitdiff
path: root/src/arm32/instruction/display.rs
blob: 93f5e32fa266d032cd5d4687ddc61ac885f5c2e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2024 Gabriel Bjørnager Jensen.
//
// This file is part of Pollex.
//
// Pollex is free software: you can redistribute it
// and/or modify it under the terms of the GNU Af-
// fero General Public License as published by the
// Free Software Foundation, either version 3 of
// the License, or (at your option) any later ver-
// sion.
//
// Pollex is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Af-
// fero General Public License along with Pollex.
// If not, see <https://www.gnu.org/licenses/>.

use crate::arm32::Instruction;

use core::fmt::Display;

impl Display for Instruction {
	fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
		use Instruction::*;

		match *self {
			Add { predicate, destination, base, source, s }
			=> write!(f, "ADD{predicate}{s} {destination}, {base}, {source}"),

			AddCarry { predicate, destination, base, source, s }
			=> write!(f, "ADC{predicate}{s} {destination}, {base}, {source}"),

			And { predicate, destination, base, source, s }
			=> write!(f, "AND{predicate}{s} {destination}, {base}, {source}"),

			BitClear { predicate, destination, base, source, s }
			=> write!(f, "BIC{predicate}{s} {destination}, {base}, {source}"),

			Branch { predicate, immediate }
			=> write!(f, "B{predicate} <#{immediate}>"),

			BranchExchange { predicate, register }
			=> write!(f, "BX{predicate} {register}"),

			BranchLink { predicate, immediate }
			=> write!(f, "BL{predicate} <#{immediate}>"),

			Breakpoint { immediate }
			=> write!(f, "BKPT #{immediate}"),

			CountLeadingZeroes { predicate, destination, source }
			=> write!(f, "CLZ{predicate} {destination}, {source}"),

			Compare { predicate, lhs, rhs }
			=> write!(f, "CMP{predicate} {lhs}, {rhs}"),

			CompareNegated { predicate, lhs, rhs }
			=> write!(f, "CMN{predicate} {lhs}, {rhs}"),

			ExclusiveOr { predicate, destination, base, source, s }
			=> write!(f, "EOR{predicate}{s} {destination}, {base}, {source}"),

			InclusiveOr { predicate, destination, base, source, s }
			=> write!(f, "ORR{predicate}{s} {destination}, {base}, {source}"),

			Move { predicate, destination, source, s }
			=> write!(f, "MOV{predicate}{s} {destination}, {source}"),

			MoveNot { predicate, destination, source, s }
			=> write!(f, "MVN{predicate}{s} {destination}, {source}"),

			Multiply { predicate, destination, base, source, s }
			=> write!(f, "MUL{predicate}{s} {destination}, {base}, {source}"),

			MultiplyAccumulate { predicate, destination, base, source, shift, s }
			=> write!(f, "MLA{predicate}{s} {destination}, {base}, {source}, {shift}"),

			Reverse { predicate, destination, source }
			=> write!(f, "REV{predicate} {destination}, {source}"),

			ReverseSubtract { predicate, destination, base, source, s }
			=> write!(f, "RSB{predicate}{s} {destination}, {base}, {source}"),

			ReverseSubtractCarry { predicate, destination, base, source, s }
			=> write!(f, "RSC{predicate}{s} {destination}, {base}, {source}"),

			SaturatingAdd { predicate, destination, base, source }
			=> write!(f, "QADD{predicate} {destination}, {base}, {source}"),

			SaturatingSubtract { predicate, destination, base, source }
			=> write!(f, "QSUB{predicate} {destination}, {base}, {source}"),

			SoftwareInterrupt { predicate, immediate }
			=> write!(f, "SWI{predicate} #{immediate}"),

			Subtract { predicate, destination, base, source, s }
			=> write!(f, "SUB{predicate}{s} {destination}, {base}, {source}"),

			SubtractCarry { predicate, destination, base, source, s }
			=> write!(f, "SBC{predicate}{s} {destination}, {base}, {source}"),
		}
	}
}