authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 14:47:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 14:47:58-05:00
log7567448b91fd7012bf61d3f5532bfd86304899ae
tree8594cca58bec29362b257e8c536edf0ae805004c
parent05bf666eb690d1a1328234cc408960133dba9563

codegen for cancel

See #727

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

src/all_types.hpp+1
...@@ -1609,6 +1609,7 @@ struct CodeGen {...@@ -1609,6 +1609,7 @@ struct CodeGen {
1609 LLVMValueRef trap_fn_val;1609 LLVMValueRef trap_fn_val;
1610 LLVMValueRef return_address_fn_val;1610 LLVMValueRef return_address_fn_val;
1611 LLVMValueRef frame_address_fn_val;1611 LLVMValueRef frame_address_fn_val;
1612 LLVMValueRef coro_destroy_fn_val;
1612 bool error_during_imports;1613 bool error_during_imports;
16131614
1614 const char **clang_argv;1615 const char **clang_argv;
src/codegen.cpp+18-1
...@@ -927,6 +927,21 @@ static LLVMValueRef get_memcpy_fn_val(CodeGen *g) {...@@ -927,6 +927,21 @@ static LLVMValueRef get_memcpy_fn_val(CodeGen *g) {
927 return g->memcpy_fn_val;927 return g->memcpy_fn_val;
928}928}
929929
930static LLVMValueRef get_coro_destroy_fn_val(CodeGen *g) {
931 if (g->coro_destroy_fn_val)
932 return g->coro_destroy_fn_val;
933
934 LLVMTypeRef param_types[] = {
935 LLVMPointerType(LLVMInt8Type(), 0),
936 };
937 LLVMTypeRef fn_type = LLVMFunctionType(LLVMVoidType(), param_types, 1, false);
938 Buf *name = buf_sprintf("llvm.coro.destroy");
939 g->coro_destroy_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
940 assert(LLVMGetIntrinsicID(g->coro_destroy_fn_val));
941
942 return g->coro_destroy_fn_val;
943}
944
930static LLVMValueRef get_return_address_fn_val(CodeGen *g) {945static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
931 if (g->return_address_fn_val)946 if (g->return_address_fn_val)
932 return g->return_address_fn_val;947 return g->return_address_fn_val;
...@@ -3113,7 +3128,9 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu...@@ -3113,7 +3128,9 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
3113}3128}
31143129
3115static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {3130static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {
3116 zig_panic("TODO ir_render_cancel");3131 LLVMValueRef target_handle = ir_llvm_value(g, instruction->target);
3132 LLVMBuildCall(g->builder, get_coro_destroy_fn_val(g), &target_handle, 1, "");
3133 return nullptr;
3117}3134}
31183135
3119static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable, IrInstructionGetImplicitAllocator *instruction) {3136static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable, IrInstructionGetImplicitAllocator *instruction) {