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
signature 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) {...@@ -5590,6 +5590,15 @@ static ResultLocVar *create_var_result_loc(IrInstruction *alloca, ZigVar *var) {
5590 return result_loc_var;5590 return result_loc_var;
5591}5591}
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
5593static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {5602static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {
5594 assert(node->type == NodeTypeVariableDeclaration);5603 assert(node->type == NodeTypeVariableDeclaration);
55955604
...@@ -5967,13 +5976,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5967,13 +5976,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5967 index_var = ir_create_var(irb, node, parent_scope, nullptr, true, false, true, is_comptime);5976 index_var = ir_create_var(irb, node, parent_scope, nullptr, true, false, true, is_comptime);
5968 index_var_name = "i";5977 index_var_name = "i";
5969 }5978 }
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);
5974 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);5980 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);5981 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
5976 ir_build_var_decl_src(irb, parent_scope, index_var_source_node, index_var, nullptr, index_alloca);5982 parent_scope = index_var->parent_scope;
59775983
5978 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);5984 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);
5979 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);5985 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...@@ -7495,7 +7501,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
7495 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);7501 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
7496 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);7502 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);
7497 IrInstruction *undef_promise_result = ir_build_implicit_cast(irb, scope, node, promise_result_type, undef);7503 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);
7499 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);7505 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);
7500 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);7506 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);
7501 IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle);7507 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...@@ -7930,7 +7936,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7930 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);7936 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
7931 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);7937 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
7932 IrInstruction *undef_coro_frame = ir_build_implicit_cast(irb, coro_scope, node, coro_frame_type_value, undef);7938 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);
7934 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);7940 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
79357941
7936 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7942 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...@@ -7938,7 +7944,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7938 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,7944 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
7939 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));7945 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
7940 IrInstruction *null_await_handle = ir_build_implicit_cast(irb, coro_scope, node, await_handle_type_val, null_value);7946 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);
7942 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);7948 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
79437949
7944 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,7950 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...@@ -7948,11 +7954,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7948 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);7954 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);
7949 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7955 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7950 IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node);7956 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);
7952 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,7958 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,
7953 ImplicitAllocatorIdArg);7959 ImplicitAllocatorIdArg);
7954 irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false);7960 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);
7956 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);7963 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
7957 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);7964 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);
7958 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);7965 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);