Skip to content

Commit 523416f

Browse files
committed
add trait method for emit_exit
1 parent 5e3cbac commit 523416f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

hugr-llvm/src/extension/prelude.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ pub trait PreludeCodegen: Clone {
149149
emit_libc_abort(ctx)
150150
}
151151

152+
/// Emit instructions to halt execution with the error `err`.
153+
///
154+
/// The type of `err` must match that returned from [Self::error_type].
155+
///
156+
/// The default implementation emits calls to libc's `printf` and `abort`,
157+
/// matching the default implementation of [Self::emit_panic].
158+
///
159+
/// Note that implementations of `emit_panic` must not emit `unreachable`
160+
/// terminators, that, if appropriate, is the responsibility of the caller.
161+
fn emit_exit<H: HugrView<Node = Node>>(
162+
&self,
163+
ctx: &mut EmitFuncContext<H>,
164+
err: BasicValueEnum,
165+
) -> Result<()> {
166+
self.emit_panic(ctx, err)
167+
}
168+
152169
/// Emit instructions to materialise an LLVM value representing `str`.
153170
///
154171
/// The type of the returned value must match [Self::string_type].
@@ -351,7 +368,7 @@ pub fn add_prelude_extensions<'a, H: HugrView<Node = Node> + 'a>(
351368
.error_type(&context.typing_session())?
352369
.as_basic_type_enum()
353370
);
354-
pcg.emit_panic(context, err)?;
371+
pcg.emit_exit(context, err)?;
355372
let returns = args
356373
.outputs
357374
.get_types()

0 commit comments

Comments
 (0)