| ... | @@ -1003,6 +1003,22 @@ static LLVMValueRef get_coro_begin_fn_val(CodeGen *g) { | ... | @@ -1003,6 +1003,22 @@ static LLVMValueRef get_coro_begin_fn_val(CodeGen *g) { |
| 1003 | return g->coro_begin_fn_val; | 1003 | return g->coro_begin_fn_val; |
| 1004 | } | 1004 | } |
| 1005 | | 1005 | |
| | 1006 | static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) { |
| | 1007 | if (g->coro_suspend_fn_val) |
| | 1008 | return g->coro_suspend_fn_val; |
| | 1009 | |
| | 1010 | LLVMTypeRef param_types[] = { |
| | 1011 | ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()), |
| | 1012 | LLVMInt1Type(), |
| | 1013 | }; |
| | 1014 | LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt8Type(), param_types, 2, false); |
| | 1015 | Buf *name = buf_sprintf("llvm.coro.suspend"); |
| | 1016 | g->coro_suspend_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type); |
| | 1017 | assert(LLVMGetIntrinsicID(g->coro_suspend_fn_val)); |
| | 1018 | |
| | 1019 | return g->coro_suspend_fn_val; |
| | 1020 | } |
| | 1021 | |
| 1006 | static LLVMValueRef get_return_address_fn_val(CodeGen *g) { | 1022 | static LLVMValueRef get_return_address_fn_val(CodeGen *g) { |
| 1007 | if (g->return_address_fn_val) | 1023 | if (g->return_address_fn_val) |
| 1008 | return g->return_address_fn_val; | 1024 | return g->return_address_fn_val; |
| ... | @@ -3854,7 +3870,18 @@ static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executab | ... | @@ -3854,7 +3870,18 @@ static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executab |
| 3854 | } | 3870 | } |
| 3855 | | 3871 | |
| 3856 | static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, IrInstructionCoroSuspend *instruction) { | 3872 | static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, IrInstructionCoroSuspend *instruction) { |
| 3857 | zig_panic("TODO ir_render_coro_suspend"); | 3873 | LLVMValueRef save_point; |
| | 3874 | if (instruction->save_point == nullptr) { |
| | 3875 | save_point = LLVMConstNull(ZigLLVMTokenTypeInContext(LLVMGetGlobalContext())); |
| | 3876 | } else { |
| | 3877 | save_point = ir_llvm_value(g, instruction->save_point); |
| | 3878 | } |
| | 3879 | LLVMValueRef is_final = ir_llvm_value(g, instruction->is_final); |
| | 3880 | LLVMValueRef params[] = { |
| | 3881 | save_point, |
| | 3882 | is_final, |
| | 3883 | }; |
| | 3884 | return LLVMBuildCall(g->builder, get_coro_suspend_fn_val(g), params, 2, ""); |
| 3858 | } | 3885 | } |
| 3859 | | 3886 | |
| 3860 | static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) { | 3887 | static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) { |