Skip to main content

InstDesc

Struct InstDesc 

Source
pub struct InstDesc { /* private fields */ }
Expand description

One machine instruction’s description.

§Examples

use backend_lang::target::InstKind;
use backend_lang::x86_64::{self, op, RAX, RDX, FLAGS};

let div = x86_64::TARGET.inst(op::IDIV64).unwrap();
assert_eq!(div.name(), "idiv64");
assert_eq!(div.kind(), InstKind::Plain);
assert_eq!(div.implicit_uses(), [RAX, RDX]);
assert_eq!(div.implicit_defs(), [RAX, RDX, FLAGS]);

Implementations§

Source§

impl InstDesc

Source

pub const fn new( name: &'static str, kind: InstKind, operands: &'static [OperandRule], implicit_uses: &'static [PReg], implicit_defs: &'static [PReg], clobbers: RegSet, ) -> InstDesc

Describes an instruction.

implicit_uses are registers read without being named as operands, implicit_defs registers written that way (results the code may read afterwards, such as idiv’s quotient in rax), and clobbers registers left with unspecified contents.

§Examples
use backend_lang::RegSet;
use backend_lang::target::{InstDesc, InstKind};

let nop = InstDesc::new("nop", InstKind::Plain, &[], &[], &[], RegSet::EMPTY);
assert!(nop.operands().is_empty());
Source

pub const fn name(&self) -> &'static str

The instruction’s MIR name.

§Examples
use backend_lang::x86_64::{self, op};

assert_eq!(x86_64::TARGET.inst(op::MOVZX8).unwrap().name(), "movzx8");
Source

pub const fn kind(&self) -> InstKind

What the instruction does to control flow.

§Examples
use backend_lang::target::InstKind;
use backend_lang::x86_64::{self, op};

assert_eq!(x86_64::TARGET.inst(op::RET).unwrap().kind(), InstKind::Return);
Source

pub const fn operands(&self) -> &'static [OperandRule]

The explicit operands, definitions first. Empty for Opcode::COPY and Opcode::PCOPY, whose operands are checked by their own rule.

§Examples
use backend_lang::x86_64::{self, op};

assert_eq!(x86_64::TARGET.inst(op::CMP64).unwrap().operands().len(), 2);
Source

pub fn defs(&self) -> usize

The number of explicit definitions (the leading Def operands).

§Examples
use backend_lang::x86_64::{self, op};

assert_eq!(x86_64::TARGET.inst(op::ADD64).unwrap().defs(), 1);
assert_eq!(x86_64::TARGET.inst(op::CMP64).unwrap().defs(), 0);
Source

pub const fn implicit_uses(&self) -> &'static [PReg]

Registers the instruction reads without naming them.

§Examples
use backend_lang::x86_64::{self, op, RAX};

assert_eq!(x86_64::TARGET.inst(op::CQO).unwrap().implicit_uses(), [RAX]);
Source

pub const fn implicit_defs(&self) -> &'static [PReg]

Registers the instruction writes without naming them, with defined results.

§Examples
use backend_lang::x86_64::{self, op, RDX};

assert_eq!(x86_64::TARGET.inst(op::CQO).unwrap().implicit_defs(), [RDX]);
Source

pub const fn clobbers(&self) -> RegSet

Registers the instruction leaves with unspecified contents.

§Examples
use backend_lang::x86_64::{self, op, RCX, R11};

let clobbers = x86_64::TARGET.inst(op::SYSCALL).unwrap().clobbers();
assert!(clobbers.contains(RCX) && clobbers.contains(R11));

Trait Implementations§

Source§

impl Clone for InstDesc

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 InstDesc

Source§

impl Debug for InstDesc

Source§

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

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

impl Eq for InstDesc

Source§

impl PartialEq for InstDesc

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 InstDesc

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.