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>
impl<'cx, V: Copy + Eq + Hash> Lowering<'cx, V>
Sourcepub fn new(cx: &'cx mut Context) -> Self
pub fn new(cx: &'cx mut Context) -> Self
A lowering into cx (reuse one context per function: Context::clear keeps its
allocations).
Sourcepub fn detach(self) -> Lowered<V>
pub fn detach(self) -> Lowered<V>
Releases the context, keeping the values: Lowered::attach resumes.
Sourcepub fn context(&mut self) -> &mut Context
pub fn context(&mut self) -> &mut Context
The context, to build expressions in (and to simplify).
Sourcepub fn value(&mut self, v: V, width: Width) -> Result<Expr, Error>
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.
Sourcepub fn input(
&mut self,
v: V,
width: Width,
known: Option<KnownBits>,
) -> Result<Expr, Error>
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.
Sourcepub fn input_named(
&mut self,
v: V,
key: impl Into<SymbolKey>,
width: Width,
known: Option<KnownBits>,
) -> Result<Expr, Error>
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.
Sourcepub fn define(&mut self, v: V, e: Expr) -> Result<(), Error>
pub fn define(&mut self, v: V, e: Expr) -> Result<(), Error>
Records that host value v is e (an expression of this context).
Sourcepub fn lower<S: Semantics<Value = V> + ?Sized>(
&mut self,
inst: &S,
) -> Result<Option<Expr>, Error>
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.
Sourcepub fn lower_all<'i, S, I>(&mut self, insts: I) -> Result<(), Error>
pub fn lower_all<'i, S, I>(&mut self, insts: I) -> Result<(), Error>
Lowers instructions in order (each defines its result before the next reads it).
Sourcepub fn inputs(&self) -> &[(V, Expr)]
pub fn inputs(&self) -> &[(V, Expr)]
The values defined outside that were read, in order, with their symbols.
Sourcepub fn owner(&self, e: Expr) -> Option<V>
pub fn owner(&self, e: Expr) -> Option<V>
A host value that computes e already, if one does (the first defined).
Sourcepub fn raise<R: Raise<Value = V> + ?Sized>(
&mut self,
e: Expr,
r: &mut R,
) -> Result<V, Error>
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.