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 string_type<'c>(
&self,
session: &TypingSession<'c, '_>,
) -> Result<impl BasicType<'c>> { ... }
fn emit_print<H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
text: BasicValueEnum<'_>,
) -> Result<()> { ... }
fn emit_const_error<'c, H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
err: &ConstError,
) -> Result<BasicValueEnum<'c>> { ... }
fn emit_panic<H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()> { ... }
fn emit_exit<H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()> { ... }
fn emit_const_string<'c, H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
str: &ConstString,
) -> Result<BasicValueEnum<'c>> { ... }
fn emit_barrier<'c, H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
args: EmitOpArgs<'c, '_, ExtensionOp, H>,
) -> Result<()> { ... }
}
Expand description
A helper trait for customising the lowering hugr_core::extension::prelude
types, CustomConst
s, 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 string_type<'c>(
&self,
session: &TypingSession<'c, '_>,
) -> Result<impl BasicType<'c>>
fn string_type<'c>( &self, session: &TypingSession<'c, '_>, ) -> Result<impl BasicType<'c>>
Return the llvm type of hugr_core::extension::prelude::string_type()
.
The returned type must always match the type of the returned value of
Self::emit_const_string
, and the text
argument of Self::emit_print
.
The default implementation is i8*.
Sourcefn emit_print<H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
text: BasicValueEnum<'_>,
) -> Result<()>
fn emit_print<H: HugrView<Node = Node>>( &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<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
err: &ConstError,
) -> Result<BasicValueEnum<'c>>
fn emit_const_error<'c, H: HugrView<Node = Node>>( &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<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()>
fn emit_panic<H: HugrView<Node = Node>>( &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.
Sourcefn emit_exit<H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'_, '_, H>,
err: BasicValueEnum<'_>,
) -> Result<()>
fn emit_exit<H: HugrView<Node = Node>>( &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
,
matching the default implementation of Self::emit_panic
.
Note that implementations of emit_panic
must not emit unreachable
terminators, that, if appropriate, is the responsibility of the caller.
Sourcefn emit_const_string<'c, H: HugrView<Node = Node>>(
&self,
ctx: &mut EmitFuncContext<'c, '_, H>,
str: &ConstString,
) -> Result<BasicValueEnum<'c>>
fn emit_const_string<'c, H: HugrView<Node = Node>>( &self, ctx: &mut EmitFuncContext<'c, '_, H>, str: &ConstString, ) -> Result<BasicValueEnum<'c>>
Emit instructions to materialise an LLVM value representing str
.
The type of the returned value must match Self::string_type
.
The default implementation creates a global C string.
fn emit_barrier<'c, H: HugrView<Node = Node>>( &self, ctx: &mut EmitFuncContext<'c, '_, H>, args: EmitOpArgs<'c, '_, ExtensionOp, H>, ) -> Result<()>
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.