@@ -39,9 +39,6 @@ struct IrAnalyze {
39
39
IrBasicBlock *const_predecessor_bb;
40
40
};
41
41
42
- static const LVal LVAL_NONE = { false, false, false };
43
- static const LVal LVAL_PTR = { true, false, false };
44
-
45
42
enum ConstCastResultId {
46
43
ConstCastResultIdOk,
47
44
ConstCastResultIdErrSet,
@@ -3164,7 +3161,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3164
3161
case ReturnKindError:
3165
3162
{
3166
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
3165
if (err_union_ptr == irb->codegen->invalid_instruction)
3169
3166
return irb->codegen->invalid_instruction;
3170
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
3189
3193
3190
ir_set_cursor_at_end_and_append_block(irb, continue_block);
3194
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
3193
return unwrapped_ptr;
3197
3194
else
3198
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
3354
}
3358
3355
3359
3356
static 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
3358
IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3362
3359
3363
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
3365
}
3369
3366
3370
3367
static 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
3369
if (lvalue == irb->codegen->invalid_instruction)
3373
3370
return lvalue;
3374
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
3467
AstNode *op1_node = node->data.bin_op_expr.op1;
3471
3468
AstNode *op2_node = node->data.bin_op_expr.op2;
3472
3469
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
3471
if (maybe_ptr == irb->codegen->invalid_instruction)
3475
3472
return irb->codegen->invalid_instruction;
3476
3473
@@ -3657,7 +3654,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3657
3654
3658
3655
Buf *variable_name = node->data.symbol_expr.symbol;
3659
3656
3660
- if (buf_eql_str(variable_name, "_") && lval.is_ptr ) {
3657
+ if (buf_eql_str(variable_name, "_") && lval == LValPtr ) {
3661
3658
IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);
3662
3659
const_instruction->base.value.type = get_pointer_to_type(irb->codegen,
3663
3660
irb->codegen->builtin_types.entry_void, false);
@@ -3669,8 +3666,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3669
3666
auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);
3670
3667
if (primitive_table_entry) {
3671
3668
IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value);
3672
- if (lval.is_ptr ) {
3673
- return ir_build_ref(irb, scope, node, value, lval.is_const, lval.is_volatile );
3669
+ if (lval == LValPtr ) {
3670
+ return ir_build_ref(irb, scope, node, value, false, false );
3674
3671
} else {
3675
3672
return value;
3676
3673
}
@@ -3679,7 +3676,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3679
3676
VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3680
3677
if (var) {
3681
3678
IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3682
- if (lval.is_ptr )
3679
+ if (lval == LValPtr )
3683
3680
return var_ptr;
3684
3681
else
3685
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
3702
assert(node->type == NodeTypeArrayAccessExpr);
3706
3703
3707
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
3706
if (array_ref_instruction == irb->codegen->invalid_instruction)
3710
3707
return array_ref_instruction;
3711
3708
@@ -3716,7 +3713,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
3716
3713
3717
3714
IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
3718
3715
subscript_instruction, true, PtrLenSingle);
3719
- if (lval.is_ptr )
3716
+ if (lval == LValPtr )
3720
3717
return ptr_instruction;
3721
3718
3722
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
3725
AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
3729
3726
Buf *field_name = node->data.field_access_expr.field_name;
3730
3727
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
3729
if (container_ref_instruction == irb->codegen->invalid_instruction)
3733
3730
return container_ref_instruction;
3734
3731
@@ -4386,7 +4383,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4386
4383
case BuiltinFnIdField:
4387
4384
{
4388
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
4387
if (arg0_value == irb->codegen->invalid_instruction)
4391
4388
return arg0_value;
4392
4389
@@ -4397,7 +4394,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4397
4394
4398
4395
IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, arg0_value, arg1_value);
4399
4396
4400
- if (lval.is_ptr )
4397
+ if (lval == LValPtr )
4401
4398
return ptr_instruction;
4402
4399
4403
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
4925
}
4929
4926
4930
4927
static 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
}
4933
4930
4934
4931
static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval) {
4935
- if (! lval.is_ptr )
4932
+ if (lval != LValPtr )
4936
4933
return value;
4937
4934
if (value == irb->codegen->invalid_instruction)
4938
4935
return value;
4939
4936
4940
4937
// We needed a pointer to a value, but we got a value. So we create
4941
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
}
4944
4941
4945
4942
static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
@@ -5001,15 +4998,15 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
5001
4998
static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,
5002
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
5002
if (err_union_ptr == irb->codegen->invalid_instruction)
5006
5003
return irb->codegen->invalid_instruction;
5007
5004
5008
5005
IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true);
5009
5006
if (payload_ptr == irb->codegen->invalid_instruction)
5010
5007
return irb->codegen->invalid_instruction;
5011
5008
5012
- if (lval.is_ptr )
5009
+ if (lval == LValPtr )
5013
5010
return payload_ptr;
5014
5011
5015
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
5043
return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
5047
5044
case PrefixOpAddrOf: {
5048
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
5049
zig_unreachable();
@@ -5186,7 +5183,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5186
5183
} else {
5187
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
5187
if (err_val_ptr == irb->codegen->invalid_instruction)
5191
5188
return err_val_ptr;
5192
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
5266
VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
5270
5267
true, false, false, is_comptime);
5271
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
5270
if (maybe_val_ptr == irb->codegen->invalid_instruction)
5274
5271
return maybe_val_ptr;
5275
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
5410
}
5414
5411
assert(elem_node->type == NodeTypeSymbol);
5415
5412
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
5414
if (array_val_ptr == irb->codegen->invalid_instruction)
5418
5415
return array_val_ptr;
5419
5416
@@ -5700,7 +5697,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
5700
5697
AstNode *else_node = node->data.test_expr.else_node;
5701
5698
bool var_is_ptr = node->data.test_expr.var_is_ptr;
5702
5699
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
5701
if (maybe_val_ptr == irb->codegen->invalid_instruction)
5705
5702
return maybe_val_ptr;
5706
5703
@@ -5778,7 +5775,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
5778
5775
Buf *var_symbol = node->data.if_err_expr.var_symbol;
5779
5776
Buf *err_symbol = node->data.if_err_expr.err_symbol;
5780
5777
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
5779
if (err_val_ptr == irb->codegen->invalid_instruction)
5783
5780
return err_val_ptr;
5784
5781
@@ -5904,7 +5901,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
5904
5901
assert(node->type == NodeTypeSwitchExpr);
5905
5902
5906
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
5905
if (target_value_ptr == irb->codegen->invalid_instruction)
5909
5906
return target_value_ptr;
5910
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
6274
AstNode *start_node = slice_expr->start;
6278
6275
AstNode *end_node = slice_expr->end;
6279
6276
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
6278
if (ptr_value == irb->codegen->invalid_instruction)
6282
6279
return irb->codegen->invalid_instruction;
6283
6280
@@ -6311,11 +6308,11 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
6311
6308
add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
6312
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
}
6316
6313
6317
6314
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
6316
if (err_union_ptr == irb->codegen->invalid_instruction)
6320
6317
return irb->codegen->invalid_instruction;
6321
6318
@@ -6868,7 +6865,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
6868
6865
IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);
6869
6866
if (ptr_instruction == irb->codegen->invalid_instruction)
6870
6867
return ptr_instruction;
6871
- if (lval.is_ptr )
6868
+ if (lval == LValPtr )
6872
6869
return ptr_instruction;
6873
6870
6874
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
6881
case NodeTypeUnwrapOptional: {
6885
6882
AstNode *expr_node = node->data.unwrap_optional.expr;
6886
6883
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
6885
if (maybe_ptr == irb->codegen->invalid_instruction)
6889
6886
return irb->codegen->invalid_instruction;
6890
6887
6891
6888
IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true);
6892
- if (lval.is_ptr )
6889
+ if (lval == LValPtr )
6893
6890
return unwrapped_ptr;
6894
6891
6895
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
6956
}
6960
6957
6961
6958
static 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
}
6964
6961
6965
6962
static void invalidate_exec(IrExecutable *exec) {
@@ -7089,7 +7086,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7089
7086
irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");
7090
7087
}
7091
7088
7092
- IrInstruction *result = ir_gen_node_extra(irb, node, scope, LVAL_NONE );
7089
+ IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone );
7093
7090
assert(result);
7094
7091
if (irb->exec->invalid)
7095
7092
return false;
@@ -19752,7 +19749,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
19752
19749
Tld *tld = instruction->tld;
19753
19750
LVal lval = instruction->lval;
19754
19751
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
19753
if (tld->resolution == TldResolutionInvalid)
19757
19754
return ira->codegen->builtin_types.entry_invalid;
19758
19755
@@ -19773,7 +19770,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
19773
19770
add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node);
19774
19771
}
19775
19772
19776
- if (lval.is_ptr ) {
19773
+ if (lval == LValPtr ) {
19777
19774
ir_link_new_instruction(var_ptr, &instruction->base);
19778
19775
return var_ptr->value.type;
19779
19776
} else {
@@ -19794,7 +19791,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
19794
19791
19795
19792
IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope,
19796
19793
instruction->base.source_node, fn_entry);
19797
- if (lval.is_ptr ) {
19794
+ if (lval == LValPtr ) {
19798
19795
IrInstruction *ptr_instr = ir_get_ref(ira, &instruction->base, ref_instruction, true, false);
19799
19796
ir_link_new_instruction(ptr_instr, &instruction->base);
19800
19797
return ptr_instr->value.type;
0 commit comments