1313// enabling peephole optimizations before final assembly emission.
1414//
1515
16- // Allow unused variants/methods - LIR defines complete instruction set for future use
17- #![ allow( dead_code) ]
18-
1916use super :: codegen:: { Reg , VReg } ;
2017use crate :: arch:: lir:: { Directive , EmitAsm , FpSize , Label , OperandSize , Symbol } ;
2118use crate :: target:: { Os , Target } ;
@@ -26,6 +23,7 @@ use std::fmt::{self, Write};
2623// ============================================================================
2724
2825/// AArch64 memory addressing mode
26+ #[ allow( dead_code) ] // Documents full instruction set
2927#[ derive( Debug , Clone , PartialEq ) ]
3028pub enum MemAddr {
3129 /// [base] - Register indirect
@@ -96,49 +94,26 @@ impl GpOperand {
9694 GpOperand :: Imm ( v) => format ! ( "#{}" , v) ,
9795 }
9896 }
99-
100- /// Check if this is a register operand
101- pub fn is_reg ( & self ) -> bool {
102- matches ! ( self , GpOperand :: Reg ( _) )
103- }
104-
105- /// Get register if this is a register operand
106- pub fn as_reg ( & self ) -> Option < Reg > {
107- match self {
108- GpOperand :: Reg ( r) => Some ( * r) ,
109- _ => None ,
110- }
111- }
11297}
11398
11499// ============================================================================
115100// FP/SIMD Operands
116101// ============================================================================
117102
118103/// AArch64 FP/SIMD operand (register)
104+ #[ allow( dead_code) ] // Documents full instruction set
119105#[ derive( Debug , Clone , PartialEq ) ]
120106pub enum FpOperand {
121107 /// FP register operand
122108 Reg ( VReg ) ,
123109}
124110
125- impl FpOperand {
126- /// Format operand in AArch64 syntax
127- pub fn format ( & self , size : FpSize ) -> String {
128- match self {
129- FpOperand :: Reg ( r) => match size {
130- FpSize :: Single => r. name_s ( ) . to_string ( ) ,
131- FpSize :: Double => r. name_d ( ) . to_string ( ) ,
132- } ,
133- }
134- }
135- }
136-
137111// ============================================================================
138112// Condition Codes
139113// ============================================================================
140114
141115/// AArch64 condition codes for comparisons and conditional operations
116+ #[ allow( dead_code) ] // Documents full instruction set
142117#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
143118pub enum Cond {
144119 /// Equal (Z=1)
@@ -197,28 +172,6 @@ impl Cond {
197172 Cond :: Nv => "nv" ,
198173 }
199174 }
200-
201- /// Get the inverse condition
202- pub fn inverse ( & self ) -> Cond {
203- match self {
204- Cond :: Eq => Cond :: Ne ,
205- Cond :: Ne => Cond :: Eq ,
206- Cond :: Cs => Cond :: Cc ,
207- Cond :: Cc => Cond :: Cs ,
208- Cond :: Mi => Cond :: Pl ,
209- Cond :: Pl => Cond :: Mi ,
210- Cond :: Vs => Cond :: Vc ,
211- Cond :: Vc => Cond :: Vs ,
212- Cond :: Hi => Cond :: Ls ,
213- Cond :: Ls => Cond :: Hi ,
214- Cond :: Ge => Cond :: Lt ,
215- Cond :: Lt => Cond :: Ge ,
216- Cond :: Gt => Cond :: Le ,
217- Cond :: Le => Cond :: Gt ,
218- Cond :: Al => Cond :: Nv ,
219- Cond :: Nv => Cond :: Al ,
220- }
221- }
222175}
223176
224177impl fmt:: Display for Cond {
@@ -232,6 +185,7 @@ impl fmt::Display for Cond {
232185// ============================================================================
233186
234187/// Shift type for shifted register operands
188+ #[ allow( dead_code) ] // Documents full instruction set
235189#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
236190pub enum ShiftType {
237191 /// Logical shift left
@@ -244,22 +198,12 @@ pub enum ShiftType {
244198 Ror ,
245199}
246200
247- impl ShiftType {
248- pub fn as_str ( & self ) -> & ' static str {
249- match self {
250- ShiftType :: Lsl => "lsl" ,
251- ShiftType :: Lsr => "lsr" ,
252- ShiftType :: Asr => "asr" ,
253- ShiftType :: Ror => "ror" ,
254- }
255- }
256- }
257-
258201// ============================================================================
259202// Extend Type
260203// ============================================================================
261204
262205/// Extend type for extended register operands
206+ #[ allow( dead_code) ] // Documents full instruction set
263207#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
264208pub enum ExtendType {
265209 /// Unsigned extend byte
@@ -280,26 +224,12 @@ pub enum ExtendType {
280224 Sxtx ,
281225}
282226
283- impl ExtendType {
284- pub fn as_str ( & self ) -> & ' static str {
285- match self {
286- ExtendType :: Uxtb => "uxtb" ,
287- ExtendType :: Uxth => "uxth" ,
288- ExtendType :: Uxtw => "uxtw" ,
289- ExtendType :: Uxtx => "uxtx" ,
290- ExtendType :: Sxtb => "sxtb" ,
291- ExtendType :: Sxth => "sxth" ,
292- ExtendType :: Sxtw => "sxtw" ,
293- ExtendType :: Sxtx => "sxtx" ,
294- }
295- }
296- }
297-
298227// ============================================================================
299228// Call Target
300229// ============================================================================
301230
302231/// Target for call instructions
232+ #[ allow( dead_code) ] // Documents full instruction set
303233#[ derive( Debug , Clone , PartialEq ) ]
304234pub enum CallTarget {
305235 /// Direct call to symbol
@@ -313,6 +243,7 @@ pub enum CallTarget {
313243// ============================================================================
314244
315245/// AArch64 Low-level IR instruction
246+ #[ allow( dead_code) ] // Documents full instruction set
316247#[ derive( Debug , Clone ) ]
317248pub enum Aarch64Inst {
318249 // ========================================================================
@@ -1553,19 +1484,6 @@ fn size_bits(size: FpSize) -> u32 {
15531484 }
15541485}
15551486
1556- // ============================================================================
1557- // Utility Functions
1558- // ============================================================================
1559-
1560- /// Emit a sequence of LIR instructions to assembly text
1561- pub fn emit_instrs ( instrs : & [ Aarch64Inst ] , target : & Target ) -> String {
1562- let mut out = String :: new ( ) ;
1563- for inst in instrs {
1564- inst. emit ( target, & mut out) ;
1565- }
1566- out
1567- }
1568-
15691487// ============================================================================
15701488// Tests
15711489// ============================================================================
@@ -1768,39 +1686,4 @@ mod tests {
17681686 inst. emit ( & macos, & mut out) ;
17691687 assert ! ( out. contains( "bl _printf" ) ) ;
17701688 }
1771-
1772- #[ test]
1773- fn test_condition_inverse ( ) {
1774- assert_eq ! ( Cond :: Eq . inverse( ) , Cond :: Ne ) ;
1775- assert_eq ! ( Cond :: Lt . inverse( ) , Cond :: Ge ) ;
1776- assert_eq ! ( Cond :: Hi . inverse( ) , Cond :: Ls ) ;
1777- }
1778-
1779- #[ test]
1780- fn test_emit_instrs ( ) {
1781- let target = linux_target ( ) ;
1782-
1783- let instrs = vec ! [
1784- Aarch64Inst :: Stp {
1785- size: OperandSize :: B64 ,
1786- src1: Reg :: X29 ,
1787- src2: Reg :: X30 ,
1788- addr: MemAddr :: PreIndex {
1789- base: Reg :: X29 ,
1790- offset: -16 ,
1791- } ,
1792- } ,
1793- Aarch64Inst :: Mov {
1794- size: OperandSize :: B64 ,
1795- src: GpOperand :: Imm ( 42 ) ,
1796- dst: Reg :: X0 ,
1797- } ,
1798- Aarch64Inst :: Ret ,
1799- ] ;
1800-
1801- let out = emit_instrs ( & instrs, & target) ;
1802- assert ! ( out. contains( "stp x29, x30" ) ) ;
1803- assert ! ( out. contains( "mov x0, #42" ) ) ;
1804- assert ! ( out. contains( "ret" ) ) ;
1805- }
18061689}
0 commit comments