diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 16:40:00 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 16:40:00 -0500 |
| commit | d2d2ba10e9688e6760e75290a29dc055d04a0296 (patch) | |
| tree | 78b70062508bd40024d9faba9f5131ba08187b6c | |
| parent | 0cf327eb17360cddcdfab623db049aca5afd7010 (diff) | |
| download | zig-d2d2ba10e9688e6760e75290a29dc055d04a0296.tar.gz zig-d2d2ba10e9688e6760e75290a29dc055d04a0296.zip | |
codegen for coro_end instruction
See #727
| -rw-r--r-- | src/all_types.hpp | 1 | ||||
| -rw-r--r-- | src/codegen.cpp | 22 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 7efede5333..b7a0625926 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1615,6 +1615,7 @@ struct CodeGen { LLVMValueRef coro_size_fn_val; LLVMValueRef coro_begin_fn_val; LLVMValueRef coro_suspend_fn_val; + LLVMValueRef coro_end_fn_val; bool error_during_imports; const char **clang_argv; diff --git a/src/codegen.cpp b/src/codegen.cpp index 5643333f99..4cc9880fea 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1019,6 +1019,22 @@ static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) { return g->coro_suspend_fn_val; } +static LLVMValueRef get_coro_end_fn_val(CodeGen *g) { + if (g->coro_end_fn_val) + return g->coro_end_fn_val; + + LLVMTypeRef param_types[] = { + LLVMPointerType(LLVMInt8Type(), 0), + LLVMInt1Type(), + }; + LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 2, false); + Buf *name = buf_sprintf("llvm.coro.end"); + g->coro_end_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type); + assert(LLVMGetIntrinsicID(g->coro_end_fn_val)); + + return g->coro_end_fn_val; +} + static LLVMValueRef get_return_address_fn_val(CodeGen *g) { if (g->return_address_fn_val) return g->return_address_fn_val; @@ -3885,7 +3901,11 @@ static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, } static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) { - zig_panic("TODO ir_render_coro_end"); + LLVMValueRef params[] = { + LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)), + LLVMConstNull(LLVMInt1Type()), + }; + return LLVMBuildCall(g->builder, get_coro_end_fn_val(g), params, 2, ""); } static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) { |
