Trait hugr_llvm::custom::prelude::PreludeCodegen
source · pub trait PreludeCodegen: Clone {
// Provided methods
fn usize_type<'c, H: HugrView>(
&self,
session: &TypingSession<'c, H>,
) -> IntType<'c> { ... }
fn qubit_type<'c, H: HugrView>(
&self,
session: &TypingSession<'c, H>,
) -> impl BasicType<'c> { ... }
fn array_type<'c, H: HugrView>(
&self,
_session: &TypingSession<'c, H>,
elem_ty: BasicTypeEnum<'c>,
size: u64,
) -> impl BasicType<'c> { ... }
fn emit_new_array_alloc<'c, H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'c, H>,
elem_ty: BasicTypeEnum<'c>,
elems: Vec<BasicValueEnum<'_>>,
) -> Result<BasicValueEnum<'c>> { ... }
fn emit_print<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, H>,
text: BasicValueEnum<'_>,
) -> Result<()> { ... }
fn emit_panic<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, H>,
signal: IntValue<'_>,
msg: BasicValueEnum<'_>,
) -> Result<()> { ... }
}
Expand description
A helper trait for implementing CodegenExtensions for hugr::extension::prelude.
All methods have sensible defaults provided, and DefaultPreludeCodegen is trivial implementation of this trait, which delegates everything to those default implementations.
One should use either PreludeCodegenExtension::new, or CodegenExtsMap::add_prelude_extensions to work with the CodegenExtension.
TODO several types and ops are unimplemented. We expect to add methods to
this trait as necessary, allowing downstream users to customise the lowering
of prelude
.
Provided Methods§
sourcefn usize_type<'c, H: HugrView>(
&self,
session: &TypingSession<'c, H>,
) -> IntType<'c>
fn usize_type<'c, H: HugrView>( &self, session: &TypingSession<'c, H>, ) -> IntType<'c>
Return the llvm type of hugr::extension::prelude::USIZE_T. That type must be an IntType.
sourcefn qubit_type<'c, H: HugrView>(
&self,
session: &TypingSession<'c, H>,
) -> impl BasicType<'c>
fn qubit_type<'c, H: HugrView>( &self, session: &TypingSession<'c, H>, ) -> impl BasicType<'c>
Return the llvm type of hugr::extension::prelude::QB_T.
sourcefn array_type<'c, H: HugrView>(
&self,
_session: &TypingSession<'c, H>,
elem_ty: BasicTypeEnum<'c>,
size: u64,
) -> impl BasicType<'c>
fn array_type<'c, H: HugrView>( &self, _session: &TypingSession<'c, H>, elem_ty: BasicTypeEnum<'c>, size: u64, ) -> impl BasicType<'c>
Return the llvm type of hugr::extension::prelude::array_type.
sourcefn emit_new_array_alloc<'c, H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'c, H>,
elem_ty: BasicTypeEnum<'c>,
elems: Vec<BasicValueEnum<'_>>,
) -> Result<BasicValueEnum<'c>>
fn emit_new_array_alloc<'c, H: HugrView>( &self, ctx: &mut EmitFuncContext<'c, H>, elem_ty: BasicTypeEnum<'c>, elems: Vec<BasicValueEnum<'_>>, ) -> Result<BasicValueEnum<'c>>
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::extension::prelude::PRINT_OP_ID node.
sourcefn emit_panic<H: HugrView>(
&self,
ctx: &mut EmitFuncContext<'_, H>,
signal: IntValue<'_>,
msg: BasicValueEnum<'_>,
) -> Result<()>
fn emit_panic<H: HugrView>( &self, ctx: &mut EmitFuncContext<'_, H>, signal: IntValue<'_>, msg: BasicValueEnum<'_>, ) -> Result<()>
Emit a hugr::extension::prelude::PANIC_OP_ID node.