authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:40:00-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:40:00-05:00
logd2d2ba10e9688e6760e75290a29dc055d04a0296
tree78b70062508bd40024d9faba9f5131ba08187b6c
parent0cf327eb17360cddcdfab623db049aca5afd7010

codegen for coro_end instruction

See #727

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

src/all_types.hpp+1
...@@ -1615,6 +1615,7 @@ struct CodeGen {...@@ -1615,6 +1615,7 @@ struct CodeGen {
1615 LLVMValueRef coro_size_fn_val;1615 LLVMValueRef coro_size_fn_val;
1616 LLVMValueRef coro_begin_fn_val;1616 LLVMValueRef coro_begin_fn_val;
1617 LLVMValueRef coro_suspend_fn_val;1617 LLVMValueRef coro_suspend_fn_val;
1618 LLVMValueRef coro_end_fn_val;
1618 bool error_during_imports;1619 bool error_during_imports;
16191620
1620 const char **clang_argv;1621 const char **clang_argv;
src/codegen.cpp+21-1
...@@ -1019,6 +1019,22 @@ static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) {...@@ -1019,6 +1019,22 @@ static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) {
1019 return g->coro_suspend_fn_val;1019 return g->coro_suspend_fn_val;
1020}1020}
10211021
1022static 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
1022static LLVMValueRef get_return_address_fn_val(CodeGen *g) {1038static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
1023 if (g->return_address_fn_val)1039 if (g->return_address_fn_val)
1024 return g->return_address_fn_val;1040 return g->return_address_fn_val;
...@@ -3885,7 +3901,11 @@ static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable,...@@ -3885,7 +3901,11 @@ static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable,
3885}3901}
38863902
3887static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) {3903static 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, "");
3889}3909}
38903910
3891static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {3911static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {