pub struct Mem {
pub base: Option<Operand>,
pub index: Option<Operand>,
pub scale: u8,
pub disp: i32,
pub symbol: Option<Symbol>,
pub got: bool,
pub segment: Option<Segment>,
}Expand description
A memory addressing mode as a caller writes one down.
The difference from Amode is that the registers are here rather than in the operand
vector, which is what crate::InstBuilder::mem fixes. Keeping the two apart is what lets
the operand indices in an Amode be an invariant of the builder rather than something
every caller has to get right.
Fields§
§base: Option<Operand>The base register, which the instruction reads.
index: Option<Operand>The index register, which the instruction reads.
scale: u8What the index is multiplied by.
disp: i32The constant added to the address.
symbol: Option<Symbol>The symbol the address is relative to.
got: boolWhether the address is read out of the global offset table rather than worked out from the
instruction pointer. See Self::got.
segment: Option<Segment>Which storage the address is counted from, when it is not the flat one. See Segment.
Implementations§
Source§impl Mem
impl Mem
Sourcepub const fn in_segment(segment: Segment, disp: i32) -> Self
pub const fn in_segment(segment: Segment, disp: i32) -> Self
That many bytes into a thread’s own block of words, which names no register at all.
The whole address is the constant, because where the block is is something only the machine
knows: the segment register is what holds it and nothing loads one. See Segment.
Sourcepub const fn got(symbol: Symbol) -> Self
pub const fn got(symbol: Symbol) -> Self
The slot of the global offset table holding that symbol’s address.
Not the same thing as Self::of and not an optimization of it. sym(%rip) is the
address worked out from where the instruction is, which is only the right address when the
symbol is in this same object, and the linker refuses it in a position independent
executable when the symbol may turn out to be in a shared library. sym@GOTPCREL(%rip) is
a slot the linker fills in with the one address everybody agrees on, so it is a load rather
than an arithmetic, and whatever reads it gets an address rather than a place.
The linker relaxes it back into the arithmetic when the symbol turns out to be in this program after all, which is why nothing is lost by asking for it.