Skip to main content

Function

Struct Function 

Source
pub struct Function {
    pub name: String,
    pub ty: TypeId,
    pub args: Vec<Argument>,
    pub blocks: Vec<BasicBlock>,
    pub instructions: Vec<Instruction>,
    pub instr_dbg_locs: HashMap<InstrId, u32>,
    pub instr_metadata: HashMap<InstrId, Vec<(String, String)>>,
    pub value_names: HashMap<String, InstrId>,
    pub arg_names: HashMap<String, ArgId>,
    pub is_declaration: bool,
    pub linkage: Linkage,
    /* private fields */
}
Expand description

A function definition or declaration.

Fields§

§name: String

Public API for name.

§ty: TypeId

Function type (FunctionType TypeId).

§args: Vec<Argument>

Formal arguments.

§blocks: Vec<BasicBlock>

Basic blocks in program order.

§instructions: Vec<Instruction>

Flat instruction pool; InstrId(i) indexes instructions[i].

§instr_dbg_locs: HashMap<InstrId, u32>

Optional !dbg !N attachment for each instruction id.

§instr_metadata: HashMap<InstrId, Vec<(String, String)>>

Arbitrary metadata attachments per instruction, e.g. !dbg !12, !tbaa !7.

§value_names: HashMap<String, InstrId>

Maps result name → InstrId.

§arg_names: HashMap<String, ArgId>

Maps argument name → ArgId.

§is_declaration: bool

True if this is a declaration (no body).

§linkage: Linkage

Public API for linkage.

Implementations§

Source§

impl Function

Source

pub fn new( name: impl Into<String>, ty: TypeId, args: Vec<Argument>, linkage: Linkage, ) -> Self

Public API for new.

Source

pub fn new_declaration( name: impl Into<String>, ty: TypeId, args: Vec<Argument>, linkage: Linkage, ) -> Self

Public API for new_declaration.

Source

pub fn add_block(&mut self, bb: BasicBlock) -> BlockId

Add a new basic block and return its BlockId.

Source

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

Public API for block.

Source

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

Public API for block_mut.

Source

pub fn num_blocks(&self) -> usize

Public API for num_blocks.

Source

pub fn alloc_instr(&mut self, instr: Instruction) -> InstrId

Allocate an instruction in the flat pool, register its name if any, and return the InstrId.

Source

pub fn instr(&self, id: InstrId) -> &Instruction

Public API for instr.

Source

pub fn instr_mut(&mut self, id: InstrId) -> &mut Instruction

Public API for instr_mut.

Source

pub fn num_instrs(&self) -> usize

Public API for num_instrs.

Source

pub fn set_instr_dbg_loc(&mut self, id: InstrId, loc_id: u32)

Public API for set_instr_dbg_loc.

Source

pub fn instr_dbg_loc(&self, id: InstrId) -> Option<u32>

Public API for instr_dbg_loc.

Source

pub fn add_instr_metadata( &mut self, id: InstrId, key: impl Into<String>, value: impl Into<String>, )

Public API for add_instr_metadata.

Source

pub fn instr_metadata(&self, id: InstrId) -> Option<&[(String, String)]>

Public API for instr_metadata.

Source

pub fn arg(&self, id: ArgId) -> &Argument

Public API for arg.

Source

pub fn num_args(&self) -> usize

Public API for num_args.

Source

pub fn lookup_value(&self, name: &str) -> Option<ValueRef>

Public API for lookup_value.

Source

pub fn lookup_block(&self, name: &str) -> Option<BlockId>

Public API for lookup_block.

Source

pub fn type_of_value(&self, vref: ValueRef) -> Option<TypeId>

Public API for type_of_value.

Source

pub fn fresh_name(&mut self) -> String

Produce a unique name like "1", "2", … for unnamed SSA values.

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