diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 15:20:31 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 15:20:31 -0500 |
| commit | 93cbd4eeb97f30062311d6e083dd056b8fb8b021 (patch) | |
| tree | e8644b453c39df5ecb7c8aec88fd20a089930b56 /src/codegen.cpp | |
| parent | 9f6c5a20de03a59bfcaead703fe9490a6d622f84 (diff) | |
| download | zig-93cbd4eeb97f30062311d6e083dd056b8fb8b021.tar.gz zig-93cbd4eeb97f30062311d6e083dd056b8fb8b021.zip | |
codegen for coro_alloc and coro_size instructions
See #727
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 21ad715977..c7b6ce1f7c 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -960,6 +960,33 @@ static LLVMValueRef get_coro_id_fn_val(CodeGen *g) { return g->coro_id_fn_val; } +static LLVMValueRef get_coro_alloc_fn_val(CodeGen *g) { + if (g->coro_alloc_fn_val) + return g->coro_alloc_fn_val; + + LLVMTypeRef param_types[] = { + ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()), + }; + LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 1, false); + Buf *name = buf_sprintf("llvm.coro.alloc"); + g->coro_alloc_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type); + assert(LLVMGetIntrinsicID(g->coro_alloc_fn_val)); + + return g->coro_alloc_fn_val; +} + +static LLVMValueRef get_coro_size_fn_val(CodeGen *g) { + if (g->coro_size_fn_val) + return g->coro_size_fn_val; + + LLVMTypeRef fn_type = LLVMFunctionType(g->builtin_types.entry_usize->type_ref, nullptr, 0, false); + Buf *name = buf_sprintf("llvm.coro.size.i%d", g->pointer_size_bytes * 8); + g->coro_size_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type); + assert(LLVMGetIntrinsicID(g->coro_size_fn_val)); + + return g->coro_size_fn_val; +} + static LLVMValueRef get_return_address_fn_val(CodeGen *g) { if (g->return_address_fn_val) return g->return_address_fn_val; @@ -3762,11 +3789,12 @@ static LLVMValueRef ir_render_coro_id(CodeGen *g, IrExecutable *executable, IrIn } static LLVMValueRef ir_render_coro_alloc(CodeGen *g, IrExecutable *executable, IrInstructionCoroAlloc *instruction) { - zig_panic("TODO ir_render_coro_alloc"); + LLVMValueRef token = ir_llvm_value(g, instruction->coro_id); + return LLVMBuildCall(g->builder, get_coro_alloc_fn_val(g), &token, 1, ""); } static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, IrInstructionCoroSize *instruction) { - zig_panic("TODO ir_render_coro_size"); + return LLVMBuildCall(g->builder, get_coro_size_fn_val(g), nullptr, 0, ""); } static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) { |
