Skip to main content

Mem

Struct Mem 

Source
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: u8

What the index is multiplied by.

§disp: i32

The constant added to the address.

§symbol: Option<Symbol>

The symbol the address is relative to.

§got: bool

Whether 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

Source

pub const fn at(base: Operand) -> Self

The address in that register.

Source

pub const fn of(symbol: Symbol) -> Self

The address of that symbol.

Source

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.

Source

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.

Source

pub const fn indexed(self, index: Operand, scale: u8) -> Self

The same address with an index register scaled by that much.

Source

pub const fn plus(self, disp: i32) -> Self

The same address, that many bytes along.

Trait Implementations§

Source§

impl Clone for Mem

Source§

fn clone(&self) -> Mem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Mem

Source§

impl Debug for Mem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mem

Source§

fn default() -> Mem

Returns the “default value” for a type. Read more
Source§

impl Eq for Mem

Source§

impl PartialEq for Mem

Source§

fn eq(&self, other: &Mem) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mem

Auto Trait Implementations§

§

impl Freeze for Mem

§

impl RefUnwindSafe for Mem

§

impl Send for Mem

§

impl Sync for Mem

§

impl Unpin for Mem

§

impl UnsafeUnpin for Mem

§

impl UnwindSafe for Mem

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.