Skip to main content

Operand

Enum Operand 

Source
#[non_exhaustive]
pub enum Operand { Reg(Reg), Imm(i64), Mem(Mem), Slot { slot: StackSlot, offset: i32, }, Symbol(Symbol), Cond(CondCode), Block(BlockCall), }
Expand description

One operand of a machine instruction.

Which shapes an operand position takes is the instruction’s OperandRule; Function::push checks them.

§Examples

use backend_lang::mir::{Mem, Operand};
use backend_lang::x86_64::RDI;

let ops = [
    Operand::Reg(RDI.into()),
    Operand::Imm(-1),
    Operand::Mem(Mem::base(RDI.into()).with_disp(8)),
];
assert!(matches!(ops[1], Operand::Imm(-1)));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Reg(Reg)

A register, virtual or physical.

§

Imm(i64)

An immediate: a signed value of the operation’s width.

§

Mem(Mem)

Memory at an address computed from registers.

§

Slot

Memory in a stack slot, offset bytes into it.

Fields

§slot: StackSlot

The slot.

§offset: i32

Bytes from the slot’s start.

§

Symbol(Symbol)

A function, by name: a direct call target, or (as a memory operand of lea) the function’s address.

§

Cond(CondCode)

A condition code.

§

Block(BlockCall)

A branch target with arguments.

Implementations§

Source§

impl Operand

Source

pub const fn slot(slot: StackSlot) -> Operand

The stack slot itself (offset 0): the form block parameters, branch arguments, and copies use.

§Examples
use backend_lang::mir::{Operand, StackSlot};

let s = StackSlot::new(2);
assert_eq!(Operand::slot(s), Operand::Slot { slot: s, offset: 0 });
Source

pub const fn reg(&self) -> Option<Reg>

The register, if this is a register operand.

§Examples
use backend_lang::mir::Operand;
use backend_lang::x86_64::RAX;

assert_eq!(Operand::from(RAX).reg(), Some(RAX.into()));
assert_eq!(Operand::Imm(0).reg(), None);
Source

pub const fn is_mem(&self) -> bool

Whether the operand is memory: an address or a stack slot.

§Examples
use backend_lang::mir::{Mem, Operand, StackSlot};

assert!(Operand::slot(StackSlot::new(0)).is_mem());
assert!(Operand::Mem(Mem::absolute(0)).is_mem());
assert!(!Operand::Imm(0).is_mem());

Trait Implementations§

Source§

impl Clone for Operand

Source§

fn clone(&self) -> Self

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 Operand

Source§

impl Debug for Operand

Source§

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

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

impl Eq for Operand

Source§

impl From<BlockCall> for Operand

Source§

fn from(b: BlockCall) -> Operand

Converts to this type from the input type.
Source§

impl From<CondCode> for Operand

Source§

fn from(c: CondCode) -> Operand

Converts to this type from the input type.
Source§

impl From<Mem> for Operand

Source§

fn from(m: Mem) -> Operand

Converts to this type from the input type.
Source§

impl From<PReg> for Operand

Source§

fn from(r: PReg) -> Operand

Converts to this type from the input type.
Source§

impl From<Reg> for Operand

Source§

fn from(r: Reg) -> Operand

Converts to this type from the input type.
Source§

impl From<Symbol> for Operand

Source§

fn from(s: Symbol) -> Operand

Converts to this type from the input type.
Source§

impl Hash for Operand

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Operand

Source§

fn eq(&self, other: &Self) -> 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 Operand

Auto Trait Implementations§

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.