Cfg

Struct Cfg 

Source
pub struct Cfg {
    pub entry: BlockId,
    /* private fields */
}
Expand description

The complete CFG for a function.

Fields§

§entry: BlockId

Entry block

Implementations§

Source§

impl Cfg

Source

pub fn new( return_type: Type, num_locals: u32, num_params: u32, fn_name: String, param_modes: Vec<bool>, param_types: Vec<Type>, ) -> Self

Create a new CFG.

Source

pub fn return_type(&self) -> Type

Get the return type.

Source

pub fn num_locals(&self) -> u32

Get the number of local variable slots.

Source

pub fn alloc_temp_local(&mut self) -> u32

Allocate a new temporary local slot for spilling computed values.

This is used during CFG construction when a computed value (e.g., method call result) needs to be accessed via a place expression. The value is spilled to this temporary slot.

Returns the slot number for the new local.

Source

pub fn num_params(&self) -> u32

Get the number of parameter slots.

Source

pub fn fn_name(&self) -> &str

Get the function name.

Source

pub fn is_param_inout(&self, slot: u32) -> bool

Get whether a parameter slot is inout.

Source

pub fn param_modes(&self) -> &[bool]

Get the parameter modes slice.

Source

pub fn param_type(&self, slot: u32) -> Option<Type>

Get the type of a parameter slot.

Returns None if the slot index is out of range.

Source

pub fn new_block(&mut self) -> BlockId

Create a new basic block and return its ID.

Source

pub fn get_block(&self, id: BlockId) -> &BasicBlock

Get a block by ID.

Source

pub fn get_block_mut(&mut self, id: BlockId) -> &mut BasicBlock

Get a block mutably by ID.

Source

pub fn add_inst(&mut self, inst: CfgInst) -> CfgValue

Add an instruction and return its value reference.

Source

pub fn get_inst(&self, value: CfgValue) -> &CfgInst

Get an instruction by value reference.

Source

pub fn get_inst_mut(&mut self, value: CfgValue) -> &mut CfgInst

Get a mutable instruction by value reference.

Source

pub fn value_count(&self) -> usize

Get the total number of values (instructions) in the CFG.

Source

pub fn push_extra( &mut self, values: impl IntoIterator<Item = CfgValue>, ) -> (u32, u32)

Add values to the extra array and return (start, len).

Used for StructInit fields, ArrayInit elements, and Intrinsic args.

Source

pub fn get_extra(&self, start: u32, len: u32) -> &[CfgValue]

Get a slice from the extra array.

Source

pub fn push_call_args( &mut self, args: impl IntoIterator<Item = CfgCallArg>, ) -> (u32, u32)

Add call arguments to the call_args array and return (start, len).

Used for Call instruction arguments.

Source

pub fn get_call_args(&self, start: u32, len: u32) -> &[CfgCallArg]

Get a slice from the call_args array.

Source

pub fn push_switch_cases( &mut self, cases: impl IntoIterator<Item = (i64, BlockId)>, ) -> (u32, u32)

Add switch cases to the switch_cases array and return (start, len).

Used for Switch terminator cases.

Source

pub fn get_switch_cases(&self, start: u32, len: u32) -> &[(i64, BlockId)]

Get a slice from the switch_cases array.

Source

pub fn push_projections( &mut self, projs: impl IntoIterator<Item = Projection>, ) -> (u32, u32)

Add projections to the projections array and return (start, len).

Used for PlaceRead and PlaceWrite instructions (ADR-0030).

Source

pub fn get_projections(&self, start: u32, len: u32) -> &[Projection]

Get a slice from the projections array.

Source

pub fn get_place_projections(&self, place: &Place) -> &[Projection]

Get projections for a place.

Source

pub fn make_place( &mut self, base: PlaceBase, projs: impl IntoIterator<Item = Projection>, ) -> Place

Create a place with the given base and projections.

This adds the projections to the projections array and returns a Place that references them.

Source

pub fn get_goto_args(&self, term: &Terminator) -> &[CfgValue]

Get the block arguments from a Goto terminator.

§Panics

Panics if the terminator is not a Goto.

Source

pub fn get_branch_then_args(&self, term: &Terminator) -> &[CfgValue]

Get the then branch arguments from a Branch terminator.

§Panics

Panics if the terminator is not a Branch.

Source

pub fn get_branch_else_args(&self, term: &Terminator) -> &[CfgValue]

Get the else branch arguments from a Branch terminator.

§Panics

Panics if the terminator is not a Branch.

Source

pub fn add_inst_to_block(&mut self, block: BlockId, inst: CfgInst) -> CfgValue

Add an instruction to a block.

Source

pub fn add_block_param(&mut self, block: BlockId, ty: Type) -> CfgValue

Add a block parameter and return its value.

Source

pub fn set_terminator(&mut self, block: BlockId, term: Terminator)

Set the terminator for a block.

Source

pub fn blocks(&self) -> &[BasicBlock]

Get all blocks.

Source

pub fn block_count(&self) -> usize

Get the number of blocks.

Source

pub fn block_ids(&self) -> impl Iterator<Item = BlockId>

Iterate over block IDs.

Source

pub fn compute_predecessors(&mut self)

Compute predecessor lists for all blocks.

Trait Implementations§

Source§

impl Debug for Cfg

Source§

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

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

impl Display for Cfg

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cfg

§

impl RefUnwindSafe for Cfg

§

impl Send for Cfg

§

impl Sync for Cfg

§

impl Unpin for Cfg

§

impl UnwindSafe for Cfg

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more