aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-02-25 15:20:31 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-02-25 15:20:31 -0500
commit93cbd4eeb97f30062311d6e083dd056b8fb8b021 (patch)
treee8644b453c39df5ecb7c8aec88fd20a089930b56
parent9f6c5a20de03a59bfcaead703fe9490a6d622f84 (diff)
downloadzig-93cbd4eeb97f30062311d6e083dd056b8fb8b021.tar.gz
zig-93cbd4eeb97f30062311d6e083dd056b8fb8b021.zip
codegen for coro_alloc and coro_size instructions
See #727
-rw-r--r--src/all_types.hpp2
-rw-r--r--src/codegen.cpp32
2 files changed, 32 insertions, 2 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index 8e362cd64e..f95cb8425a 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1611,6 +1611,8 @@ struct CodeGen {
LLVMValueRef frame_address_fn_val;
LLVMValueRef coro_destroy_fn_val;
LLVMValueRef coro_id_fn_val;
+ LLVMValueRef coro_alloc_fn_val;
+ LLVMValueRef coro_size_fn_val;
bool error_during_imports;
const char **clang_argv;
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) {