Skip to main content

Lowering

Struct Lowering 

Source
pub struct Lowering<'cx, V> { /* private fields */ }
Expand description

A function (or block) of the host’s IR being translated into expressions of a context: the expression of every host value it has seen, and a symbol for every value defined outside.

Implementations§

Source§

impl<'cx, V: Copy + Eq + Hash> Lowering<'cx, V>

Source

pub fn new(cx: &'cx mut Context) -> Self

A lowering into cx (reuse one context per function: Context::clear keeps its allocations).

Source

pub fn detach(self) -> Lowered<V>

Releases the context, keeping the values: Lowered::attach resumes.

Source

pub fn context(&mut self) -> &mut Context

The context, to build expressions in (and to simplify).

Source

pub fn value(&mut self, v: V, width: Width) -> Result<Expr, Error>

The expression of host value v of width bits: its definition, or for a value not defined here, a new symbol that stands for it (see input). A width other than the value’s is an error.

Source

pub fn input( &mut self, v: V, width: Width, known: Option<KnownBits>, ) -> Result<Expr, Error>

A value defined outside (a parameter, a load, a call result): a fresh symbol of width bits that stands for it, with the known bits the host has of it, if any (Context::declare_known). Its expression if it already has one.

Source

pub fn input_named( &mut self, v: V, key: impl Into<SymbolKey>, width: Width, known: Option<KnownBits>, ) -> Result<Expr, Error>

input with a symbol of the host’s choosing (a readable name, say). The key must not be a symbol of another width in the context.

Source

pub fn define(&mut self, v: V, e: Expr) -> Result<(), Error>

Records that host value v is e (an expression of this context).

Source

pub fn lower<S: Semantics<Value = V> + ?Sized>( &mut self, inst: &S, ) -> Result<Option<Expr>, Error>

Lowers one instruction: defines its result, if it has one, and returns its expression.

Source

pub fn lower_all<'i, S, I>(&mut self, insts: I) -> Result<(), Error>
where S: Semantics<Value = V> + 'i, I: IntoIterator<Item = &'i S>,

Lowers instructions in order (each defines its result before the next reads it).

Source

pub fn get(&self, v: V) -> Option<Expr>

The expression of host value v, if it has one.

Source

pub fn inputs(&self) -> &[(V, Expr)]

The values defined outside that were read, in order, with their symbols.

Source

pub fn owner(&self, e: Expr) -> Option<V>

A host value that computes e already, if one does (the first defined).

Source

pub fn raise<R: Raise<Value = V> + ?Sized>( &mut self, e: Expr, r: &mut R, ) -> Result<V, Error>

Turns e into host instructions: the value computing it. A node some host value computes is that value; every other node is emitted through r, operands first, and then owned by the value r returns (so later raises reuse it). A symbol no host value stands for is an error.

Source

pub fn unraised(&mut self, e: Expr) -> Result<Vec<Expr>, Error>

The nodes of e that raise would emit, operands first: those no host value computes. With emitted, a raise in steps, for a host that must emit with the context released (a language binding calling back into its interpreter). A symbol no host value stands for is an error.

Source

pub fn emitted(&mut self, e: Expr, v: V) -> Result<(), Error>

Records that host value v computes node e, emitted by the host: what raise does after each emit. Later raises reuse it.

Trait Implementations§

Source§

impl<V> Debug for Lowering<'_, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'cx, V> !RefUnwindSafe for Lowering<'cx, V>

§

impl<'cx, V> !UnwindSafe for Lowering<'cx, V>

§

impl<'cx, V> Forget for Lowering<'cx, V>

§

impl<'cx, V> Freeze for Lowering<'cx, V>
where HashMap<V, Expr>: Freeze, Vec<(V, Expr)>: Freeze, HashMap<Expr, V>: Freeze,

§

impl<'cx, V> Move for Lowering<'cx, V>

§

impl<'cx, V> Send for Lowering<'cx, V>
where HashMap<V, Expr>: Send, Vec<(V, Expr)>: Send, HashMap<Expr, V>: Send,

§

impl<'cx, V> Sync for Lowering<'cx, V>
where HashMap<V, Expr>: Sync, Vec<(V, Expr)>: Sync, HashMap<Expr, V>: Sync,

§

impl<'cx, V> Unpin for Lowering<'cx, V>
where HashMap<V, Expr>: Unpin, Vec<(V, Expr)>: Unpin, HashMap<Expr, V>: Unpin,

§

impl<'cx, V> UnsafeUnpin for Lowering<'cx, V>

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.