pub trait PreludeCodegen: Clone {
// Provided methods
fn usize_type<'c>(&self, session: &TypingSession<'c, '_>) -> IntType<'c> { ... }
fn qubit_type<'c>(
&self,
session: &TypingSession<'c, '_>,
) -> impl BasicType<'c> { ... }
fn error_type<'c>(
&self,
session: &TypingSession<'c, '_>,
) -> Result<impl BasicType<'c>> { ... }
fn emit_print<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
text: BasicValueEnum<'_>,
) -> Result<()> { ... }
fn emit_const_error<'c, H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
err: &ConstError,
) -> Result<BasicValueEnum<'c>> { ... }
fn emit_panic<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()> { ... }
}
Expand description
A helper trait for customising the lowering hugr_core::extension::prelude types, CustomConsts, and ops.
All methods have sensible defaults provided, and DefaultPreludeCodegen is a trivial implementation of this trait which delegates everything to those default implementations.
Provided Methods§
Sourcefn usize_type<'c>(&self, session: &TypingSession<'c, '_>) -> IntType<'c>
fn usize_type<'c>(&self, session: &TypingSession<'c, '_>) -> IntType<'c>
Return the llvm type of hugr_core::extension::prelude::usize_t. That type must be an IntType.
Sourcefn qubit_type<'c>(&self, session: &TypingSession<'c, '_>) -> impl BasicType<'c>
fn qubit_type<'c>(&self, session: &TypingSession<'c, '_>) -> impl BasicType<'c>
Return the llvm type of hugr_core::extension::prelude::qb_t.
Sourcefn error_type<'c>(
&self,
session: &TypingSession<'c, '_>,
) -> Result<impl BasicType<'c>>
fn error_type<'c>( &self, session: &TypingSession<'c, '_>, ) -> Result<impl BasicType<'c>>
Return the llvm type of hugr_core::extension::prelude::error_type().
The returned type must always match the type of the returned value of
Self::emit_const_error, and the err
argument of Self::emit_panic.
The default implementation is a struct type with an i32 field and an i8* field for the code and message.
Sourcefn emit_print<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
text: BasicValueEnum<'_>,
) -> Result<()>
fn emit_print<H: HugrView>( &self, ctx: &mut EmitFuncContext<'_, '_, H>, text: BasicValueEnum<'_>, ) -> Result<()>
Emit a hugr_core::extension::prelude::PRINT_OP_ID node.
Sourcefn emit_const_error<'c, H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
err: &ConstError,
) -> Result<BasicValueEnum<'c>>
fn emit_const_error<'c, H: HugrView>( &self, ctx: &mut EmitFuncContext<'c, '_, H>, err: &ConstError, ) -> Result<BasicValueEnum<'c>>
Emit instructions to materialise an LLVM value representing err
.
The type of the returned value must match Self::error_type.
The default implementation materialises an LLVM struct with the
ConstError::signal and ConstError::message of err
.
Sourcefn emit_panic<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()>
fn emit_panic<H: HugrView>( &self, ctx: &mut EmitFuncContext<'_, '_, H>, err: BasicValueEnum<'_>, ) -> Result<()>
Emit instructions to halt execution with the error err
.
The type of err
must match that returned from Self::error_type.
The default implementation emits calls to libc’s printf
and abort
.
Note that implementations of emit_panic
must not emit unreachable
terminators, that, if appropriate, is the responsibility of the caller.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.