authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-11 21:37:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-11 21:37:47-04:00
logce11d6d16cf388ec7abff9680ee3a263185a9986
tree1176e1ff7c0b9ec94fc124c35922826a305a60fd
parent30c4add85a0f4af727ad7cf8f2134114329d0f07

ir: refactor lvalues


3 files changed, 44 insertions(+), 50 deletions(-)

src/all_types.hpp+5-6
...@@ -2005,12 +2005,6 @@ struct IrBasicBlock {...@@ -2005,12 +2005,6 @@ struct IrBasicBlock {
2005 IrInstruction *must_be_comptime_source_instr;2005 IrInstruction *must_be_comptime_source_instr;
2006};2006};
20072007
2008struct LVal {
2009 bool is_ptr;
2010 bool is_const;
2011 bool is_volatile;
2012};
2013
2014enum IrInstructionId {2008enum IrInstructionId {
2015 IrInstructionIdInvalid,2009 IrInstructionIdInvalid,
2016 IrInstructionIdBr,2010 IrInstructionIdBr,
...@@ -2972,6 +2966,11 @@ struct IrInstructionTypeName {...@@ -2972,6 +2966,11 @@ struct IrInstructionTypeName {
2972 IrInstruction *type_value;2966 IrInstruction *type_value;
2973};2967};
29742968
2969enum LVal {
2970 LValNone,
2971 LValPtr,
2972};
2973
2975struct IrInstructionDeclRef {2974struct IrInstructionDeclRef {
2976 IrInstruction base;2975 IrInstruction base;
29772976
src/ir.cpp+37-40
...@@ -39,9 +39,6 @@ struct IrAnalyze {...@@ -39,9 +39,6 @@ struct IrAnalyze {
39 IrBasicBlock *const_predecessor_bb;39 IrBasicBlock *const_predecessor_bb;
40};40};
4141
42static const LVal LVAL_NONE = { false, false, false };
43static const LVal LVAL_PTR = { true, false, false };
44
45enum ConstCastResultId {42enum ConstCastResultId {
46 ConstCastResultIdOk,43 ConstCastResultIdOk,
47 ConstCastResultIdErrSet,44 ConstCastResultIdErrSet,
...@@ -3164,7 +3161,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3164,7 +3161,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3164 case ReturnKindError:3161 case ReturnKindError:
3165 {3162 {
3166 assert(expr_node);3163 assert(expr_node);
3167 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);3164 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);
3168 if (err_union_ptr == irb->codegen->invalid_instruction)3165 if (err_union_ptr == irb->codegen->invalid_instruction)
3169 return irb->codegen->invalid_instruction;3166 return irb->codegen->invalid_instruction;
3170 IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr);3167 IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr);
...@@ -3192,7 +3189,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3192,7 +3189,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
31923189
3193 ir_set_cursor_at_end_and_append_block(irb, continue_block);3190 ir_set_cursor_at_end_and_append_block(irb, continue_block);
3194 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false);3191 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false);
3195 if (lval.is_ptr)3192 if (lval == LValPtr)
3196 return unwrapped_ptr;3193 return unwrapped_ptr;
3197 else3194 else
3198 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);3195 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
...@@ -3357,7 +3354,7 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no...@@ -3357,7 +3354,7 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
3357}3354}
33583355
3359static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {3356static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
3360 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LVAL_PTR);3357 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr);
3361 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);3358 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
33623359
3363 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)3360 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)
...@@ -3368,7 +3365,7 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -3368,7 +3365,7 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
3368}3365}
33693366
3370static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {3367static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
3371 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LVAL_PTR);3368 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr);
3372 if (lvalue == irb->codegen->invalid_instruction)3369 if (lvalue == irb->codegen->invalid_instruction)
3373 return lvalue;3370 return lvalue;
3374 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);3371 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
...@@ -3470,7 +3467,7 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As...@@ -3470,7 +3467,7 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As
3470 AstNode *op1_node = node->data.bin_op_expr.op1;3467 AstNode *op1_node = node->data.bin_op_expr.op1;
3471 AstNode *op2_node = node->data.bin_op_expr.op2;3468 AstNode *op2_node = node->data.bin_op_expr.op2;
34723469
3473 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LVAL_PTR);3470 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr);
3474 if (maybe_ptr == irb->codegen->invalid_instruction)3471 if (maybe_ptr == irb->codegen->invalid_instruction)
3475 return irb->codegen->invalid_instruction;3472 return irb->codegen->invalid_instruction;
34763473
...@@ -3657,7 +3654,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3657,7 +3654,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
36573654
3658 Buf *variable_name = node->data.symbol_expr.symbol;3655 Buf *variable_name = node->data.symbol_expr.symbol;
36593656
3660 if (buf_eql_str(variable_name, "_") && lval.is_ptr) {3657 if (buf_eql_str(variable_name, "_") && lval == LValPtr) {
3661 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);3658 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);
3662 const_instruction->base.value.type = get_pointer_to_type(irb->codegen,3659 const_instruction->base.value.type = get_pointer_to_type(irb->codegen,
3663 irb->codegen->builtin_types.entry_void, false);3660 irb->codegen->builtin_types.entry_void, false);
...@@ -3669,8 +3666,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3669,8 +3666,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3669 auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);3666 auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);
3670 if (primitive_table_entry) {3667 if (primitive_table_entry) {
3671 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value);3668 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value);
3672 if (lval.is_ptr) {3669 if (lval == LValPtr) {
3673 return ir_build_ref(irb, scope, node, value, lval.is_const, lval.is_volatile);3670 return ir_build_ref(irb, scope, node, value, false, false);
3674 } else {3671 } else {
3675 return value;3672 return value;
3676 }3673 }
...@@ -3679,7 +3676,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3679,7 +3676,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3679 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);3676 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3680 if (var) {3677 if (var) {
3681 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);3678 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3682 if (lval.is_ptr)3679 if (lval == LValPtr)
3683 return var_ptr;3680 return var_ptr;
3684 else3681 else
3685 return ir_build_load_ptr(irb, scope, node, var_ptr);3682 return ir_build_load_ptr(irb, scope, node, var_ptr);
...@@ -3705,7 +3702,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode...@@ -3705,7 +3702,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
3705 assert(node->type == NodeTypeArrayAccessExpr);3702 assert(node->type == NodeTypeArrayAccessExpr);
37063703
3707 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;3704 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
3708 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LVAL_PTR);3705 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr);
3709 if (array_ref_instruction == irb->codegen->invalid_instruction)3706 if (array_ref_instruction == irb->codegen->invalid_instruction)
3710 return array_ref_instruction;3707 return array_ref_instruction;
37113708
...@@ -3716,7 +3713,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode...@@ -3716,7 +3713,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
37163713
3717 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,3714 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
3718 subscript_instruction, true, PtrLenSingle);3715 subscript_instruction, true, PtrLenSingle);
3719 if (lval.is_ptr)3716 if (lval == LValPtr)
3720 return ptr_instruction;3717 return ptr_instruction;
37213718
3722 return ir_build_load_ptr(irb, scope, node, ptr_instruction);3719 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
...@@ -3728,7 +3725,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode...@@ -3728,7 +3725,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode
3728 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;3725 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
3729 Buf *field_name = node->data.field_access_expr.field_name;3726 Buf *field_name = node->data.field_access_expr.field_name;
37303727
3731 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LVAL_PTR);3728 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr);
3732 if (container_ref_instruction == irb->codegen->invalid_instruction)3729 if (container_ref_instruction == irb->codegen->invalid_instruction)
3733 return container_ref_instruction;3730 return container_ref_instruction;
37343731
...@@ -4386,7 +4383,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4386,7 +4383,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4386 case BuiltinFnIdField:4383 case BuiltinFnIdField:
4387 {4384 {
4388 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4385 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4389 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LVAL_PTR);4386 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr);
4390 if (arg0_value == irb->codegen->invalid_instruction)4387 if (arg0_value == irb->codegen->invalid_instruction)
4391 return arg0_value;4388 return arg0_value;
43924389
...@@ -4397,7 +4394,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4397,7 +4394,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
43974394
4398 IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, arg0_value, arg1_value);4395 IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, arg0_value, arg1_value);
43994396
4400 if (lval.is_ptr)4397 if (lval == LValPtr)
4401 return ptr_instruction;4398 return ptr_instruction;
44024399
4403 return ir_build_load_ptr(irb, scope, node, ptr_instruction);4400 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
...@@ -4928,18 +4925,18 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, Ast...@@ -4928,18 +4925,18 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, Ast
4928}4925}
49294926
4930static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) {4927static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
4931 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LVAL_NONE);4928 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
4932}4929}
49334930
4934static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval) {4931static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval) {
4935 if (!lval.is_ptr)4932 if (lval != LValPtr)
4936 return value;4933 return value;
4937 if (value == irb->codegen->invalid_instruction)4934 if (value == irb->codegen->invalid_instruction)
4938 return value;4935 return value;
49394936
4940 // We needed a pointer to a value, but we got a value. So we create4937 // We needed a pointer to a value, but we got a value. So we create
4941 // an instruction which just makes a const pointer of it.4938 // an instruction which just makes a const pointer of it.
4942 return ir_build_ref(irb, scope, value->source_node, value, lval.is_const, lval.is_volatile);4939 return ir_build_ref(irb, scope, value->source_node, value, false, false);
4943}4940}
49444941
4945static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {4942static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -5001,7 +4998,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -5001,7 +4998,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
5001static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,4998static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,
5002 LVal lval)4999 LVal lval)
5003{5000{
5004 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);5001 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);
5005 if (err_union_ptr == irb->codegen->invalid_instruction)5002 if (err_union_ptr == irb->codegen->invalid_instruction)
5006 return irb->codegen->invalid_instruction;5003 return irb->codegen->invalid_instruction;
50075004
...@@ -5009,7 +5006,7 @@ static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode...@@ -5009,7 +5006,7 @@ static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode
5009 if (payload_ptr == irb->codegen->invalid_instruction)5006 if (payload_ptr == irb->codegen->invalid_instruction)
5010 return irb->codegen->invalid_instruction;5007 return irb->codegen->invalid_instruction;
50115008
5012 if (lval.is_ptr)5009 if (lval == LValPtr)
5013 return payload_ptr;5010 return payload_ptr;
50145011
5015 return ir_build_load_ptr(irb, scope, source_node, payload_ptr);5012 return ir_build_load_ptr(irb, scope, source_node, payload_ptr);
...@@ -5046,7 +5043,7 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -5046,7 +5043,7 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
5046 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);5043 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
5047 case PrefixOpAddrOf: {5044 case PrefixOpAddrOf: {
5048 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;5045 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
5049 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval);5046 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr), lval);
5050 }5047 }
5051 }5048 }
5052 zig_unreachable();5049 zig_unreachable();
...@@ -5186,7 +5183,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5186,7 +5183,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5186 } else {5183 } else {
5187 payload_scope = scope;5184 payload_scope = scope;
5188 }5185 }
5189 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LVAL_PTR);5186 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
5190 if (err_val_ptr == irb->codegen->invalid_instruction)5187 if (err_val_ptr == irb->codegen->invalid_instruction)
5191 return err_val_ptr;5188 return err_val_ptr;
5192 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);5189 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);
...@@ -5269,7 +5266,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5269,7 +5266,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5269 VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,5266 VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
5270 true, false, false, is_comptime);5267 true, false, false, is_comptime);
5271 Scope *child_scope = payload_var->child_scope;5268 Scope *child_scope = payload_var->child_scope;
5272 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LVAL_PTR);5269 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
5273 if (maybe_val_ptr == irb->codegen->invalid_instruction)5270 if (maybe_val_ptr == irb->codegen->invalid_instruction)
5274 return maybe_val_ptr;5271 return maybe_val_ptr;
5275 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);5272 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
...@@ -5413,7 +5410,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5413,7 +5410,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5413 }5410 }
5414 assert(elem_node->type == NodeTypeSymbol);5411 assert(elem_node->type == NodeTypeSymbol);
54155412
5416 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, parent_scope, LVAL_PTR);5413 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, parent_scope, LValPtr);
5417 if (array_val_ptr == irb->codegen->invalid_instruction)5414 if (array_val_ptr == irb->codegen->invalid_instruction)
5418 return array_val_ptr;5415 return array_val_ptr;
54195416
...@@ -5700,7 +5697,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no...@@ -5700,7 +5697,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
5700 AstNode *else_node = node->data.test_expr.else_node;5697 AstNode *else_node = node->data.test_expr.else_node;
5701 bool var_is_ptr = node->data.test_expr.var_is_ptr;5698 bool var_is_ptr = node->data.test_expr.var_is_ptr;
57025699
5703 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);5700 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);
5704 if (maybe_val_ptr == irb->codegen->invalid_instruction)5701 if (maybe_val_ptr == irb->codegen->invalid_instruction)
5705 return maybe_val_ptr;5702 return maybe_val_ptr;
57065703
...@@ -5778,7 +5775,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5778,7 +5775,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
5778 Buf *var_symbol = node->data.if_err_expr.var_symbol;5775 Buf *var_symbol = node->data.if_err_expr.var_symbol;
5779 Buf *err_symbol = node->data.if_err_expr.err_symbol;5776 Buf *err_symbol = node->data.if_err_expr.err_symbol;
57805777
5781 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LVAL_PTR);5778 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr);
5782 if (err_val_ptr == irb->codegen->invalid_instruction)5779 if (err_val_ptr == irb->codegen->invalid_instruction)
5783 return err_val_ptr;5780 return err_val_ptr;
57845781
...@@ -5904,7 +5901,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5904,7 +5901,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
5904 assert(node->type == NodeTypeSwitchExpr);5901 assert(node->type == NodeTypeSwitchExpr);
59055902
5906 AstNode *target_node = node->data.switch_expr.expr;5903 AstNode *target_node = node->data.switch_expr.expr;
5907 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LVAL_PTR);5904 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr);
5908 if (target_value_ptr == irb->codegen->invalid_instruction)5905 if (target_value_ptr == irb->codegen->invalid_instruction)
5909 return target_value_ptr;5906 return target_value_ptr;
5910 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);5907 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
...@@ -6277,7 +6274,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -6277,7 +6274,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node)
6277 AstNode *start_node = slice_expr->start;6274 AstNode *start_node = slice_expr->start;
6278 AstNode *end_node = slice_expr->end;6275 AstNode *end_node = slice_expr->end;
62796276
6280 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LVAL_PTR);6277 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr);
6281 if (ptr_value == irb->codegen->invalid_instruction)6278 if (ptr_value == irb->codegen->invalid_instruction)
6282 return irb->codegen->invalid_instruction;6279 return irb->codegen->invalid_instruction;
62836280
...@@ -6311,11 +6308,11 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN...@@ -6311,11 +6308,11 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
6311 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));6308 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
6312 return irb->codegen->invalid_instruction;6309 return irb->codegen->invalid_instruction;
6313 }6310 }
6314 return ir_gen_err_assert_ok(irb, parent_scope, node, op1_node, LVAL_NONE);6311 return ir_gen_err_assert_ok(irb, parent_scope, node, op1_node, LValNone);
6315 }6312 }
63166313
63176314
6318 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LVAL_PTR);6315 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr);
6319 if (err_union_ptr == irb->codegen->invalid_instruction)6316 if (err_union_ptr == irb->codegen->invalid_instruction)
6320 return irb->codegen->invalid_instruction;6317 return irb->codegen->invalid_instruction;
63216318
...@@ -6868,7 +6865,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6868,7 +6865,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
6868 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);6865 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);
6869 if (ptr_instruction == irb->codegen->invalid_instruction)6866 if (ptr_instruction == irb->codegen->invalid_instruction)
6870 return ptr_instruction;6867 return ptr_instruction;
6871 if (lval.is_ptr)6868 if (lval == LValPtr)
6872 return ptr_instruction;6869 return ptr_instruction;
68736870
6874 return ir_build_load_ptr(irb, scope, node, ptr_instruction);6871 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
...@@ -6884,12 +6881,12 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6884,12 +6881,12 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
6884 case NodeTypeUnwrapOptional: {6881 case NodeTypeUnwrapOptional: {
6885 AstNode *expr_node = node->data.unwrap_optional.expr;6882 AstNode *expr_node = node->data.unwrap_optional.expr;
68866883
6887 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);6884 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);
6888 if (maybe_ptr == irb->codegen->invalid_instruction)6885 if (maybe_ptr == irb->codegen->invalid_instruction)
6889 return irb->codegen->invalid_instruction;6886 return irb->codegen->invalid_instruction;
68906887
6891 IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true);6888 IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true);
6892 if (lval.is_ptr)6889 if (lval == LValPtr)
6893 return unwrapped_ptr;6890 return unwrapped_ptr;
68946891
6895 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);6892 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
...@@ -6959,7 +6956,7 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc...@@ -6959,7 +6956,7 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
6959}6956}
69606957
6961static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {6958static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
6962 return ir_gen_node_extra(irb, node, scope, LVAL_NONE);6959 return ir_gen_node_extra(irb, node, scope, LValNone);
6963}6960}
69646961
6965static void invalidate_exec(IrExecutable *exec) {6962static void invalidate_exec(IrExecutable *exec) {
...@@ -7089,7 +7086,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7089,7 +7086,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7089 irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");7086 irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");
7090 }7087 }
70917088
7092 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LVAL_NONE);7089 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone);
7093 assert(result);7090 assert(result);
7094 if (irb->exec->invalid)7091 if (irb->exec->invalid)
7095 return false;7092 return false;
...@@ -19752,7 +19749,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -19752,7 +19749,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
19752 Tld *tld = instruction->tld;19749 Tld *tld = instruction->tld;
19753 LVal lval = instruction->lval;19750 LVal lval = instruction->lval;
1975419751
19755 resolve_top_level_decl(ira->codegen, tld, lval.is_ptr, instruction->base.source_node);19752 resolve_top_level_decl(ira->codegen, tld, lval == LValPtr, instruction->base.source_node);
19756 if (tld->resolution == TldResolutionInvalid)19753 if (tld->resolution == TldResolutionInvalid)
19757 return ira->codegen->builtin_types.entry_invalid;19754 return ira->codegen->builtin_types.entry_invalid;
1975819755
...@@ -19773,7 +19770,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -19773,7 +19770,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
19773 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node);19770 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node);
19774 }19771 }
1977519772
19776 if (lval.is_ptr) {19773 if (lval == LValPtr) {
19777 ir_link_new_instruction(var_ptr, &instruction->base);19774 ir_link_new_instruction(var_ptr, &instruction->base);
19778 return var_ptr->value.type;19775 return var_ptr->value.type;
19779 } else {19776 } else {
...@@ -19794,7 +19791,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -19794,7 +19791,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
1979419791
19795 IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope,19792 IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope,
19796 instruction->base.source_node, fn_entry);19793 instruction->base.source_node, fn_entry);
19797 if (lval.is_ptr) {19794 if (lval == LValPtr) {
19798 IrInstruction *ptr_instr = ir_get_ref(ira, &instruction->base, ref_instruction, true, false);19795 IrInstruction *ptr_instr = ir_get_ref(ira, &instruction->base, ref_instruction, true, false);
19799 ir_link_new_instruction(ptr_instr, &instruction->base);19796 ir_link_new_instruction(ptr_instr, &instruction->base);
19800 return ptr_instr->value.type;19797 return ptr_instr->value.type;
src/ir_print.cpp+2-4
...@@ -1005,10 +1005,8 @@ static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {...@@ -1005,10 +1005,8 @@ static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
1005}1005}
10061006
1007static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {1007static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
1008 const char *ptr_str = instruction->lval.is_ptr ? "ptr " : "";1008 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
1009 const char *const_str = instruction->lval.is_const ? "const " : "";1009 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
1010 const char *volatile_str = instruction->lval.is_volatile ? "volatile " : "";
1011 fprintf(irp->f, "declref %s%s%s%s", const_str, volatile_str, ptr_str, buf_ptr(instruction->tld->name));
1012}1010}
10131011
1014static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {1012static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {