authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:22:19-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:22:19-05:00
logd0f2eca106f556fe5826d96b08ffdf1be1293915
tree2ae3ab3e22d1ae9248d5154d9f43bc87852620f4
parent79f1ff574b3badf7cf0a0cd7632c529801b4c611

codegen for coro_begin instruction

See #727

2 files changed, 24 insertions(+), 1 deletions(-)

src/all_types.hpp+1
...@@ -1613,6 +1613,7 @@ struct CodeGen {...@@ -1613,6 +1613,7 @@ struct CodeGen {
1613 LLVMValueRef coro_id_fn_val;1613 LLVMValueRef coro_id_fn_val;
1614 LLVMValueRef coro_alloc_fn_val;1614 LLVMValueRef coro_alloc_fn_val;
1615 LLVMValueRef coro_size_fn_val;1615 LLVMValueRef coro_size_fn_val;
1616 LLVMValueRef coro_begin_fn_val;
1616 bool error_during_imports;1617 bool error_during_imports;
16171618
1618 const char **clang_argv;1619 const char **clang_argv;
src/codegen.cpp+23-1
...@@ -987,6 +987,22 @@ static LLVMValueRef get_coro_size_fn_val(CodeGen *g) {...@@ -987,6 +987,22 @@ static LLVMValueRef get_coro_size_fn_val(CodeGen *g) {
987 return g->coro_size_fn_val;987 return g->coro_size_fn_val;
988}988}
989989
990static 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
990static LLVMValueRef get_return_address_fn_val(CodeGen *g) {1006static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
991 if (g->return_address_fn_val)1007 if (g->return_address_fn_val)
992 return g->return_address_fn_val;1008 return g->return_address_fn_val;
...@@ -3808,7 +3824,13 @@ static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, Ir...@@ -3808,7 +3824,13 @@ static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, Ir
3808}3824}
38093825
3810static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) {3826static 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, "");
3812}3834}
38133835
3814static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable,3836static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable,