aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-02-25 16:46:01 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-02-25 16:46:01 -0500
commit4eac75914bcdf9648518d1837f48e07e35744dc1 (patch)
treef8f10ac027c164e5333f04801b1bbdc47331cb7b
parentd2d2ba10e9688e6760e75290a29dc055d04a0296 (diff)
downloadzig-4eac75914bcdf9648518d1837f48e07e35744dc1.tar.gz
zig-4eac75914bcdf9648518d1837f48e07e35744dc1.zip
codegen for coro_free instruction
See #727
-rw-r--r--src/all_types.hpp1
-rw-r--r--src/codegen.cpp24
2 files changed, 24 insertions, 1 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index b7a0625926..d4ec5ac427 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1616,6 +1616,7 @@ struct CodeGen {
LLVMValueRef coro_begin_fn_val;
LLVMValueRef coro_suspend_fn_val;
LLVMValueRef coro_end_fn_val;
+ LLVMValueRef coro_free_fn_val;
bool error_during_imports;
const char **clang_argv;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 4cc9880fea..163e9d804b 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1035,6 +1035,22 @@ static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {
return g->coro_end_fn_val;
}
+static LLVMValueRef get_coro_free_fn_val(CodeGen *g) {
+ if (g->coro_free_fn_val)
+ return g->coro_free_fn_val;
+
+ LLVMTypeRef param_types[] = {
+ ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
+ LLVMPointerType(LLVMInt8Type(), 0),
+ };
+ LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 2, false);
+ Buf *name = buf_sprintf("llvm.coro.free");
+ g->coro_free_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
+ assert(LLVMGetIntrinsicID(g->coro_free_fn_val));
+
+ return g->coro_free_fn_val;
+}
+
static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
if (g->return_address_fn_val)
return g->return_address_fn_val;
@@ -3909,7 +3925,13 @@ static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrI
}
static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {
- zig_panic("TODO ir_render_coro_free");
+ LLVMValueRef coro_id = ir_llvm_value(g, instruction->coro_id);
+ LLVMValueRef coro_handle = ir_llvm_value(g, instruction->coro_handle);
+ LLVMValueRef params[] = {
+ coro_id,
+ coro_handle,
+ };
+ return LLVMBuildCall(g->builder, get_coro_free_fn_val(g), params, 2, "");
}
static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, IrInstructionCoroResume *instruction) {