Skip to main content

Module

Struct Module 

Source
pub struct Module {
    pub name: Symbol,
    pub triple: Triple,
    pub datalayout: DataLayout,
    /* private fields */
}
Expand description

One translation unit, or after LTO the several that were linked into one.

Fields§

§name: Symbol

What it is called, which is the source file name for a module from the frontend. It appears in the textual form and in the debug info and nothing branches on it.

§triple: Triple

The target it is for.

§datalayout: DataLayout

The layout it was built assuming.

Implementations§

Source§

impl Module

Source

pub fn new(name: Symbol, target: &TargetInfo) -> Self

An empty module for that target.

Source

pub fn add_func(&mut self, func: Func) -> FuncId

Adds a function, which is a declaration if it has no blocks.

§Panics

Panics if the module already has a symbol of that name. Merging a declaration with a definition is the frontend’s job and it has the declarations to do it with; by the time something is in the IR a name means one thing.

Source

pub fn add_global(&mut self, global: Global) -> GlobalId

Adds a global variable, which is a declaration if it has no image.

§Panics

Panics if the module already has a symbol of that name.

Source

pub fn add_alias(&mut self, alias: Alias) -> AliasId

Adds an alias.

The target is not resolved here, and it need not be in this module: an alias of something in another object is a thing people write.

§Panics

Panics if the module already has a symbol of that name.

Source

pub fn lookup(&self, name: Symbol) -> Option<SymbolRef>

What that name refers to, or None if this module does not define or declare it.

Source

pub fn funcs(&self) -> impl Iterator<Item = FuncId> + use<>

Every function, in the order they were added.

Source

pub fn globals(&self) -> impl Iterator<Item = GlobalId> + use<>

Every global variable, in the order they were added.

Source

pub fn aliases(&self) -> impl Iterator<Item = AliasId> + use<>

Every alias, in the order they were added.

Source

pub fn add_meta(&mut self, node: MetaNode) -> Meta

Adds a metadata node and gives back the reference an instruction holds.

The nodes live here rather than in a function because a TBAA tree is shared by every memory operation in the module and duplicating it per function would make two accesses to the same type look unrelated.

Source

pub fn metadata(&self) -> impl Iterator<Item = Meta> + use<>

Every metadata node, in the order they were added.

Source

pub fn push_data(&mut self, data: &[Datum]) -> DataList

Records a run of data and gives back the list a global holds.

Source

pub fn push_bytes(&mut self, bytes: &[u8]) -> ByteRange

Records literal bytes and gives back the range a Datum::Bytes holds.

Source

pub fn add_imm(&mut self, imm: Imm) -> Idx<Imm>

Records a scalar value and gives back the index a Datum::Scalar holds.

Source

pub fn add_reloc(&mut self, reloc: Reloc) -> Idx<Reloc>

Records a relocation and gives back the index a Datum::Addr holds.

Source

pub fn counts(&self) -> ModuleCounts

How much is in it, for the -fstats output and for a test that wants to say a pass deleted something without saying which.

Trait Implementations§

Source§

impl Debug for Module

Source§

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

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

impl Index<Idx<Alias>> for Module

Source§

type Output = Alias

The returned type after indexing.
Source§

fn index(&self, id: AliasId) -> &Alias

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<Func>> for Module

Source§

type Output = Func

The returned type after indexing.
Source§

fn index(&self, id: FuncId) -> &Func

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<Global>> for Module

Source§

type Output = Global

The returned type after indexing.
Source§

fn index(&self, id: GlobalId) -> &Global

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<Imm>> for Module

Source§

type Output = Imm

The returned type after indexing.
Source§

fn index(&self, imm: Idx<Imm>) -> &Imm

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<MetaNode>> for Module

Source§

type Output = MetaNode

The returned type after indexing.
Source§

fn index(&self, meta: Meta) -> &MetaNode

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Idx<Reloc>> for Module

Source§

type Output = Reloc

The returned type after indexing.
Source§

fn index(&self, reloc: Idx<Reloc>) -> &Reloc

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<IdxRange<Byte>> for Module

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, range: ByteRange) -> &[u8]

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<IdxRange<Datum>> for Module

Source§

type Output = [Datum]

The returned type after indexing.
Source§

fn index(&self, list: DataList) -> &[Datum]

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Idx<Func>> for Module

Source§

fn index_mut(&mut self, id: FuncId) -> &mut Func

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Idx<Global>> for Module

Source§

fn index_mut(&mut self, id: GlobalId) -> &mut Global

Performs the mutable indexing (container[index]) operation. Read more

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 = !

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.