summaryrefslogtreecommitdiff
path: root/src/test/arm32/instruction_display.rs
blob: 4f834ef58964500ec7c7b6dc6f3c27219ad66f12 (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
108
109
110
111
112
113
114
// 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::{
	Predicate,
	Sflag,
	Instruction,
	Register,
	Shifter,
};

use alloc::string::ToString;
use alloc::vec::Vec;

#[test]
fn test_instruction_display() {
	let tree = [
		Instruction::Add {
			predicate:   Predicate::GreaterThanOrEqual,
			destination: Register::R1,
			base:        Register::R2,
			source:      Shifter::RotateRightImmediate { source: Register::R3, shift: 0x2 },
			s:           Sflag::Off,
		},

		Instruction::SaturatingSubtract {
			predicate:   Predicate::LessThan,
			destination: Register::R4,
			base:        Register::R5,
			source:      Register::R6,
		},

		Instruction::InclusiveOr {
			predicate:   Predicate::Always,
			destination: Register::R7,
			base:        Register::R8,
			source:      Shifter::LogicalShiftLeftImmediate { source: Register::R9, shift: 0x0 },
			s:           Sflag::On,
		},

		Instruction::MultiplyAccumulate {
			predicate:   Predicate::Equal,
			destination: Register::R0,
			base:        Register::Pc,
			source:      Register::Pc,
			shift:       Register::Lr,
			s:           Sflag::Off,
		},

		Instruction::Move {
			predicate:   Predicate::NotEqual,
			destination: Register::R0,
			source:      Shifter::LogicalShiftLeftImmediate { source: Register::Pc, shift: 0x0 },
			s:           Sflag::Off,
		},

		Instruction::ReverseSubtract {
			predicate:   Predicate::Always,
			destination: Register::R0,
			base:        Register::R0,
			source:      Shifter::Immediate(0x0),
			s:           Sflag::On,
		},

		Instruction::Move {
			predicate:   Predicate::GreaterThan,
			destination: Register::R0,
			source:      Shifter::LogicalShiftRightImmediate { source: Register::R7, shift: 0x20 },
			s:           Sflag::On,
		},

		Instruction::Move {
			predicate:   Predicate::Always,
			destination: Register::R0,
			source:      Shifter::LogicalShiftLeftImmediate { source: Register::R0, shift: 0x0 },
			s:           Sflag::On,
		},
	];

	let mut displays = Vec::with_capacity(tree.len());
 	for instruction in tree { displays.push(instruction.to_string()) }

	assert_eq!(
		displays,
		[
			"ADDGE r1, r2, r3, ROR #2",
			"QSUBLT r4, r5, r6",
			"ORRS r7, r8, r9",
			"MLAEQ r0, pc, pc, lr",
			"CPYNE r0, pc",
			"NEGS r0, r0",
			"LSRGTS r0, r7, #32",
			"MOVS r0, r0",
		],
	);
}