authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 22:21:50-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 22:21:50-04:00
log057b96006b055ca480167ac4ca66c87c2be89354
tree784a1dc2956d5cf49198ba8d574034feb5ec818f
parenta32abcd365f0a019d3f858c4ee769a8348f0f4a2
signaturelock-open Commit is signed but in an unrecognized format.

fix the rest of the ir_build_alloca_src callsites

except for switch expressions

1 files changed, 17 insertions(+), 10 deletions(-)

src/ir.cpp+17-10
......@@ -5590,6 +5590,15 @@ static ResultLocVar *create_var_result_loc(IrInstruction *alloca, ZigVar *var) {
55905590 return result_loc_var;
55915591}
55925592
5593static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
5594 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
5595{
5596 IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
5597 ResultLocVar *var_result_loc = create_var_result_loc(alloca, var);
5598 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
5599 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
5600}
5601
55935602static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {
55945603 assert(node->type == NodeTypeVariableDeclaration);
55955604
......@@ -5967,13 +5976,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
59675976 index_var = ir_create_var(irb, node, parent_scope, nullptr, true, false, true, is_comptime);
59685977 index_var_name = "i";
59695978 }
5970 parent_scope = index_var->parent_scope;
59715979
5972 IrInstruction *index_alloca = ir_build_alloca_src(irb, parent_scope, node, nullptr, index_var_name, is_comptime);
5973 ResultLocVar *var_result_loc = create_var_result_loc(index_alloca, index_var);
59745980 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);
5975 ir_build_end_expr(irb, parent_scope, node, zero, &var_result_loc->base);
5976 ir_build_var_decl_src(irb, parent_scope, index_var_source_node, index_var, nullptr, index_alloca);
5981 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
5982 parent_scope = index_var->parent_scope;
59775983
59785984 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);
59795985 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
......@@ -7495,7 +7501,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
74957501 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
74967502 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);
74977503 IrInstruction *undef_promise_result = ir_build_implicit_cast(irb, scope, node, promise_result_type, undef);
7498 ir_build_var_decl_src(irb, scope, node, result_var, nullptr, undef_promise_result);
7504 build_decl_var_and_init(irb, scope, node, result_var, undef_promise_result, "result", const_bool_false);
74997505 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);
75007506 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);
75017507 IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle);
......@@ -7930,7 +7936,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
79307936 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
79317937 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
79327938 IrInstruction *undef_coro_frame = ir_build_implicit_cast(irb, coro_scope, node, coro_frame_type_value, undef);
7933 ir_build_var_decl_src(irb, coro_scope, node, promise_var, nullptr, undef_coro_frame);
7939 build_decl_var_and_init(irb, coro_scope, node, promise_var, undef_coro_frame, "promise", const_bool_false);
79347940 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
79357941
79367942 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
......@@ -7938,7 +7944,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
79387944 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
79397945 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
79407946 IrInstruction *null_await_handle = ir_build_implicit_cast(irb, coro_scope, node, await_handle_type_val, null_value);
7941 ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_await_handle);
7947 build_decl_var_and_init(irb, coro_scope, node, await_handle_var, null_await_handle, "await_handle", const_bool_false);
79427948 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
79437949
79447950 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
......@@ -7948,11 +7954,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
79487954 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);
79497955 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
79507956 IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node);
7951 ir_build_var_decl_src(irb, coro_scope, node, coro_size_var, nullptr, coro_size);
7957 build_decl_var_and_init(irb, coro_scope, node, coro_size_var, coro_size, "coro_size", const_bool_false);
79527958 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,
79537959 ImplicitAllocatorIdArg);
79547960 irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false);
7955 ir_build_var_decl_src(irb, coro_scope, node, irb->exec->coro_allocator_var, nullptr, implicit_allocator_ptr);
7961 build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr,
7962 "allocator", const_bool_false);
79567963 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
79577964 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);
79587965 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);