Rir

Struct Rir 

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

The complete RIR for a source file.

Implementations§

Source§

impl Rir

Source

pub fn new() -> Self

Create a new empty RIR.

Source

pub fn add_inst(&mut self, inst: Inst) -> InstRef

Add an instruction and return its reference.

Source

pub fn get(&self, inst_ref: InstRef) -> &Inst

Get an instruction by reference.

Source

pub fn get_mut(&mut self, inst_ref: InstRef) -> &mut Inst

Get a mutable reference to an instruction.

Source

pub fn len(&self) -> usize

The number of instructions.

Source

pub fn is_empty(&self) -> bool

Whether there are no instructions.

Source

pub fn iter(&self) -> impl Iterator<Item = (InstRef, &Inst)>

Iterate over all instructions with their references.

Source

pub fn add_extra(&mut self, data: &[u32]) -> u32

Add extra data and return the start index.

Source

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

Get extra data by index.

Source

pub fn add_inst_refs(&mut self, refs: &[InstRef]) -> (u32, u32)

Store a slice of InstRefs and return (start, len).

Source

pub fn get_inst_refs(&self, start: u32, len: u32) -> Vec<InstRef>

Retrieve InstRefs from the extra array.

Source

pub fn add_symbols(&mut self, symbols: &[Spur]) -> (u32, u32)

Store a slice of Spurs and return (start, len).

Source

pub fn get_symbols(&self, start: u32, len: u32) -> Vec<Spur>

Retrieve Spurs from the extra array.

Source

pub fn add_enum_variant_decls( &mut self, variants: &[(Spur, Vec<Spur>, Vec<Spur>)], ) -> (u32, u32)

Store enum variant declarations and return (start, variant_count).

Each variant is encoded as variable-length data in the extra array: [name_spur, field_count, is_struct, field_type_0, ..., field_type_n, field_name_0?, ..., field_name_n?]

  • is_struct: 0 for unit/tuple variants, 1 for struct variants.
  • For struct variants, field names follow field types.
  • Unit variants have field_count = 0.
Source

pub fn get_enum_variant_decls( &self, start: u32, variant_count: u32, ) -> Vec<(Spur, Vec<Spur>, Vec<Spur>)>

Retrieve enum variant declarations from the extra array. Returns a vec of (variant_name, field_types, field_names) triples. field_names is empty for unit/tuple variants.

Source

pub fn add_call_args(&mut self, args: &[RirCallArg]) -> (u32, u32)

Store RirCallArgs and return (start, len). Layout: [value: u32, mode: u32] per arg

Source

pub fn get_call_args(&self, start: u32, len: u32) -> Vec<RirCallArg>

Retrieve RirCallArgs from the extra array.

Source

pub fn add_params(&mut self, params: &[RirParam]) -> (u32, u32)

Store RirParams and return (start, len). Layout: [name: u32, ty: u32, mode: u32, is_comptime: u32] per param

Source

pub fn get_params(&self, start: u32, len: u32) -> Vec<RirParam>

Retrieve RirParams from the extra array.

Source

pub fn add_match_arms(&mut self, arms: &[(RirPattern, InstRef)]) -> (u32, u32)

Store match arms (pattern + body pairs) and return (start, arm_count). Each arm is stored with variable size depending on pattern kind.

Source

pub fn get_match_arms( &self, start: u32, arm_count: u32, ) -> Vec<(RirPattern, InstRef)>

Retrieve match arms from the extra array.

Source

pub fn add_field_inits(&mut self, fields: &[(Spur, InstRef)]) -> (u32, u32)

Store field initializers (name, value) and return (start, len). Layout: [name: u32, value: u32] per field

Source

pub fn get_field_inits(&self, start: u32, len: u32) -> Vec<(Spur, InstRef)>

Retrieve field initializers from the extra array.

Source

pub fn add_field_decls(&mut self, fields: &[(Spur, Spur)]) -> (u32, u32)

Store field declarations (name, type) and return (start, len). Layout: [name: u32, type: u32] per field

Source

pub fn get_field_decls(&self, start: u32, len: u32) -> Vec<(Spur, Spur)>

Retrieve field declarations from the extra array.

Source

pub fn add_directives(&mut self, directives: &[RirDirective]) -> (u32, u32)

Store directives and return (start, directive_count). Layout: [name: u32, span_start: u32, span_len: u32, args_len: u32, args…] per directive

Source

pub fn get_directives( &self, start: u32, directive_count: u32, ) -> Vec<RirDirective>

Retrieve directives from the extra array.

Source

pub fn add_destructure_fields( &mut self, fields: &[RirDestructureField], ) -> (u32, u32)

Store destructure fields and return (start, field_count).

Source

pub fn get_destructure_fields( &self, start: u32, count: u32, ) -> Vec<RirDestructureField>

Retrieve destructure fields from the extra array.

Source

pub fn add_function_span(&mut self, span: FunctionSpan)

Add a function span to track function boundaries.

Source

pub fn function_spans(&self) -> &[FunctionSpan]

Get all function spans.

Source

pub fn functions(&self) -> impl Iterator<Item = &FunctionSpan>

Iterate over function spans.

Source

pub fn function_count(&self) -> usize

Get the number of functions.

Source

pub fn function_view(&self, fn_span: &FunctionSpan) -> RirFunctionView<'_>

Get a view of just one function’s instructions.

Source

pub fn find_function(&self, name: Spur) -> Option<&FunctionSpan>

Find a function span by name.

Source

pub fn current_inst_index(&self) -> u32

Get the current instruction count (useful for tracking body start).

Source

pub fn merge(rirs: &[Rir]) -> Rir

Merge multiple RIRs into a single RIR.

This is used for parallel per-file RIR generation. Each file generates its own RIR in parallel, then they are merged into a single RIR with all instruction references renumbered to be valid in the merged RIR.

§Arguments
  • rirs - Slice of RIRs to merge (typically one per source file)
§Returns

A new merged RIR containing all instructions from all input RIRs.

Trait Implementations§

Source§

impl Debug for Rir

Source§

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

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

impl Default for Rir

Source§

fn default() -> Rir

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

Auto Trait Implementations§

§

impl Freeze for Rir

§

impl RefUnwindSafe for Rir

§

impl Send for Rir

§

impl Sync for Rir

§

impl Unpin for Rir

§

impl UnwindSafe for Rir

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.

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