@@ -22,6 +22,94 @@ pub trait AllocConst {
22
22
fn alloc_const < T : Into < UntypedVal > > ( & mut self , value : T ) -> Result < Reg , Error > ;
23
23
}
24
24
25
+ /// Extension trait to return [`Reg`] result of compare [`Instruction`]s.
26
+ pub trait CompareResult {
27
+ /// Returns the result [`Reg`] of the compare [`Instruction`].
28
+ ///
29
+ /// Returns `None` if the [`Instruction`] is not a compare instruction.
30
+ fn compare_result ( & self ) -> Option < Reg > ;
31
+ }
32
+
33
+ impl CompareResult for Instruction {
34
+ fn compare_result ( & self ) -> Option < Reg > {
35
+ use crate :: ir:: Instruction as I ;
36
+ let result = match * self {
37
+ | I :: I32BitAnd { result, .. }
38
+ | I :: I32BitAndImm16 { result, .. }
39
+ | I :: I32BitOr { result, .. }
40
+ | I :: I32BitOrImm16 { result, .. }
41
+ | I :: I32BitXor { result, .. }
42
+ | I :: I32BitXorImm16 { result, .. }
43
+ | I :: I32And { result, .. }
44
+ | I :: I32AndImm16 { result, .. }
45
+ | I :: I32Or { result, .. }
46
+ | I :: I32OrImm16 { result, .. }
47
+ | I :: I32Xor { result, .. }
48
+ | I :: I32XorImm16 { result, .. }
49
+ | I :: I32Nand { result, .. }
50
+ | I :: I32NandImm16 { result, .. }
51
+ | I :: I32Nor { result, .. }
52
+ | I :: I32NorImm16 { result, .. }
53
+ | I :: I32Xnor { result, .. }
54
+ | I :: I32XnorImm16 { result, .. }
55
+ | I :: I32Eq { result, .. }
56
+ | I :: I32EqImm16 { result, .. }
57
+ | I :: I32Ne { result, .. }
58
+ | I :: I32NeImm16 { result, .. }
59
+ | I :: I32LtS { result, .. }
60
+ | I :: I32LtSImm16Lhs { result, .. }
61
+ | I :: I32LtSImm16Rhs { result, .. }
62
+ | I :: I32LtU { result, .. }
63
+ | I :: I32LtUImm16Lhs { result, .. }
64
+ | I :: I32LtUImm16Rhs { result, .. }
65
+ | I :: I32LeS { result, .. }
66
+ | I :: I32LeSImm16Lhs { result, .. }
67
+ | I :: I32LeSImm16Rhs { result, .. }
68
+ | I :: I32LeU { result, .. }
69
+ | I :: I32LeUImm16Lhs { result, .. }
70
+ | I :: I32LeUImm16Rhs { result, .. }
71
+ | I :: I64And { result, .. }
72
+ | I :: I64AndImm16 { result, .. }
73
+ | I :: I64Or { result, .. }
74
+ | I :: I64OrImm16 { result, .. }
75
+ | I :: I64Xor { result, .. }
76
+ | I :: I64XorImm16 { result, .. }
77
+ | I :: I64Nand { result, .. }
78
+ | I :: I64NandImm16 { result, .. }
79
+ | I :: I64Nor { result, .. }
80
+ | I :: I64NorImm16 { result, .. }
81
+ | I :: I64Xnor { result, .. }
82
+ | I :: I64XnorImm16 { result, .. }
83
+ | I :: I64Eq { result, .. }
84
+ | I :: I64EqImm16 { result, .. }
85
+ | I :: I64Ne { result, .. }
86
+ | I :: I64NeImm16 { result, .. }
87
+ | I :: I64LtS { result, .. }
88
+ | I :: I64LtSImm16Lhs { result, .. }
89
+ | I :: I64LtSImm16Rhs { result, .. }
90
+ | I :: I64LtU { result, .. }
91
+ | I :: I64LtUImm16Lhs { result, .. }
92
+ | I :: I64LtUImm16Rhs { result, .. }
93
+ | I :: I64LeS { result, .. }
94
+ | I :: I64LeSImm16Lhs { result, .. }
95
+ | I :: I64LeSImm16Rhs { result, .. }
96
+ | I :: I64LeU { result, .. }
97
+ | I :: I64LeUImm16Lhs { result, .. }
98
+ | I :: I64LeUImm16Rhs { result, .. }
99
+ | I :: F32Eq { result, .. }
100
+ | I :: F32Ne { result, .. }
101
+ | I :: F32Lt { result, .. }
102
+ | I :: F32Le { result, .. }
103
+ | I :: F64Eq { result, .. }
104
+ | I :: F64Ne { result, .. }
105
+ | I :: F64Lt { result, .. }
106
+ | I :: F64Le { result, .. } => result,
107
+ _ => return None ,
108
+ } ;
109
+ Some ( result)
110
+ }
111
+ }
112
+
25
113
pub trait NegateCmpInstr : Sized {
26
114
/// Negates the compare (`cmp`) [`Instruction`].
27
115
fn negate_cmp_instr ( & self ) -> Option < Self > ;
0 commit comments