11//! Memory operands to instructions.
22
33use crate :: api:: { AsReg , CodeSink , Constant , KnownOffset , KnownOffsetTable , Label , TrapCode } ;
4- use crate :: reg :: { self , NonRspGpr , Size } ;
4+ use crate :: gpr :: { self , NonRspGpr , Size } ;
55use crate :: rex:: { encode_modrm, encode_sib, Imm , RexFlags } ;
66use crate :: xmm;
77
@@ -169,7 +169,7 @@ impl<R: AsReg> std::fmt::Display for Amode<R> {
169169 Amode :: ImmReg { simm32, base, .. } => {
170170 // Note: size is always 8; the address is 64 bits,
171171 // even if the addressed operand is smaller.
172- let base = reg :: enc:: to_string ( base. enc ( ) , Size :: Quadword ) ;
172+ let base = gpr :: enc:: to_string ( base. enc ( ) , Size :: Quadword ) ;
173173 write ! ( f, "{simm32:x}({base})" )
174174 }
175175 Amode :: ImmRegRegShift {
@@ -179,8 +179,8 @@ impl<R: AsReg> std::fmt::Display for Amode<R> {
179179 scale,
180180 ..
181181 } => {
182- let base = reg :: enc:: to_string ( base. enc ( ) , Size :: Quadword ) ;
183- let index = reg :: enc:: to_string ( index. enc ( ) , Size :: Quadword ) ;
182+ let base = gpr :: enc:: to_string ( base. enc ( ) , Size :: Quadword ) ;
183+ let index = gpr :: enc:: to_string ( index. enc ( ) , Size :: Quadword ) ;
184184 let shift = scale. shift ( ) ;
185185 if shift > 1 {
186186 write ! ( f, "{simm32:x}({base}, {index}, {shift})" )
@@ -256,7 +256,7 @@ impl<R: AsReg, M: AsReg> GprMem<R, M> {
256256 /// Pretty-print the operand.
257257 pub fn to_string ( & self , size : Size ) -> String {
258258 match self {
259- GprMem :: Gpr ( gpr) => reg :: enc :: to_string ( gpr. enc ( ) , size) . to_owned ( ) ,
259+ GprMem :: Gpr ( gpr) => gpr. to_string ( Some ( size) ) ,
260260 GprMem :: Mem ( amode) => amode. to_string ( ) ,
261261 }
262262 }
@@ -313,7 +313,7 @@ pub fn emit_modrm_sib_disp<R: AsReg>(
313313 // optional immediate. If rsp is the base register, however, then a
314314 // SIB byte must be used.
315315 let enc_e_low3 = enc_e & 7 ;
316- if enc_e_low3 == reg :: enc:: RSP {
316+ if enc_e_low3 == gpr :: enc:: RSP {
317317 // Displacement from RSP is encoded with a SIB byte where
318318 // the index and base are both encoded as RSP's encoding of
319319 // 0b100. This special encoding means that the index register
@@ -326,7 +326,7 @@ pub fn emit_modrm_sib_disp<R: AsReg>(
326326 // If the base register is rbp and there's no offset then force
327327 // a 1-byte zero offset since otherwise the encoding would be
328328 // invalid.
329- if enc_e_low3 == reg :: enc:: RBP {
329+ if enc_e_low3 == gpr :: enc:: RBP {
330330 imm. force_immediate ( ) ;
331331 }
332332 sink. put1 ( encode_modrm ( imm. m0d ( ) , enc_g & 7 , enc_e & 7 ) ) ;
@@ -348,14 +348,14 @@ pub fn emit_modrm_sib_disp<R: AsReg>(
348348 // ever be rsp. Note, though, that the encoding of r12, whose three
349349 // lower bits match the encoding of rsp, is explicitly allowed with
350350 // REX bytes so only rsp is disallowed.
351- assert ! ( enc_index != reg :: enc:: RSP ) ;
351+ assert ! ( enc_index != gpr :: enc:: RSP ) ;
352352
353353 // If the offset is zero then there is no immediate. Note, though,
354354 // that if the base register's lower three bits are `101` then an
355355 // offset must be present. This is a special case in the encoding of
356356 // the SIB byte and requires an explicit displacement with rbp/r13.
357357 let mut imm = Imm :: new ( simm32. value ( ) , evex_scaling) ;
358- if enc_base & 7 == reg :: enc:: RBP {
358+ if enc_base & 7 == gpr :: enc:: RBP {
359359 imm. force_immediate ( ) ;
360360 }
361361
0 commit comments