Skip to content

Commit d0f2eca

Browse files
committed
codegen for coro_begin instruction
See #727
1 parent 79f1ff5 commit d0f2eca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/all_types.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ struct CodeGen {
16131613
LLVMValueRef coro_id_fn_val;
16141614
LLVMValueRef coro_alloc_fn_val;
16151615
LLVMValueRef coro_size_fn_val;
1616+
LLVMValueRef coro_begin_fn_val;
16161617
bool error_during_imports;
16171618

16181619
const char **clang_argv;

src/codegen.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,22 @@ static LLVMValueRef get_coro_size_fn_val(CodeGen *g) {
987987
return g->coro_size_fn_val;
988988
}
989989

990+
static LLVMValueRef get_coro_begin_fn_val(CodeGen *g) {
991+
if (g->coro_begin_fn_val)
992+
return g->coro_begin_fn_val;
993+
994+
LLVMTypeRef param_types[] = {
995+
ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
996+
LLVMPointerType(LLVMInt8Type(), 0),
997+
};
998+
LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 2, false);
999+
Buf *name = buf_sprintf("llvm.coro.begin");
1000+
g->coro_begin_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1001+
assert(LLVMGetIntrinsicID(g->coro_begin_fn_val));
1002+
1003+
return g->coro_begin_fn_val;
1004+
}
1005+
9901006
static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
9911007
if (g->return_address_fn_val)
9921008
return g->return_address_fn_val;
@@ -3808,7 +3824,13 @@ static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, Ir
38083824
}
38093825

38103826
static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) {
3811-
zig_panic("TODO ir_render_coro_begin");
3827+
LLVMValueRef coro_id = ir_llvm_value(g, instruction->coro_id);
3828+
LLVMValueRef coro_mem_ptr = ir_llvm_value(g, instruction->coro_mem_ptr);
3829+
LLVMValueRef params[] = {
3830+
coro_id,
3831+
coro_mem_ptr,
3832+
};
3833+
return LLVMBuildCall(g->builder, get_coro_begin_fn_val(g), params, 2, "");
38123834
}
38133835

38143836
static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable,

0 commit comments

Comments
 (0)