1 //! x64 addressing mode.
2 
3 use crate::reg::Reg;
4 use cranelift_codegen::VCodeConstant;
5 
6 /// Memory address representation.
7 #[derive(Debug, Copy, Clone)]
8 pub(crate) enum Address {
9     /// Base register with an immediate offset.
10     Offset { base: Reg, offset: u32 },
11     /// Address to identify a constant.
12     Const(VCodeConstant),
13     /// Address at `(base + index * 2^shift) + simm32`
14     ImmRegRegShift {
15         simm32: i32,
16         base: Reg,
17         index: Reg,
18         shift: u8,
19     },
20 }
21 
22 impl Address {
23     /// Create an offset.
24     pub fn offset(base: Reg, offset: u32) -> Self {
25         Self::Offset { base, offset }
26     }
27 
28     /// Create an address for a constant.
29     pub fn constant(data: VCodeConstant) -> Self {
30         Self::Const(data)
31     }
32 
33     /// Check if the address is a made of a base and offset.
34     pub fn is_offset(&self) -> bool {
35         match self {
36             Self::Offset { .. } => true,
37             _ => false,
38         }
39     }
40 }
41