Skip to content

Commit d2d2ba1

Browse files
committed
codegen for coro_end instruction
See #727
1 parent 0cf327e commit d2d2ba1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/all_types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,7 @@ struct CodeGen {
16151615
LLVMValueRef coro_size_fn_val;
16161616
LLVMValueRef coro_begin_fn_val;
16171617
LLVMValueRef coro_suspend_fn_val;
1618+
LLVMValueRef coro_end_fn_val;
16181619
bool error_during_imports;
16191620

16201621
const char **clang_argv;

src/codegen.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,22 @@ static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) {
10191019
return g->coro_suspend_fn_val;
10201020
}
10211021

1022+
static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {
1023+
if (g->coro_end_fn_val)
1024+
return g->coro_end_fn_val;
1025+
1026+
LLVMTypeRef param_types[] = {
1027+
LLVMPointerType(LLVMInt8Type(), 0),
1028+
LLVMInt1Type(),
1029+
};
1030+
LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 2, false);
1031+
Buf *name = buf_sprintf("llvm.coro.end");
1032+
g->coro_end_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1033+
assert(LLVMGetIntrinsicID(g->coro_end_fn_val));
1034+
1035+
return g->coro_end_fn_val;
1036+
}
1037+
10221038
static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
10231039
if (g->return_address_fn_val)
10241040
return g->return_address_fn_val;
@@ -3885,7 +3901,11 @@ static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable,
38853901
}
38863902

38873903
static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) {
3888-
zig_panic("TODO ir_render_coro_end");
3904+
LLVMValueRef params[] = {
3905+
LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)),
3906+
LLVMConstNull(LLVMInt1Type()),
3907+
};
3908+
return LLVMBuildCall(g->builder, get_coro_end_fn_val(g), params, 2, "");
38893909
}
38903910

38913911
static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {

0 commit comments

Comments
 (0)