Skip to main content

FrameLayout

Struct FrameLayout 

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

A laid-out frame: slot offsets and the prologue and epilogue.

Offsets are from the stack pointer after the prologue; they are negative for locals kept in the red zone.

§Examples

use backend_lang::mir::{Function, SlotKind};
use backend_lang::x86_64::SYSV;

let mut f = Function::new("leaf", &SYSV);
let a = f.stack_slot(SlotKind::Local { size: 8, align: 8 })?;
let frame = f.frame_layout().unwrap();
// A leaf with 8 bytes of locals uses the red zone: nothing is allocated.
assert!(frame.uses_red_zone());
assert_eq!(frame.alloc(), 0);
assert!(frame.slot_offset(a).unwrap() < 0);

Implementations§

Source§

impl FrameLayout

Source

pub fn slot_offset(&self, slot: StackSlot) -> Option<i32>

A slot’s offset from the stack pointer after the prologue, or None for a slot the layout does not have.

§Examples
use backend_lang::mir::{Function, SlotKind};
use backend_lang::x86_64::SYSV;

let mut f = Function::new("f", &SYSV);
let arg = f.stack_slot(SlotKind::Incoming { offset: 0, size: 8 })?;
let frame = f.frame_layout().unwrap();
// rbp is pushed: [rsp] = saved rbp, [rsp+8] = return address, [rsp+16] = argument.
assert_eq!(frame.slot_offset(arg), Some(16));
Source

pub fn pushed(&self) -> &[PReg]

The general-purpose callee-saved registers pushed after the frame pointer, in push order.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

assert!(Function::new("f", &SYSV).frame_layout().unwrap().pushed().is_empty());
Source

pub fn vec_saves(&self) -> &[(PReg, i32)]

Vector callee-saved registers saved into the frame, with their save slots’ offsets.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

assert!(Function::new("f", &SYSV).frame_layout().unwrap().vec_saves().is_empty());
Source

pub fn prologue(&self) -> &[FrameStep]

The prologue, in execution order.

§Examples
use backend_lang::mir::Function;
use backend_lang::target::frame::FrameStep;
use backend_lang::x86_64::{SYSV, RBP};

let frame = Function::new("f", &SYSV).frame_layout().unwrap();
assert_eq!(frame.prologue(), [FrameStep::Push(RBP), FrameStep::SetFramePointer]);
Source

pub fn epilogue(&self) -> &[FrameStep]

The epilogue, in execution order (the return itself is not part of it).

§Examples
use backend_lang::mir::Function;
use backend_lang::target::frame::FrameStep;
use backend_lang::x86_64::{SYSV, RBP};

let frame = Function::new("f", &SYSV).frame_layout().unwrap();
assert_eq!(frame.epilogue(), [FrameStep::Pop(RBP)]);
Source

pub const fn alloc(&self) -> u32

Bytes the prologue subtracts from the stack pointer after its pushes.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

assert_eq!(Function::new("f", &SYSV).frame_layout().unwrap().alloc(), 0);
Source

pub const fn cfa_offset(&self) -> u32

The canonical frame address (the stack pointer before the call) minus the stack pointer after the prologue: return address, pushes, and allocation.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

// Return address plus the saved rbp.
assert_eq!(Function::new("f", &SYSV).frame_layout().unwrap().cfa_offset(), 16);
Source

pub const fn frame_pointer(&self) -> bool

Whether the frame keeps a frame pointer.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

assert!(Function::new("f", &SYSV).frame_layout().unwrap().frame_pointer());
Source

pub const fn uses_red_zone(&self) -> bool

Whether the locals live in the red zone below the stack pointer.

§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::SYSV;

assert!(!Function::new("f", &SYSV).frame_layout().unwrap().uses_red_zone());

Trait Implementations§

Source§

impl Clone for FrameLayout

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 Debug for FrameLayout

Source§

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

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

impl Eq for FrameLayout

Source§

impl PartialEq for FrameLayout

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 FrameLayout

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.