|
3 | 3 | use crate::api::{AsReg, CodeSink, Constant, KnownOffset, KnownOffsetTable, Label, TrapCode};
|
4 | 4 | use crate::gpr::{self, NonRspGpr, Size};
|
5 | 5 | use crate::rex::{Disp, RexPrefix, encode_modrm, encode_sib};
|
6 |
| -use crate::{RegisterVisitor, Registers}; |
7 | 6 |
|
8 | 7 | /// x64 memory addressing modes.
|
9 |
| -#[derive(Clone, Debug)] |
| 8 | +#[derive(Copy, Clone, Debug)] |
10 | 9 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
11 | 10 | pub enum Amode<R: AsReg> {
|
12 | 11 | ImmReg {
|
@@ -62,27 +61,6 @@ impl<R: AsReg> Amode<R> {
|
62 | 61 | }
|
63 | 62 | }
|
64 | 63 |
|
65 |
| -/// Visit the registers in an [`Amode`]. |
66 |
| -/// |
67 |
| -/// This is helpful for generated code: it allows capturing the `R::ReadGpr` |
68 |
| -/// type (which an `Amode` method cannot) and simplifies the code to be |
69 |
| -/// generated. |
70 |
| -pub(crate) fn visit_amode<R: Registers>( |
71 |
| - amode: &mut Amode<R::ReadGpr>, |
72 |
| - visitor: &mut impl RegisterVisitor<R>, |
73 |
| -) { |
74 |
| - match amode { |
75 |
| - Amode::ImmReg { base, .. } => { |
76 |
| - visitor.read_gpr(base); |
77 |
| - } |
78 |
| - Amode::ImmRegRegShift { base, index, .. } => { |
79 |
| - visitor.read_gpr(base); |
80 |
| - visitor.read_gpr(index.as_mut()); |
81 |
| - } |
82 |
| - Amode::RipRelative { .. } => {} |
83 |
| - } |
84 |
| -} |
85 |
| - |
86 | 64 | /// A 32-bit immediate for address offsets.
|
87 | 65 | #[derive(Clone, Copy, Debug)]
|
88 | 66 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
@@ -134,7 +112,7 @@ impl std::fmt::LowerHex for AmodeOffset {
|
134 | 112 | /// happens immediately before emission:
|
135 | 113 | /// - the [`KnownOffset`] is looked up, mapping it to an offset value
|
136 | 114 | /// - the [`Simm32`] value is added to the offset value
|
137 |
| -#[derive(Clone, Debug)] |
| 115 | +#[derive(Copy, Clone, Debug)] |
138 | 116 | pub struct AmodeOffsetPlusKnownOffset {
|
139 | 117 | pub simm32: AmodeOffset,
|
140 | 118 | pub offset: Option<KnownOffset>,
|
@@ -166,7 +144,7 @@ impl std::fmt::LowerHex for AmodeOffsetPlusKnownOffset {
|
166 | 144 | }
|
167 | 145 |
|
168 | 146 | /// For RIP-relative addressing, keep track of the [`CodeSink`]-specific target.
|
169 |
| -#[derive(Clone, Debug)] |
| 147 | +#[derive(Copy, Clone, Debug)] |
170 | 148 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
171 | 149 | pub enum DeferredTarget {
|
172 | 150 | Label(Label),
|
@@ -205,7 +183,7 @@ impl<R: AsReg> std::fmt::Display for Amode<R> {
|
205 | 183 | }
|
206 | 184 |
|
207 | 185 | /// The scaling factor for the index register in certain [`Amode`]s.
|
208 |
| -#[derive(Clone, Debug)] |
| 186 | +#[derive(Copy, Clone, Debug)] |
209 | 187 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
210 | 188 | pub enum Scale {
|
211 | 189 | One,
|
@@ -252,7 +230,7 @@ impl Scale {
|
252 | 230 | }
|
253 | 231 |
|
254 | 232 | /// A general-purpose register or memory operand.
|
255 |
| -#[derive(Clone, Debug)] |
| 233 | +#[derive(Copy, Clone, Debug)] |
256 | 234 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
257 | 235 | #[allow(
|
258 | 236 | clippy::module_name_repetitions,
|
@@ -313,7 +291,7 @@ impl<R: AsReg, M: AsReg> From<Amode<M>> for GprMem<R, M> {
|
313 | 291 | }
|
314 | 292 |
|
315 | 293 | /// An XMM register or memory operand.
|
316 |
| -#[derive(Clone, Debug)] |
| 294 | +#[derive(Copy, Clone, Debug)] |
317 | 295 | #[cfg_attr(any(test, feature = "fuzz"), derive(arbitrary::Arbitrary))]
|
318 | 296 | #[allow(
|
319 | 297 | clippy::module_name_repetitions,
|
@@ -382,7 +360,7 @@ fn emit_modrm_sib_disp<R: AsReg>(
|
382 | 360 | bytes_at_end: u8,
|
383 | 361 | evex_scaling: Option<i8>,
|
384 | 362 | ) {
|
385 |
| - match mem_e.clone() { |
| 363 | + match *mem_e { |
386 | 364 | Amode::ImmReg { simm32, base, .. } => {
|
387 | 365 | let enc_e = base.enc();
|
388 | 366 | let mut imm = Disp::new(simm32.value(offsets), evex_scaling);
|
@@ -450,8 +428,8 @@ fn emit_modrm_sib_disp<R: AsReg>(
|
450 | 428 |
|
451 | 429 | let offset = sink.current_offset();
|
452 | 430 | let target = match target {
|
453 |
| - DeferredTarget::Label(label) => label.clone(), |
454 |
| - DeferredTarget::Constant(constant) => sink.get_label_for_constant(constant.clone()), |
| 431 | + DeferredTarget::Label(label) => label, |
| 432 | + DeferredTarget::Constant(constant) => sink.get_label_for_constant(constant), |
455 | 433 | };
|
456 | 434 | sink.use_label_at_offset(offset, target);
|
457 | 435 |
|
|
0 commit comments