| ... | @@ -11,7 +11,7 @@ | ... | @@ -11,7 +11,7 @@ |
| 11 | #include "os.hpp" | 11 | #include "os.hpp" |
| 12 | #include "parser.hpp" | 12 | #include "parser.hpp" |
| 13 | | 13 | |
| 14 | struct IrBuilderSrc { | 14 | struct Stage1AstGen { |
| 15 | CodeGen *codegen; | 15 | CodeGen *codegen; |
| 16 | Stage1Zir *exec; | 16 | Stage1Zir *exec; |
| 17 | IrBasicBlockSrc *current_basic_block; | 17 | IrBasicBlockSrc *current_basic_block; |
| ... | @@ -19,22 +19,22 @@ struct IrBuilderSrc { | ... | @@ -19,22 +19,22 @@ struct IrBuilderSrc { |
| 19 | size_t next_debug_id; | 19 | size_t next_debug_id; |
| 20 | }; | 20 | }; |
| 21 | | 21 | |
| 22 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope); | 22 | static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope); |
| 23 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, | 23 | static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, |
| 24 | ResultLoc *result_loc); | 24 | ResultLoc *result_loc); |
| 25 | | 25 | |
| 26 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, | 26 | static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value, LVal lval, |
| 27 | ResultLoc *result_loc); | 27 | ResultLoc *result_loc); |
| 28 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, | 28 | static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, |
| 29 | ResultLoc *result_loc); | 29 | ResultLoc *result_loc); |
| 30 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 30 | static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 31 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, | 31 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 32 | LVal lval, ResultLoc *parent_result_loc); | 32 | LVal lval, ResultLoc *parent_result_loc); |
| 33 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, | 33 | static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest_type, |
| 34 | ResultLoc *parent_result_loc); | 34 | ResultLoc *parent_result_loc); |
| 35 | static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name, | 35 | static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf *name, |
| 36 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime); | 36 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime); |
| 37 | static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 37 | static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 38 | ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime); | 38 | ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime); |
| 39 | | 39 | |
| 40 | static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) { | 40 | static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) { |
| ... | @@ -362,9 +362,9 @@ static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instr | ... | @@ -362,9 +362,9 @@ static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instr |
| 362 | basic_block->instruction_list.append(instruction); | 362 | basic_block->instruction_list.append(instruction); |
| 363 | } | 363 | } |
| 364 | | 364 | |
| 365 | static size_t irb_next_debug_id(IrBuilderSrc *irb) { | 365 | static size_t irb_next_debug_id(Stage1AstGen *ag) { |
| 366 | size_t result = irb->next_debug_id; | 366 | size_t result = ag->next_debug_id; |
| 367 | irb->next_debug_id += 1; | 367 | ag->next_debug_id += 1; |
| 368 | return result; | 368 | return result; |
| 369 | } | 369 | } |
| 370 | | 370 | |
| ... | @@ -390,11 +390,11 @@ static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) | ... | @@ -390,11 +390,11 @@ static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) |
| 390 | } | 390 | } |
| 391 | } | 391 | } |
| 392 | | 392 | |
| 393 | static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) { | 393 | static IrBasicBlockSrc *ir_create_basic_block(Stage1AstGen *ag, Scope *scope, const char *name_hint) { |
| 394 | IrBasicBlockSrc *result = heap::c_allocator.create<IrBasicBlockSrc>(); | 394 | IrBasicBlockSrc *result = heap::c_allocator.create<IrBasicBlockSrc>(); |
| 395 | result->scope = scope; | 395 | result->scope = scope; |
| 396 | result->name_hint = name_hint; | 396 | result->name_hint = name_hint; |
| 397 | result->debug_id = irb_next_debug_id(irb); | 397 | result->debug_id = irb_next_debug_id(ag); |
| 398 | result->index = UINT32_MAX; // set later | 398 | result->index = UINT32_MAX; // set later |
| 399 | return result; | 399 | return result; |
| 400 | } | 400 | } |
| ... | @@ -932,208 +932,208 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSrc *) { | ... | @@ -932,208 +932,208 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSrc *) { |
| 932 | } | 932 | } |
| 933 | | 933 | |
| 934 | template<typename T> | 934 | template<typename T> |
| 935 | static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 935 | static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 936 | T *special_instruction = heap::c_allocator.create<T>(); | 936 | T *special_instruction = heap::c_allocator.create<T>(); |
| 937 | special_instruction->base.id = ir_inst_id(special_instruction); | 937 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 938 | special_instruction->base.base.scope = scope; | 938 | special_instruction->base.base.scope = scope; |
| 939 | special_instruction->base.base.source_node = source_node; | 939 | special_instruction->base.base.source_node = source_node; |
| 940 | special_instruction->base.base.debug_id = irb_next_debug_id(irb); | 940 | special_instruction->base.base.debug_id = irb_next_debug_id(ag); |
| 941 | special_instruction->base.owner_bb = irb->current_basic_block; | 941 | special_instruction->base.owner_bb = ag->current_basic_block; |
| 942 | return special_instruction; | 942 | return special_instruction; |
| 943 | } | 943 | } |
| 944 | | 944 | |
| 945 | template<typename T> | 945 | template<typename T> |
| 946 | static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 946 | static T *ir_build_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 947 | T *special_instruction = ir_create_instruction<T>(irb, scope, source_node); | 947 | T *special_instruction = ir_create_instruction<T>(ag, scope, source_node); |
| 948 | ir_instruction_append(irb->current_basic_block, &special_instruction->base); | 948 | ir_instruction_append(ag->current_basic_block, &special_instruction->base); |
| 949 | return special_instruction; | 949 | return special_instruction; |
| 950 | } | 950 | } |
| 951 | | 951 | |
| 952 | static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition, | 952 | static IrInstSrc *ir_build_cond_br(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *condition, |
| 953 | IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime) | 953 | IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime) |
| 954 | { | 954 | { |
| 955 | IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node); | 955 | IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(ag, scope, source_node); |
| 956 | inst->base.is_noreturn = true; | 956 | inst->base.is_noreturn = true; |
| 957 | inst->condition = condition; | 957 | inst->condition = condition; |
| 958 | inst->then_block = then_block; | 958 | inst->then_block = then_block; |
| 959 | inst->else_block = else_block; | 959 | inst->else_block = else_block; |
| 960 | inst->is_comptime = is_comptime; | 960 | inst->is_comptime = is_comptime; |
| 961 | | 961 | |
| 962 | ir_ref_instruction(condition, irb->current_basic_block); | 962 | ir_ref_instruction(condition, ag->current_basic_block); |
| 963 | ir_ref_bb(then_block); | 963 | ir_ref_bb(then_block); |
| 964 | ir_ref_bb(else_block); | 964 | ir_ref_bb(else_block); |
| 965 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block); | 965 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, ag->current_basic_block); |
| 966 | | 966 | |
| 967 | return &inst->base; | 967 | return &inst->base; |
| 968 | } | 968 | } |
| 969 | | 969 | |
| 970 | static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) { | 970 | static IrInstSrc *ir_build_return_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *operand) { |
| 971 | IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node); | 971 | IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(ag, scope, source_node); |
| 972 | inst->base.is_noreturn = true; | 972 | inst->base.is_noreturn = true; |
| 973 | inst->operand = operand; | 973 | inst->operand = operand; |
| 974 | | 974 | |
| 975 | if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); | 975 | if (operand != nullptr) ir_ref_instruction(operand, ag->current_basic_block); |
| 976 | | 976 | |
| 977 | return &inst->base; | 977 | return &inst->base; |
| 978 | } | 978 | } |
| 979 | | 979 | |
| 980 | static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 980 | static IrInstSrc *ir_build_const_void(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 981 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); | 981 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 982 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 982 | ir_instruction_append(ag->current_basic_block, &const_instruction->base); |
| 983 | const_instruction->value = irb->codegen->intern.for_void(); | 983 | const_instruction->value = ag->codegen->intern.for_void(); |
| 984 | return &const_instruction->base; | 984 | return &const_instruction->base; |
| 985 | } | 985 | } |
| 986 | | 986 | |
| 987 | static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 987 | static IrInstSrc *ir_build_const_undefined(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 988 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); | 988 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 989 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 989 | ir_instruction_append(ag->current_basic_block, &const_instruction->base); |
| 990 | const_instruction->value = irb->codegen->intern.for_undefined(); | 990 | const_instruction->value = ag->codegen->intern.for_undefined(); |
| 991 | const_instruction->value->special = ConstValSpecialUndef; | 991 | const_instruction->value->special = ConstValSpecialUndef; |
| 992 | return &const_instruction->base; | 992 | return &const_instruction->base; |
| 993 | } | 993 | } |
| 994 | | 994 | |
| 995 | static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { | 995 | static IrInstSrc *ir_build_const_uint(Stage1AstGen *ag, Scope *scope, AstNode *source_node, uint64_t value) { |
| 996 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 996 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 997 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 997 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 998 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; | 998 | const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_int; |
| 999 | const_instruction->value->special = ConstValSpecialStatic; | 999 | const_instruction->value->special = ConstValSpecialStatic; |
| 1000 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); | 1000 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1001 | return &const_instruction->base; | 1001 | return &const_instruction->base; |
| 1002 | } | 1002 | } |
| 1003 | | 1003 | |
| 1004 | static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1004 | static IrInstSrc *ir_build_const_bigint(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1005 | BigInt bigint) | 1005 | BigInt bigint) |
| 1006 | { | 1006 | { |
| 1007 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1007 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1008 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1008 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1009 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; | 1009 | const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_int; |
| 1010 | const_instruction->value->special = ConstValSpecialStatic; | 1010 | const_instruction->value->special = ConstValSpecialStatic; |
| 1011 | const_instruction->value->data.x_bigint = bigint; | 1011 | const_instruction->value->data.x_bigint = bigint; |
| 1012 | return &const_instruction->base; | 1012 | return &const_instruction->base; |
| 1013 | } | 1013 | } |
| 1014 | | 1014 | |
| 1015 | static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1015 | static IrInstSrc *ir_build_const_bigfloat(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1016 | BigFloat bigfloat) | 1016 | BigFloat bigfloat) |
| 1017 | { | 1017 | { |
| 1018 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1018 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1019 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1019 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1020 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float; | 1020 | const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_float; |
| 1021 | const_instruction->value->special = ConstValSpecialStatic; | 1021 | const_instruction->value->special = ConstValSpecialStatic; |
| 1022 | const_instruction->value->data.x_bigfloat = bigfloat; | 1022 | const_instruction->value->data.x_bigfloat = bigfloat; |
| 1023 | return &const_instruction->base; | 1023 | return &const_instruction->base; |
| 1024 | } | 1024 | } |
| 1025 | | 1025 | |
| 1026 | static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 1026 | static IrInstSrc *ir_build_const_null(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 1027 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); | 1027 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1028 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 1028 | ir_instruction_append(ag->current_basic_block, &const_instruction->base); |
| 1029 | const_instruction->value = irb->codegen->intern.for_null(); | 1029 | const_instruction->value = ag->codegen->intern.for_null(); |
| 1030 | return &const_instruction->base; | 1030 | return &const_instruction->base; |
| 1031 | } | 1031 | } |
| 1032 | | 1032 | |
| 1033 | static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { | 1033 | static IrInstSrc *ir_build_const_usize(Stage1AstGen *ag, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1034 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1034 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1035 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1035 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1036 | const_instruction->value->type = irb->codegen->builtin_types.entry_usize; | 1036 | const_instruction->value->type = ag->codegen->builtin_types.entry_usize; |
| 1037 | const_instruction->value->special = ConstValSpecialStatic; | 1037 | const_instruction->value->special = ConstValSpecialStatic; |
| 1038 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); | 1038 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1039 | return &const_instruction->base; | 1039 | return &const_instruction->base; |
| 1040 | } | 1040 | } |
| 1041 | | 1041 | |
| 1042 | static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1042 | static IrInstSrc *ir_create_const_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1043 | ZigType *type_entry) | 1043 | ZigType *type_entry) |
| 1044 | { | 1044 | { |
| 1045 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); | 1045 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1046 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1046 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1047 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; | 1047 | const_instruction->value->type = ag->codegen->builtin_types.entry_type; |
| 1048 | const_instruction->value->special = ConstValSpecialStatic; | 1048 | const_instruction->value->special = ConstValSpecialStatic; |
| 1049 | const_instruction->value->data.x_type = type_entry; | 1049 | const_instruction->value->data.x_type = type_entry; |
| 1050 | return &const_instruction->base; | 1050 | return &const_instruction->base; |
| 1051 | } | 1051 | } |
| 1052 | | 1052 | |
| 1053 | static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1053 | static IrInstSrc *ir_build_const_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1054 | ZigType *type_entry) | 1054 | ZigType *type_entry) |
| 1055 | { | 1055 | { |
| 1056 | IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry); | 1056 | IrInstSrc *instruction = ir_create_const_type(ag, scope, source_node, type_entry); |
| 1057 | ir_instruction_append(irb->current_basic_block, instruction); | 1057 | ir_instruction_append(ag->current_basic_block, instruction); |
| 1058 | return instruction; | 1058 | return instruction; |
| 1059 | } | 1059 | } |
| 1060 | | 1060 | |
| 1061 | static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) { | 1061 | static IrInstSrc *ir_build_const_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigType *import) { |
| 1062 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1062 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1063 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1063 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1064 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; | 1064 | const_instruction->value->type = ag->codegen->builtin_types.entry_type; |
| 1065 | const_instruction->value->special = ConstValSpecialStatic; | 1065 | const_instruction->value->special = ConstValSpecialStatic; |
| 1066 | const_instruction->value->data.x_type = import; | 1066 | const_instruction->value->data.x_type = import; |
| 1067 | return &const_instruction->base; | 1067 | return &const_instruction->base; |
| 1068 | } | 1068 | } |
| 1069 | | 1069 | |
| 1070 | static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) { | 1070 | static IrInstSrc *ir_build_const_bool(Stage1AstGen *ag, Scope *scope, AstNode *source_node, bool value) { |
| 1071 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1071 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1072 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1072 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1073 | const_instruction->value->type = irb->codegen->builtin_types.entry_bool; | 1073 | const_instruction->value->type = ag->codegen->builtin_types.entry_bool; |
| 1074 | const_instruction->value->special = ConstValSpecialStatic; | 1074 | const_instruction->value->special = ConstValSpecialStatic; |
| 1075 | const_instruction->value->data.x_bool = value; | 1075 | const_instruction->value->data.x_bool = value; |
| 1076 | return &const_instruction->base; | 1076 | return &const_instruction->base; |
| 1077 | } | 1077 | } |
| 1078 | | 1078 | |
| 1079 | static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { | 1079 | static IrInstSrc *ir_build_const_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *name) { |
| 1080 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); | 1080 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1081 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1081 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1082 | const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal; | 1082 | const_instruction->value->type = ag->codegen->builtin_types.entry_enum_literal; |
| 1083 | const_instruction->value->special = ConstValSpecialStatic; | 1083 | const_instruction->value->special = ConstValSpecialStatic; |
| 1084 | const_instruction->value->data.x_enum_literal = name; | 1084 | const_instruction->value->data.x_enum_literal = name; |
| 1085 | return &const_instruction->base; | 1085 | return &const_instruction->base; |
| 1086 | } | 1086 | } |
| 1087 | | 1087 | |
| 1088 | // Consumes `str`. | 1088 | // Consumes `str`. |
| 1089 | static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { | 1089 | static IrInstSrc *ir_create_const_str_lit(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *str) { |
| 1090 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); | 1090 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node); |
| 1091 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 1091 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 1092 | init_const_str_lit(irb->codegen, const_instruction->value, str, true); | 1092 | init_const_str_lit(ag->codegen, const_instruction->value, str, true); |
| 1093 | | 1093 | |
| 1094 | return &const_instruction->base; | 1094 | return &const_instruction->base; |
| 1095 | } | 1095 | } |
| 1096 | | 1096 | |
| 1097 | // Consumes `str`. | 1097 | // Consumes `str`. |
| 1098 | static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { | 1098 | static IrInstSrc *ir_build_const_str_lit(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *str) { |
| 1099 | IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str); | 1099 | IrInstSrc *instruction = ir_create_const_str_lit(ag, scope, source_node, str); |
| 1100 | ir_instruction_append(irb->current_basic_block, instruction); | 1100 | ir_instruction_append(ag->current_basic_block, instruction); |
| 1101 | return instruction; | 1101 | return instruction; |
| 1102 | } | 1102 | } |
| 1103 | | 1103 | |
| 1104 | static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, | 1104 | static IrInstSrc *ir_build_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 1105 | IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on) | 1105 | IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on) |
| 1106 | { | 1106 | { |
| 1107 | IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node); | 1107 | IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(ag, scope, source_node); |
| 1108 | inst->op_id = op_id; | 1108 | inst->op_id = op_id; |
| 1109 | inst->op1 = op1; | 1109 | inst->op1 = op1; |
| 1110 | inst->op2 = op2; | 1110 | inst->op2 = op2; |
| 1111 | inst->safety_check_on = safety_check_on; | 1111 | inst->safety_check_on = safety_check_on; |
| 1112 | | 1112 | |
| 1113 | ir_ref_instruction(op1, irb->current_basic_block); | 1113 | ir_ref_instruction(op1, ag->current_basic_block); |
| 1114 | ir_ref_instruction(op2, irb->current_basic_block); | 1114 | ir_ref_instruction(op2, ag->current_basic_block); |
| 1115 | | 1115 | |
| 1116 | return &inst->base; | 1116 | return &inst->base; |
| 1117 | } | 1117 | } |
| 1118 | | 1118 | |
| 1119 | static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1119 | static IrInstSrc *ir_build_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1120 | IrInstSrc *op1, IrInstSrc *op2, Buf *type_name) | 1120 | IrInstSrc *op1, IrInstSrc *op2, Buf *type_name) |
| 1121 | { | 1121 | { |
| 1122 | IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node); | 1122 | IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(ag, scope, source_node); |
| 1123 | inst->op1 = op1; | 1123 | inst->op1 = op1; |
| 1124 | inst->op2 = op2; | 1124 | inst->op2 = op2; |
| 1125 | inst->type_name = type_name; | 1125 | inst->type_name = type_name; |
| 1126 | | 1126 | |
| 1127 | ir_ref_instruction(op1, irb->current_basic_block); | 1127 | ir_ref_instruction(op1, ag->current_basic_block); |
| 1128 | ir_ref_instruction(op2, irb->current_basic_block); | 1128 | ir_ref_instruction(op2, ag->current_basic_block); |
| 1129 | | 1129 | |
| 1130 | return &inst->base; | 1130 | return &inst->base; |
| 1131 | } | 1131 | } |
| 1132 | | 1132 | |
| 1133 | static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, | 1133 | static IrInstSrc *ir_build_var_ptr_x(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var, |
| 1134 | ScopeFnDef *crossed_fndef_scope) | 1134 | ScopeFnDef *crossed_fndef_scope) |
| 1135 | { | 1135 | { |
| 1136 | IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node); | 1136 | IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(ag, scope, source_node); |
| 1137 | instruction->var = var; | 1137 | instruction->var = var; |
| 1138 | instruction->crossed_fndef_scope = crossed_fndef_scope; | 1138 | instruction->crossed_fndef_scope = crossed_fndef_scope; |
| 1139 | | 1139 | |
| ... | @@ -1142,89 +1142,89 @@ static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *s | ... | @@ -1142,89 +1142,89 @@ static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *s |
| 1142 | return &instruction->base; | 1142 | return &instruction->base; |
| 1143 | } | 1143 | } |
| 1144 | | 1144 | |
| 1145 | static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) { | 1145 | static IrInstSrc *ir_build_var_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 1146 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); | 1146 | return ir_build_var_ptr_x(ag, scope, source_node, var, nullptr); |
| 1147 | } | 1147 | } |
| 1148 | | 1148 | |
| 1149 | static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1149 | static IrInstSrc *ir_build_elem_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1150 | IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len, | 1150 | IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len, |
| 1151 | AstNode *init_array_type_source_node) | 1151 | AstNode *init_array_type_source_node) |
| 1152 | { | 1152 | { |
| 1153 | IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node); | 1153 | IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(ag, scope, source_node); |
| 1154 | instruction->array_ptr = array_ptr; | 1154 | instruction->array_ptr = array_ptr; |
| 1155 | instruction->elem_index = elem_index; | 1155 | instruction->elem_index = elem_index; |
| 1156 | instruction->safety_check_on = safety_check_on; | 1156 | instruction->safety_check_on = safety_check_on; |
| 1157 | instruction->ptr_len = ptr_len; | 1157 | instruction->ptr_len = ptr_len; |
| 1158 | instruction->init_array_type_source_node = init_array_type_source_node; | 1158 | instruction->init_array_type_source_node = init_array_type_source_node; |
| 1159 | | 1159 | |
| 1160 | ir_ref_instruction(array_ptr, irb->current_basic_block); | 1160 | ir_ref_instruction(array_ptr, ag->current_basic_block); |
| 1161 | ir_ref_instruction(elem_index, irb->current_basic_block); | 1161 | ir_ref_instruction(elem_index, ag->current_basic_block); |
| 1162 | | 1162 | |
| 1163 | return &instruction->base; | 1163 | return &instruction->base; |
| 1164 | } | 1164 | } |
| 1165 | | 1165 | |
| 1166 | static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1166 | static IrInstSrc *ir_build_field_ptr_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1167 | IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing) | 1167 | IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing) |
| 1168 | { | 1168 | { |
| 1169 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); | 1169 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(ag, scope, source_node); |
| 1170 | instruction->container_ptr = container_ptr; | 1170 | instruction->container_ptr = container_ptr; |
| 1171 | instruction->field_name_buffer = nullptr; | 1171 | instruction->field_name_buffer = nullptr; |
| 1172 | instruction->field_name_expr = field_name_expr; | 1172 | instruction->field_name_expr = field_name_expr; |
| 1173 | instruction->initializing = initializing; | 1173 | instruction->initializing = initializing; |
| 1174 | | 1174 | |
| 1175 | ir_ref_instruction(container_ptr, irb->current_basic_block); | 1175 | ir_ref_instruction(container_ptr, ag->current_basic_block); |
| 1176 | ir_ref_instruction(field_name_expr, irb->current_basic_block); | 1176 | ir_ref_instruction(field_name_expr, ag->current_basic_block); |
| 1177 | | 1177 | |
| 1178 | return &instruction->base; | 1178 | return &instruction->base; |
| 1179 | } | 1179 | } |
| 1180 | | 1180 | |
| 1181 | static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1181 | static IrInstSrc *ir_build_field_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1182 | IrInstSrc *container_ptr, Buf *field_name, bool initializing) | 1182 | IrInstSrc *container_ptr, Buf *field_name, bool initializing) |
| 1183 | { | 1183 | { |
| 1184 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); | 1184 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(ag, scope, source_node); |
| 1185 | instruction->container_ptr = container_ptr; | 1185 | instruction->container_ptr = container_ptr; |
| 1186 | instruction->field_name_buffer = field_name; | 1186 | instruction->field_name_buffer = field_name; |
| 1187 | instruction->field_name_expr = nullptr; | 1187 | instruction->field_name_expr = nullptr; |
| 1188 | instruction->initializing = initializing; | 1188 | instruction->initializing = initializing; |
| 1189 | | 1189 | |
| 1190 | ir_ref_instruction(container_ptr, irb->current_basic_block); | 1190 | ir_ref_instruction(container_ptr, ag->current_basic_block); |
| 1191 | | 1191 | |
| 1192 | return &instruction->base; | 1192 | return &instruction->base; |
| 1193 | } | 1193 | } |
| 1194 | | 1194 | |
| 1195 | static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1195 | static IrInstSrc *ir_build_has_field(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1196 | IrInstSrc *container_type, IrInstSrc *field_name) | 1196 | IrInstSrc *container_type, IrInstSrc *field_name) |
| 1197 | { | 1197 | { |
| 1198 | IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node); | 1198 | IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(ag, scope, source_node); |
| 1199 | instruction->container_type = container_type; | 1199 | instruction->container_type = container_type; |
| 1200 | instruction->field_name = field_name; | 1200 | instruction->field_name = field_name; |
| 1201 | | 1201 | |
| 1202 | ir_ref_instruction(container_type, irb->current_basic_block); | 1202 | ir_ref_instruction(container_type, ag->current_basic_block); |
| 1203 | ir_ref_instruction(field_name, irb->current_basic_block); | 1203 | ir_ref_instruction(field_name, ag->current_basic_block); |
| 1204 | | 1204 | |
| 1205 | return &instruction->base; | 1205 | return &instruction->base; |
| 1206 | } | 1206 | } |
| 1207 | | 1207 | |
| 1208 | static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1208 | static IrInstSrc *ir_build_call_extra(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1209 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc) | 1209 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc) |
| 1210 | { | 1210 | { |
| 1211 | IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node); | 1211 | IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(ag, scope, source_node); |
| 1212 | call_instruction->options = options; | 1212 | call_instruction->options = options; |
| 1213 | call_instruction->fn_ref = fn_ref; | 1213 | call_instruction->fn_ref = fn_ref; |
| 1214 | call_instruction->args = args; | 1214 | call_instruction->args = args; |
| 1215 | call_instruction->result_loc = result_loc; | 1215 | call_instruction->result_loc = result_loc; |
| 1216 | | 1216 | |
| 1217 | ir_ref_instruction(options, irb->current_basic_block); | 1217 | ir_ref_instruction(options, ag->current_basic_block); |
| 1218 | ir_ref_instruction(fn_ref, irb->current_basic_block); | 1218 | ir_ref_instruction(fn_ref, ag->current_basic_block); |
| 1219 | ir_ref_instruction(args, irb->current_basic_block); | 1219 | ir_ref_instruction(args, ag->current_basic_block); |
| 1220 | | 1220 | |
| 1221 | return &call_instruction->base; | 1221 | return &call_instruction->base; |
| 1222 | } | 1222 | } |
| 1223 | | 1223 | |
| 1224 | static IrInstSrc *ir_build_async_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1224 | static IrInstSrc *ir_build_async_call_extra(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1225 | CallModifier modifier, IrInstSrc *fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstSrc *args, ResultLoc *result_loc) | 1225 | CallModifier modifier, IrInstSrc *fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstSrc *args, ResultLoc *result_loc) |
| 1226 | { | 1226 | { |
| 1227 | IrInstSrcAsyncCallExtra *call_instruction = ir_build_instruction<IrInstSrcAsyncCallExtra>(irb, scope, source_node); | 1227 | IrInstSrcAsyncCallExtra *call_instruction = ir_build_instruction<IrInstSrcAsyncCallExtra>(ag, scope, source_node); |
| 1228 | call_instruction->modifier = modifier; | 1228 | call_instruction->modifier = modifier; |
| 1229 | call_instruction->fn_ref = fn_ref; | 1229 | call_instruction->fn_ref = fn_ref; |
| 1230 | call_instruction->ret_ptr = ret_ptr; | 1230 | call_instruction->ret_ptr = ret_ptr; |
| ... | @@ -1232,39 +1232,39 @@ static IrInstSrc *ir_build_async_call_extra(IrBuilderSrc *irb, Scope *scope, Ast | ... | @@ -1232,39 +1232,39 @@ static IrInstSrc *ir_build_async_call_extra(IrBuilderSrc *irb, Scope *scope, Ast |
| 1232 | call_instruction->args = args; | 1232 | call_instruction->args = args; |
| 1233 | call_instruction->result_loc = result_loc; | 1233 | call_instruction->result_loc = result_loc; |
| 1234 | | 1234 | |
| 1235 | ir_ref_instruction(fn_ref, irb->current_basic_block); | 1235 | ir_ref_instruction(fn_ref, ag->current_basic_block); |
| 1236 | if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, irb->current_basic_block); | 1236 | if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, ag->current_basic_block); |
| 1237 | ir_ref_instruction(new_stack, irb->current_basic_block); | 1237 | ir_ref_instruction(new_stack, ag->current_basic_block); |
| 1238 | ir_ref_instruction(args, irb->current_basic_block); | 1238 | ir_ref_instruction(args, ag->current_basic_block); |
| 1239 | | 1239 | |
| 1240 | return &call_instruction->base; | 1240 | return &call_instruction->base; |
| 1241 | } | 1241 | } |
| 1242 | | 1242 | |
| 1243 | static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1243 | static IrInstSrc *ir_build_call_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1244 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len, | 1244 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len, |
| 1245 | ResultLoc *result_loc) | 1245 | ResultLoc *result_loc) |
| 1246 | { | 1246 | { |
| 1247 | IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node); | 1247 | IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(ag, scope, source_node); |
| 1248 | call_instruction->options = options; | 1248 | call_instruction->options = options; |
| 1249 | call_instruction->fn_ref = fn_ref; | 1249 | call_instruction->fn_ref = fn_ref; |
| 1250 | call_instruction->args_ptr = args_ptr; | 1250 | call_instruction->args_ptr = args_ptr; |
| 1251 | call_instruction->args_len = args_len; | 1251 | call_instruction->args_len = args_len; |
| 1252 | call_instruction->result_loc = result_loc; | 1252 | call_instruction->result_loc = result_loc; |
| 1253 | | 1253 | |
| 1254 | ir_ref_instruction(options, irb->current_basic_block); | 1254 | ir_ref_instruction(options, ag->current_basic_block); |
| 1255 | ir_ref_instruction(fn_ref, irb->current_basic_block); | 1255 | ir_ref_instruction(fn_ref, ag->current_basic_block); |
| 1256 | for (size_t i = 0; i < args_len; i += 1) | 1256 | for (size_t i = 0; i < args_len; i += 1) |
| 1257 | ir_ref_instruction(args_ptr[i], irb->current_basic_block); | 1257 | ir_ref_instruction(args_ptr[i], ag->current_basic_block); |
| 1258 | | 1258 | |
| 1259 | return &call_instruction->base; | 1259 | return &call_instruction->base; |
| 1260 | } | 1260 | } |
| 1261 | | 1261 | |
| 1262 | static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1262 | static IrInstSrc *ir_build_call_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1263 | ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args, | 1263 | ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args, |
| 1264 | IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin, | 1264 | IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin, |
| 1265 | IrInstSrc *new_stack, ResultLoc *result_loc) | 1265 | IrInstSrc *new_stack, ResultLoc *result_loc) |
| 1266 | { | 1266 | { |
| 1267 | IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node); | 1267 | IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(ag, scope, source_node); |
| 1268 | call_instruction->fn_entry = fn_entry; | 1268 | call_instruction->fn_entry = fn_entry; |
| 1269 | call_instruction->fn_ref = fn_ref; | 1269 | call_instruction->fn_ref = fn_ref; |
| 1270 | call_instruction->args = args; | 1270 | call_instruction->args = args; |
| ... | @@ -1275,23 +1275,23 @@ static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *so | ... | @@ -1275,23 +1275,23 @@ static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *so |
| 1275 | call_instruction->result_loc = result_loc; | 1275 | call_instruction->result_loc = result_loc; |
| 1276 | call_instruction->ret_ptr = ret_ptr; | 1276 | call_instruction->ret_ptr = ret_ptr; |
| 1277 | | 1277 | |
| 1278 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block); | 1278 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ag->current_basic_block); |
| 1279 | for (size_t i = 0; i < arg_count; i += 1) | 1279 | for (size_t i = 0; i < arg_count; i += 1) |
| 1280 | ir_ref_instruction(args[i], irb->current_basic_block); | 1280 | ir_ref_instruction(args[i], ag->current_basic_block); |
| 1281 | if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, irb->current_basic_block); | 1281 | if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, ag->current_basic_block); |
| 1282 | if (new_stack != nullptr) ir_ref_instruction(new_stack, irb->current_basic_block); | 1282 | if (new_stack != nullptr) ir_ref_instruction(new_stack, ag->current_basic_block); |
| 1283 | | 1283 | |
| 1284 | return &call_instruction->base; | 1284 | return &call_instruction->base; |
| 1285 | } | 1285 | } |
| 1286 | | 1286 | |
| 1287 | static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1287 | static IrInstSrc *ir_build_phi(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1288 | size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values, | 1288 | size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values, |
| 1289 | ResultLocPeerParent *peer_parent) | 1289 | ResultLocPeerParent *peer_parent) |
| 1290 | { | 1290 | { |
| 1291 | assert(incoming_count != 0); | 1291 | assert(incoming_count != 0); |
| 1292 | assert(incoming_count != SIZE_MAX); | 1292 | assert(incoming_count != SIZE_MAX); |
| 1293 | | 1293 | |
| 1294 | IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node); | 1294 | IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(ag, scope, source_node); |
| 1295 | phi_instruction->incoming_count = incoming_count; | 1295 | phi_instruction->incoming_count = incoming_count; |
| 1296 | phi_instruction->incoming_blocks = incoming_blocks; | 1296 | phi_instruction->incoming_blocks = incoming_blocks; |
| 1297 | phi_instruction->incoming_values = incoming_values; | 1297 | phi_instruction->incoming_values = incoming_values; |
| ... | @@ -1299,45 +1299,45 @@ static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_ | ... | @@ -1299,45 +1299,45 @@ static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_ |
| 1299 | | 1299 | |
| 1300 | for (size_t i = 0; i < incoming_count; i += 1) { | 1300 | for (size_t i = 0; i < incoming_count; i += 1) { |
| 1301 | ir_ref_bb(incoming_blocks[i]); | 1301 | ir_ref_bb(incoming_blocks[i]); |
| 1302 | ir_ref_instruction(incoming_values[i], irb->current_basic_block); | 1302 | ir_ref_instruction(incoming_values[i], ag->current_basic_block); |
| 1303 | } | 1303 | } |
| 1304 | | 1304 | |
| 1305 | return &phi_instruction->base; | 1305 | return &phi_instruction->base; |
| 1306 | } | 1306 | } |
| 1307 | | 1307 | |
| 1308 | static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1308 | static IrInstSrc *ir_build_br(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1309 | IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime) | 1309 | IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime) |
| 1310 | { | 1310 | { |
| 1311 | IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node); | 1311 | IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(ag, scope, source_node); |
| 1312 | inst->base.is_noreturn = true; | 1312 | inst->base.is_noreturn = true; |
| 1313 | inst->dest_block = dest_block; | 1313 | inst->dest_block = dest_block; |
| 1314 | inst->is_comptime = is_comptime; | 1314 | inst->is_comptime = is_comptime; |
| 1315 | | 1315 | |
| 1316 | ir_ref_bb(dest_block); | 1316 | ir_ref_bb(dest_block); |
| 1317 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); | 1317 | if (is_comptime) ir_ref_instruction(is_comptime, ag->current_basic_block); |
| 1318 | | 1318 | |
| 1319 | return &inst->base; | 1319 | return &inst->base; |
| 1320 | } | 1320 | } |
| 1321 | | 1321 | |
| 1322 | static IrInstSrc *ir_build_ptr_type_simple(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1322 | static IrInstSrc *ir_build_ptr_type_simple(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1323 | IrInstSrc *child_type, bool is_const) | 1323 | IrInstSrc *child_type, bool is_const) |
| 1324 | { | 1324 | { |
| 1325 | IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>(); | 1325 | IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>(); |
| 1326 | inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple; | 1326 | inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple; |
| 1327 | inst->base.base.scope = scope; | 1327 | inst->base.base.scope = scope; |
| 1328 | inst->base.base.source_node = source_node; | 1328 | inst->base.base.source_node = source_node; |
| 1329 | inst->base.base.debug_id = irb_next_debug_id(irb); | 1329 | inst->base.base.debug_id = irb_next_debug_id(ag); |
| 1330 | inst->base.owner_bb = irb->current_basic_block; | 1330 | inst->base.owner_bb = ag->current_basic_block; |
| 1331 | ir_instruction_append(irb->current_basic_block, &inst->base); | 1331 | ir_instruction_append(ag->current_basic_block, &inst->base); |
| 1332 | | 1332 | |
| 1333 | inst->child_type = child_type; | 1333 | inst->child_type = child_type; |
| 1334 | | 1334 | |
| 1335 | ir_ref_instruction(child_type, irb->current_basic_block); | 1335 | ir_ref_instruction(child_type, ag->current_basic_block); |
| 1336 | | 1336 | |
| 1337 | return &inst->base; | 1337 | return &inst->base; |
| 1338 | } | 1338 | } |
| 1339 | | 1339 | |
| 1340 | static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1340 | static IrInstSrc *ir_build_ptr_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1341 | IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, | 1341 | IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 1342 | IrInstSrc *sentinel, IrInstSrc *align_value, | 1342 | IrInstSrc *sentinel, IrInstSrc *align_value, |
| 1343 | uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) | 1343 | uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) |
| ... | @@ -1345,10 +1345,10 @@ static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *so | ... | @@ -1345,10 +1345,10 @@ static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *so |
| 1345 | if (!is_volatile && ptr_len == PtrLenSingle && sentinel == nullptr && align_value == nullptr && | 1345 | if (!is_volatile && ptr_len == PtrLenSingle && sentinel == nullptr && align_value == nullptr && |
| 1346 | bit_offset_start == 0 && host_int_bytes == 0 && is_allow_zero == 0) | 1346 | bit_offset_start == 0 && host_int_bytes == 0 && is_allow_zero == 0) |
| 1347 | { | 1347 | { |
| 1348 | return ir_build_ptr_type_simple(irb, scope, source_node, child_type, is_const); | 1348 | return ir_build_ptr_type_simple(ag, scope, source_node, child_type, is_const); |
| 1349 | } | 1349 | } |
| 1350 | | 1350 | |
| 1351 | IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node); | 1351 | IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(ag, scope, source_node); |
| 1352 | inst->sentinel = sentinel; | 1352 | inst->sentinel = sentinel; |
| 1353 | inst->align_value = align_value; | 1353 | inst->align_value = align_value; |
| 1354 | inst->child_type = child_type; | 1354 | inst->child_type = child_type; |
| ... | @@ -1359,225 +1359,225 @@ static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *so | ... | @@ -1359,225 +1359,225 @@ static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *so |
| 1359 | inst->host_int_bytes = host_int_bytes; | 1359 | inst->host_int_bytes = host_int_bytes; |
| 1360 | inst->is_allow_zero = is_allow_zero; | 1360 | inst->is_allow_zero = is_allow_zero; |
| 1361 | | 1361 | |
| 1362 | if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block); | 1362 | if (sentinel) ir_ref_instruction(sentinel, ag->current_basic_block); |
| 1363 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); | 1363 | if (align_value) ir_ref_instruction(align_value, ag->current_basic_block); |
| 1364 | ir_ref_instruction(child_type, irb->current_basic_block); | 1364 | ir_ref_instruction(child_type, ag->current_basic_block); |
| 1365 | | 1365 | |
| 1366 | return &inst->base; | 1366 | return &inst->base; |
| 1367 | } | 1367 | } |
| 1368 | | 1368 | |
| 1369 | static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, | 1369 | static IrInstSrc *ir_build_un_op_lval(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 1370 | IrInstSrc *value, LVal lval, ResultLoc *result_loc) | 1370 | IrInstSrc *value, LVal lval, ResultLoc *result_loc) |
| 1371 | { | 1371 | { |
| 1372 | IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node); | 1372 | IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(ag, scope, source_node); |
| 1373 | instruction->op_id = op_id; | 1373 | instruction->op_id = op_id; |
| 1374 | instruction->value = value; | 1374 | instruction->value = value; |
| 1375 | instruction->lval = lval; | 1375 | instruction->lval = lval; |
| 1376 | instruction->result_loc = result_loc; | 1376 | instruction->result_loc = result_loc; |
| 1377 | | 1377 | |
| 1378 | ir_ref_instruction(value, irb->current_basic_block); | 1378 | ir_ref_instruction(value, ag->current_basic_block); |
| 1379 | | 1379 | |
| 1380 | return &instruction->base; | 1380 | return &instruction->base; |
| 1381 | } | 1381 | } |
| 1382 | | 1382 | |
| 1383 | static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, | 1383 | static IrInstSrc *ir_build_un_op(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 1384 | IrInstSrc *value) | 1384 | IrInstSrc *value) |
| 1385 | { | 1385 | { |
| 1386 | return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr); | 1386 | return ir_build_un_op_lval(ag, scope, source_node, op_id, value, LValNone, nullptr); |
| 1387 | } | 1387 | } |
| 1388 | | 1388 | |
| 1389 | static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1389 | static IrInstSrc *ir_build_container_init_list(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1390 | size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc, | 1390 | size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc, |
| 1391 | AstNode *init_array_type_source_node) | 1391 | AstNode *init_array_type_source_node) |
| 1392 | { | 1392 | { |
| 1393 | IrInstSrcContainerInitList *container_init_list_instruction = | 1393 | IrInstSrcContainerInitList *container_init_list_instruction = |
| 1394 | ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node); | 1394 | ir_build_instruction<IrInstSrcContainerInitList>(ag, scope, source_node); |
| 1395 | container_init_list_instruction->item_count = item_count; | 1395 | container_init_list_instruction->item_count = item_count; |
| 1396 | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; | 1396 | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; |
| 1397 | container_init_list_instruction->result_loc = result_loc; | 1397 | container_init_list_instruction->result_loc = result_loc; |
| 1398 | container_init_list_instruction->init_array_type_source_node = init_array_type_source_node; | 1398 | container_init_list_instruction->init_array_type_source_node = init_array_type_source_node; |
| 1399 | | 1399 | |
| 1400 | for (size_t i = 0; i < item_count; i += 1) { | 1400 | for (size_t i = 0; i < item_count; i += 1) { |
| 1401 | ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block); | 1401 | ir_ref_instruction(elem_result_loc_list[i], ag->current_basic_block); |
| 1402 | } | 1402 | } |
| 1403 | if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block); | 1403 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ag->current_basic_block); |
| 1404 | | 1404 | |
| 1405 | return &container_init_list_instruction->base; | 1405 | return &container_init_list_instruction->base; |
| 1406 | } | 1406 | } |
| 1407 | | 1407 | |
| 1408 | static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1408 | static IrInstSrc *ir_build_container_init_fields(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1409 | size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc) | 1409 | size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc) |
| 1410 | { | 1410 | { |
| 1411 | IrInstSrcContainerInitFields *container_init_fields_instruction = | 1411 | IrInstSrcContainerInitFields *container_init_fields_instruction = |
| 1412 | ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node); | 1412 | ir_build_instruction<IrInstSrcContainerInitFields>(ag, scope, source_node); |
| 1413 | container_init_fields_instruction->field_count = field_count; | 1413 | container_init_fields_instruction->field_count = field_count; |
| 1414 | container_init_fields_instruction->fields = fields; | 1414 | container_init_fields_instruction->fields = fields; |
| 1415 | container_init_fields_instruction->result_loc = result_loc; | 1415 | container_init_fields_instruction->result_loc = result_loc; |
| 1416 | | 1416 | |
| 1417 | for (size_t i = 0; i < field_count; i += 1) { | 1417 | for (size_t i = 0; i < field_count; i += 1) { |
| 1418 | ir_ref_instruction(fields[i].result_loc, irb->current_basic_block); | 1418 | ir_ref_instruction(fields[i].result_loc, ag->current_basic_block); |
| 1419 | } | 1419 | } |
| 1420 | if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block); | 1420 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ag->current_basic_block); |
| 1421 | | 1421 | |
| 1422 | return &container_init_fields_instruction->base; | 1422 | return &container_init_fields_instruction->base; |
| 1423 | } | 1423 | } |
| 1424 | | 1424 | |
| 1425 | static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 1425 | static IrInstSrc *ir_build_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 1426 | IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node); | 1426 | IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(ag, scope, source_node); |
| 1427 | inst->base.is_noreturn = true; | 1427 | inst->base.is_noreturn = true; |
| 1428 | return &inst->base; | 1428 | return &inst->base; |
| 1429 | } | 1429 | } |
| 1430 | | 1430 | |
| 1431 | static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1431 | static IrInstSrcStorePtr *ir_build_store_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1432 | IrInstSrc *ptr, IrInstSrc *value) | 1432 | IrInstSrc *ptr, IrInstSrc *value) |
| 1433 | { | 1433 | { |
| 1434 | IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node); | 1434 | IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(ag, scope, source_node); |
| 1435 | instruction->ptr = ptr; | 1435 | instruction->ptr = ptr; |
| 1436 | instruction->value = value; | 1436 | instruction->value = value; |
| 1437 | | 1437 | |
| 1438 | ir_ref_instruction(ptr, irb->current_basic_block); | 1438 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 1439 | ir_ref_instruction(value, irb->current_basic_block); | 1439 | ir_ref_instruction(value, ag->current_basic_block); |
| 1440 | | 1440 | |
| 1441 | return instruction; | 1441 | return instruction; |
| 1442 | } | 1442 | } |
| 1443 | | 1443 | |
| 1444 | static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1444 | static IrInstSrc *ir_build_var_decl_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1445 | ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr) | 1445 | ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr) |
| 1446 | { | 1446 | { |
| 1447 | IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node); | 1447 | IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(ag, scope, source_node); |
| 1448 | inst->var = var; | 1448 | inst->var = var; |
| 1449 | inst->align_value = align_value; | 1449 | inst->align_value = align_value; |
| 1450 | inst->ptr = ptr; | 1450 | inst->ptr = ptr; |
| 1451 | | 1451 | |
| 1452 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); | 1452 | if (align_value != nullptr) ir_ref_instruction(align_value, ag->current_basic_block); |
| 1453 | ir_ref_instruction(ptr, irb->current_basic_block); | 1453 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 1454 | | 1454 | |
| 1455 | return &inst->base; | 1455 | return &inst->base; |
| 1456 | } | 1456 | } |
| 1457 | | 1457 | |
| 1458 | static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1458 | static IrInstSrc *ir_build_export(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1459 | IrInstSrc *target, IrInstSrc *options) | 1459 | IrInstSrc *target, IrInstSrc *options) |
| 1460 | { | 1460 | { |
| 1461 | IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>( | 1461 | IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>( |
| 1462 | irb, scope, source_node); | 1462 | ag, scope, source_node); |
| 1463 | export_instruction->target = target; | 1463 | export_instruction->target = target; |
| 1464 | export_instruction->options = options; | 1464 | export_instruction->options = options; |
| 1465 | | 1465 | |
| 1466 | ir_ref_instruction(target, irb->current_basic_block); | 1466 | ir_ref_instruction(target, ag->current_basic_block); |
| 1467 | ir_ref_instruction(options, irb->current_basic_block); | 1467 | ir_ref_instruction(options, ag->current_basic_block); |
| 1468 | | 1468 | |
| 1469 | return &export_instruction->base; | 1469 | return &export_instruction->base; |
| 1470 | } | 1470 | } |
| 1471 | | 1471 | |
| 1472 | static IrInstSrc *ir_build_extern(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1472 | static IrInstSrc *ir_build_extern(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1473 | IrInstSrc *type, IrInstSrc *options) | 1473 | IrInstSrc *type, IrInstSrc *options) |
| 1474 | { | 1474 | { |
| 1475 | IrInstSrcExtern *extern_instruction = ir_build_instruction<IrInstSrcExtern>( | 1475 | IrInstSrcExtern *extern_instruction = ir_build_instruction<IrInstSrcExtern>( |
| 1476 | irb, scope, source_node); | 1476 | ag, scope, source_node); |
| 1477 | extern_instruction->type = type; | 1477 | extern_instruction->type = type; |
| 1478 | extern_instruction->options = options; | 1478 | extern_instruction->options = options; |
| 1479 | | 1479 | |
| 1480 | ir_ref_instruction(type, irb->current_basic_block); | 1480 | ir_ref_instruction(type, ag->current_basic_block); |
| 1481 | ir_ref_instruction(options, irb->current_basic_block); | 1481 | ir_ref_instruction(options, ag->current_basic_block); |
| 1482 | | 1482 | |
| 1483 | return &extern_instruction->base; | 1483 | return &extern_instruction->base; |
| 1484 | } | 1484 | } |
| 1485 | | 1485 | |
| 1486 | static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) { | 1486 | static IrInstSrc *ir_build_load_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *ptr) { |
| 1487 | IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node); | 1487 | IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(ag, scope, source_node); |
| 1488 | instruction->ptr = ptr; | 1488 | instruction->ptr = ptr; |
| 1489 | | 1489 | |
| 1490 | ir_ref_instruction(ptr, irb->current_basic_block); | 1490 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 1491 | | 1491 | |
| 1492 | return &instruction->base; | 1492 | return &instruction->base; |
| 1493 | } | 1493 | } |
| 1494 | | 1494 | |
| 1495 | static IrInstSrc *ir_build_typeof_n(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1495 | static IrInstSrc *ir_build_typeof_n(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1496 | IrInstSrc **values, size_t value_count) | 1496 | IrInstSrc **values, size_t value_count) |
| 1497 | { | 1497 | { |
| 1498 | assert(value_count >= 2); | 1498 | assert(value_count >= 2); |
| 1499 | | 1499 | |
| 1500 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node); | 1500 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(ag, scope, source_node); |
| 1501 | instruction->value.list = values; | 1501 | instruction->value.list = values; |
| 1502 | instruction->value_count = value_count; | 1502 | instruction->value_count = value_count; |
| 1503 | | 1503 | |
| 1504 | for (size_t i = 0; i < value_count; i++) | 1504 | for (size_t i = 0; i < value_count; i++) |
| 1505 | ir_ref_instruction(values[i], irb->current_basic_block); | 1505 | ir_ref_instruction(values[i], ag->current_basic_block); |
| 1506 | | 1506 | |
| 1507 | return &instruction->base; | 1507 | return &instruction->base; |
| 1508 | } | 1508 | } |
| 1509 | | 1509 | |
| 1510 | static IrInstSrc *ir_build_typeof_1(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { | 1510 | static IrInstSrc *ir_build_typeof_1(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 1511 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node); | 1511 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(ag, scope, source_node); |
| 1512 | instruction->value.scalar = value; | 1512 | instruction->value.scalar = value; |
| 1513 | | 1513 | |
| 1514 | ir_ref_instruction(value, irb->current_basic_block); | 1514 | ir_ref_instruction(value, ag->current_basic_block); |
| 1515 | | 1515 | |
| 1516 | return &instruction->base; | 1516 | return &instruction->base; |
| 1517 | } | 1517 | } |
| 1518 | | 1518 | |
| 1519 | static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) { | 1519 | static IrInstSrc *ir_build_set_cold(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) { |
| 1520 | IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node); | 1520 | IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(ag, scope, source_node); |
| 1521 | instruction->is_cold = is_cold; | 1521 | instruction->is_cold = is_cold; |
| 1522 | | 1522 | |
| 1523 | ir_ref_instruction(is_cold, irb->current_basic_block); | 1523 | ir_ref_instruction(is_cold, ag->current_basic_block); |
| 1524 | | 1524 | |
| 1525 | return &instruction->base; | 1525 | return &instruction->base; |
| 1526 | } | 1526 | } |
| 1527 | | 1527 | |
| 1528 | static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1528 | static IrInstSrc *ir_build_set_runtime_safety(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1529 | IrInstSrc *safety_on) | 1529 | IrInstSrc *safety_on) |
| 1530 | { | 1530 | { |
| 1531 | IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node); | 1531 | IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(ag, scope, source_node); |
| 1532 | inst->safety_on = safety_on; | 1532 | inst->safety_on = safety_on; |
| 1533 | | 1533 | |
| 1534 | ir_ref_instruction(safety_on, irb->current_basic_block); | 1534 | ir_ref_instruction(safety_on, ag->current_basic_block); |
| 1535 | | 1535 | |
| 1536 | return &inst->base; | 1536 | return &inst->base; |
| 1537 | } | 1537 | } |
| 1538 | | 1538 | |
| 1539 | static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1539 | static IrInstSrc *ir_build_set_float_mode(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1540 | IrInstSrc *mode_value) | 1540 | IrInstSrc *mode_value) |
| 1541 | { | 1541 | { |
| 1542 | IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node); | 1542 | IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(ag, scope, source_node); |
| 1543 | instruction->mode_value = mode_value; | 1543 | instruction->mode_value = mode_value; |
| 1544 | | 1544 | |
| 1545 | ir_ref_instruction(mode_value, irb->current_basic_block); | 1545 | ir_ref_instruction(mode_value, ag->current_basic_block); |
| 1546 | | 1546 | |
| 1547 | return &instruction->base; | 1547 | return &instruction->base; |
| 1548 | } | 1548 | } |
| 1549 | | 1549 | |
| 1550 | static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size, | 1550 | static IrInstSrc *ir_build_array_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *size, |
| 1551 | IrInstSrc *sentinel, IrInstSrc *child_type) | 1551 | IrInstSrc *sentinel, IrInstSrc *child_type) |
| 1552 | { | 1552 | { |
| 1553 | IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node); | 1553 | IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(ag, scope, source_node); |
| 1554 | instruction->size = size; | 1554 | instruction->size = size; |
| 1555 | instruction->sentinel = sentinel; | 1555 | instruction->sentinel = sentinel; |
| 1556 | instruction->child_type = child_type; | 1556 | instruction->child_type = child_type; |
| 1557 | | 1557 | |
| 1558 | ir_ref_instruction(size, irb->current_basic_block); | 1558 | ir_ref_instruction(size, ag->current_basic_block); |
| 1559 | if (sentinel != nullptr) ir_ref_instruction(sentinel, irb->current_basic_block); | 1559 | if (sentinel != nullptr) ir_ref_instruction(sentinel, ag->current_basic_block); |
| 1560 | ir_ref_instruction(child_type, irb->current_basic_block); | 1560 | ir_ref_instruction(child_type, ag->current_basic_block); |
| 1561 | | 1561 | |
| 1562 | return &instruction->base; | 1562 | return &instruction->base; |
| 1563 | } | 1563 | } |
| 1564 | | 1564 | |
| 1565 | static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1565 | static IrInstSrc *ir_build_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1566 | IrInstSrc *payload_type) | 1566 | IrInstSrc *payload_type) |
| 1567 | { | 1567 | { |
| 1568 | IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node); | 1568 | IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(ag, scope, source_node); |
| 1569 | instruction->payload_type = payload_type; | 1569 | instruction->payload_type = payload_type; |
| 1570 | | 1570 | |
| 1571 | if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block); | 1571 | if (payload_type != nullptr) ir_ref_instruction(payload_type, ag->current_basic_block); |
| 1572 | | 1572 | |
| 1573 | return &instruction->base; | 1573 | return &instruction->base; |
| 1574 | } | 1574 | } |
| 1575 | | 1575 | |
| 1576 | static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1576 | static IrInstSrc *ir_build_slice_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1577 | IrInstSrc *child_type, bool is_const, bool is_volatile, | 1577 | IrInstSrc *child_type, bool is_const, bool is_volatile, |
| 1578 | IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero) | 1578 | IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero) |
| 1579 | { | 1579 | { |
| 1580 | IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node); | 1580 | IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(ag, scope, source_node); |
| 1581 | instruction->is_const = is_const; | 1581 | instruction->is_const = is_const; |
| 1582 | instruction->is_volatile = is_volatile; | 1582 | instruction->is_volatile = is_volatile; |
| 1583 | instruction->child_type = child_type; | 1583 | instruction->child_type = child_type; |
| ... | @@ -1585,18 +1585,18 @@ static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode * | ... | @@ -1585,18 +1585,18 @@ static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode * |
| 1585 | instruction->align_value = align_value; | 1585 | instruction->align_value = align_value; |
| 1586 | instruction->is_allow_zero = is_allow_zero; | 1586 | instruction->is_allow_zero = is_allow_zero; |
| 1587 | | 1587 | |
| 1588 | if (sentinel != nullptr) ir_ref_instruction(sentinel, irb->current_basic_block); | 1588 | if (sentinel != nullptr) ir_ref_instruction(sentinel, ag->current_basic_block); |
| 1589 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); | 1589 | if (align_value != nullptr) ir_ref_instruction(align_value, ag->current_basic_block); |
| 1590 | ir_ref_instruction(child_type, irb->current_basic_block); | 1590 | ir_ref_instruction(child_type, ag->current_basic_block); |
| 1591 | | 1591 | |
| 1592 | return &instruction->base; | 1592 | return &instruction->base; |
| 1593 | } | 1593 | } |
| 1594 | | 1594 | |
| 1595 | static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1595 | static IrInstSrc *ir_build_asm_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1596 | IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types, | 1596 | IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types, |
| 1597 | ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global) | 1597 | ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global) |
| 1598 | { | 1598 | { |
| 1599 | IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node); | 1599 | IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(ag, scope, source_node); |
| 1600 | instruction->asm_template = asm_template; | 1600 | instruction->asm_template = asm_template; |
| 1601 | instruction->input_list = input_list; | 1601 | instruction->input_list = input_list; |
| 1602 | instruction->output_types = output_types; | 1602 | instruction->output_types = output_types; |
| ... | @@ -1608,122 +1608,122 @@ static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *sou | ... | @@ -1608,122 +1608,122 @@ static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *sou |
| 1608 | assert(source_node->type == NodeTypeAsmExpr); | 1608 | assert(source_node->type == NodeTypeAsmExpr); |
| 1609 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { | 1609 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 1610 | IrInstSrc *output_type = output_types[i]; | 1610 | IrInstSrc *output_type = output_types[i]; |
| 1611 | if (output_type) ir_ref_instruction(output_type, irb->current_basic_block); | 1611 | if (output_type) ir_ref_instruction(output_type, ag->current_basic_block); |
| 1612 | } | 1612 | } |
| 1613 | | 1613 | |
| 1614 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { | 1614 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 1615 | IrInstSrc *input_value = input_list[i]; | 1615 | IrInstSrc *input_value = input_list[i]; |
| 1616 | ir_ref_instruction(input_value, irb->current_basic_block); | 1616 | ir_ref_instruction(input_value, ag->current_basic_block); |
| 1617 | } | 1617 | } |
| 1618 | | 1618 | |
| 1619 | return &instruction->base; | 1619 | return &instruction->base; |
| 1620 | } | 1620 | } |
| 1621 | | 1621 | |
| 1622 | static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value, | 1622 | static IrInstSrc *ir_build_size_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value, |
| 1623 | bool bit_size) | 1623 | bool bit_size) |
| 1624 | { | 1624 | { |
| 1625 | IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node); | 1625 | IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(ag, scope, source_node); |
| 1626 | instruction->type_value = type_value; | 1626 | instruction->type_value = type_value; |
| 1627 | instruction->bit_size = bit_size; | 1627 | instruction->bit_size = bit_size; |
| 1628 | | 1628 | |
| 1629 | ir_ref_instruction(type_value, irb->current_basic_block); | 1629 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 1630 | | 1630 | |
| 1631 | return &instruction->base; | 1631 | return &instruction->base; |
| 1632 | } | 1632 | } |
| 1633 | | 1633 | |
| 1634 | static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1634 | static IrInstSrc *ir_build_test_non_null_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1635 | IrInstSrc *value) | 1635 | IrInstSrc *value) |
| 1636 | { | 1636 | { |
| 1637 | IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node); | 1637 | IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(ag, scope, source_node); |
| 1638 | instruction->value = value; | 1638 | instruction->value = value; |
| 1639 | | 1639 | |
| 1640 | ir_ref_instruction(value, irb->current_basic_block); | 1640 | ir_ref_instruction(value, ag->current_basic_block); |
| 1641 | | 1641 | |
| 1642 | return &instruction->base; | 1642 | return &instruction->base; |
| 1643 | } | 1643 | } |
| 1644 | | 1644 | |
| 1645 | static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1645 | static IrInstSrc *ir_build_optional_unwrap_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1646 | IrInstSrc *base_ptr, bool safety_check_on) | 1646 | IrInstSrc *base_ptr, bool safety_check_on) |
| 1647 | { | 1647 | { |
| 1648 | IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node); | 1648 | IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(ag, scope, source_node); |
| 1649 | instruction->base_ptr = base_ptr; | 1649 | instruction->base_ptr = base_ptr; |
| 1650 | instruction->safety_check_on = safety_check_on; | 1650 | instruction->safety_check_on = safety_check_on; |
| 1651 | | 1651 | |
| 1652 | ir_ref_instruction(base_ptr, irb->current_basic_block); | 1652 | ir_ref_instruction(base_ptr, ag->current_basic_block); |
| 1653 | | 1653 | |
| 1654 | return &instruction->base; | 1654 | return &instruction->base; |
| 1655 | } | 1655 | } |
| 1656 | | 1656 | |
| 1657 | static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, | 1657 | static IrInstSrc *ir_build_clz(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 1658 | IrInstSrc *op) | 1658 | IrInstSrc *op) |
| 1659 | { | 1659 | { |
| 1660 | IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node); | 1660 | IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(ag, scope, source_node); |
| 1661 | instruction->type = type; | 1661 | instruction->type = type; |
| 1662 | instruction->op = op; | 1662 | instruction->op = op; |
| 1663 | | 1663 | |
| 1664 | ir_ref_instruction(type, irb->current_basic_block); | 1664 | ir_ref_instruction(type, ag->current_basic_block); |
| 1665 | ir_ref_instruction(op, irb->current_basic_block); | 1665 | ir_ref_instruction(op, ag->current_basic_block); |
| 1666 | | 1666 | |
| 1667 | return &instruction->base; | 1667 | return &instruction->base; |
| 1668 | } | 1668 | } |
| 1669 | | 1669 | |
| 1670 | static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, | 1670 | static IrInstSrc *ir_build_ctz(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 1671 | IrInstSrc *op) | 1671 | IrInstSrc *op) |
| 1672 | { | 1672 | { |
| 1673 | IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node); | 1673 | IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(ag, scope, source_node); |
| 1674 | instruction->type = type; | 1674 | instruction->type = type; |
| 1675 | instruction->op = op; | 1675 | instruction->op = op; |
| 1676 | | 1676 | |
| 1677 | ir_ref_instruction(type, irb->current_basic_block); | 1677 | ir_ref_instruction(type, ag->current_basic_block); |
| 1678 | ir_ref_instruction(op, irb->current_basic_block); | 1678 | ir_ref_instruction(op, ag->current_basic_block); |
| 1679 | | 1679 | |
| 1680 | return &instruction->base; | 1680 | return &instruction->base; |
| 1681 | } | 1681 | } |
| 1682 | | 1682 | |
| 1683 | static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, | 1683 | static IrInstSrc *ir_build_pop_count(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 1684 | IrInstSrc *op) | 1684 | IrInstSrc *op) |
| 1685 | { | 1685 | { |
| 1686 | IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node); | 1686 | IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(ag, scope, source_node); |
| 1687 | instruction->type = type; | 1687 | instruction->type = type; |
| 1688 | instruction->op = op; | 1688 | instruction->op = op; |
| 1689 | | 1689 | |
| 1690 | ir_ref_instruction(type, irb->current_basic_block); | 1690 | ir_ref_instruction(type, ag->current_basic_block); |
| 1691 | ir_ref_instruction(op, irb->current_basic_block); | 1691 | ir_ref_instruction(op, ag->current_basic_block); |
| 1692 | | 1692 | |
| 1693 | return &instruction->base; | 1693 | return &instruction->base; |
| 1694 | } | 1694 | } |
| 1695 | | 1695 | |
| 1696 | static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, | 1696 | static IrInstSrc *ir_build_bswap(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 1697 | IrInstSrc *op) | 1697 | IrInstSrc *op) |
| 1698 | { | 1698 | { |
| 1699 | IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node); | 1699 | IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(ag, scope, source_node); |
| 1700 | instruction->type = type; | 1700 | instruction->type = type; |
| 1701 | instruction->op = op; | 1701 | instruction->op = op; |
| 1702 | | 1702 | |
| 1703 | ir_ref_instruction(type, irb->current_basic_block); | 1703 | ir_ref_instruction(type, ag->current_basic_block); |
| 1704 | ir_ref_instruction(op, irb->current_basic_block); | 1704 | ir_ref_instruction(op, ag->current_basic_block); |
| 1705 | | 1705 | |
| 1706 | return &instruction->base; | 1706 | return &instruction->base; |
| 1707 | } | 1707 | } |
| 1708 | | 1708 | |
| 1709 | static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, | 1709 | static IrInstSrc *ir_build_bit_reverse(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 1710 | IrInstSrc *op) | 1710 | IrInstSrc *op) |
| 1711 | { | 1711 | { |
| 1712 | IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node); | 1712 | IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(ag, scope, source_node); |
| 1713 | instruction->type = type; | 1713 | instruction->type = type; |
| 1714 | instruction->op = op; | 1714 | instruction->op = op; |
| 1715 | | 1715 | |
| 1716 | ir_ref_instruction(type, irb->current_basic_block); | 1716 | ir_ref_instruction(type, ag->current_basic_block); |
| 1717 | ir_ref_instruction(op, irb->current_basic_block); | 1717 | ir_ref_instruction(op, ag->current_basic_block); |
| 1718 | | 1718 | |
| 1719 | return &instruction->base; | 1719 | return &instruction->base; |
| 1720 | } | 1720 | } |
| 1721 | | 1721 | |
| 1722 | static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1722 | static IrInstSrcSwitchBr *ir_build_switch_br_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1723 | IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases, | 1723 | IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases, |
| 1724 | IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void) | 1724 | IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void) |
| 1725 | { | 1725 | { |
| 1726 | IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node); | 1726 | IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(ag, scope, source_node); |
| 1727 | instruction->base.is_noreturn = true; | 1727 | instruction->base.is_noreturn = true; |
| 1728 | instruction->target_value = target_value; | 1728 | instruction->target_value = target_value; |
| 1729 | instruction->else_block = else_block; | 1729 | instruction->else_block = else_block; |
| ... | @@ -1732,156 +1732,156 @@ static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope | ... | @@ -1732,156 +1732,156 @@ static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope |
| 1732 | instruction->is_comptime = is_comptime; | 1732 | instruction->is_comptime = is_comptime; |
| 1733 | instruction->switch_prongs_void = switch_prongs_void; | 1733 | instruction->switch_prongs_void = switch_prongs_void; |
| 1734 | | 1734 | |
| 1735 | ir_ref_instruction(target_value, irb->current_basic_block); | 1735 | ir_ref_instruction(target_value, ag->current_basic_block); |
| 1736 | ir_ref_instruction(is_comptime, irb->current_basic_block); | 1736 | ir_ref_instruction(is_comptime, ag->current_basic_block); |
| 1737 | ir_ref_bb(else_block); | 1737 | ir_ref_bb(else_block); |
| 1738 | ir_ref_instruction(switch_prongs_void, irb->current_basic_block); | 1738 | ir_ref_instruction(switch_prongs_void, ag->current_basic_block); |
| 1739 | | 1739 | |
| 1740 | for (size_t i = 0; i < case_count; i += 1) { | 1740 | for (size_t i = 0; i < case_count; i += 1) { |
| 1741 | ir_ref_instruction(cases[i].value, irb->current_basic_block); | 1741 | ir_ref_instruction(cases[i].value, ag->current_basic_block); |
| 1742 | ir_ref_bb(cases[i].block); | 1742 | ir_ref_bb(cases[i].block); |
| 1743 | } | 1743 | } |
| 1744 | | 1744 | |
| 1745 | return instruction; | 1745 | return instruction; |
| 1746 | } | 1746 | } |
| 1747 | | 1747 | |
| 1748 | static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1748 | static IrInstSrc *ir_build_switch_target(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1749 | IrInstSrc *target_value_ptr) | 1749 | IrInstSrc *target_value_ptr) |
| 1750 | { | 1750 | { |
| 1751 | IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node); | 1751 | IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(ag, scope, source_node); |
| 1752 | instruction->target_value_ptr = target_value_ptr; | 1752 | instruction->target_value_ptr = target_value_ptr; |
| 1753 | | 1753 | |
| 1754 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); | 1754 | ir_ref_instruction(target_value_ptr, ag->current_basic_block); |
| 1755 | | 1755 | |
| 1756 | return &instruction->base; | 1756 | return &instruction->base; |
| 1757 | } | 1757 | } |
| 1758 | | 1758 | |
| 1759 | static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1759 | static IrInstSrc *ir_build_switch_var(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1760 | IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len) | 1760 | IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len) |
| 1761 | { | 1761 | { |
| 1762 | IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node); | 1762 | IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(ag, scope, source_node); |
| 1763 | instruction->target_value_ptr = target_value_ptr; | 1763 | instruction->target_value_ptr = target_value_ptr; |
| 1764 | instruction->prongs_ptr = prongs_ptr; | 1764 | instruction->prongs_ptr = prongs_ptr; |
| 1765 | instruction->prongs_len = prongs_len; | 1765 | instruction->prongs_len = prongs_len; |
| 1766 | | 1766 | |
| 1767 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); | 1767 | ir_ref_instruction(target_value_ptr, ag->current_basic_block); |
| 1768 | for (size_t i = 0; i < prongs_len; i += 1) { | 1768 | for (size_t i = 0; i < prongs_len; i += 1) { |
| 1769 | ir_ref_instruction(prongs_ptr[i], irb->current_basic_block); | 1769 | ir_ref_instruction(prongs_ptr[i], ag->current_basic_block); |
| 1770 | } | 1770 | } |
| 1771 | | 1771 | |
| 1772 | return &instruction->base; | 1772 | return &instruction->base; |
| 1773 | } | 1773 | } |
| 1774 | | 1774 | |
| 1775 | // For this instruction the switch_br must be set later. | 1775 | // For this instruction the switch_br must be set later. |
| 1776 | static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1776 | static IrInstSrcSwitchElseVar *ir_build_switch_else_var(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1777 | IrInstSrc *target_value_ptr) | 1777 | IrInstSrc *target_value_ptr) |
| 1778 | { | 1778 | { |
| 1779 | IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node); | 1779 | IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(ag, scope, source_node); |
| 1780 | instruction->target_value_ptr = target_value_ptr; | 1780 | instruction->target_value_ptr = target_value_ptr; |
| 1781 | | 1781 | |
| 1782 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); | 1782 | ir_ref_instruction(target_value_ptr, ag->current_basic_block); |
| 1783 | | 1783 | |
| 1784 | return instruction; | 1784 | return instruction; |
| 1785 | } | 1785 | } |
| 1786 | | 1786 | |
| 1787 | static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { | 1787 | static IrInstSrc *ir_build_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 1788 | IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node); | 1788 | IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(ag, scope, source_node); |
| 1789 | instruction->name = name; | 1789 | instruction->name = name; |
| 1790 | | 1790 | |
| 1791 | ir_ref_instruction(name, irb->current_basic_block); | 1791 | ir_ref_instruction(name, ag->current_basic_block); |
| 1792 | | 1792 | |
| 1793 | return &instruction->base; | 1793 | return &instruction->base; |
| 1794 | } | 1794 | } |
| 1795 | | 1795 | |
| 1796 | static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { | 1796 | static IrInstSrc *ir_build_ref_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 1797 | IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node); | 1797 | IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(ag, scope, source_node); |
| 1798 | instruction->value = value; | 1798 | instruction->value = value; |
| 1799 | | 1799 | |
| 1800 | ir_ref_instruction(value, irb->current_basic_block); | 1800 | ir_ref_instruction(value, ag->current_basic_block); |
| 1801 | | 1801 | |
| 1802 | return &instruction->base; | 1802 | return &instruction->base; |
| 1803 | } | 1803 | } |
| 1804 | | 1804 | |
| 1805 | static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { | 1805 | static IrInstSrc *ir_build_compile_err(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 1806 | IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node); | 1806 | IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(ag, scope, source_node); |
| 1807 | instruction->msg = msg; | 1807 | instruction->msg = msg; |
| 1808 | | 1808 | |
| 1809 | ir_ref_instruction(msg, irb->current_basic_block); | 1809 | ir_ref_instruction(msg, ag->current_basic_block); |
| 1810 | | 1810 | |
| 1811 | return &instruction->base; | 1811 | return &instruction->base; |
| 1812 | } | 1812 | } |
| 1813 | | 1813 | |
| 1814 | static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1814 | static IrInstSrc *ir_build_compile_log(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1815 | size_t msg_count, IrInstSrc **msg_list) | 1815 | size_t msg_count, IrInstSrc **msg_list) |
| 1816 | { | 1816 | { |
| 1817 | IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node); | 1817 | IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(ag, scope, source_node); |
| 1818 | instruction->msg_count = msg_count; | 1818 | instruction->msg_count = msg_count; |
| 1819 | instruction->msg_list = msg_list; | 1819 | instruction->msg_list = msg_list; |
| 1820 | | 1820 | |
| 1821 | for (size_t i = 0; i < msg_count; i += 1) { | 1821 | for (size_t i = 0; i < msg_count; i += 1) { |
| 1822 | ir_ref_instruction(msg_list[i], irb->current_basic_block); | 1822 | ir_ref_instruction(msg_list[i], ag->current_basic_block); |
| 1823 | } | 1823 | } |
| 1824 | | 1824 | |
| 1825 | return &instruction->base; | 1825 | return &instruction->base; |
| 1826 | } | 1826 | } |
| 1827 | | 1827 | |
| 1828 | static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { | 1828 | static IrInstSrc *ir_build_err_name(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 1829 | IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node); | 1829 | IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(ag, scope, source_node); |
| 1830 | instruction->value = value; | 1830 | instruction->value = value; |
| 1831 | | 1831 | |
| 1832 | ir_ref_instruction(value, irb->current_basic_block); | 1832 | ir_ref_instruction(value, ag->current_basic_block); |
| 1833 | | 1833 | |
| 1834 | return &instruction->base; | 1834 | return &instruction->base; |
| 1835 | } | 1835 | } |
| 1836 | | 1836 | |
| 1837 | static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 1837 | static IrInstSrc *ir_build_c_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 1838 | IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node); | 1838 | IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(ag, scope, source_node); |
| 1839 | return &instruction->base; | 1839 | return &instruction->base; |
| 1840 | } | 1840 | } |
| 1841 | | 1841 | |
| 1842 | static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { | 1842 | static IrInstSrc *ir_build_c_include(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 1843 | IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node); | 1843 | IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(ag, scope, source_node); |
| 1844 | instruction->name = name; | 1844 | instruction->name = name; |
| 1845 | | 1845 | |
| 1846 | ir_ref_instruction(name, irb->current_basic_block); | 1846 | ir_ref_instruction(name, ag->current_basic_block); |
| 1847 | | 1847 | |
| 1848 | return &instruction->base; | 1848 | return &instruction->base; |
| 1849 | } | 1849 | } |
| 1850 | | 1850 | |
| 1851 | static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) { | 1851 | static IrInstSrc *ir_build_c_define(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) { |
| 1852 | IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node); | 1852 | IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(ag, scope, source_node); |
| 1853 | instruction->name = name; | 1853 | instruction->name = name; |
| 1854 | instruction->value = value; | 1854 | instruction->value = value; |
| 1855 | | 1855 | |
| 1856 | ir_ref_instruction(name, irb->current_basic_block); | 1856 | ir_ref_instruction(name, ag->current_basic_block); |
| 1857 | ir_ref_instruction(value, irb->current_basic_block); | 1857 | ir_ref_instruction(value, ag->current_basic_block); |
| 1858 | | 1858 | |
| 1859 | return &instruction->base; | 1859 | return &instruction->base; |
| 1860 | } | 1860 | } |
| 1861 | | 1861 | |
| 1862 | static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { | 1862 | static IrInstSrc *ir_build_c_undef(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 1863 | IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node); | 1863 | IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(ag, scope, source_node); |
| 1864 | instruction->name = name; | 1864 | instruction->name = name; |
| 1865 | | 1865 | |
| 1866 | ir_ref_instruction(name, irb->current_basic_block); | 1866 | ir_ref_instruction(name, ag->current_basic_block); |
| 1867 | | 1867 | |
| 1868 | return &instruction->base; | 1868 | return &instruction->base; |
| 1869 | } | 1869 | } |
| 1870 | | 1870 | |
| 1871 | static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { | 1871 | static IrInstSrc *ir_build_embed_file(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 1872 | IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node); | 1872 | IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(ag, scope, source_node); |
| 1873 | instruction->name = name; | 1873 | instruction->name = name; |
| 1874 | | 1874 | |
| 1875 | ir_ref_instruction(name, irb->current_basic_block); | 1875 | ir_ref_instruction(name, ag->current_basic_block); |
| 1876 | | 1876 | |
| 1877 | return &instruction->base; | 1877 | return &instruction->base; |
| 1878 | } | 1878 | } |
| 1879 | | 1879 | |
| 1880 | static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1880 | static IrInstSrc *ir_build_cmpxchg_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1881 | IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value, | 1881 | IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value, |
| 1882 | IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc) | 1882 | IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc) |
| 1883 | { | 1883 | { |
| 1884 | IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node); | 1884 | IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(ag, scope, source_node); |
| 1885 | instruction->type_value = type_value; | 1885 | instruction->type_value = type_value; |
| 1886 | instruction->ptr = ptr; | 1886 | instruction->ptr = ptr; |
| 1887 | instruction->cmp_value = cmp_value; | 1887 | instruction->cmp_value = cmp_value; |
| ... | @@ -1891,210 +1891,210 @@ static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode | ... | @@ -1891,210 +1891,210 @@ static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode |
| 1891 | instruction->is_weak = is_weak; | 1891 | instruction->is_weak = is_weak; |
| 1892 | instruction->result_loc = result_loc; | 1892 | instruction->result_loc = result_loc; |
| 1893 | | 1893 | |
| 1894 | ir_ref_instruction(type_value, irb->current_basic_block); | 1894 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 1895 | ir_ref_instruction(ptr, irb->current_basic_block); | 1895 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 1896 | ir_ref_instruction(cmp_value, irb->current_basic_block); | 1896 | ir_ref_instruction(cmp_value, ag->current_basic_block); |
| 1897 | ir_ref_instruction(new_value, irb->current_basic_block); | 1897 | ir_ref_instruction(new_value, ag->current_basic_block); |
| 1898 | ir_ref_instruction(success_order_value, irb->current_basic_block); | 1898 | ir_ref_instruction(success_order_value, ag->current_basic_block); |
| 1899 | ir_ref_instruction(failure_order_value, irb->current_basic_block); | 1899 | ir_ref_instruction(failure_order_value, ag->current_basic_block); |
| 1900 | | 1900 | |
| 1901 | return &instruction->base; | 1901 | return &instruction->base; |
| 1902 | } | 1902 | } |
| 1903 | | 1903 | |
| 1904 | static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) { | 1904 | static IrInstSrc *ir_build_fence(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *order) { |
| 1905 | IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node); | 1905 | IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(ag, scope, source_node); |
| 1906 | instruction->order = order; | 1906 | instruction->order = order; |
| 1907 | | 1907 | |
| 1908 | ir_ref_instruction(order, irb->current_basic_block); | 1908 | ir_ref_instruction(order, ag->current_basic_block); |
| 1909 | | 1909 | |
| 1910 | return &instruction->base; | 1910 | return &instruction->base; |
| 1911 | } | 1911 | } |
| 1912 | | 1912 | |
| 1913 | static IrInstSrc *ir_build_reduce(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *op, IrInstSrc *value) { | 1913 | static IrInstSrc *ir_build_reduce(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *op, IrInstSrc *value) { |
| 1914 | IrInstSrcReduce *instruction = ir_build_instruction<IrInstSrcReduce>(irb, scope, source_node); | 1914 | IrInstSrcReduce *instruction = ir_build_instruction<IrInstSrcReduce>(ag, scope, source_node); |
| 1915 | instruction->op = op; | 1915 | instruction->op = op; |
| 1916 | instruction->value = value; | 1916 | instruction->value = value; |
| 1917 | | 1917 | |
| 1918 | ir_ref_instruction(op, irb->current_basic_block); | 1918 | ir_ref_instruction(op, ag->current_basic_block); |
| 1919 | ir_ref_instruction(value, irb->current_basic_block); | 1919 | ir_ref_instruction(value, ag->current_basic_block); |
| 1920 | | 1920 | |
| 1921 | return &instruction->base; | 1921 | return &instruction->base; |
| 1922 | } | 1922 | } |
| 1923 | | 1923 | |
| 1924 | static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1924 | static IrInstSrc *ir_build_truncate(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1925 | IrInstSrc *dest_type, IrInstSrc *target) | 1925 | IrInstSrc *dest_type, IrInstSrc *target) |
| 1926 | { | 1926 | { |
| 1927 | IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node); | 1927 | IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(ag, scope, source_node); |
| 1928 | instruction->dest_type = dest_type; | 1928 | instruction->dest_type = dest_type; |
| 1929 | instruction->target = target; | 1929 | instruction->target = target; |
| 1930 | | 1930 | |
| 1931 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1931 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1932 | ir_ref_instruction(target, irb->current_basic_block); | 1932 | ir_ref_instruction(target, ag->current_basic_block); |
| 1933 | | 1933 | |
| 1934 | return &instruction->base; | 1934 | return &instruction->base; |
| 1935 | } | 1935 | } |
| 1936 | | 1936 | |
| 1937 | static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, | 1937 | static IrInstSrc *ir_build_int_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 1938 | IrInstSrc *target) | 1938 | IrInstSrc *target) |
| 1939 | { | 1939 | { |
| 1940 | IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node); | 1940 | IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(ag, scope, source_node); |
| 1941 | instruction->dest_type = dest_type; | 1941 | instruction->dest_type = dest_type; |
| 1942 | instruction->target = target; | 1942 | instruction->target = target; |
| 1943 | | 1943 | |
| 1944 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1944 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1945 | ir_ref_instruction(target, irb->current_basic_block); | 1945 | ir_ref_instruction(target, ag->current_basic_block); |
| 1946 | | 1946 | |
| 1947 | return &instruction->base; | 1947 | return &instruction->base; |
| 1948 | } | 1948 | } |
| 1949 | | 1949 | |
| 1950 | static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, | 1950 | static IrInstSrc *ir_build_float_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 1951 | IrInstSrc *target) | 1951 | IrInstSrc *target) |
| 1952 | { | 1952 | { |
| 1953 | IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node); | 1953 | IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(ag, scope, source_node); |
| 1954 | instruction->dest_type = dest_type; | 1954 | instruction->dest_type = dest_type; |
| 1955 | instruction->target = target; | 1955 | instruction->target = target; |
| 1956 | | 1956 | |
| 1957 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1957 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1958 | ir_ref_instruction(target, irb->current_basic_block); | 1958 | ir_ref_instruction(target, ag->current_basic_block); |
| 1959 | | 1959 | |
| 1960 | return &instruction->base; | 1960 | return &instruction->base; |
| 1961 | } | 1961 | } |
| 1962 | | 1962 | |
| 1963 | static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1963 | static IrInstSrc *ir_build_err_set_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1964 | IrInstSrc *dest_type, IrInstSrc *target) | 1964 | IrInstSrc *dest_type, IrInstSrc *target) |
| 1965 | { | 1965 | { |
| 1966 | IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node); | 1966 | IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(ag, scope, source_node); |
| 1967 | instruction->dest_type = dest_type; | 1967 | instruction->dest_type = dest_type; |
| 1968 | instruction->target = target; | 1968 | instruction->target = target; |
| 1969 | | 1969 | |
| 1970 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1970 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1971 | ir_ref_instruction(target, irb->current_basic_block); | 1971 | ir_ref_instruction(target, ag->current_basic_block); |
| 1972 | | 1972 | |
| 1973 | return &instruction->base; | 1973 | return &instruction->base; |
| 1974 | } | 1974 | } |
| 1975 | | 1975 | |
| 1976 | static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1976 | static IrInstSrc *ir_build_int_to_float(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1977 | IrInstSrc *dest_type, IrInstSrc *target) | 1977 | IrInstSrc *dest_type, IrInstSrc *target) |
| 1978 | { | 1978 | { |
| 1979 | IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node); | 1979 | IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(ag, scope, source_node); |
| 1980 | instruction->dest_type = dest_type; | 1980 | instruction->dest_type = dest_type; |
| 1981 | instruction->target = target; | 1981 | instruction->target = target; |
| 1982 | | 1982 | |
| 1983 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1983 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1984 | ir_ref_instruction(target, irb->current_basic_block); | 1984 | ir_ref_instruction(target, ag->current_basic_block); |
| 1985 | | 1985 | |
| 1986 | return &instruction->base; | 1986 | return &instruction->base; |
| 1987 | } | 1987 | } |
| 1988 | | 1988 | |
| 1989 | static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 1989 | static IrInstSrc *ir_build_float_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1990 | IrInstSrc *dest_type, IrInstSrc *target) | 1990 | IrInstSrc *dest_type, IrInstSrc *target) |
| 1991 | { | 1991 | { |
| 1992 | IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node); | 1992 | IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(ag, scope, source_node); |
| 1993 | instruction->dest_type = dest_type; | 1993 | instruction->dest_type = dest_type; |
| 1994 | instruction->target = target; | 1994 | instruction->target = target; |
| 1995 | | 1995 | |
| 1996 | ir_ref_instruction(dest_type, irb->current_basic_block); | 1996 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 1997 | ir_ref_instruction(target, irb->current_basic_block); | 1997 | ir_ref_instruction(target, ag->current_basic_block); |
| 1998 | | 1998 | |
| 1999 | return &instruction->base; | 1999 | return &instruction->base; |
| 2000 | } | 2000 | } |
| 2001 | | 2001 | |
| 2002 | static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { | 2002 | static IrInstSrc *ir_build_bool_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 2003 | IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node); | 2003 | IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(ag, scope, source_node); |
| 2004 | instruction->target = target; | 2004 | instruction->target = target; |
| 2005 | | 2005 | |
| 2006 | ir_ref_instruction(target, irb->current_basic_block); | 2006 | ir_ref_instruction(target, ag->current_basic_block); |
| 2007 | | 2007 | |
| 2008 | return &instruction->base; | 2008 | return &instruction->base; |
| 2009 | } | 2009 | } |
| 2010 | | 2010 | |
| 2011 | static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len, | 2011 | static IrInstSrc *ir_build_vector_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *len, |
| 2012 | IrInstSrc *elem_type) | 2012 | IrInstSrc *elem_type) |
| 2013 | { | 2013 | { |
| 2014 | IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node); | 2014 | IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(ag, scope, source_node); |
| 2015 | instruction->len = len; | 2015 | instruction->len = len; |
| 2016 | instruction->elem_type = elem_type; | 2016 | instruction->elem_type = elem_type; |
| 2017 | | 2017 | |
| 2018 | ir_ref_instruction(len, irb->current_basic_block); | 2018 | ir_ref_instruction(len, ag->current_basic_block); |
| 2019 | ir_ref_instruction(elem_type, irb->current_basic_block); | 2019 | ir_ref_instruction(elem_type, ag->current_basic_block); |
| 2020 | | 2020 | |
| 2021 | return &instruction->base; | 2021 | return &instruction->base; |
| 2022 | } | 2022 | } |
| 2023 | | 2023 | |
| 2024 | static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2024 | static IrInstSrc *ir_build_shuffle_vector(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2025 | IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask) | 2025 | IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask) |
| 2026 | { | 2026 | { |
| 2027 | IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node); | 2027 | IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(ag, scope, source_node); |
| 2028 | instruction->scalar_type = scalar_type; | 2028 | instruction->scalar_type = scalar_type; |
| 2029 | instruction->a = a; | 2029 | instruction->a = a; |
| 2030 | instruction->b = b; | 2030 | instruction->b = b; |
| 2031 | instruction->mask = mask; | 2031 | instruction->mask = mask; |
| 2032 | | 2032 | |
| 2033 | if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block); | 2033 | if (scalar_type != nullptr) ir_ref_instruction(scalar_type, ag->current_basic_block); |
| 2034 | ir_ref_instruction(a, irb->current_basic_block); | 2034 | ir_ref_instruction(a, ag->current_basic_block); |
| 2035 | ir_ref_instruction(b, irb->current_basic_block); | 2035 | ir_ref_instruction(b, ag->current_basic_block); |
| 2036 | ir_ref_instruction(mask, irb->current_basic_block); | 2036 | ir_ref_instruction(mask, ag->current_basic_block); |
| 2037 | | 2037 | |
| 2038 | return &instruction->base; | 2038 | return &instruction->base; |
| 2039 | } | 2039 | } |
| 2040 | | 2040 | |
| 2041 | static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2041 | static IrInstSrc *ir_build_splat_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2042 | IrInstSrc *len, IrInstSrc *scalar) | 2042 | IrInstSrc *len, IrInstSrc *scalar) |
| 2043 | { | 2043 | { |
| 2044 | IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node); | 2044 | IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(ag, scope, source_node); |
| 2045 | instruction->len = len; | 2045 | instruction->len = len; |
| 2046 | instruction->scalar = scalar; | 2046 | instruction->scalar = scalar; |
| 2047 | | 2047 | |
| 2048 | ir_ref_instruction(len, irb->current_basic_block); | 2048 | ir_ref_instruction(len, ag->current_basic_block); |
| 2049 | ir_ref_instruction(scalar, irb->current_basic_block); | 2049 | ir_ref_instruction(scalar, ag->current_basic_block); |
| 2050 | | 2050 | |
| 2051 | return &instruction->base; | 2051 | return &instruction->base; |
| 2052 | } | 2052 | } |
| 2053 | | 2053 | |
| 2054 | static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { | 2054 | static IrInstSrc *ir_build_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 2055 | IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node); | 2055 | IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(ag, scope, source_node); |
| 2056 | instruction->value = value; | 2056 | instruction->value = value; |
| 2057 | | 2057 | |
| 2058 | ir_ref_instruction(value, irb->current_basic_block); | 2058 | ir_ref_instruction(value, ag->current_basic_block); |
| 2059 | | 2059 | |
| 2060 | return &instruction->base; | 2060 | return &instruction->base; |
| 2061 | } | 2061 | } |
| 2062 | | 2062 | |
| 2063 | static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2063 | static IrInstSrc *ir_build_memset_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2064 | IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count) | 2064 | IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count) |
| 2065 | { | 2065 | { |
| 2066 | IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node); | 2066 | IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(ag, scope, source_node); |
| 2067 | instruction->dest_ptr = dest_ptr; | 2067 | instruction->dest_ptr = dest_ptr; |
| 2068 | instruction->byte = byte; | 2068 | instruction->byte = byte; |
| 2069 | instruction->count = count; | 2069 | instruction->count = count; |
| 2070 | | 2070 | |
| 2071 | ir_ref_instruction(dest_ptr, irb->current_basic_block); | 2071 | ir_ref_instruction(dest_ptr, ag->current_basic_block); |
| 2072 | ir_ref_instruction(byte, irb->current_basic_block); | 2072 | ir_ref_instruction(byte, ag->current_basic_block); |
| 2073 | ir_ref_instruction(count, irb->current_basic_block); | 2073 | ir_ref_instruction(count, ag->current_basic_block); |
| 2074 | | 2074 | |
| 2075 | return &instruction->base; | 2075 | return &instruction->base; |
| 2076 | } | 2076 | } |
| 2077 | | 2077 | |
| 2078 | static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2078 | static IrInstSrc *ir_build_memcpy_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2079 | IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count) | 2079 | IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count) |
| 2080 | { | 2080 | { |
| 2081 | IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node); | 2081 | IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(ag, scope, source_node); |
| 2082 | instruction->dest_ptr = dest_ptr; | 2082 | instruction->dest_ptr = dest_ptr; |
| 2083 | instruction->src_ptr = src_ptr; | 2083 | instruction->src_ptr = src_ptr; |
| 2084 | instruction->count = count; | 2084 | instruction->count = count; |
| 2085 | | 2085 | |
| 2086 | ir_ref_instruction(dest_ptr, irb->current_basic_block); | 2086 | ir_ref_instruction(dest_ptr, ag->current_basic_block); |
| 2087 | ir_ref_instruction(src_ptr, irb->current_basic_block); | 2087 | ir_ref_instruction(src_ptr, ag->current_basic_block); |
| 2088 | ir_ref_instruction(count, irb->current_basic_block); | 2088 | ir_ref_instruction(count, ag->current_basic_block); |
| 2089 | | 2089 | |
| 2090 | return &instruction->base; | 2090 | return &instruction->base; |
| 2091 | } | 2091 | } |
| 2092 | | 2092 | |
| 2093 | static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2093 | static IrInstSrc *ir_build_slice_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2094 | IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel, | 2094 | IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel, |
| 2095 | bool safety_check_on, ResultLoc *result_loc) | 2095 | bool safety_check_on, ResultLoc *result_loc) |
| 2096 | { | 2096 | { |
| 2097 | IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node); | 2097 | IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(ag, scope, source_node); |
| 2098 | instruction->ptr = ptr; | 2098 | instruction->ptr = ptr; |
| 2099 | instruction->start = start; | 2099 | instruction->start = start; |
| 2100 | instruction->end = end; | 2100 | instruction->end = end; |
| ... | @@ -2102,150 +2102,150 @@ static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *s | ... | @@ -2102,150 +2102,150 @@ static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *s |
| 2102 | instruction->safety_check_on = safety_check_on; | 2102 | instruction->safety_check_on = safety_check_on; |
| 2103 | instruction->result_loc = result_loc; | 2103 | instruction->result_loc = result_loc; |
| 2104 | | 2104 | |
| 2105 | ir_ref_instruction(ptr, irb->current_basic_block); | 2105 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 2106 | ir_ref_instruction(start, irb->current_basic_block); | 2106 | ir_ref_instruction(start, ag->current_basic_block); |
| 2107 | if (end) ir_ref_instruction(end, irb->current_basic_block); | 2107 | if (end) ir_ref_instruction(end, ag->current_basic_block); |
| 2108 | if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block); | 2108 | if (sentinel) ir_ref_instruction(sentinel, ag->current_basic_block); |
| 2109 | | 2109 | |
| 2110 | return &instruction->base; | 2110 | return &instruction->base; |
| 2111 | } | 2111 | } |
| 2112 | | 2112 | |
| 2113 | static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2113 | static IrInstSrc *ir_build_breakpoint(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2114 | IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node); | 2114 | IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(ag, scope, source_node); |
| 2115 | return &instruction->base; | 2115 | return &instruction->base; |
| 2116 | } | 2116 | } |
| 2117 | | 2117 | |
| 2118 | static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2118 | static IrInstSrc *ir_build_return_address_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2119 | IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node); | 2119 | IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(ag, scope, source_node); |
| 2120 | return &instruction->base; | 2120 | return &instruction->base; |
| 2121 | } | 2121 | } |
| 2122 | | 2122 | |
| 2123 | static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2123 | static IrInstSrc *ir_build_frame_address_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2124 | IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node); | 2124 | IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(ag, scope, source_node); |
| 2125 | return &inst->base; | 2125 | return &inst->base; |
| 2126 | } | 2126 | } |
| 2127 | | 2127 | |
| 2128 | static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2128 | static IrInstSrc *ir_build_handle_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2129 | IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node); | 2129 | IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(ag, scope, source_node); |
| 2130 | return &inst->base; | 2130 | return &inst->base; |
| 2131 | } | 2131 | } |
| 2132 | | 2132 | |
| 2133 | static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { | 2133 | static IrInstSrc *ir_build_frame_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 2134 | IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node); | 2134 | IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(ag, scope, source_node); |
| 2135 | inst->fn = fn; | 2135 | inst->fn = fn; |
| 2136 | | 2136 | |
| 2137 | ir_ref_instruction(fn, irb->current_basic_block); | 2137 | ir_ref_instruction(fn, ag->current_basic_block); |
| 2138 | | 2138 | |
| 2139 | return &inst->base; | 2139 | return &inst->base; |
| 2140 | } | 2140 | } |
| 2141 | | 2141 | |
| 2142 | static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { | 2142 | static IrInstSrc *ir_build_frame_size_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 2143 | IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node); | 2143 | IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(ag, scope, source_node); |
| 2144 | inst->fn = fn; | 2144 | inst->fn = fn; |
| 2145 | | 2145 | |
| 2146 | ir_ref_instruction(fn, irb->current_basic_block); | 2146 | ir_ref_instruction(fn, ag->current_basic_block); |
| 2147 | | 2147 | |
| 2148 | return &inst->base; | 2148 | return &inst->base; |
| 2149 | } | 2149 | } |
| 2150 | | 2150 | |
| 2151 | static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2151 | static IrInstSrc *ir_build_overflow_op_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2152 | IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr) | 2152 | IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr) |
| 2153 | { | 2153 | { |
| 2154 | IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node); | 2154 | IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(ag, scope, source_node); |
| 2155 | instruction->op = op; | 2155 | instruction->op = op; |
| 2156 | instruction->type_value = type_value; | 2156 | instruction->type_value = type_value; |
| 2157 | instruction->op1 = op1; | 2157 | instruction->op1 = op1; |
| 2158 | instruction->op2 = op2; | 2158 | instruction->op2 = op2; |
| 2159 | instruction->result_ptr = result_ptr; | 2159 | instruction->result_ptr = result_ptr; |
| 2160 | | 2160 | |
| 2161 | ir_ref_instruction(type_value, irb->current_basic_block); | 2161 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2162 | ir_ref_instruction(op1, irb->current_basic_block); | 2162 | ir_ref_instruction(op1, ag->current_basic_block); |
| 2163 | ir_ref_instruction(op2, irb->current_basic_block); | 2163 | ir_ref_instruction(op2, ag->current_basic_block); |
| 2164 | ir_ref_instruction(result_ptr, irb->current_basic_block); | 2164 | ir_ref_instruction(result_ptr, ag->current_basic_block); |
| 2165 | | 2165 | |
| 2166 | return &instruction->base; | 2166 | return &instruction->base; |
| 2167 | } | 2167 | } |
| 2168 | | 2168 | |
| 2169 | static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand, | 2169 | static IrInstSrc *ir_build_float_op_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *operand, |
| 2170 | BuiltinFnId fn_id) | 2170 | BuiltinFnId fn_id) |
| 2171 | { | 2171 | { |
| 2172 | IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node); | 2172 | IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(ag, scope, source_node); |
| 2173 | instruction->operand = operand; | 2173 | instruction->operand = operand; |
| 2174 | instruction->fn_id = fn_id; | 2174 | instruction->fn_id = fn_id; |
| 2175 | | 2175 | |
| 2176 | ir_ref_instruction(operand, irb->current_basic_block); | 2176 | ir_ref_instruction(operand, ag->current_basic_block); |
| 2177 | | 2177 | |
| 2178 | return &instruction->base; | 2178 | return &instruction->base; |
| 2179 | } | 2179 | } |
| 2180 | | 2180 | |
| 2181 | static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2181 | static IrInstSrc *ir_build_mul_add_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2182 | IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3) | 2182 | IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3) |
| 2183 | { | 2183 | { |
| 2184 | IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node); | 2184 | IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(ag, scope, source_node); |
| 2185 | instruction->type_value = type_value; | 2185 | instruction->type_value = type_value; |
| 2186 | instruction->op1 = op1; | 2186 | instruction->op1 = op1; |
| 2187 | instruction->op2 = op2; | 2187 | instruction->op2 = op2; |
| 2188 | instruction->op3 = op3; | 2188 | instruction->op3 = op3; |
| 2189 | | 2189 | |
| 2190 | ir_ref_instruction(type_value, irb->current_basic_block); | 2190 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2191 | ir_ref_instruction(op1, irb->current_basic_block); | 2191 | ir_ref_instruction(op1, ag->current_basic_block); |
| 2192 | ir_ref_instruction(op2, irb->current_basic_block); | 2192 | ir_ref_instruction(op2, ag->current_basic_block); |
| 2193 | ir_ref_instruction(op3, irb->current_basic_block); | 2193 | ir_ref_instruction(op3, ag->current_basic_block); |
| 2194 | | 2194 | |
| 2195 | return &instruction->base; | 2195 | return &instruction->base; |
| 2196 | } | 2196 | } |
| 2197 | | 2197 | |
| 2198 | static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { | 2198 | static IrInstSrc *ir_build_align_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 2199 | IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node); | 2199 | IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(ag, scope, source_node); |
| 2200 | instruction->type_value = type_value; | 2200 | instruction->type_value = type_value; |
| 2201 | | 2201 | |
| 2202 | ir_ref_instruction(type_value, irb->current_basic_block); | 2202 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2203 | | 2203 | |
| 2204 | return &instruction->base; | 2204 | return &instruction->base; |
| 2205 | } | 2205 | } |
| 2206 | | 2206 | |
| 2207 | static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2207 | static IrInstSrc *ir_build_test_err_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2208 | IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload) | 2208 | IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload) |
| 2209 | { | 2209 | { |
| 2210 | IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node); | 2210 | IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(ag, scope, source_node); |
| 2211 | instruction->base_ptr = base_ptr; | 2211 | instruction->base_ptr = base_ptr; |
| 2212 | instruction->resolve_err_set = resolve_err_set; | 2212 | instruction->resolve_err_set = resolve_err_set; |
| 2213 | instruction->base_ptr_is_payload = base_ptr_is_payload; | 2213 | instruction->base_ptr_is_payload = base_ptr_is_payload; |
| 2214 | | 2214 | |
| 2215 | ir_ref_instruction(base_ptr, irb->current_basic_block); | 2215 | ir_ref_instruction(base_ptr, ag->current_basic_block); |
| 2216 | | 2216 | |
| 2217 | return &instruction->base; | 2217 | return &instruction->base; |
| 2218 | } | 2218 | } |
| 2219 | | 2219 | |
| 2220 | static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2220 | static IrInstSrc *ir_build_unwrap_err_code_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2221 | IrInstSrc *err_union_ptr) | 2221 | IrInstSrc *err_union_ptr) |
| 2222 | { | 2222 | { |
| 2223 | IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node); | 2223 | IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(ag, scope, source_node); |
| 2224 | inst->err_union_ptr = err_union_ptr; | 2224 | inst->err_union_ptr = err_union_ptr; |
| 2225 | | 2225 | |
| 2226 | ir_ref_instruction(err_union_ptr, irb->current_basic_block); | 2226 | ir_ref_instruction(err_union_ptr, ag->current_basic_block); |
| 2227 | | 2227 | |
| 2228 | return &inst->base; | 2228 | return &inst->base; |
| 2229 | } | 2229 | } |
| 2230 | | 2230 | |
| 2231 | static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2231 | static IrInstSrc *ir_build_unwrap_err_payload_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2232 | IrInstSrc *value, bool safety_check_on, bool initializing) | 2232 | IrInstSrc *value, bool safety_check_on, bool initializing) |
| 2233 | { | 2233 | { |
| 2234 | IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node); | 2234 | IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(ag, scope, source_node); |
| 2235 | inst->value = value; | 2235 | inst->value = value; |
| 2236 | inst->safety_check_on = safety_check_on; | 2236 | inst->safety_check_on = safety_check_on; |
| 2237 | inst->initializing = initializing; | 2237 | inst->initializing = initializing; |
| 2238 | | 2238 | |
| 2239 | ir_ref_instruction(value, irb->current_basic_block); | 2239 | ir_ref_instruction(value, ag->current_basic_block); |
| 2240 | | 2240 | |
| 2241 | return &inst->base; | 2241 | return &inst->base; |
| 2242 | } | 2242 | } |
| 2243 | | 2243 | |
| 2244 | static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2244 | static IrInstSrc *ir_build_fn_proto(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2245 | IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value, | 2245 | IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value, |
| 2246 | IrInstSrc *return_type, bool is_var_args) | 2246 | IrInstSrc *return_type, bool is_var_args) |
| 2247 | { | 2247 | { |
| 2248 | IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node); | 2248 | IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(ag, scope, source_node); |
| 2249 | instruction->param_types = param_types; | 2249 | instruction->param_types = param_types; |
| 2250 | instruction->align_value = align_value; | 2250 | instruction->align_value = align_value; |
| 2251 | instruction->callconv_value = callconv_value; | 2251 | instruction->callconv_value = callconv_value; |
| ... | @@ -2256,136 +2256,136 @@ static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *so | ... | @@ -2256,136 +2256,136 @@ static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *so |
| 2256 | size_t param_count = source_node->data.fn_proto.params.length; | 2256 | size_t param_count = source_node->data.fn_proto.params.length; |
| 2257 | if (is_var_args) param_count -= 1; | 2257 | if (is_var_args) param_count -= 1; |
| 2258 | for (size_t i = 0; i < param_count; i += 1) { | 2258 | for (size_t i = 0; i < param_count; i += 1) { |
| 2259 | if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block); | 2259 | if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], ag->current_basic_block); |
| 2260 | } | 2260 | } |
| 2261 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); | 2261 | if (align_value != nullptr) ir_ref_instruction(align_value, ag->current_basic_block); |
| 2262 | if (callconv_value != nullptr) ir_ref_instruction(callconv_value, irb->current_basic_block); | 2262 | if (callconv_value != nullptr) ir_ref_instruction(callconv_value, ag->current_basic_block); |
| 2263 | ir_ref_instruction(return_type, irb->current_basic_block); | 2263 | ir_ref_instruction(return_type, ag->current_basic_block); |
| 2264 | | 2264 | |
| 2265 | return &instruction->base; | 2265 | return &instruction->base; |
| 2266 | } | 2266 | } |
| 2267 | | 2267 | |
| 2268 | static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { | 2268 | static IrInstSrc *ir_build_test_comptime(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 2269 | IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node); | 2269 | IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(ag, scope, source_node); |
| 2270 | instruction->value = value; | 2270 | instruction->value = value; |
| 2271 | | 2271 | |
| 2272 | ir_ref_instruction(value, irb->current_basic_block); | 2272 | ir_ref_instruction(value, ag->current_basic_block); |
| 2273 | | 2273 | |
| 2274 | return &instruction->base; | 2274 | return &instruction->base; |
| 2275 | } | 2275 | } |
| 2276 | | 2276 | |
| 2277 | static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2277 | static IrInstSrc *ir_build_ptr_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2278 | IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on) | 2278 | IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on) |
| 2279 | { | 2279 | { |
| 2280 | IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>( | 2280 | IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>( |
| 2281 | irb, scope, source_node); | 2281 | ag, scope, source_node); |
| 2282 | instruction->dest_type = dest_type; | 2282 | instruction->dest_type = dest_type; |
| 2283 | instruction->ptr = ptr; | 2283 | instruction->ptr = ptr; |
| 2284 | instruction->safety_check_on = safety_check_on; | 2284 | instruction->safety_check_on = safety_check_on; |
| 2285 | | 2285 | |
| 2286 | ir_ref_instruction(dest_type, irb->current_basic_block); | 2286 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 2287 | ir_ref_instruction(ptr, irb->current_basic_block); | 2287 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 2288 | | 2288 | |
| 2289 | return &instruction->base; | 2289 | return &instruction->base; |
| 2290 | } | 2290 | } |
| 2291 | | 2291 | |
| 2292 | static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2292 | static IrInstSrc *ir_build_implicit_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2293 | IrInstSrc *operand, ResultLocCast *result_loc_cast) | 2293 | IrInstSrc *operand, ResultLocCast *result_loc_cast) |
| 2294 | { | 2294 | { |
| 2295 | IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node); | 2295 | IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(ag, scope, source_node); |
| 2296 | instruction->operand = operand; | 2296 | instruction->operand = operand; |
| 2297 | instruction->result_loc_cast = result_loc_cast; | 2297 | instruction->result_loc_cast = result_loc_cast; |
| 2298 | | 2298 | |
| 2299 | ir_ref_instruction(operand, irb->current_basic_block); | 2299 | ir_ref_instruction(operand, ag->current_basic_block); |
| 2300 | | 2300 | |
| 2301 | return &instruction->base; | 2301 | return &instruction->base; |
| 2302 | } | 2302 | } |
| 2303 | | 2303 | |
| 2304 | static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2304 | static IrInstSrc *ir_build_bit_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2305 | IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast) | 2305 | IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast) |
| 2306 | { | 2306 | { |
| 2307 | IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node); | 2307 | IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(ag, scope, source_node); |
| 2308 | instruction->operand = operand; | 2308 | instruction->operand = operand; |
| 2309 | instruction->result_loc_bit_cast = result_loc_bit_cast; | 2309 | instruction->result_loc_bit_cast = result_loc_bit_cast; |
| 2310 | | 2310 | |
| 2311 | ir_ref_instruction(operand, irb->current_basic_block); | 2311 | ir_ref_instruction(operand, ag->current_basic_block); |
| 2312 | | 2312 | |
| 2313 | return &instruction->base; | 2313 | return &instruction->base; |
| 2314 | } | 2314 | } |
| 2315 | | 2315 | |
| 2316 | static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2316 | static IrInstSrc *ir_build_int_to_ptr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2317 | IrInstSrc *dest_type, IrInstSrc *target) | 2317 | IrInstSrc *dest_type, IrInstSrc *target) |
| 2318 | { | 2318 | { |
| 2319 | IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node); | 2319 | IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(ag, scope, source_node); |
| 2320 | instruction->dest_type = dest_type; | 2320 | instruction->dest_type = dest_type; |
| 2321 | instruction->target = target; | 2321 | instruction->target = target; |
| 2322 | | 2322 | |
| 2323 | ir_ref_instruction(dest_type, irb->current_basic_block); | 2323 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 2324 | ir_ref_instruction(target, irb->current_basic_block); | 2324 | ir_ref_instruction(target, ag->current_basic_block); |
| 2325 | | 2325 | |
| 2326 | return &instruction->base; | 2326 | return &instruction->base; |
| 2327 | } | 2327 | } |
| 2328 | | 2328 | |
| 2329 | static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2329 | static IrInstSrc *ir_build_ptr_to_int_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2330 | IrInstSrc *target) | 2330 | IrInstSrc *target) |
| 2331 | { | 2331 | { |
| 2332 | IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node); | 2332 | IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(ag, scope, source_node); |
| 2333 | inst->target = target; | 2333 | inst->target = target; |
| 2334 | | 2334 | |
| 2335 | ir_ref_instruction(target, irb->current_basic_block); | 2335 | ir_ref_instruction(target, ag->current_basic_block); |
| 2336 | | 2336 | |
| 2337 | return &inst->base; | 2337 | return &inst->base; |
| 2338 | } | 2338 | } |
| 2339 | | 2339 | |
| 2340 | static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2340 | static IrInstSrc *ir_build_int_to_enum_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2341 | IrInstSrc *dest_type, IrInstSrc *target) | 2341 | IrInstSrc *dest_type, IrInstSrc *target) |
| 2342 | { | 2342 | { |
| 2343 | IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node); | 2343 | IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(ag, scope, source_node); |
| 2344 | instruction->dest_type = dest_type; | 2344 | instruction->dest_type = dest_type; |
| 2345 | instruction->target = target; | 2345 | instruction->target = target; |
| 2346 | | 2346 | |
| 2347 | if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block); | 2347 | if (dest_type) ir_ref_instruction(dest_type, ag->current_basic_block); |
| 2348 | ir_ref_instruction(target, irb->current_basic_block); | 2348 | ir_ref_instruction(target, ag->current_basic_block); |
| 2349 | | 2349 | |
| 2350 | return &instruction->base; | 2350 | return &instruction->base; |
| 2351 | } | 2351 | } |
| 2352 | | 2352 | |
| 2353 | static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2353 | static IrInstSrc *ir_build_enum_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2354 | IrInstSrc *target) | 2354 | IrInstSrc *target) |
| 2355 | { | 2355 | { |
| 2356 | IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>( | 2356 | IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>( |
| 2357 | irb, scope, source_node); | 2357 | ag, scope, source_node); |
| 2358 | instruction->target = target; | 2358 | instruction->target = target; |
| 2359 | | 2359 | |
| 2360 | ir_ref_instruction(target, irb->current_basic_block); | 2360 | ir_ref_instruction(target, ag->current_basic_block); |
| 2361 | | 2361 | |
| 2362 | return &instruction->base; | 2362 | return &instruction->base; |
| 2363 | } | 2363 | } |
| 2364 | | 2364 | |
| 2365 | static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2365 | static IrInstSrc *ir_build_int_to_err_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2366 | IrInstSrc *target) | 2366 | IrInstSrc *target) |
| 2367 | { | 2367 | { |
| 2368 | IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node); | 2368 | IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(ag, scope, source_node); |
| 2369 | instruction->target = target; | 2369 | instruction->target = target; |
| 2370 | | 2370 | |
| 2371 | ir_ref_instruction(target, irb->current_basic_block); | 2371 | ir_ref_instruction(target, ag->current_basic_block); |
| 2372 | | 2372 | |
| 2373 | return &instruction->base; | 2373 | return &instruction->base; |
| 2374 | } | 2374 | } |
| 2375 | | 2375 | |
| 2376 | static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2376 | static IrInstSrc *ir_build_err_to_int_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2377 | IrInstSrc *target) | 2377 | IrInstSrc *target) |
| 2378 | { | 2378 | { |
| 2379 | IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>( | 2379 | IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>( |
| 2380 | irb, scope, source_node); | 2380 | ag, scope, source_node); |
| 2381 | instruction->target = target; | 2381 | instruction->target = target; |
| 2382 | | 2382 | |
| 2383 | ir_ref_instruction(target, irb->current_basic_block); | 2383 | ir_ref_instruction(target, ag->current_basic_block); |
| 2384 | | 2384 | |
| 2385 | return &instruction->base; | 2385 | return &instruction->base; |
| 2386 | } | 2386 | } |
| 2387 | | 2387 | |
| 2388 | static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2388 | static IrInstSrc *ir_build_check_switch_prongs(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2389 | IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count, | 2389 | IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count, |
| 2390 | AstNode* else_prong, bool have_underscore_prong) | 2390 | AstNode* else_prong, bool have_underscore_prong) |
| 2391 | { | 2391 | { |
| ... | @@ -2394,192 +2394,192 @@ static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, | ... | @@ -2394,192 +2394,192 @@ static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, |
| 2394 | IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo; | 2394 | IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo; |
| 2395 | instruction->base.base.scope = scope; | 2395 | instruction->base.base.scope = scope; |
| 2396 | instruction->base.base.source_node = source_node; | 2396 | instruction->base.base.source_node = source_node; |
| 2397 | instruction->base.base.debug_id = irb_next_debug_id(irb); | 2397 | instruction->base.base.debug_id = irb_next_debug_id(ag); |
| 2398 | instruction->base.owner_bb = irb->current_basic_block; | 2398 | instruction->base.owner_bb = ag->current_basic_block; |
| 2399 | ir_instruction_append(irb->current_basic_block, &instruction->base); | 2399 | ir_instruction_append(ag->current_basic_block, &instruction->base); |
| 2400 | | 2400 | |
| 2401 | instruction->target_value = target_value; | 2401 | instruction->target_value = target_value; |
| 2402 | instruction->ranges = ranges; | 2402 | instruction->ranges = ranges; |
| 2403 | instruction->range_count = range_count; | 2403 | instruction->range_count = range_count; |
| 2404 | instruction->else_prong = else_prong; | 2404 | instruction->else_prong = else_prong; |
| 2405 | | 2405 | |
| 2406 | ir_ref_instruction(target_value, irb->current_basic_block); | 2406 | ir_ref_instruction(target_value, ag->current_basic_block); |
| 2407 | for (size_t i = 0; i < range_count; i += 1) { | 2407 | for (size_t i = 0; i < range_count; i += 1) { |
| 2408 | ir_ref_instruction(ranges[i].start, irb->current_basic_block); | 2408 | ir_ref_instruction(ranges[i].start, ag->current_basic_block); |
| 2409 | ir_ref_instruction(ranges[i].end, irb->current_basic_block); | 2409 | ir_ref_instruction(ranges[i].end, ag->current_basic_block); |
| 2410 | } | 2410 | } |
| 2411 | | 2411 | |
| 2412 | return &instruction->base; | 2412 | return &instruction->base; |
| 2413 | } | 2413 | } |
| 2414 | | 2414 | |
| 2415 | static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2415 | static IrInstSrc *ir_build_check_statement_is_void(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2416 | IrInstSrc* statement_value) | 2416 | IrInstSrc* statement_value) |
| 2417 | { | 2417 | { |
| 2418 | IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>( | 2418 | IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>( |
| 2419 | irb, scope, source_node); | 2419 | ag, scope, source_node); |
| 2420 | instruction->statement_value = statement_value; | 2420 | instruction->statement_value = statement_value; |
| 2421 | | 2421 | |
| 2422 | ir_ref_instruction(statement_value, irb->current_basic_block); | 2422 | ir_ref_instruction(statement_value, ag->current_basic_block); |
| 2423 | | 2423 | |
| 2424 | return &instruction->base; | 2424 | return &instruction->base; |
| 2425 | } | 2425 | } |
| 2426 | | 2426 | |
| 2427 | static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2427 | static IrInstSrc *ir_build_type_name(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2428 | IrInstSrc *type_value) | 2428 | IrInstSrc *type_value) |
| 2429 | { | 2429 | { |
| 2430 | IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node); | 2430 | IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(ag, scope, source_node); |
| 2431 | instruction->type_value = type_value; | 2431 | instruction->type_value = type_value; |
| 2432 | | 2432 | |
| 2433 | ir_ref_instruction(type_value, irb->current_basic_block); | 2433 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2434 | | 2434 | |
| 2435 | return &instruction->base; | 2435 | return &instruction->base; |
| 2436 | } | 2436 | } |
| 2437 | | 2437 | |
| 2438 | static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { | 2438 | static IrInstSrc *ir_build_decl_ref(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { |
| 2439 | IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node); | 2439 | IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(ag, scope, source_node); |
| 2440 | instruction->tld = tld; | 2440 | instruction->tld = tld; |
| 2441 | instruction->lval = lval; | 2441 | instruction->lval = lval; |
| 2442 | | 2442 | |
| 2443 | return &instruction->base; | 2443 | return &instruction->base; |
| 2444 | } | 2444 | } |
| 2445 | | 2445 | |
| 2446 | static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { | 2446 | static IrInstSrc *ir_build_panic_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 2447 | IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node); | 2447 | IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(ag, scope, source_node); |
| 2448 | instruction->base.is_noreturn = true; | 2448 | instruction->base.is_noreturn = true; |
| 2449 | instruction->msg = msg; | 2449 | instruction->msg = msg; |
| 2450 | | 2450 | |
| 2451 | ir_ref_instruction(msg, irb->current_basic_block); | 2451 | ir_ref_instruction(msg, ag->current_basic_block); |
| 2452 | | 2452 | |
| 2453 | return &instruction->base; | 2453 | return &instruction->base; |
| 2454 | } | 2454 | } |
| 2455 | | 2455 | |
| 2456 | static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { | 2456 | static IrInstSrc *ir_build_tag_name_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 2457 | IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node); | 2457 | IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(ag, scope, source_node); |
| 2458 | instruction->target = target; | 2458 | instruction->target = target; |
| 2459 | | 2459 | |
| 2460 | ir_ref_instruction(target, irb->current_basic_block); | 2460 | ir_ref_instruction(target, ag->current_basic_block); |
| 2461 | | 2461 | |
| 2462 | return &instruction->base; | 2462 | return &instruction->base; |
| 2463 | } | 2463 | } |
| 2464 | | 2464 | |
| 2465 | static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2465 | static IrInstSrc *ir_build_field_parent_ptr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2466 | IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr) | 2466 | IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr) |
| 2467 | { | 2467 | { |
| 2468 | IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>( | 2468 | IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>( |
| 2469 | irb, scope, source_node); | 2469 | ag, scope, source_node); |
| 2470 | inst->type_value = type_value; | 2470 | inst->type_value = type_value; |
| 2471 | inst->field_name = field_name; | 2471 | inst->field_name = field_name; |
| 2472 | inst->field_ptr = field_ptr; | 2472 | inst->field_ptr = field_ptr; |
| 2473 | | 2473 | |
| 2474 | ir_ref_instruction(type_value, irb->current_basic_block); | 2474 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2475 | ir_ref_instruction(field_name, irb->current_basic_block); | 2475 | ir_ref_instruction(field_name, ag->current_basic_block); |
| 2476 | ir_ref_instruction(field_ptr, irb->current_basic_block); | 2476 | ir_ref_instruction(field_ptr, ag->current_basic_block); |
| 2477 | | 2477 | |
| 2478 | return &inst->base; | 2478 | return &inst->base; |
| 2479 | } | 2479 | } |
| 2480 | | 2480 | |
| 2481 | static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2481 | static IrInstSrc *ir_build_byte_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2482 | IrInstSrc *type_value, IrInstSrc *field_name) | 2482 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 2483 | { | 2483 | { |
| 2484 | IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node); | 2484 | IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(ag, scope, source_node); |
| 2485 | instruction->type_value = type_value; | 2485 | instruction->type_value = type_value; |
| 2486 | instruction->field_name = field_name; | 2486 | instruction->field_name = field_name; |
| 2487 | | 2487 | |
| 2488 | ir_ref_instruction(type_value, irb->current_basic_block); | 2488 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2489 | ir_ref_instruction(field_name, irb->current_basic_block); | 2489 | ir_ref_instruction(field_name, ag->current_basic_block); |
| 2490 | | 2490 | |
| 2491 | return &instruction->base; | 2491 | return &instruction->base; |
| 2492 | } | 2492 | } |
| 2493 | | 2493 | |
| 2494 | static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2494 | static IrInstSrc *ir_build_bit_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2495 | IrInstSrc *type_value, IrInstSrc *field_name) | 2495 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 2496 | { | 2496 | { |
| 2497 | IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node); | 2497 | IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(ag, scope, source_node); |
| 2498 | instruction->type_value = type_value; | 2498 | instruction->type_value = type_value; |
| 2499 | instruction->field_name = field_name; | 2499 | instruction->field_name = field_name; |
| 2500 | | 2500 | |
| 2501 | ir_ref_instruction(type_value, irb->current_basic_block); | 2501 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2502 | ir_ref_instruction(field_name, irb->current_basic_block); | 2502 | ir_ref_instruction(field_name, ag->current_basic_block); |
| 2503 | | 2503 | |
| 2504 | return &instruction->base; | 2504 | return &instruction->base; |
| 2505 | } | 2505 | } |
| 2506 | | 2506 | |
| 2507 | static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { | 2507 | static IrInstSrc *ir_build_type_info(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 2508 | IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node); | 2508 | IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(ag, scope, source_node); |
| 2509 | instruction->type_value = type_value; | 2509 | instruction->type_value = type_value; |
| 2510 | | 2510 | |
| 2511 | ir_ref_instruction(type_value, irb->current_basic_block); | 2511 | ir_ref_instruction(type_value, ag->current_basic_block); |
| 2512 | | 2512 | |
| 2513 | return &instruction->base; | 2513 | return &instruction->base; |
| 2514 | } | 2514 | } |
| 2515 | | 2515 | |
| 2516 | static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) { | 2516 | static IrInstSrc *ir_build_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_info) { |
| 2517 | IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node); | 2517 | IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(ag, scope, source_node); |
| 2518 | instruction->type_info = type_info; | 2518 | instruction->type_info = type_info; |
| 2519 | | 2519 | |
| 2520 | ir_ref_instruction(type_info, irb->current_basic_block); | 2520 | ir_ref_instruction(type_info, ag->current_basic_block); |
| 2521 | | 2521 | |
| 2522 | return &instruction->base; | 2522 | return &instruction->base; |
| 2523 | } | 2523 | } |
| 2524 | | 2524 | |
| 2525 | static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2525 | static IrInstSrc *ir_build_set_eval_branch_quota(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2526 | IrInstSrc *new_quota) | 2526 | IrInstSrc *new_quota) |
| 2527 | { | 2527 | { |
| 2528 | IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node); | 2528 | IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(ag, scope, source_node); |
| 2529 | instruction->new_quota = new_quota; | 2529 | instruction->new_quota = new_quota; |
| 2530 | | 2530 | |
| 2531 | ir_ref_instruction(new_quota, irb->current_basic_block); | 2531 | ir_ref_instruction(new_quota, ag->current_basic_block); |
| 2532 | | 2532 | |
| 2533 | return &instruction->base; | 2533 | return &instruction->base; |
| 2534 | } | 2534 | } |
| 2535 | | 2535 | |
| 2536 | static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2536 | static IrInstSrc *ir_build_align_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2537 | IrInstSrc *align_bytes, IrInstSrc *target) | 2537 | IrInstSrc *align_bytes, IrInstSrc *target) |
| 2538 | { | 2538 | { |
| 2539 | IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node); | 2539 | IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(ag, scope, source_node); |
| 2540 | instruction->align_bytes = align_bytes; | 2540 | instruction->align_bytes = align_bytes; |
| 2541 | instruction->target = target; | 2541 | instruction->target = target; |
| 2542 | | 2542 | |
| 2543 | ir_ref_instruction(align_bytes, irb->current_basic_block); | 2543 | ir_ref_instruction(align_bytes, ag->current_basic_block); |
| 2544 | ir_ref_instruction(target, irb->current_basic_block); | 2544 | ir_ref_instruction(target, ag->current_basic_block); |
| 2545 | | 2545 | |
| 2546 | return &instruction->base; | 2546 | return &instruction->base; |
| 2547 | } | 2547 | } |
| 2548 | | 2548 | |
| 2549 | static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2549 | static IrInstSrc *ir_build_resolve_result(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2550 | ResultLoc *result_loc, IrInstSrc *ty) | 2550 | ResultLoc *result_loc, IrInstSrc *ty) |
| 2551 | { | 2551 | { |
| 2552 | IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node); | 2552 | IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(ag, scope, source_node); |
| 2553 | instruction->result_loc = result_loc; | 2553 | instruction->result_loc = result_loc; |
| 2554 | instruction->ty = ty; | 2554 | instruction->ty = ty; |
| 2555 | | 2555 | |
| 2556 | if (ty != nullptr) ir_ref_instruction(ty, irb->current_basic_block); | 2556 | if (ty != nullptr) ir_ref_instruction(ty, ag->current_basic_block); |
| 2557 | | 2557 | |
| 2558 | return &instruction->base; | 2558 | return &instruction->base; |
| 2559 | } | 2559 | } |
| 2560 | | 2560 | |
| 2561 | static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2561 | static IrInstSrc *ir_build_reset_result(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2562 | ResultLoc *result_loc) | 2562 | ResultLoc *result_loc) |
| 2563 | { | 2563 | { |
| 2564 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node); | 2564 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(ag, scope, source_node); |
| 2565 | instruction->result_loc = result_loc; | 2565 | instruction->result_loc = result_loc; |
| 2566 | instruction->base.is_gen = true; | 2566 | instruction->base.is_gen = true; |
| 2567 | | 2567 | |
| 2568 | return &instruction->base; | 2568 | return &instruction->base; |
| 2569 | } | 2569 | } |
| 2570 | | 2570 | |
| 2571 | static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2571 | static IrInstSrc *ir_build_set_align_stack(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2572 | IrInstSrc *align_bytes) | 2572 | IrInstSrc *align_bytes) |
| 2573 | { | 2573 | { |
| 2574 | IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node); | 2574 | IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(ag, scope, source_node); |
| 2575 | instruction->align_bytes = align_bytes; | 2575 | instruction->align_bytes = align_bytes; |
| 2576 | | 2576 | |
| 2577 | ir_ref_instruction(align_bytes, irb->current_basic_block); | 2577 | ir_ref_instruction(align_bytes, ag->current_basic_block); |
| 2578 | | 2578 | |
| 2579 | return &instruction->base; | 2579 | return &instruction->base; |
| 2580 | } | 2580 | } |
| 2581 | | 2581 | |
| 2582 | static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2582 | static IrInstSrc *ir_build_arg_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2583 | IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var) | 2583 | IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var) |
| 2584 | { | 2584 | { |
| 2585 | IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>(); | 2585 | IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>(); |
| ... | @@ -2587,273 +2587,273 @@ static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *so | ... | @@ -2587,273 +2587,273 @@ static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *so |
| 2587 | IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse; | 2587 | IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse; |
| 2588 | instruction->base.base.scope = scope; | 2588 | instruction->base.base.scope = scope; |
| 2589 | instruction->base.base.source_node = source_node; | 2589 | instruction->base.base.source_node = source_node; |
| 2590 | instruction->base.base.debug_id = irb_next_debug_id(irb); | 2590 | instruction->base.base.debug_id = irb_next_debug_id(ag); |
| 2591 | instruction->base.owner_bb = irb->current_basic_block; | 2591 | instruction->base.owner_bb = ag->current_basic_block; |
| 2592 | ir_instruction_append(irb->current_basic_block, &instruction->base); | 2592 | ir_instruction_append(ag->current_basic_block, &instruction->base); |
| 2593 | | 2593 | |
| 2594 | instruction->fn_type = fn_type; | 2594 | instruction->fn_type = fn_type; |
| 2595 | instruction->arg_index = arg_index; | 2595 | instruction->arg_index = arg_index; |
| 2596 | | 2596 | |
| 2597 | ir_ref_instruction(fn_type, irb->current_basic_block); | 2597 | ir_ref_instruction(fn_type, ag->current_basic_block); |
| 2598 | ir_ref_instruction(arg_index, irb->current_basic_block); | 2598 | ir_ref_instruction(arg_index, ag->current_basic_block); |
| 2599 | | 2599 | |
| 2600 | return &instruction->base; | 2600 | return &instruction->base; |
| 2601 | } | 2601 | } |
| 2602 | | 2602 | |
| 2603 | static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2603 | static IrInstSrc *ir_build_error_return_trace_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2604 | IrInstErrorReturnTraceOptional optional) | 2604 | IrInstErrorReturnTraceOptional optional) |
| 2605 | { | 2605 | { |
| 2606 | IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node); | 2606 | IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(ag, scope, source_node); |
| 2607 | inst->optional = optional; | 2607 | inst->optional = optional; |
| 2608 | | 2608 | |
| 2609 | return &inst->base; | 2609 | return &inst->base; |
| 2610 | } | 2610 | } |
| 2611 | | 2611 | |
| 2612 | static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2612 | static IrInstSrc *ir_build_error_union(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2613 | IrInstSrc *err_set, IrInstSrc *payload) | 2613 | IrInstSrc *err_set, IrInstSrc *payload) |
| 2614 | { | 2614 | { |
| 2615 | IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node); | 2615 | IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(ag, scope, source_node); |
| 2616 | instruction->err_set = err_set; | 2616 | instruction->err_set = err_set; |
| 2617 | instruction->payload = payload; | 2617 | instruction->payload = payload; |
| 2618 | | 2618 | |
| 2619 | ir_ref_instruction(err_set, irb->current_basic_block); | 2619 | ir_ref_instruction(err_set, ag->current_basic_block); |
| 2620 | ir_ref_instruction(payload, irb->current_basic_block); | 2620 | ir_ref_instruction(payload, ag->current_basic_block); |
| 2621 | | 2621 | |
| 2622 | return &instruction->base; | 2622 | return &instruction->base; |
| 2623 | } | 2623 | } |
| 2624 | | 2624 | |
| 2625 | static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2625 | static IrInstSrc *ir_build_atomic_rmw_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2626 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand, | 2626 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand, |
| 2627 | IrInstSrc *ordering) | 2627 | IrInstSrc *ordering) |
| 2628 | { | 2628 | { |
| 2629 | IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node); | 2629 | IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(ag, scope, source_node); |
| 2630 | instruction->operand_type = operand_type; | 2630 | instruction->operand_type = operand_type; |
| 2631 | instruction->ptr = ptr; | 2631 | instruction->ptr = ptr; |
| 2632 | instruction->op = op; | 2632 | instruction->op = op; |
| 2633 | instruction->operand = operand; | 2633 | instruction->operand = operand; |
| 2634 | instruction->ordering = ordering; | 2634 | instruction->ordering = ordering; |
| 2635 | | 2635 | |
| 2636 | ir_ref_instruction(operand_type, irb->current_basic_block); | 2636 | ir_ref_instruction(operand_type, ag->current_basic_block); |
| 2637 | ir_ref_instruction(ptr, irb->current_basic_block); | 2637 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 2638 | ir_ref_instruction(op, irb->current_basic_block); | 2638 | ir_ref_instruction(op, ag->current_basic_block); |
| 2639 | ir_ref_instruction(operand, irb->current_basic_block); | 2639 | ir_ref_instruction(operand, ag->current_basic_block); |
| 2640 | ir_ref_instruction(ordering, irb->current_basic_block); | 2640 | ir_ref_instruction(ordering, ag->current_basic_block); |
| 2641 | | 2641 | |
| 2642 | return &instruction->base; | 2642 | return &instruction->base; |
| 2643 | } | 2643 | } |
| 2644 | | 2644 | |
| 2645 | static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2645 | static IrInstSrc *ir_build_atomic_load_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2646 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering) | 2646 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering) |
| 2647 | { | 2647 | { |
| 2648 | IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node); | 2648 | IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(ag, scope, source_node); |
| 2649 | instruction->operand_type = operand_type; | 2649 | instruction->operand_type = operand_type; |
| 2650 | instruction->ptr = ptr; | 2650 | instruction->ptr = ptr; |
| 2651 | instruction->ordering = ordering; | 2651 | instruction->ordering = ordering; |
| 2652 | | 2652 | |
| 2653 | ir_ref_instruction(operand_type, irb->current_basic_block); | 2653 | ir_ref_instruction(operand_type, ag->current_basic_block); |
| 2654 | ir_ref_instruction(ptr, irb->current_basic_block); | 2654 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 2655 | ir_ref_instruction(ordering, irb->current_basic_block); | 2655 | ir_ref_instruction(ordering, ag->current_basic_block); |
| 2656 | | 2656 | |
| 2657 | return &instruction->base; | 2657 | return &instruction->base; |
| 2658 | } | 2658 | } |
| 2659 | | 2659 | |
| 2660 | static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2660 | static IrInstSrc *ir_build_atomic_store_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2661 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering) | 2661 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering) |
| 2662 | { | 2662 | { |
| 2663 | IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node); | 2663 | IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(ag, scope, source_node); |
| 2664 | instruction->operand_type = operand_type; | 2664 | instruction->operand_type = operand_type; |
| 2665 | instruction->ptr = ptr; | 2665 | instruction->ptr = ptr; |
| 2666 | instruction->value = value; | 2666 | instruction->value = value; |
| 2667 | instruction->ordering = ordering; | 2667 | instruction->ordering = ordering; |
| 2668 | | 2668 | |
| 2669 | ir_ref_instruction(operand_type, irb->current_basic_block); | 2669 | ir_ref_instruction(operand_type, ag->current_basic_block); |
| 2670 | ir_ref_instruction(ptr, irb->current_basic_block); | 2670 | ir_ref_instruction(ptr, ag->current_basic_block); |
| 2671 | ir_ref_instruction(value, irb->current_basic_block); | 2671 | ir_ref_instruction(value, ag->current_basic_block); |
| 2672 | ir_ref_instruction(ordering, irb->current_basic_block); | 2672 | ir_ref_instruction(ordering, ag->current_basic_block); |
| 2673 | | 2673 | |
| 2674 | return &instruction->base; | 2674 | return &instruction->base; |
| 2675 | } | 2675 | } |
| 2676 | | 2676 | |
| 2677 | static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2677 | static IrInstSrc *ir_build_save_err_ret_addr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2678 | IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node); | 2678 | IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(ag, scope, source_node); |
| 2679 | return &inst->base; | 2679 | return &inst->base; |
| 2680 | } | 2680 | } |
| 2681 | | 2681 | |
| 2682 | static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2682 | static IrInstSrc *ir_build_add_implicit_return_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2683 | IrInstSrc *value, ResultLocReturn *result_loc_ret) | 2683 | IrInstSrc *value, ResultLocReturn *result_loc_ret) |
| 2684 | { | 2684 | { |
| 2685 | IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node); | 2685 | IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(ag, scope, source_node); |
| 2686 | inst->value = value; | 2686 | inst->value = value; |
| 2687 | inst->result_loc_ret = result_loc_ret; | 2687 | inst->result_loc_ret = result_loc_ret; |
| 2688 | | 2688 | |
| 2689 | ir_ref_instruction(value, irb->current_basic_block); | 2689 | ir_ref_instruction(value, ag->current_basic_block); |
| 2690 | | 2690 | |
| 2691 | return &inst->base; | 2691 | return &inst->base; |
| 2692 | } | 2692 | } |
| 2693 | | 2693 | |
| 2694 | static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2694 | static IrInstSrc *ir_build_has_decl(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2695 | IrInstSrc *container, IrInstSrc *name) | 2695 | IrInstSrc *container, IrInstSrc *name) |
| 2696 | { | 2696 | { |
| 2697 | IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node); | 2697 | IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(ag, scope, source_node); |
| 2698 | instruction->container = container; | 2698 | instruction->container = container; |
| 2699 | instruction->name = name; | 2699 | instruction->name = name; |
| 2700 | | 2700 | |
| 2701 | ir_ref_instruction(container, irb->current_basic_block); | 2701 | ir_ref_instruction(container, ag->current_basic_block); |
| 2702 | ir_ref_instruction(name, irb->current_basic_block); | 2702 | ir_ref_instruction(name, ag->current_basic_block); |
| 2703 | | 2703 | |
| 2704 | return &instruction->base; | 2704 | return &instruction->base; |
| 2705 | } | 2705 | } |
| 2706 | | 2706 | |
| 2707 | static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { | 2707 | static IrInstSrc *ir_build_undeclared_identifier(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *name) { |
| 2708 | IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node); | 2708 | IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(ag, scope, source_node); |
| 2709 | instruction->name = name; | 2709 | instruction->name = name; |
| 2710 | | 2710 | |
| 2711 | return &instruction->base; | 2711 | return &instruction->base; |
| 2712 | } | 2712 | } |
| 2713 | | 2713 | |
| 2714 | static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) { | 2714 | static IrInstSrc *ir_build_check_runtime_scope(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) { |
| 2715 | IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node); | 2715 | IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(ag, scope, source_node); |
| 2716 | instruction->scope_is_comptime = scope_is_comptime; | 2716 | instruction->scope_is_comptime = scope_is_comptime; |
| 2717 | instruction->is_comptime = is_comptime; | 2717 | instruction->is_comptime = is_comptime; |
| 2718 | | 2718 | |
| 2719 | ir_ref_instruction(scope_is_comptime, irb->current_basic_block); | 2719 | ir_ref_instruction(scope_is_comptime, ag->current_basic_block); |
| 2720 | ir_ref_instruction(is_comptime, irb->current_basic_block); | 2720 | ir_ref_instruction(is_comptime, ag->current_basic_block); |
| 2721 | | 2721 | |
| 2722 | return &instruction->base; | 2722 | return &instruction->base; |
| 2723 | } | 2723 | } |
| 2724 | | 2724 | |
| 2725 | static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2725 | static IrInstSrc *ir_build_union_init_named_field(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2726 | IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc) | 2726 | IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc) |
| 2727 | { | 2727 | { |
| 2728 | IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node); | 2728 | IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(ag, scope, source_node); |
| 2729 | instruction->union_type = union_type; | 2729 | instruction->union_type = union_type; |
| 2730 | instruction->field_name = field_name; | 2730 | instruction->field_name = field_name; |
| 2731 | instruction->field_result_loc = field_result_loc; | 2731 | instruction->field_result_loc = field_result_loc; |
| 2732 | instruction->result_loc = result_loc; | 2732 | instruction->result_loc = result_loc; |
| 2733 | | 2733 | |
| 2734 | ir_ref_instruction(union_type, irb->current_basic_block); | 2734 | ir_ref_instruction(union_type, ag->current_basic_block); |
| 2735 | ir_ref_instruction(field_name, irb->current_basic_block); | 2735 | ir_ref_instruction(field_name, ag->current_basic_block); |
| 2736 | ir_ref_instruction(field_result_loc, irb->current_basic_block); | 2736 | ir_ref_instruction(field_result_loc, ag->current_basic_block); |
| 2737 | if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block); | 2737 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ag->current_basic_block); |
| 2738 | | 2738 | |
| 2739 | return &instruction->base; | 2739 | return &instruction->base; |
| 2740 | } | 2740 | } |
| 2741 | | 2741 | |
| 2742 | static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2742 | static IrInstSrc *ir_build_alloca_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2743 | IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime) | 2743 | IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime) |
| 2744 | { | 2744 | { |
| 2745 | IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node); | 2745 | IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(ag, scope, source_node); |
| 2746 | instruction->base.is_gen = true; | 2746 | instruction->base.is_gen = true; |
| 2747 | instruction->align = align; | 2747 | instruction->align = align; |
| 2748 | instruction->name_hint = name_hint; | 2748 | instruction->name_hint = name_hint; |
| 2749 | instruction->is_comptime = is_comptime; | 2749 | instruction->is_comptime = is_comptime; |
| 2750 | | 2750 | |
| 2751 | if (align != nullptr) ir_ref_instruction(align, irb->current_basic_block); | 2751 | if (align != nullptr) ir_ref_instruction(align, ag->current_basic_block); |
| 2752 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block); | 2752 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, ag->current_basic_block); |
| 2753 | | 2753 | |
| 2754 | return &instruction->base; | 2754 | return &instruction->base; |
| 2755 | } | 2755 | } |
| 2756 | | 2756 | |
| 2757 | static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2757 | static IrInstSrc *ir_build_end_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2758 | IrInstSrc *value, ResultLoc *result_loc) | 2758 | IrInstSrc *value, ResultLoc *result_loc) |
| 2759 | { | 2759 | { |
| 2760 | IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node); | 2760 | IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(ag, scope, source_node); |
| 2761 | instruction->base.is_gen = true; | 2761 | instruction->base.is_gen = true; |
| 2762 | instruction->value = value; | 2762 | instruction->value = value; |
| 2763 | instruction->result_loc = result_loc; | 2763 | instruction->result_loc = result_loc; |
| 2764 | | 2764 | |
| 2765 | ir_ref_instruction(value, irb->current_basic_block); | 2765 | ir_ref_instruction(value, ag->current_basic_block); |
| 2766 | | 2766 | |
| 2767 | return &instruction->base; | 2767 | return &instruction->base; |
| 2768 | } | 2768 | } |
| 2769 | | 2769 | |
| 2770 | static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2770 | static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2771 | return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node); | 2771 | return ir_build_instruction<IrInstSrcSuspendBegin>(ag, scope, source_node); |
| 2772 | } | 2772 | } |
| 2773 | | 2773 | |
| 2774 | static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2774 | static IrInstSrc *ir_build_suspend_finish_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2775 | IrInstSrcSuspendBegin *begin) | 2775 | IrInstSrcSuspendBegin *begin) |
| 2776 | { | 2776 | { |
| 2777 | IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node); | 2777 | IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(ag, scope, source_node); |
| 2778 | inst->begin = begin; | 2778 | inst->begin = begin; |
| 2779 | | 2779 | |
| 2780 | ir_ref_instruction(&begin->base, irb->current_basic_block); | 2780 | ir_ref_instruction(&begin->base, ag->current_basic_block); |
| 2781 | | 2781 | |
| 2782 | return &inst->base; | 2782 | return &inst->base; |
| 2783 | } | 2783 | } |
| 2784 | | 2784 | |
| 2785 | static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2785 | static IrInstSrc *ir_build_await_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2786 | IrInstSrc *frame, ResultLoc *result_loc, bool is_nosuspend) | 2786 | IrInstSrc *frame, ResultLoc *result_loc, bool is_nosuspend) |
| 2787 | { | 2787 | { |
| 2788 | IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node); | 2788 | IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(ag, scope, source_node); |
| 2789 | instruction->frame = frame; | 2789 | instruction->frame = frame; |
| 2790 | instruction->result_loc = result_loc; | 2790 | instruction->result_loc = result_loc; |
| 2791 | instruction->is_nosuspend = is_nosuspend; | 2791 | instruction->is_nosuspend = is_nosuspend; |
| 2792 | | 2792 | |
| 2793 | ir_ref_instruction(frame, irb->current_basic_block); | 2793 | ir_ref_instruction(frame, ag->current_basic_block); |
| 2794 | | 2794 | |
| 2795 | return &instruction->base; | 2795 | return &instruction->base; |
| 2796 | } | 2796 | } |
| 2797 | | 2797 | |
| 2798 | static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) { | 2798 | static IrInstSrc *ir_build_resume_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *frame) { |
| 2799 | IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node); | 2799 | IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(ag, scope, source_node); |
| 2800 | instruction->frame = frame; | 2800 | instruction->frame = frame; |
| 2801 | | 2801 | |
| 2802 | ir_ref_instruction(frame, irb->current_basic_block); | 2802 | ir_ref_instruction(frame, ag->current_basic_block); |
| 2803 | | 2803 | |
| 2804 | return &instruction->base; | 2804 | return &instruction->base; |
| 2805 | } | 2805 | } |
| 2806 | | 2806 | |
| 2807 | static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2807 | static IrInstSrcSpillBegin *ir_build_spill_begin_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2808 | IrInstSrc *operand, SpillId spill_id) | 2808 | IrInstSrc *operand, SpillId spill_id) |
| 2809 | { | 2809 | { |
| 2810 | IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node); | 2810 | IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(ag, scope, source_node); |
| 2811 | instruction->operand = operand; | 2811 | instruction->operand = operand; |
| 2812 | instruction->spill_id = spill_id; | 2812 | instruction->spill_id = spill_id; |
| 2813 | | 2813 | |
| 2814 | ir_ref_instruction(operand, irb->current_basic_block); | 2814 | ir_ref_instruction(operand, ag->current_basic_block); |
| 2815 | | 2815 | |
| 2816 | return instruction; | 2816 | return instruction; |
| 2817 | } | 2817 | } |
| 2818 | | 2818 | |
| 2819 | static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 2819 | static IrInstSrc *ir_build_spill_end_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 2820 | IrInstSrcSpillBegin *begin) | 2820 | IrInstSrcSpillBegin *begin) |
| 2821 | { | 2821 | { |
| 2822 | IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node); | 2822 | IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(ag, scope, source_node); |
| 2823 | instruction->begin = begin; | 2823 | instruction->begin = begin; |
| 2824 | | 2824 | |
| 2825 | ir_ref_instruction(&begin->base, irb->current_basic_block); | 2825 | ir_ref_instruction(&begin->base, ag->current_basic_block); |
| 2826 | | 2826 | |
| 2827 | return &instruction->base; | 2827 | return &instruction->base; |
| 2828 | } | 2828 | } |
| 2829 | | 2829 | |
| 2830 | static IrInstSrc *ir_build_wasm_memory_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *index) { | 2830 | static IrInstSrc *ir_build_wasm_memory_size_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *index) { |
| 2831 | IrInstSrcWasmMemorySize *instruction = ir_build_instruction<IrInstSrcWasmMemorySize>(irb, scope, source_node); | 2831 | IrInstSrcWasmMemorySize *instruction = ir_build_instruction<IrInstSrcWasmMemorySize>(ag, scope, source_node); |
| 2832 | instruction->index = index; | 2832 | instruction->index = index; |
| 2833 | | 2833 | |
| 2834 | ir_ref_instruction(index, irb->current_basic_block); | 2834 | ir_ref_instruction(index, ag->current_basic_block); |
| 2835 | | 2835 | |
| 2836 | return &instruction->base; | 2836 | return &instruction->base; |
| 2837 | } | 2837 | } |
| 2838 | | 2838 | |
| 2839 | static IrInstSrc *ir_build_wasm_memory_grow_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *index, IrInstSrc *delta) { | 2839 | static IrInstSrc *ir_build_wasm_memory_grow_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *index, IrInstSrc *delta) { |
| 2840 | IrInstSrcWasmMemoryGrow *instruction = ir_build_instruction<IrInstSrcWasmMemoryGrow>(irb, scope, source_node); | 2840 | IrInstSrcWasmMemoryGrow *instruction = ir_build_instruction<IrInstSrcWasmMemoryGrow>(ag, scope, source_node); |
| 2841 | instruction->index = index; | 2841 | instruction->index = index; |
| 2842 | instruction->delta = delta; | 2842 | instruction->delta = delta; |
| 2843 | | 2843 | |
| 2844 | ir_ref_instruction(index, irb->current_basic_block); | 2844 | ir_ref_instruction(index, ag->current_basic_block); |
| 2845 | ir_ref_instruction(delta, irb->current_basic_block); | 2845 | ir_ref_instruction(delta, ag->current_basic_block); |
| 2846 | | 2846 | |
| 2847 | return &instruction->base; | 2847 | return &instruction->base; |
| 2848 | } | 2848 | } |
| 2849 | | 2849 | |
| 2850 | static IrInstSrc *ir_build_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { | 2850 | static IrInstSrc *ir_build_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) { |
| 2851 | IrInstSrcSrc *instruction = ir_build_instruction<IrInstSrcSrc>(irb, scope, source_node); | 2851 | IrInstSrcSrc *instruction = ir_build_instruction<IrInstSrcSrc>(ag, scope, source_node); |
| 2852 | | 2852 | |
| 2853 | return &instruction->base; | 2853 | return &instruction->base; |
| 2854 | } | 2854 | } |
| 2855 | | 2855 | |
| 2856 | static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { | 2856 | static void ir_count_defers(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 2857 | results[ReturnKindUnconditional] = 0; | 2857 | results[ReturnKindUnconditional] = 0; |
| 2858 | results[ReturnKindError] = 0; | 2858 | results[ReturnKindError] = 0; |
| 2859 | | 2859 | |
| ... | @@ -2896,7 +2896,7 @@ static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) { | ... | @@ -2896,7 +2896,7 @@ static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) { |
| 2896 | return instruction; | 2896 | return instruction; |
| 2897 | } | 2897 | } |
| 2898 | | 2898 | |
| 2899 | static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) { | 2899 | static bool ir_gen_defers_for_block(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) { |
| 2900 | Scope *scope = inner_scope; | 2900 | Scope *scope = inner_scope; |
| 2901 | if (is_noreturn != nullptr) *is_noreturn = false; | 2901 | if (is_noreturn != nullptr) *is_noreturn = false; |
| 2902 | while (scope != outer_scope) { | 2902 | while (scope != outer_scope) { |
| ... | @@ -2925,36 +2925,36 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope | ... | @@ -2925,36 +2925,36 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope |
| 2925 | Buf *var_name = node_identifier_buf(defer_var_node); | 2925 | Buf *var_name = node_identifier_buf(defer_var_node); |
| 2926 | | 2926 | |
| 2927 | if (defer_expr_node->type == NodeTypeUnreachable) { | 2927 | if (defer_expr_node->type == NodeTypeUnreachable) { |
| 2928 | add_node_error(irb->codegen, defer_var_node, | 2928 | add_node_error(ag->codegen, defer_var_node, |
| 2929 | buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); | 2929 | buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 2930 | return false; | 2930 | return false; |
| 2931 | } | 2931 | } |
| 2932 | | 2932 | |
| 2933 | IrInstSrc *is_comptime; | 2933 | IrInstSrc *is_comptime; |
| 2934 | if (ir_should_inline(irb->exec, defer_expr_scope)) { | 2934 | if (ir_should_inline(ag->exec, defer_expr_scope)) { |
| 2935 | is_comptime = ir_build_const_bool(irb, defer_expr_scope, | 2935 | is_comptime = ir_build_const_bool(ag, defer_expr_scope, |
| 2936 | defer_expr_node, true); | 2936 | defer_expr_node, true); |
| 2937 | } else { | 2937 | } else { |
| 2938 | is_comptime = ir_build_test_comptime(irb, defer_expr_scope, | 2938 | is_comptime = ir_build_test_comptime(ag, defer_expr_scope, |
| 2939 | defer_expr_node, err_value); | 2939 | defer_expr_node, err_value); |
| 2940 | } | 2940 | } |
| 2941 | | 2941 | |
| 2942 | ZigVar *err_var = ir_create_var(irb, defer_var_node, defer_expr_scope, | 2942 | ZigVar *err_var = ir_create_var(ag, defer_var_node, defer_expr_scope, |
| 2943 | var_name, true, true, false, is_comptime); | 2943 | var_name, true, true, false, is_comptime); |
| 2944 | build_decl_var_and_init(irb, defer_expr_scope, defer_var_node, err_var, err_value, | 2944 | build_decl_var_and_init(ag, defer_expr_scope, defer_var_node, err_var, err_value, |
| 2945 | buf_ptr(var_name), is_comptime); | 2945 | buf_ptr(var_name), is_comptime); |
| 2946 | | 2946 | |
| 2947 | defer_expr_scope = err_var->child_scope; | 2947 | defer_expr_scope = err_var->child_scope; |
| 2948 | } | 2948 | } |
| 2949 | | 2949 | |
| 2950 | IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); | 2950 | IrInstSrc *defer_expr_value = ir_gen_node(ag, defer_expr_node, defer_expr_scope); |
| 2951 | if (defer_expr_value == irb->codegen->invalid_inst_src) | 2951 | if (defer_expr_value == ag->codegen->invalid_inst_src) |
| 2952 | return irb->codegen->invalid_inst_src; | 2952 | return ag->codegen->invalid_inst_src; |
| 2953 | | 2953 | |
| 2954 | if (defer_expr_value->is_noreturn) { | 2954 | if (defer_expr_value->is_noreturn) { |
| 2955 | if (is_noreturn != nullptr) *is_noreturn = true; | 2955 | if (is_noreturn != nullptr) *is_noreturn = true; |
| 2956 | } else { | 2956 | } else { |
| 2957 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, | 2957 | ir_mark_gen(ir_build_check_statement_is_void(ag, defer_expr_scope, defer_expr_node, |
| 2958 | defer_expr_value)); | 2958 | defer_expr_value)); |
| 2959 | } | 2959 | } |
| 2960 | scope = scope->parent; | 2960 | scope = scope->parent; |
| ... | @@ -2982,15 +2982,15 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope | ... | @@ -2982,15 +2982,15 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope |
| 2982 | return true; | 2982 | return true; |
| 2983 | } | 2983 | } |
| 2984 | | 2984 | |
| 2985 | static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { | 2985 | static void ir_set_cursor_at_end(Stage1AstGen *ag, IrBasicBlockSrc *basic_block) { |
| 2986 | assert(basic_block); | 2986 | assert(basic_block); |
| 2987 | irb->current_basic_block = basic_block; | 2987 | ag->current_basic_block = basic_block; |
| 2988 | } | 2988 | } |
| 2989 | | 2989 | |
| 2990 | static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { | 2990 | static void ir_set_cursor_at_end_and_append_block(Stage1AstGen *ag, IrBasicBlockSrc *basic_block) { |
| 2991 | basic_block->index = irb->exec->basic_block_list.length; | 2991 | basic_block->index = ag->exec->basic_block_list.length; |
| 2992 | irb->exec->basic_block_list.append(basic_block); | 2992 | ag->exec->basic_block_list.append(basic_block); |
| 2993 | ir_set_cursor_at_end(irb, basic_block); | 2993 | ir_set_cursor_at_end(ag, basic_block); |
| 2994 | } | 2994 | } |
| 2995 | | 2995 | |
| 2996 | static ScopeSuspend *get_scope_suspend(Scope *scope) { | 2996 | static ScopeSuspend *get_scope_suspend(Scope *scope) { |
| ... | @@ -3017,19 +3017,19 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { | ... | @@ -3017,19 +3017,19 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 3017 | return nullptr; | 3017 | return nullptr; |
| 3018 | } | 3018 | } |
| 3019 | | 3019 | |
| 3020 | static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 3020 | static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 3021 | assert(node->type == NodeTypeReturnExpr); | 3021 | assert(node->type == NodeTypeReturnExpr); |
| 3022 | | 3022 | |
| 3023 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); | 3023 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); |
| 3024 | if (scope_defer_expr) { | 3024 | if (scope_defer_expr) { |
| 3025 | if (!scope_defer_expr->reported_err) { | 3025 | if (!scope_defer_expr->reported_err) { |
| 3026 | add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression")); | 3026 | add_node_error(ag->codegen, node, buf_sprintf("cannot return from defer expression")); |
| 3027 | scope_defer_expr->reported_err = true; | 3027 | scope_defer_expr->reported_err = true; |
| 3028 | } | 3028 | } |
| 3029 | return irb->codegen->invalid_inst_src; | 3029 | return ag->codegen->invalid_inst_src; |
| 3030 | } | 3030 | } |
| 3031 | | 3031 | |
| 3032 | Scope *outer_scope = irb->exec->begin_scope; | 3032 | Scope *outer_scope = ag->exec->begin_scope; |
| 3033 | | 3033 | |
| 3034 | AstNode *expr_node = node->data.return_expr.expr; | 3034 | AstNode *expr_node = node->data.return_expr.expr; |
| 3035 | switch (node->data.return_expr.kind) { | 3035 | switch (node->data.return_expr.kind) { |
| ... | @@ -3037,119 +3037,119 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, | ... | @@ -3037,119 +3037,119 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, |
| 3037 | { | 3037 | { |
| 3038 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); | 3038 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); |
| 3039 | result_loc_ret->base.id = ResultLocIdReturn; | 3039 | result_loc_ret->base.id = ResultLocIdReturn; |
| 3040 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); | 3040 | ir_build_reset_result(ag, scope, node, &result_loc_ret->base); |
| 3041 | | 3041 | |
| 3042 | IrInstSrc *return_value; | 3042 | IrInstSrc *return_value; |
| 3043 | if (expr_node) { | 3043 | if (expr_node) { |
| 3044 | // Temporarily set this so that if we return a type it gets the name of the function | 3044 | // Temporarily set this so that if we return a type it gets the name of the function |
| 3045 | ZigFn *prev_name_fn = irb->exec->name_fn; | 3045 | ZigFn *prev_name_fn = ag->exec->name_fn; |
| 3046 | irb->exec->name_fn = exec_fn_entry(irb->exec); | 3046 | ag->exec->name_fn = exec_fn_entry(ag->exec); |
| 3047 | return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base); | 3047 | return_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, &result_loc_ret->base); |
| 3048 | irb->exec->name_fn = prev_name_fn; | 3048 | ag->exec->name_fn = prev_name_fn; |
| 3049 | if (return_value == irb->codegen->invalid_inst_src) | 3049 | if (return_value == ag->codegen->invalid_inst_src) |
| 3050 | return irb->codegen->invalid_inst_src; | 3050 | return ag->codegen->invalid_inst_src; |
| 3051 | } else { | 3051 | } else { |
| 3052 | return_value = ir_build_const_void(irb, scope, node); | 3052 | return_value = ir_build_const_void(ag, scope, node); |
| 3053 | ir_build_end_expr(irb, scope, node, return_value, &result_loc_ret->base); | 3053 | ir_build_end_expr(ag, scope, node, return_value, &result_loc_ret->base); |
| 3054 | } | 3054 | } |
| 3055 | | 3055 | |
| 3056 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, return_value, result_loc_ret)); | 3056 | ir_mark_gen(ir_build_add_implicit_return_type(ag, scope, node, return_value, result_loc_ret)); |
| 3057 | | 3057 | |
| 3058 | size_t defer_counts[2]; | 3058 | size_t defer_counts[2]; |
| 3059 | ir_count_defers(irb, scope, outer_scope, defer_counts); | 3059 | ir_count_defers(ag, scope, outer_scope, defer_counts); |
| 3060 | bool have_err_defers = defer_counts[ReturnKindError] > 0; | 3060 | bool have_err_defers = defer_counts[ReturnKindError] > 0; |
| 3061 | if (!have_err_defers && !irb->codegen->have_err_ret_tracing) { | 3061 | if (!have_err_defers && !ag->codegen->have_err_ret_tracing) { |
| 3062 | // only generate unconditional defers | 3062 | // only generate unconditional defers |
| 3063 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr)) | 3063 | if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) |
| 3064 | return irb->codegen->invalid_inst_src; | 3064 | return ag->codegen->invalid_inst_src; |
| 3065 | IrInstSrc *result = ir_build_return_src(irb, scope, node, nullptr); | 3065 | IrInstSrc *result = ir_build_return_src(ag, scope, node, nullptr); |
| 3066 | result_loc_ret->base.source_instruction = result; | 3066 | result_loc_ret->base.source_instruction = result; |
| 3067 | return result; | 3067 | return result; |
| 3068 | } | 3068 | } |
| 3069 | bool should_inline = ir_should_inline(irb->exec, scope); | 3069 | bool should_inline = ir_should_inline(ag->exec, scope); |
| 3070 | | 3070 | |
| 3071 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); | 3071 | IrBasicBlockSrc *err_block = ir_create_basic_block(ag, scope, "ErrRetErr"); |
| 3072 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); | 3072 | IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, scope, "ErrRetOk"); |
| 3073 | | 3073 | |
| 3074 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true); | 3074 | IrInstSrc *is_err = ir_build_test_err_src(ag, scope, node, return_value, false, true); |
| 3075 | | 3075 | |
| 3076 | IrInstSrc *is_comptime; | 3076 | IrInstSrc *is_comptime; |
| 3077 | if (should_inline) { | 3077 | if (should_inline) { |
| 3078 | is_comptime = ir_build_const_bool(irb, scope, node, should_inline); | 3078 | is_comptime = ir_build_const_bool(ag, scope, node, should_inline); |
| 3079 | } else { | 3079 | } else { |
| 3080 | is_comptime = ir_build_test_comptime(irb, scope, node, is_err); | 3080 | is_comptime = ir_build_test_comptime(ag, scope, node, is_err); |
| 3081 | } | 3081 | } |
| 3082 | | 3082 | |
| 3083 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime)); | 3083 | ir_mark_gen(ir_build_cond_br(ag, scope, node, is_err, err_block, ok_block, is_comptime)); |
| 3084 | IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt"); | 3084 | IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(ag, scope, "RetStmt"); |
| 3085 | | 3085 | |
| 3086 | ir_set_cursor_at_end_and_append_block(irb, err_block); | 3086 | ir_set_cursor_at_end_and_append_block(ag, err_block); |
| 3087 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, return_value)) | 3087 | if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, return_value)) |
| 3088 | return irb->codegen->invalid_inst_src; | 3088 | return ag->codegen->invalid_inst_src; |
| 3089 | if (irb->codegen->have_err_ret_tracing && !should_inline) { | 3089 | if (ag->codegen->have_err_ret_tracing && !should_inline) { |
| 3090 | ir_build_save_err_ret_addr_src(irb, scope, node); | 3090 | ir_build_save_err_ret_addr_src(ag, scope, node); |
| 3091 | } | 3091 | } |
| 3092 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); | 3092 | ir_build_br(ag, scope, node, ret_stmt_block, is_comptime); |
| 3093 | | 3093 | |
| 3094 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 3094 | ir_set_cursor_at_end_and_append_block(ag, ok_block); |
| 3095 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr)) | 3095 | if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) |
| 3096 | return irb->codegen->invalid_inst_src; | 3096 | return ag->codegen->invalid_inst_src; |
| 3097 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); | 3097 | ir_build_br(ag, scope, node, ret_stmt_block, is_comptime); |
| 3098 | | 3098 | |
| 3099 | ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block); | 3099 | ir_set_cursor_at_end_and_append_block(ag, ret_stmt_block); |
| 3100 | IrInstSrc *result = ir_build_return_src(irb, scope, node, nullptr); | 3100 | IrInstSrc *result = ir_build_return_src(ag, scope, node, nullptr); |
| 3101 | result_loc_ret->base.source_instruction = result; | 3101 | result_loc_ret->base.source_instruction = result; |
| 3102 | return result; | 3102 | return result; |
| 3103 | } | 3103 | } |
| 3104 | case ReturnKindError: | 3104 | case ReturnKindError: |
| 3105 | { | 3105 | { |
| 3106 | assert(expr_node); | 3106 | assert(expr_node); |
| 3107 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); | 3107 | IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); |
| 3108 | if (err_union_ptr == irb->codegen->invalid_inst_src) | 3108 | if (err_union_ptr == ag->codegen->invalid_inst_src) |
| 3109 | return irb->codegen->invalid_inst_src; | 3109 | return ag->codegen->invalid_inst_src; |
| 3110 | IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false); | 3110 | IrInstSrc *is_err_val = ir_build_test_err_src(ag, scope, node, err_union_ptr, true, false); |
| 3111 | | 3111 | |
| 3112 | IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); | 3112 | IrBasicBlockSrc *return_block = ir_create_basic_block(ag, scope, "ErrRetReturn"); |
| 3113 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); | 3113 | IrBasicBlockSrc *continue_block = ir_create_basic_block(ag, scope, "ErrRetContinue"); |
| 3114 | IrInstSrc *is_comptime; | 3114 | IrInstSrc *is_comptime; |
| 3115 | bool should_inline = ir_should_inline(irb->exec, scope); | 3115 | bool should_inline = ir_should_inline(ag->exec, scope); |
| 3116 | if (should_inline) { | 3116 | if (should_inline) { |
| 3117 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 3117 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 3118 | } else { | 3118 | } else { |
| 3119 | is_comptime = ir_build_test_comptime(irb, scope, node, is_err_val); | 3119 | is_comptime = ir_build_test_comptime(ag, scope, node, is_err_val); |
| 3120 | } | 3120 | } |
| 3121 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime)); | 3121 | ir_mark_gen(ir_build_cond_br(ag, scope, node, is_err_val, return_block, continue_block, is_comptime)); |
| 3122 | | 3122 | |
| 3123 | ir_set_cursor_at_end_and_append_block(irb, return_block); | 3123 | ir_set_cursor_at_end_and_append_block(ag, return_block); |
| 3124 | IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr); | 3124 | IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(ag, scope, node, err_union_ptr); |
| 3125 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); | 3125 | IrInstSrc *err_val = ir_build_load_ptr(ag, scope, node, err_val_ptr); |
| 3126 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr)); | 3126 | ir_mark_gen(ir_build_add_implicit_return_type(ag, scope, node, err_val, nullptr)); |
| 3127 | IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val, | 3127 | IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(ag, scope, node, err_val, |
| 3128 | SpillIdRetErrCode); | 3128 | SpillIdRetErrCode); |
| 3129 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); | 3129 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); |
| 3130 | result_loc_ret->base.id = ResultLocIdReturn; | 3130 | result_loc_ret->base.id = ResultLocIdReturn; |
| 3131 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); | 3131 | ir_build_reset_result(ag, scope, node, &result_loc_ret->base); |
| 3132 | ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base); | 3132 | ir_build_end_expr(ag, scope, node, err_val, &result_loc_ret->base); |
| 3133 | | 3133 | |
| 3134 | bool is_noreturn = false; | 3134 | bool is_noreturn = false; |
| 3135 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, &is_noreturn, err_val)) { | 3135 | if (!ir_gen_defers_for_block(ag, scope, outer_scope, &is_noreturn, err_val)) { |
| 3136 | return irb->codegen->invalid_inst_src; | 3136 | return ag->codegen->invalid_inst_src; |
| 3137 | } | 3137 | } |
| 3138 | if (!is_noreturn) { | 3138 | if (!is_noreturn) { |
| 3139 | if (irb->codegen->have_err_ret_tracing && !should_inline) { | 3139 | if (ag->codegen->have_err_ret_tracing && !should_inline) { |
| 3140 | ir_build_save_err_ret_addr_src(irb, scope, node); | 3140 | ir_build_save_err_ret_addr_src(ag, scope, node); |
| 3141 | } | 3141 | } |
| 3142 | err_val = ir_build_spill_end_src(irb, scope, node, spill_begin); | 3142 | err_val = ir_build_spill_end_src(ag, scope, node, spill_begin); |
| 3143 | IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val); | 3143 | IrInstSrc *ret_inst = ir_build_return_src(ag, scope, node, err_val); |
| 3144 | result_loc_ret->base.source_instruction = ret_inst; | 3144 | result_loc_ret->base.source_instruction = ret_inst; |
| 3145 | } | 3145 | } |
| 3146 | | 3146 | |
| 3147 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 3147 | ir_set_cursor_at_end_and_append_block(ag, continue_block); |
| 3148 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false); | 3148 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(ag, scope, node, err_union_ptr, false, false); |
| 3149 | if (lval == LValPtr) | 3149 | if (lval == LValPtr) |
| 3150 | return unwrapped_ptr; | 3150 | return unwrapped_ptr; |
| 3151 | else | 3151 | else |
| 3152 | return ir_expr_wrap(irb, scope, ir_build_load_ptr(irb, scope, node, unwrapped_ptr), result_loc); | 3152 | return ir_expr_wrap(ag, scope, ir_build_load_ptr(ag, scope, node, unwrapped_ptr), result_loc); |
| 3153 | } | 3153 | } |
| 3154 | } | 3154 | } |
| 3155 | zig_unreachable(); | 3155 | zig_unreachable(); |
| ... | @@ -3227,11 +3227,11 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, | ... | @@ -3227,11 +3227,11 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, |
| 3227 | | 3227 | |
| 3228 | // Set name to nullptr to make the variable anonymous (not visible to programmer). | 3228 | // Set name to nullptr to make the variable anonymous (not visible to programmer). |
| 3229 | // After you call this function var->child_scope has the variable in scope | 3229 | // After you call this function var->child_scope has the variable in scope |
| 3230 | static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name, | 3230 | static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf *name, |
| 3231 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime) | 3231 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime) |
| 3232 | { | 3232 | { |
| 3233 | bool is_underscored = name ? buf_eql_str(name, "_") : false; | 3233 | bool is_underscored = name ? buf_eql_str(name, "_") : false; |
| 3234 | ZigVar *var = create_local_var(irb->codegen, node, scope, | 3234 | ZigVar *var = create_local_var(ag->codegen, node, scope, |
| 3235 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, | 3235 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 3236 | (is_underscored ? true : is_shadowable), is_comptime, false); | 3236 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 3237 | assert(var->child_scope); | 3237 | assert(var->child_scope); |
| ... | @@ -3266,7 +3266,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam | ... | @@ -3266,7 +3266,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam |
| 3266 | return false; | 3266 | return false; |
| 3267 | } | 3267 | } |
| 3268 | | 3268 | |
| 3269 | static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval, | 3269 | static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *block_node, LVal lval, |
| 3270 | ResultLoc *result_loc) | 3270 | ResultLoc *result_loc) |
| 3271 | { | 3271 | { |
| 3272 | assert(block_node->type == NodeTypeBlock); | 3272 | assert(block_node->type == NodeTypeBlock); |
| ... | @@ -3274,10 +3274,10 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3274,10 +3274,10 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3274 | ZigList<IrInstSrc *> incoming_values = {0}; | 3274 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 3275 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; | 3275 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 3276 | | 3276 | |
| 3277 | if (is_duplicate_label(irb->codegen, parent_scope, block_node, block_node->data.block.name)) | 3277 | if (is_duplicate_label(ag->codegen, parent_scope, block_node, block_node->data.block.name)) |
| 3278 | return irb->codegen->invalid_inst_src; | 3278 | return ag->codegen->invalid_inst_src; |
| 3279 | | 3279 | |
| 3280 | ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope); | 3280 | ScopeBlock *scope_block = create_block_scope(ag->codegen, block_node, parent_scope); |
| 3281 | | 3281 | |
| 3282 | Scope *outer_block_scope = &scope_block->base; | 3282 | Scope *outer_block_scope = &scope_block->base; |
| 3283 | Scope *child_scope = outer_block_scope; | 3283 | Scope *child_scope = outer_block_scope; |
| ... | @@ -3289,19 +3289,19 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3289,19 +3289,19 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3289 | | 3289 | |
| 3290 | if (block_node->data.block.statements.length == 0) { | 3290 | if (block_node->data.block.statements.length == 0) { |
| 3291 | if (scope_block->name != nullptr) { | 3291 | if (scope_block->name != nullptr) { |
| 3292 | add_node_error(irb->codegen, block_node, buf_sprintf("unused block label")); | 3292 | add_node_error(ag->codegen, block_node, buf_sprintf("unused block label")); |
| 3293 | } | 3293 | } |
| 3294 | // {} | 3294 | // {} |
| 3295 | return ir_lval_wrap(irb, parent_scope, ir_build_const_void(irb, child_scope, block_node), lval, result_loc); | 3295 | return ir_lval_wrap(ag, parent_scope, ir_build_const_void(ag, child_scope, block_node), lval, result_loc); |
| 3296 | } | 3296 | } |
| 3297 | | 3297 | |
| 3298 | if (block_node->data.block.name != nullptr) { | 3298 | if (block_node->data.block.name != nullptr) { |
| 3299 | scope_block->lval = lval; | 3299 | scope_block->lval = lval; |
| 3300 | scope_block->incoming_blocks = &incoming_blocks; | 3300 | scope_block->incoming_blocks = &incoming_blocks; |
| 3301 | scope_block->incoming_values = &incoming_values; | 3301 | scope_block->incoming_values = &incoming_values; |
| 3302 | scope_block->end_block = ir_create_basic_block(irb, parent_scope, "BlockEnd"); | 3302 | scope_block->end_block = ir_create_basic_block(ag, parent_scope, "BlockEnd"); |
| 3303 | scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node, | 3303 | scope_block->is_comptime = ir_build_const_bool(ag, parent_scope, block_node, |
| 3304 | ir_should_inline(irb->exec, parent_scope)); | 3304 | ir_should_inline(ag->exec, parent_scope)); |
| 3305 | | 3305 | |
| 3306 | scope_block->peer_parent = heap::c_allocator.create<ResultLocPeerParent>(); | 3306 | scope_block->peer_parent = heap::c_allocator.create<ResultLocPeerParent>(); |
| 3307 | scope_block->peer_parent->base.id = ResultLocIdPeerParent; | 3307 | scope_block->peer_parent->base.id = ResultLocIdPeerParent; |
| ... | @@ -3310,7 +3310,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3310,7 +3310,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3310 | scope_block->peer_parent->end_bb = scope_block->end_block; | 3310 | scope_block->peer_parent->end_bb = scope_block->end_block; |
| 3311 | scope_block->peer_parent->is_comptime = scope_block->is_comptime; | 3311 | scope_block->peer_parent->is_comptime = scope_block->is_comptime; |
| 3312 | scope_block->peer_parent->parent = result_loc; | 3312 | scope_block->peer_parent->parent = result_loc; |
| 3313 | ir_build_reset_result(irb, parent_scope, block_node, &scope_block->peer_parent->base); | 3313 | ir_build_reset_result(ag, parent_scope, block_node, &scope_block->peer_parent->base); |
| 3314 | } | 3314 | } |
| 3315 | | 3315 | |
| 3316 | bool is_continuation_unreachable = false; | 3316 | bool is_continuation_unreachable = false; |
| ... | @@ -3319,8 +3319,8 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3319,8 +3319,8 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3319 | for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { | 3319 | for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { |
| 3320 | AstNode *statement_node = block_node->data.block.statements.at(i); | 3320 | AstNode *statement_node = block_node->data.block.statements.at(i); |
| 3321 | | 3321 | |
| 3322 | IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope); | 3322 | IrInstSrc *statement_value = ir_gen_node(ag, statement_node, child_scope); |
| 3323 | if (statement_value == irb->codegen->invalid_inst_src) { | 3323 | if (statement_value == ag->codegen->invalid_inst_src) { |
| 3324 | // keep generating all the elements of the block in case of error, | 3324 | // keep generating all the elements of the block in case of error, |
| 3325 | // we want to collect other compile errors | 3325 | // we want to collect other compile errors |
| 3326 | found_invalid_inst = true; | 3326 | found_invalid_inst = true; |
| ... | @@ -3344,16 +3344,16 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3344,16 +3344,16 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3344 | child_scope = decl_var_instruction->var->child_scope; | 3344 | child_scope = decl_var_instruction->var->child_scope; |
| 3345 | } else if (!is_continuation_unreachable) { | 3345 | } else if (!is_continuation_unreachable) { |
| 3346 | // this statement's value must be void | 3346 | // this statement's value must be void |
| 3347 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value)); | 3347 | ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, statement_node, statement_value)); |
| 3348 | } | 3348 | } |
| 3349 | } | 3349 | } |
| 3350 | | 3350 | |
| 3351 | if (scope_block->name != nullptr && scope_block->name_used == false) { | 3351 | if (scope_block->name != nullptr && scope_block->name_used == false) { |
| 3352 | add_node_error(irb->codegen, block_node, buf_sprintf("unused block label")); | 3352 | add_node_error(ag->codegen, block_node, buf_sprintf("unused block label")); |
| 3353 | } | 3353 | } |
| 3354 | | 3354 | |
| 3355 | if (found_invalid_inst) | 3355 | if (found_invalid_inst) |
| 3356 | return irb->codegen->invalid_inst_src; | 3356 | return ag->codegen->invalid_inst_src; |
| 3357 | | 3357 | |
| 3358 | if (is_continuation_unreachable) { | 3358 | if (is_continuation_unreachable) { |
| 3359 | assert(noreturn_return_value != nullptr); | 3359 | assert(noreturn_return_value != nullptr); |
| ... | @@ -3364,18 +3364,18 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3364,18 +3364,18 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3364 | if (scope_block->peer_parent != nullptr && scope_block->peer_parent->peers.length != 0) { | 3364 | if (scope_block->peer_parent != nullptr && scope_block->peer_parent->peers.length != 0) { |
| 3365 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; | 3365 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; |
| 3366 | } | 3366 | } |
| 3367 | ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block); | 3367 | ir_set_cursor_at_end_and_append_block(ag, scope_block->end_block); |
| 3368 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, | 3368 | IrInstSrc *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length, |
| 3369 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); | 3369 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 3370 | return ir_expr_wrap(irb, parent_scope, phi, result_loc); | 3370 | return ir_expr_wrap(ag, parent_scope, phi, result_loc); |
| 3371 | } else { | 3371 | } else { |
| 3372 | incoming_blocks.append(irb->current_basic_block); | 3372 | incoming_blocks.append(ag->current_basic_block); |
| 3373 | IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)); | 3373 | IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(ag, parent_scope, block_node)); |
| 3374 | | 3374 | |
| 3375 | if (scope_block->peer_parent != nullptr) { | 3375 | if (scope_block->peer_parent != nullptr) { |
| 3376 | ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent); | 3376 | ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent); |
| 3377 | scope_block->peer_parent->peers.append(peer_result); | 3377 | scope_block->peer_parent->peers.append(peer_result); |
| 3378 | ir_build_end_expr(irb, parent_scope, block_node, else_expr_result, &peer_result->base); | 3378 | ir_build_end_expr(ag, parent_scope, block_node, else_expr_result, &peer_result->base); |
| 3379 | | 3379 | |
| 3380 | if (scope_block->peer_parent->peers.length != 0) { | 3380 | if (scope_block->peer_parent->peers.length != 0) { |
| 3381 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; | 3381 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; |
| ... | @@ -3385,22 +3385,22 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3385,22 +3385,22 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3385 | incoming_values.append(else_expr_result); | 3385 | incoming_values.append(else_expr_result); |
| 3386 | } | 3386 | } |
| 3387 | | 3387 | |
| 3388 | bool is_return_from_fn = block_node == irb->main_block_node; | 3388 | bool is_return_from_fn = block_node == ag->main_block_node; |
| 3389 | if (!is_return_from_fn) { | 3389 | if (!is_return_from_fn) { |
| 3390 | if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr)) | 3390 | if (!ir_gen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) |
| 3391 | return irb->codegen->invalid_inst_src; | 3391 | return ag->codegen->invalid_inst_src; |
| 3392 | } | 3392 | } |
| 3393 | | 3393 | |
| 3394 | IrInstSrc *result; | 3394 | IrInstSrc *result; |
| 3395 | if (block_node->data.block.name != nullptr) { | 3395 | if (block_node->data.block.name != nullptr) { |
| 3396 | ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); | 3396 | ir_mark_gen(ir_build_br(ag, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); |
| 3397 | ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block); | 3397 | ir_set_cursor_at_end_and_append_block(ag, scope_block->end_block); |
| 3398 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, | 3398 | IrInstSrc *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length, |
| 3399 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); | 3399 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 3400 | result = ir_expr_wrap(irb, parent_scope, phi, result_loc); | 3400 | result = ir_expr_wrap(ag, parent_scope, phi, result_loc); |
| 3401 | } else { | 3401 | } else { |
| 3402 | IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); | 3402 | IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(ag, child_scope, block_node)); |
| 3403 | result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc); | 3403 | result = ir_lval_wrap(ag, parent_scope, void_inst, lval, result_loc); |
| 3404 | } | 3404 | } |
| 3405 | if (!is_return_from_fn) | 3405 | if (!is_return_from_fn) |
| 3406 | return result; | 3406 | return result; |
| ... | @@ -3408,108 +3408,108 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -3408,108 +3408,108 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 3408 | // no need for save_err_ret_addr because this cannot return error | 3408 | // no need for save_err_ret_addr because this cannot return error |
| 3409 | // only generate unconditional defers | 3409 | // only generate unconditional defers |
| 3410 | | 3410 | |
| 3411 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); | 3411 | ir_mark_gen(ir_build_add_implicit_return_type(ag, child_scope, block_node, result, nullptr)); |
| 3412 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); | 3412 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); |
| 3413 | result_loc_ret->base.id = ResultLocIdReturn; | 3413 | result_loc_ret->base.id = ResultLocIdReturn; |
| 3414 | ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base); | 3414 | ir_build_reset_result(ag, parent_scope, block_node, &result_loc_ret->base); |
| 3415 | ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base)); | 3415 | ir_mark_gen(ir_build_end_expr(ag, parent_scope, block_node, result, &result_loc_ret->base)); |
| 3416 | if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr)) | 3416 | if (!ir_gen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) |
| 3417 | return irb->codegen->invalid_inst_src; | 3417 | return ag->codegen->invalid_inst_src; |
| 3418 | return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result)); | 3418 | return ir_mark_gen(ir_build_return_src(ag, child_scope, result->base.source_node, result)); |
| 3419 | } | 3419 | } |
| 3420 | | 3420 | |
| 3421 | static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { | 3421 | static IrInstSrc *ir_gen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 3422 | Scope *inner_scope = scope; | 3422 | Scope *inner_scope = scope; |
| 3423 | if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) { | 3423 | if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) { |
| 3424 | inner_scope = create_comptime_scope(irb->codegen, node, scope); | 3424 | inner_scope = create_comptime_scope(ag->codegen, node, scope); |
| 3425 | } | 3425 | } |
| 3426 | | 3426 | |
| 3427 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope); | 3427 | IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, inner_scope); |
| 3428 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope); | 3428 | IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, inner_scope); |
| 3429 | | 3429 | |
| 3430 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) | 3430 | if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src) |
| 3431 | return irb->codegen->invalid_inst_src; | 3431 | return ag->codegen->invalid_inst_src; |
| 3432 | | 3432 | |
| 3433 | return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); | 3433 | return ir_build_bin_op(ag, scope, node, op_id, op1, op2, true); |
| 3434 | } | 3434 | } |
| 3435 | | 3435 | |
| 3436 | static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3436 | static IrInstSrc *ir_gen_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3437 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); | 3437 | IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); |
| 3438 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 3438 | IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); |
| 3439 | | 3439 | |
| 3440 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) | 3440 | if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src) |
| 3441 | return irb->codegen->invalid_inst_src; | 3441 | return ag->codegen->invalid_inst_src; |
| 3442 | | 3442 | |
| 3443 | // TODO only pass type_name when the || operator is the top level AST node in the var decl expr | 3443 | // TODO only pass type_name when the || operator is the top level AST node in the var decl expr |
| 3444 | Buf bare_name = BUF_INIT; | 3444 | Buf bare_name = BUF_INIT; |
| 3445 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", scope, node, &bare_name); | 3445 | Buf *type_name = get_anon_type_name(ag->codegen, ag->exec, "error", scope, node, &bare_name); |
| 3446 | | 3446 | |
| 3447 | return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name); | 3447 | return ir_build_merge_err_sets(ag, scope, node, op1, op2, type_name); |
| 3448 | } | 3448 | } |
| 3449 | | 3449 | |
| 3450 | static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3450 | static IrInstSrc *ir_gen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3451 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); | 3451 | IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); |
| 3452 | if (lvalue == irb->codegen->invalid_inst_src) | 3452 | if (lvalue == ag->codegen->invalid_inst_src) |
| 3453 | return irb->codegen->invalid_inst_src; | 3453 | return ag->codegen->invalid_inst_src; |
| 3454 | | 3454 | |
| 3455 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); | 3455 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); |
| 3456 | result_loc_inst->base.id = ResultLocIdInstruction; | 3456 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 3457 | result_loc_inst->base.source_instruction = lvalue; | 3457 | result_loc_inst->base.source_instruction = lvalue; |
| 3458 | ir_ref_instruction(lvalue, irb->current_basic_block); | 3458 | ir_ref_instruction(lvalue, ag->current_basic_block); |
| 3459 | ir_build_reset_result(irb, scope, node, &result_loc_inst->base); | 3459 | ir_build_reset_result(ag, scope, node, &result_loc_inst->base); |
| 3460 | | 3460 | |
| 3461 | IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, | 3461 | IrInstSrc *rvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op2, scope, LValNone, |
| 3462 | &result_loc_inst->base); | 3462 | &result_loc_inst->base); |
| 3463 | if (rvalue == irb->codegen->invalid_inst_src) | 3463 | if (rvalue == ag->codegen->invalid_inst_src) |
| 3464 | return irb->codegen->invalid_inst_src; | 3464 | return ag->codegen->invalid_inst_src; |
| 3465 | | 3465 | |
| 3466 | return ir_build_const_void(irb, scope, node); | 3466 | return ir_build_const_void(ag, scope, node); |
| 3467 | } | 3467 | } |
| 3468 | | 3468 | |
| 3469 | static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { | 3469 | static IrInstSrc *ir_gen_assign_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 3470 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); | 3470 | IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); |
| 3471 | if (lvalue == irb->codegen->invalid_inst_src) | 3471 | if (lvalue == ag->codegen->invalid_inst_src) |
| 3472 | return lvalue; | 3472 | return lvalue; |
| 3473 | IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); | 3473 | IrInstSrc *op1 = ir_build_load_ptr(ag, scope, node->data.bin_op_expr.op1, lvalue); |
| 3474 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 3474 | IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); |
| 3475 | if (op2 == irb->codegen->invalid_inst_src) | 3475 | if (op2 == ag->codegen->invalid_inst_src) |
| 3476 | return op2; | 3476 | return op2; |
| 3477 | IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); | 3477 | IrInstSrc *result = ir_build_bin_op(ag, scope, node, op_id, op1, op2, true); |
| 3478 | ir_build_store_ptr(irb, scope, node, lvalue, result); | 3478 | ir_build_store_ptr(ag, scope, node, lvalue, result); |
| 3479 | return ir_build_const_void(irb, scope, node); | 3479 | return ir_build_const_void(ag, scope, node); |
| 3480 | } | 3480 | } |
| 3481 | | 3481 | |
| 3482 | static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3482 | static IrInstSrc *ir_gen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3483 | assert(node->type == NodeTypeBinOpExpr); | 3483 | assert(node->type == NodeTypeBinOpExpr); |
| 3484 | | 3484 | |
| 3485 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); | 3485 | IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); |
| 3486 | if (val1 == irb->codegen->invalid_inst_src) | 3486 | if (val1 == ag->codegen->invalid_inst_src) |
| 3487 | return irb->codegen->invalid_inst_src; | 3487 | return ag->codegen->invalid_inst_src; |
| 3488 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; | 3488 | IrBasicBlockSrc *post_val1_block = ag->current_basic_block; |
| 3489 | | 3489 | |
| 3490 | IrInstSrc *is_comptime; | 3490 | IrInstSrc *is_comptime; |
| 3491 | if (ir_should_inline(irb->exec, scope)) { | 3491 | if (ir_should_inline(ag->exec, scope)) { |
| 3492 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 3492 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 3493 | } else { | 3493 | } else { |
| 3494 | is_comptime = ir_build_test_comptime(irb, scope, node, val1); | 3494 | is_comptime = ir_build_test_comptime(ag, scope, node, val1); |
| 3495 | } | 3495 | } |
| 3496 | | 3496 | |
| 3497 | // block for when val1 == false | 3497 | // block for when val1 == false |
| 3498 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); | 3498 | IrBasicBlockSrc *false_block = ir_create_basic_block(ag, scope, "BoolOrFalse"); |
| 3499 | // block for when val1 == true (don't even evaluate the second part) | 3499 | // block for when val1 == true (don't even evaluate the second part) |
| 3500 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); | 3500 | IrBasicBlockSrc *true_block = ir_create_basic_block(ag, scope, "BoolOrTrue"); |
| 3501 | | 3501 | |
| 3502 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); | 3502 | ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); |
| 3503 | | 3503 | |
| 3504 | ir_set_cursor_at_end_and_append_block(irb, false_block); | 3504 | ir_set_cursor_at_end_and_append_block(ag, false_block); |
| 3505 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 3505 | IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); |
| 3506 | if (val2 == irb->codegen->invalid_inst_src) | 3506 | if (val2 == ag->codegen->invalid_inst_src) |
| 3507 | return irb->codegen->invalid_inst_src; | 3507 | return ag->codegen->invalid_inst_src; |
| 3508 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; | 3508 | IrBasicBlockSrc *post_val2_block = ag->current_basic_block; |
| 3509 | | 3509 | |
| 3510 | ir_build_br(irb, scope, node, true_block, is_comptime); | 3510 | ir_build_br(ag, scope, node, true_block, is_comptime); |
| 3511 | | 3511 | |
| 3512 | ir_set_cursor_at_end_and_append_block(irb, true_block); | 3512 | ir_set_cursor_at_end_and_append_block(ag, true_block); |
| 3513 | | 3513 | |
| 3514 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 3514 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 3515 | incoming_values[0] = val1; | 3515 | incoming_values[0] = val1; |
| ... | @@ -3518,40 +3518,40 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) | ... | @@ -3518,40 +3518,40 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) |
| 3518 | incoming_blocks[0] = post_val1_block; | 3518 | incoming_blocks[0] = post_val1_block; |
| 3519 | incoming_blocks[1] = post_val2_block; | 3519 | incoming_blocks[1] = post_val2_block; |
| 3520 | | 3520 | |
| 3521 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); | 3521 | return ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 3522 | } | 3522 | } |
| 3523 | | 3523 | |
| 3524 | static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3524 | static IrInstSrc *ir_gen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3525 | assert(node->type == NodeTypeBinOpExpr); | 3525 | assert(node->type == NodeTypeBinOpExpr); |
| 3526 | | 3526 | |
| 3527 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); | 3527 | IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); |
| 3528 | if (val1 == irb->codegen->invalid_inst_src) | 3528 | if (val1 == ag->codegen->invalid_inst_src) |
| 3529 | return irb->codegen->invalid_inst_src; | 3529 | return ag->codegen->invalid_inst_src; |
| 3530 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; | 3530 | IrBasicBlockSrc *post_val1_block = ag->current_basic_block; |
| 3531 | | 3531 | |
| 3532 | IrInstSrc *is_comptime; | 3532 | IrInstSrc *is_comptime; |
| 3533 | if (ir_should_inline(irb->exec, scope)) { | 3533 | if (ir_should_inline(ag->exec, scope)) { |
| 3534 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 3534 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 3535 | } else { | 3535 | } else { |
| 3536 | is_comptime = ir_build_test_comptime(irb, scope, node, val1); | 3536 | is_comptime = ir_build_test_comptime(ag, scope, node, val1); |
| 3537 | } | 3537 | } |
| 3538 | | 3538 | |
| 3539 | // block for when val1 == true | 3539 | // block for when val1 == true |
| 3540 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); | 3540 | IrBasicBlockSrc *true_block = ir_create_basic_block(ag, scope, "BoolAndTrue"); |
| 3541 | // block for when val1 == false (don't even evaluate the second part) | 3541 | // block for when val1 == false (don't even evaluate the second part) |
| 3542 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); | 3542 | IrBasicBlockSrc *false_block = ir_create_basic_block(ag, scope, "BoolAndFalse"); |
| 3543 | | 3543 | |
| 3544 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); | 3544 | ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); |
| 3545 | | 3545 | |
| 3546 | ir_set_cursor_at_end_and_append_block(irb, true_block); | 3546 | ir_set_cursor_at_end_and_append_block(ag, true_block); |
| 3547 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 3547 | IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); |
| 3548 | if (val2 == irb->codegen->invalid_inst_src) | 3548 | if (val2 == ag->codegen->invalid_inst_src) |
| 3549 | return irb->codegen->invalid_inst_src; | 3549 | return ag->codegen->invalid_inst_src; |
| 3550 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; | 3550 | IrBasicBlockSrc *post_val2_block = ag->current_basic_block; |
| 3551 | | 3551 | |
| 3552 | ir_build_br(irb, scope, node, false_block, is_comptime); | 3552 | ir_build_br(ag, scope, node, false_block, is_comptime); |
| 3553 | | 3553 | |
| 3554 | ir_set_cursor_at_end_and_append_block(irb, false_block); | 3554 | ir_set_cursor_at_end_and_append_block(ag, false_block); |
| 3555 | | 3555 | |
| 3556 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 3556 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 3557 | incoming_values[0] = val1; | 3557 | incoming_values[0] = val1; |
| ... | @@ -3560,10 +3560,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node | ... | @@ -3560,10 +3560,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node |
| 3560 | incoming_blocks[0] = post_val1_block; | 3560 | incoming_blocks[0] = post_val1_block; |
| 3561 | incoming_blocks[1] = post_val2_block; | 3561 | incoming_blocks[1] = post_val2_block; |
| 3562 | | 3562 | |
| 3563 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); | 3563 | return ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 3564 | } | 3564 | } |
| 3565 | | 3565 | |
| 3566 | static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, | 3566 | static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, IrInstSrc *cond_br_inst, |
| 3567 | IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) | 3567 | IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 3568 | { | 3568 | { |
| 3569 | ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>(); | 3569 | ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>(); |
| ... | @@ -3574,19 +3574,19 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc * | ... | @@ -3574,19 +3574,19 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc * |
| 3574 | peer_parent->is_comptime = is_comptime; | 3574 | peer_parent->is_comptime = is_comptime; |
| 3575 | peer_parent->parent = parent; | 3575 | peer_parent->parent = parent; |
| 3576 | | 3576 | |
| 3577 | IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop(); | 3577 | IrInstSrc *popped_inst = ag->current_basic_block->instruction_list.pop(); |
| 3578 | ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base); | 3578 | ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base); |
| 3579 | | 3579 | |
| 3580 | ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base); | 3580 | ir_build_reset_result(ag, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base); |
| 3581 | irb->current_basic_block->instruction_list.append(popped_inst); | 3581 | ag->current_basic_block->instruction_list.append(popped_inst); |
| 3582 | | 3582 | |
| 3583 | return peer_parent; | 3583 | return peer_parent; |
| 3584 | } | 3584 | } |
| 3585 | | 3585 | |
| 3586 | static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, | 3586 | static ResultLocPeerParent *ir_build_binary_result_peers(Stage1AstGen *ag, IrInstSrc *cond_br_inst, |
| 3587 | IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) | 3587 | IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 3588 | { | 3588 | { |
| 3589 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime); | 3589 | ResultLocPeerParent *peer_parent = ir_build_result_peers(ag, cond_br_inst, end_block, parent, is_comptime); |
| 3590 | | 3590 | |
| 3591 | peer_parent->peers.append(create_peer_result(peer_parent)); | 3591 | peer_parent->peers.append(create_peer_result(peer_parent)); |
| 3592 | peer_parent->peers.last()->next_bb = else_block; | 3592 | peer_parent->peers.last()->next_bb = else_block; |
| ... | @@ -3597,7 +3597,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrIn | ... | @@ -3597,7 +3597,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrIn |
| 3597 | return peer_parent; | 3597 | return peer_parent; |
| 3598 | } | 3598 | } |
| 3599 | | 3599 | |
| 3600 | static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, | 3600 | static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, |
| 3601 | ResultLoc *result_loc) | 3601 | ResultLoc *result_loc) |
| 3602 | { | 3602 | { |
| 3603 | assert(node->type == NodeTypeBinOpExpr); | 3603 | assert(node->type == NodeTypeBinOpExpr); |
| ... | @@ -3605,73 +3605,73 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode | ... | @@ -3605,73 +3605,73 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode |
| 3605 | AstNode *op1_node = node->data.bin_op_expr.op1; | 3605 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 3606 | AstNode *op2_node = node->data.bin_op_expr.op2; | 3606 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 3607 | | 3607 | |
| 3608 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); | 3608 | IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, op1_node, parent_scope, LValPtr, nullptr); |
| 3609 | if (maybe_ptr == irb->codegen->invalid_inst_src) | 3609 | if (maybe_ptr == ag->codegen->invalid_inst_src) |
| 3610 | return irb->codegen->invalid_inst_src; | 3610 | return ag->codegen->invalid_inst_src; |
| 3611 | | 3611 | |
| 3612 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr); | 3612 | IrInstSrc *maybe_val = ir_build_load_ptr(ag, parent_scope, node, maybe_ptr); |
| 3613 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val); | 3613 | IrInstSrc *is_non_null = ir_build_test_non_null_src(ag, parent_scope, node, maybe_val); |
| 3614 | | 3614 | |
| 3615 | IrInstSrc *is_comptime; | 3615 | IrInstSrc *is_comptime; |
| 3616 | if (ir_should_inline(irb->exec, parent_scope)) { | 3616 | if (ir_should_inline(ag->exec, parent_scope)) { |
| 3617 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); | 3617 | is_comptime = ir_build_const_bool(ag, parent_scope, node, true); |
| 3618 | } else { | 3618 | } else { |
| 3619 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null); | 3619 | is_comptime = ir_build_test_comptime(ag, parent_scope, node, is_non_null); |
| 3620 | } | 3620 | } |
| 3621 | | 3621 | |
| 3622 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull"); | 3622 | IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, parent_scope, "OptionalNonNull"); |
| 3623 | IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull"); | 3623 | IrBasicBlockSrc *null_block = ir_create_basic_block(ag, parent_scope, "OptionalNull"); |
| 3624 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); | 3624 | IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "OptionalEnd"); |
| 3625 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); | 3625 | IrInstSrc *cond_br_inst = ir_build_cond_br(ag, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 3626 | | 3626 | |
| 3627 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, | 3627 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(ag, cond_br_inst, ok_block, end_block, |
| 3628 | result_loc, is_comptime); | 3628 | result_loc, is_comptime); |
| 3629 | | 3629 | |
| 3630 | ir_set_cursor_at_end_and_append_block(irb, null_block); | 3630 | ir_set_cursor_at_end_and_append_block(ag, null_block); |
| 3631 | IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone, | 3631 | IrInstSrc *null_result = ir_gen_node_extra(ag, op2_node, parent_scope, LValNone, |
| 3632 | &peer_parent->peers.at(0)->base); | 3632 | &peer_parent->peers.at(0)->base); |
| 3633 | if (null_result == irb->codegen->invalid_inst_src) | 3633 | if (null_result == ag->codegen->invalid_inst_src) |
| 3634 | return irb->codegen->invalid_inst_src; | 3634 | return ag->codegen->invalid_inst_src; |
| 3635 | IrBasicBlockSrc *after_null_block = irb->current_basic_block; | 3635 | IrBasicBlockSrc *after_null_block = ag->current_basic_block; |
| 3636 | if (!instr_is_unreachable(null_result)) | 3636 | if (!instr_is_unreachable(null_result)) |
| 3637 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); | 3637 | ir_mark_gen(ir_build_br(ag, parent_scope, node, end_block, is_comptime)); |
| 3638 | | 3638 | |
| 3639 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 3639 | ir_set_cursor_at_end_and_append_block(ag, ok_block); |
| 3640 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false); | 3640 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(ag, parent_scope, node, maybe_ptr, false); |
| 3641 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); | 3641 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(ag, parent_scope, node, unwrapped_ptr); |
| 3642 | ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); | 3642 | ir_build_end_expr(ag, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); |
| 3643 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; | 3643 | IrBasicBlockSrc *after_ok_block = ag->current_basic_block; |
| 3644 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); | 3644 | ir_build_br(ag, parent_scope, node, end_block, is_comptime); |
| 3645 | | 3645 | |
| 3646 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 3646 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 3647 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 3647 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 3648 | incoming_values[0] = null_result; | 3648 | incoming_values[0] = null_result; |
| 3649 | incoming_values[1] = unwrapped_payload; | 3649 | incoming_values[1] = unwrapped_payload; |
| 3650 | IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2); | 3650 | IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2); |
| 3651 | incoming_blocks[0] = after_null_block; | 3651 | incoming_blocks[0] = after_null_block; |
| 3652 | incoming_blocks[1] = after_ok_block; | 3652 | incoming_blocks[1] = after_ok_block; |
| 3653 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); | 3653 | IrInstSrc *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 3654 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); | 3654 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 3655 | } | 3655 | } |
| 3656 | | 3656 | |
| 3657 | static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 3657 | static IrInstSrc *ir_gen_error_union(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 3658 | assert(node->type == NodeTypeBinOpExpr); | 3658 | assert(node->type == NodeTypeBinOpExpr); |
| 3659 | | 3659 | |
| 3660 | AstNode *op1_node = node->data.bin_op_expr.op1; | 3660 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 3661 | AstNode *op2_node = node->data.bin_op_expr.op2; | 3661 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 3662 | | 3662 | |
| 3663 | IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope); | 3663 | IrInstSrc *err_set = ir_gen_node(ag, op1_node, parent_scope); |
| 3664 | if (err_set == irb->codegen->invalid_inst_src) | 3664 | if (err_set == ag->codegen->invalid_inst_src) |
| 3665 | return irb->codegen->invalid_inst_src; | 3665 | return ag->codegen->invalid_inst_src; |
| 3666 | | 3666 | |
| 3667 | IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope); | 3667 | IrInstSrc *payload = ir_gen_node(ag, op2_node, parent_scope); |
| 3668 | if (payload == irb->codegen->invalid_inst_src) | 3668 | if (payload == ag->codegen->invalid_inst_src) |
| 3669 | return irb->codegen->invalid_inst_src; | 3669 | return ag->codegen->invalid_inst_src; |
| 3670 | | 3670 | |
| 3671 | return ir_build_error_union(irb, parent_scope, node, err_set, payload); | 3671 | return ir_build_error_union(ag, parent_scope, node, err_set, payload); |
| 3672 | } | 3672 | } |
| 3673 | | 3673 | |
| 3674 | static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 3674 | static IrInstSrc *ir_gen_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 3675 | assert(node->type == NodeTypeBinOpExpr); | 3675 | assert(node->type == NodeTypeBinOpExpr); |
| 3676 | | 3676 | |
| 3677 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; | 3677 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; |
| ... | @@ -3679,99 +3679,99 @@ static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, | ... | @@ -3679,99 +3679,99 @@ static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, |
| 3679 | case BinOpTypeInvalid: | 3679 | case BinOpTypeInvalid: |
| 3680 | zig_unreachable(); | 3680 | zig_unreachable(); |
| 3681 | case BinOpTypeAssign: | 3681 | case BinOpTypeAssign: |
| 3682 | return ir_lval_wrap(irb, scope, ir_gen_assign(irb, scope, node), lval, result_loc); | 3682 | return ir_lval_wrap(ag, scope, ir_gen_assign(ag, scope, node), lval, result_loc); |
| 3683 | case BinOpTypeAssignTimes: | 3683 | case BinOpTypeAssignTimes: |
| 3684 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpMult), lval, result_loc); | 3684 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpMult), lval, result_loc); |
| 3685 | case BinOpTypeAssignTimesWrap: | 3685 | case BinOpTypeAssignTimesWrap: |
| 3686 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpMultWrap), lval, result_loc); | 3686 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpMultWrap), lval, result_loc); |
| 3687 | case BinOpTypeAssignDiv: | 3687 | case BinOpTypeAssignDiv: |
| 3688 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpDivUnspecified), lval, result_loc); | 3688 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); |
| 3689 | case BinOpTypeAssignMod: | 3689 | case BinOpTypeAssignMod: |
| 3690 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpRemUnspecified), lval, result_loc); | 3690 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); |
| 3691 | case BinOpTypeAssignPlus: | 3691 | case BinOpTypeAssignPlus: |
| 3692 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpAdd), lval, result_loc); | 3692 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpAdd), lval, result_loc); |
| 3693 | case BinOpTypeAssignPlusWrap: | 3693 | case BinOpTypeAssignPlusWrap: |
| 3694 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpAddWrap), lval, result_loc); | 3694 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpAddWrap), lval, result_loc); |
| 3695 | case BinOpTypeAssignMinus: | 3695 | case BinOpTypeAssignMinus: |
| 3696 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpSub), lval, result_loc); | 3696 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpSub), lval, result_loc); |
| 3697 | case BinOpTypeAssignMinusWrap: | 3697 | case BinOpTypeAssignMinusWrap: |
| 3698 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpSubWrap), lval, result_loc); | 3698 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpSubWrap), lval, result_loc); |
| 3699 | case BinOpTypeAssignBitShiftLeft: | 3699 | case BinOpTypeAssignBitShiftLeft: |
| 3700 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); | 3700 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); |
| 3701 | case BinOpTypeAssignBitShiftRight: | 3701 | case BinOpTypeAssignBitShiftRight: |
| 3702 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); | 3702 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); |
| 3703 | case BinOpTypeAssignBitAnd: | 3703 | case BinOpTypeAssignBitAnd: |
| 3704 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBinAnd), lval, result_loc); | 3704 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinAnd), lval, result_loc); |
| 3705 | case BinOpTypeAssignBitXor: | 3705 | case BinOpTypeAssignBitXor: |
| 3706 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBinXor), lval, result_loc); | 3706 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinXor), lval, result_loc); |
| 3707 | case BinOpTypeAssignBitOr: | 3707 | case BinOpTypeAssignBitOr: |
| 3708 | return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBinOr), lval, result_loc); | 3708 | return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinOr), lval, result_loc); |
| 3709 | case BinOpTypeBoolOr: | 3709 | case BinOpTypeBoolOr: |
| 3710 | return ir_lval_wrap(irb, scope, ir_gen_bool_or(irb, scope, node), lval, result_loc); | 3710 | return ir_lval_wrap(ag, scope, ir_gen_bool_or(ag, scope, node), lval, result_loc); |
| 3711 | case BinOpTypeBoolAnd: | 3711 | case BinOpTypeBoolAnd: |
| 3712 | return ir_lval_wrap(irb, scope, ir_gen_bool_and(irb, scope, node), lval, result_loc); | 3712 | return ir_lval_wrap(ag, scope, ir_gen_bool_and(ag, scope, node), lval, result_loc); |
| 3713 | case BinOpTypeCmpEq: | 3713 | case BinOpTypeCmpEq: |
| 3714 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpEq), lval, result_loc); | 3714 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpEq), lval, result_loc); |
| 3715 | case BinOpTypeCmpNotEq: | 3715 | case BinOpTypeCmpNotEq: |
| 3716 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpNotEq), lval, result_loc); | 3716 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpNotEq), lval, result_loc); |
| 3717 | case BinOpTypeCmpLessThan: | 3717 | case BinOpTypeCmpLessThan: |
| 3718 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpLessThan), lval, result_loc); | 3718 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpLessThan), lval, result_loc); |
| 3719 | case BinOpTypeCmpGreaterThan: | 3719 | case BinOpTypeCmpGreaterThan: |
| 3720 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpGreaterThan), lval, result_loc); | 3720 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterThan), lval, result_loc); |
| 3721 | case BinOpTypeCmpLessOrEq: | 3721 | case BinOpTypeCmpLessOrEq: |
| 3722 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpLessOrEq), lval, result_loc); | 3722 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpLessOrEq), lval, result_loc); |
| 3723 | case BinOpTypeCmpGreaterOrEq: | 3723 | case BinOpTypeCmpGreaterOrEq: |
| 3724 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpGreaterOrEq), lval, result_loc); | 3724 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterOrEq), lval, result_loc); |
| 3725 | case BinOpTypeBinOr: | 3725 | case BinOpTypeBinOr: |
| 3726 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpBinOr), lval, result_loc); | 3726 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinOr), lval, result_loc); |
| 3727 | case BinOpTypeBinXor: | 3727 | case BinOpTypeBinXor: |
| 3728 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpBinXor), lval, result_loc); | 3728 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinXor), lval, result_loc); |
| 3729 | case BinOpTypeBinAnd: | 3729 | case BinOpTypeBinAnd: |
| 3730 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpBinAnd), lval, result_loc); | 3730 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinAnd), lval, result_loc); |
| 3731 | case BinOpTypeBitShiftLeft: | 3731 | case BinOpTypeBitShiftLeft: |
| 3732 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); | 3732 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); |
| 3733 | case BinOpTypeBitShiftRight: | 3733 | case BinOpTypeBitShiftRight: |
| 3734 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); | 3734 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); |
| 3735 | case BinOpTypeAdd: | 3735 | case BinOpTypeAdd: |
| 3736 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpAdd), lval, result_loc); | 3736 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpAdd), lval, result_loc); |
| 3737 | case BinOpTypeAddWrap: | 3737 | case BinOpTypeAddWrap: |
| 3738 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpAddWrap), lval, result_loc); | 3738 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpAddWrap), lval, result_loc); |
| 3739 | case BinOpTypeSub: | 3739 | case BinOpTypeSub: |
| 3740 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpSub), lval, result_loc); | 3740 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpSub), lval, result_loc); |
| 3741 | case BinOpTypeSubWrap: | 3741 | case BinOpTypeSubWrap: |
| 3742 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpSubWrap), lval, result_loc); | 3742 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpSubWrap), lval, result_loc); |
| 3743 | case BinOpTypeMult: | 3743 | case BinOpTypeMult: |
| 3744 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpMult), lval, result_loc); | 3744 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpMult), lval, result_loc); |
| 3745 | case BinOpTypeMultWrap: | 3745 | case BinOpTypeMultWrap: |
| 3746 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpMultWrap), lval, result_loc); | 3746 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpMultWrap), lval, result_loc); |
| 3747 | case BinOpTypeDiv: | 3747 | case BinOpTypeDiv: |
| 3748 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpDivUnspecified), lval, result_loc); | 3748 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); |
| 3749 | case BinOpTypeMod: | 3749 | case BinOpTypeMod: |
| 3750 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpRemUnspecified), lval, result_loc); | 3750 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); |
| 3751 | case BinOpTypeArrayCat: | 3751 | case BinOpTypeArrayCat: |
| 3752 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayCat), lval, result_loc); | 3752 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpArrayCat), lval, result_loc); |
| 3753 | case BinOpTypeArrayMult: | 3753 | case BinOpTypeArrayMult: |
| 3754 | return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult), lval, result_loc); | 3754 | return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpArrayMult), lval, result_loc); |
| 3755 | case BinOpTypeMergeErrorSets: | 3755 | case BinOpTypeMergeErrorSets: |
| 3756 | return ir_lval_wrap(irb, scope, ir_gen_merge_err_sets(irb, scope, node), lval, result_loc); | 3756 | return ir_lval_wrap(ag, scope, ir_gen_merge_err_sets(ag, scope, node), lval, result_loc); |
| 3757 | case BinOpTypeUnwrapOptional: | 3757 | case BinOpTypeUnwrapOptional: |
| 3758 | return ir_gen_orelse(irb, scope, node, lval, result_loc); | 3758 | return ir_gen_orelse(ag, scope, node, lval, result_loc); |
| 3759 | case BinOpTypeErrorUnion: | 3759 | case BinOpTypeErrorUnion: |
| 3760 | return ir_lval_wrap(irb, scope, ir_gen_error_union(irb, scope, node), lval, result_loc); | 3760 | return ir_lval_wrap(ag, scope, ir_gen_error_union(ag, scope, node), lval, result_loc); |
| 3761 | } | 3761 | } |
| 3762 | zig_unreachable(); | 3762 | zig_unreachable(); |
| 3763 | } | 3763 | } |
| 3764 | | 3764 | |
| 3765 | static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3765 | static IrInstSrc *ir_gen_int_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3766 | assert(node->type == NodeTypeIntLiteral); | 3766 | assert(node->type == NodeTypeIntLiteral); |
| 3767 | | 3767 | |
| 3768 | RootStruct *root_struct = node->owner->data.structure.root_struct; | 3768 | RootStruct *root_struct = node->owner->data.structure.root_struct; |
| 3769 | BigInt bigint; | 3769 | BigInt bigint; |
| 3770 | token_number_literal_bigint(root_struct, &bigint, node->main_token); | 3770 | token_number_literal_bigint(root_struct, &bigint, node->main_token); |
| 3771 | return ir_build_const_bigint(irb, scope, node, bigint); | 3771 | return ir_build_const_bigint(ag, scope, node, bigint); |
| 3772 | } | 3772 | } |
| 3773 | | 3773 | |
| 3774 | static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3774 | static IrInstSrc *ir_gen_float_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3775 | Error err; | 3775 | Error err; |
| 3776 | assert(node->type == NodeTypeFloatLiteral); | 3776 | assert(node->type == NodeTypeFloatLiteral); |
| 3777 | | 3777 | |
| ... | @@ -3781,14 +3781,14 @@ static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *nod | ... | @@ -3781,14 +3781,14 @@ static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *nod |
| 3781 | | 3781 | |
| 3782 | BigFloat bigfloat; | 3782 | BigFloat bigfloat; |
| 3783 | if ((err = bigfloat_init_buf(&bigfloat, (const uint8_t *)source + byte_offset))) { | 3783 | if ((err = bigfloat_init_buf(&bigfloat, (const uint8_t *)source + byte_offset))) { |
| 3784 | add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type")); | 3784 | add_node_error(ag->codegen, node, buf_sprintf("float literal out of range of any type")); |
| 3785 | return irb->codegen->invalid_inst_src; | 3785 | return ag->codegen->invalid_inst_src; |
| 3786 | } | 3786 | } |
| 3787 | | 3787 | |
| 3788 | return ir_build_const_bigfloat(irb, scope, node, bigfloat); | 3788 | return ir_build_const_bigfloat(ag, scope, node, bigfloat); |
| 3789 | } | 3789 | } |
| 3790 | | 3790 | |
| 3791 | static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3791 | static IrInstSrc *ir_gen_char_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3792 | Error err; | 3792 | Error err; |
| 3793 | assert(node->type == NodeTypeCharLiteral); | 3793 | assert(node->type == NodeTypeCharLiteral); |
| 3794 | | 3794 | |
| ... | @@ -3802,19 +3802,19 @@ static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node | ... | @@ -3802,19 +3802,19 @@ static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node |
| 3802 | uint32_t codepoint; | 3802 | uint32_t codepoint; |
| 3803 | size_t bad_index; | 3803 | size_t bad_index; |
| 3804 | if ((err = source_char_literal(source + byte_offset, &codepoint, &bad_index))) { | 3804 | if ((err = source_char_literal(source + byte_offset, &codepoint, &bad_index))) { |
| 3805 | add_node_error(irb->codegen, node, buf_sprintf("invalid character")); | 3805 | add_node_error(ag->codegen, node, buf_sprintf("invalid character")); |
| 3806 | return irb->codegen->invalid_inst_src; | 3806 | return ag->codegen->invalid_inst_src; |
| 3807 | } | 3807 | } |
| 3808 | return ir_build_const_uint(irb, scope, node, codepoint); | 3808 | return ir_build_const_uint(ag, scope, node, codepoint); |
| 3809 | } | 3809 | } |
| 3810 | | 3810 | |
| 3811 | static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3811 | static IrInstSrc *ir_gen_null_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3812 | assert(node->type == NodeTypeNullLiteral); | 3812 | assert(node->type == NodeTypeNullLiteral); |
| 3813 | | 3813 | |
| 3814 | return ir_build_const_null(irb, scope, node); | 3814 | return ir_build_const_null(ag, scope, node); |
| 3815 | } | 3815 | } |
| 3816 | | 3816 | |
| 3817 | static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 3817 | static IrInstSrc *ir_gen_symbol(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 3818 | Error err; | 3818 | Error err; |
| 3819 | assert(node->type == NodeTypeIdentifier); | 3819 | assert(node->type == NodeTypeIdentifier); |
| 3820 | | 3820 | |
| ... | @@ -3822,113 +3822,113 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, | ... | @@ -3822,113 +3822,113 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, |
| 3822 | | 3822 | |
| 3823 | if (buf_eql_str(variable_name, "_")) { | 3823 | if (buf_eql_str(variable_name, "_")) { |
| 3824 | if (lval == LValAssign) { | 3824 | if (lval == LValAssign) { |
| 3825 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node); | 3825 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, node); |
| 3826 | const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>(); | 3826 | const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>(); |
| 3827 | const_instruction->value->type = get_pointer_to_type(irb->codegen, | 3827 | const_instruction->value->type = get_pointer_to_type(ag->codegen, |
| 3828 | irb->codegen->builtin_types.entry_void, false); | 3828 | ag->codegen->builtin_types.entry_void, false); |
| 3829 | const_instruction->value->special = ConstValSpecialStatic; | 3829 | const_instruction->value->special = ConstValSpecialStatic; |
| 3830 | const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard; | 3830 | const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 3831 | return &const_instruction->base; | 3831 | return &const_instruction->base; |
| 3832 | } else { | 3832 | } else { |
| 3833 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); | 3833 | add_node_error(ag->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| 3834 | return irb->codegen->invalid_inst_src; | 3834 | return ag->codegen->invalid_inst_src; |
| 3835 | } | 3835 | } |
| 3836 | } | 3836 | } |
| 3837 | | 3837 | |
| 3838 | ZigType *primitive_type; | 3838 | ZigType *primitive_type; |
| 3839 | if ((err = get_primitive_type(irb->codegen, variable_name, &primitive_type))) { | 3839 | if ((err = get_primitive_type(ag->codegen, variable_name, &primitive_type))) { |
| 3840 | if (err == ErrorOverflow) { | 3840 | if (err == ErrorOverflow) { |
| 3841 | add_node_error(irb->codegen, node, | 3841 | add_node_error(ag->codegen, node, |
| 3842 | buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535", | 3842 | buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535", |
| 3843 | buf_ptr(variable_name))); | 3843 | buf_ptr(variable_name))); |
| 3844 | return irb->codegen->invalid_inst_src; | 3844 | return ag->codegen->invalid_inst_src; |
| 3845 | } | 3845 | } |
| 3846 | assert(err == ErrorPrimitiveTypeNotFound); | 3846 | assert(err == ErrorPrimitiveTypeNotFound); |
| 3847 | } else { | 3847 | } else { |
| 3848 | IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type); | 3848 | IrInstSrc *value = ir_build_const_type(ag, scope, node, primitive_type); |
| 3849 | if (lval == LValPtr || lval == LValAssign) { | 3849 | if (lval == LValPtr || lval == LValAssign) { |
| 3850 | return ir_build_ref_src(irb, scope, node, value); | 3850 | return ir_build_ref_src(ag, scope, node, value); |
| 3851 | } else { | 3851 | } else { |
| 3852 | return ir_expr_wrap(irb, scope, value, result_loc); | 3852 | return ir_expr_wrap(ag, scope, value, result_loc); |
| 3853 | } | 3853 | } |
| 3854 | } | 3854 | } |
| 3855 | | 3855 | |
| 3856 | ScopeFnDef *crossed_fndef_scope; | 3856 | ScopeFnDef *crossed_fndef_scope; |
| 3857 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope); | 3857 | ZigVar *var = find_variable(ag->codegen, scope, variable_name, &crossed_fndef_scope); |
| 3858 | if (var) { | 3858 | if (var) { |
| 3859 | IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); | 3859 | IrInstSrc *var_ptr = ir_build_var_ptr_x(ag, scope, node, var, crossed_fndef_scope); |
| 3860 | if (lval == LValPtr || lval == LValAssign) { | 3860 | if (lval == LValPtr || lval == LValAssign) { |
| 3861 | return var_ptr; | 3861 | return var_ptr; |
| 3862 | } else { | 3862 | } else { |
| 3863 | return ir_expr_wrap(irb, scope, ir_build_load_ptr(irb, scope, node, var_ptr), result_loc); | 3863 | return ir_expr_wrap(ag, scope, ir_build_load_ptr(ag, scope, node, var_ptr), result_loc); |
| 3864 | } | 3864 | } |
| 3865 | } | 3865 | } |
| 3866 | | 3866 | |
| 3867 | Tld *tld = find_decl(irb->codegen, scope, variable_name); | 3867 | Tld *tld = find_decl(ag->codegen, scope, variable_name); |
| 3868 | if (tld) { | 3868 | if (tld) { |
| 3869 | IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval); | 3869 | IrInstSrc *decl_ref = ir_build_decl_ref(ag, scope, node, tld, lval); |
| 3870 | if (lval == LValPtr || lval == LValAssign) { | 3870 | if (lval == LValPtr || lval == LValAssign) { |
| 3871 | return decl_ref; | 3871 | return decl_ref; |
| 3872 | } else { | 3872 | } else { |
| 3873 | return ir_expr_wrap(irb, scope, decl_ref, result_loc); | 3873 | return ir_expr_wrap(ag, scope, decl_ref, result_loc); |
| 3874 | } | 3874 | } |
| 3875 | } | 3875 | } |
| 3876 | | 3876 | |
| 3877 | if (get_container_scope(node->owner)->any_imports_failed) { | 3877 | if (get_container_scope(node->owner)->any_imports_failed) { |
| 3878 | // skip the error message since we had a failing import in this file | 3878 | // skip the error message since we had a failing import in this file |
| 3879 | // if an import breaks we don't need redundant undeclared identifier errors | 3879 | // if an import breaks we don't need redundant undeclared identifier errors |
| 3880 | return irb->codegen->invalid_inst_src; | 3880 | return ag->codegen->invalid_inst_src; |
| 3881 | } | 3881 | } |
| 3882 | | 3882 | |
| 3883 | return ir_build_undeclared_identifier(irb, scope, node, variable_name); | 3883 | return ir_build_undeclared_identifier(ag, scope, node, variable_name); |
| 3884 | } | 3884 | } |
| 3885 | | 3885 | |
| 3886 | static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 3886 | static IrInstSrc *ir_gen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 3887 | ResultLoc *result_loc) | 3887 | ResultLoc *result_loc) |
| 3888 | { | 3888 | { |
| 3889 | assert(node->type == NodeTypeArrayAccessExpr); | 3889 | assert(node->type == NodeTypeArrayAccessExpr); |
| 3890 | | 3890 | |
| 3891 | AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; | 3891 | AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; |
| 3892 | IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr); | 3892 | IrInstSrc *array_ref_instruction = ir_gen_node_extra(ag, array_ref_node, scope, LValPtr, nullptr); |
| 3893 | if (array_ref_instruction == irb->codegen->invalid_inst_src) | 3893 | if (array_ref_instruction == ag->codegen->invalid_inst_src) |
| 3894 | return array_ref_instruction; | 3894 | return array_ref_instruction; |
| 3895 | | 3895 | |
| 3896 | // Create an usize-typed result location to hold the subscript value, this | 3896 | // Create an usize-typed result location to hold the subscript value, this |
| 3897 | // makes it possible for the compiler to infer the subscript expression type | 3897 | // makes it possible for the compiler to infer the subscript expression type |
| 3898 | // if needed | 3898 | // if needed |
| 3899 | IrInstSrc *usize_type_inst = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize); | 3899 | IrInstSrc *usize_type_inst = ir_build_const_type(ag, scope, node, ag->codegen->builtin_types.entry_usize); |
| 3900 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, usize_type_inst, no_result_loc()); | 3900 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, usize_type_inst, no_result_loc()); |
| 3901 | | 3901 | |
| 3902 | AstNode *subscript_node = node->data.array_access_expr.subscript; | 3902 | AstNode *subscript_node = node->data.array_access_expr.subscript; |
| 3903 | IrInstSrc *subscript_value = ir_gen_node_extra(irb, subscript_node, scope, LValNone, &result_loc_cast->base); | 3903 | IrInstSrc *subscript_value = ir_gen_node_extra(ag, subscript_node, scope, LValNone, &result_loc_cast->base); |
| 3904 | if (subscript_value == irb->codegen->invalid_inst_src) | 3904 | if (subscript_value == ag->codegen->invalid_inst_src) |
| 3905 | return irb->codegen->invalid_inst_src; | 3905 | return ag->codegen->invalid_inst_src; |
| 3906 | | 3906 | |
| 3907 | IrInstSrc *subscript_instruction = ir_build_implicit_cast(irb, scope, subscript_node, subscript_value, result_loc_cast); | 3907 | IrInstSrc *subscript_instruction = ir_build_implicit_cast(ag, scope, subscript_node, subscript_value, result_loc_cast); |
| 3908 | | 3908 | |
| 3909 | IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, | 3909 | IrInstSrc *ptr_instruction = ir_build_elem_ptr(ag, scope, node, array_ref_instruction, |
| 3910 | subscript_instruction, true, PtrLenSingle, nullptr); | 3910 | subscript_instruction, true, PtrLenSingle, nullptr); |
| 3911 | if (lval == LValPtr || lval == LValAssign) | 3911 | if (lval == LValPtr || lval == LValAssign) |
| 3912 | return ptr_instruction; | 3912 | return ptr_instruction; |
| 3913 | | 3913 | |
| 3914 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); | 3914 | IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction); |
| 3915 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); | 3915 | return ir_expr_wrap(ag, scope, load_ptr, result_loc); |
| 3916 | } | 3916 | } |
| 3917 | | 3917 | |
| 3918 | static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3918 | static IrInstSrc *ir_gen_field_access(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3919 | assert(node->type == NodeTypeFieldAccessExpr); | 3919 | assert(node->type == NodeTypeFieldAccessExpr); |
| 3920 | | 3920 | |
| 3921 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; | 3921 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; |
| 3922 | Buf *field_name = node->data.field_access_expr.field_name; | 3922 | Buf *field_name = node->data.field_access_expr.field_name; |
| 3923 | | 3923 | |
| 3924 | IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr); | 3924 | IrInstSrc *container_ref_instruction = ir_gen_node_extra(ag, container_ref_node, scope, LValPtr, nullptr); |
| 3925 | if (container_ref_instruction == irb->codegen->invalid_inst_src) | 3925 | if (container_ref_instruction == ag->codegen->invalid_inst_src) |
| 3926 | return container_ref_instruction; | 3926 | return container_ref_instruction; |
| 3927 | | 3927 | |
| 3928 | return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false); | 3928 | return ir_build_field_ptr(ag, scope, node, container_ref_instruction, field_name, false); |
| 3929 | } | 3929 | } |
| 3930 | | 3930 | |
| 3931 | static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) { | 3931 | static IrInstSrc *ir_gen_overflow_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrOverflowOp op) { |
| 3932 | assert(node->type == NodeTypeFnCallExpr); | 3932 | assert(node->type == NodeTypeFnCallExpr); |
| 3933 | | 3933 | |
| 3934 | AstNode *type_node = node->data.fn_call_expr.params.at(0); | 3934 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -3937,26 +3937,26 @@ static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -3937,26 +3937,26 @@ static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 3937 | AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3); | 3937 | AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3); |
| 3938 | | 3938 | |
| 3939 | | 3939 | |
| 3940 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); | 3940 | IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); |
| 3941 | if (type_value == irb->codegen->invalid_inst_src) | 3941 | if (type_value == ag->codegen->invalid_inst_src) |
| 3942 | return irb->codegen->invalid_inst_src; | 3942 | return ag->codegen->invalid_inst_src; |
| 3943 | | 3943 | |
| 3944 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); | 3944 | IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope); |
| 3945 | if (op1 == irb->codegen->invalid_inst_src) | 3945 | if (op1 == ag->codegen->invalid_inst_src) |
| 3946 | return irb->codegen->invalid_inst_src; | 3946 | return ag->codegen->invalid_inst_src; |
| 3947 | | 3947 | |
| 3948 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); | 3948 | IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope); |
| 3949 | if (op2 == irb->codegen->invalid_inst_src) | 3949 | if (op2 == ag->codegen->invalid_inst_src) |
| 3950 | return irb->codegen->invalid_inst_src; | 3950 | return ag->codegen->invalid_inst_src; |
| 3951 | | 3951 | |
| 3952 | IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope); | 3952 | IrInstSrc *result_ptr = ir_gen_node(ag, result_ptr_node, scope); |
| 3953 | if (result_ptr == irb->codegen->invalid_inst_src) | 3953 | if (result_ptr == ag->codegen->invalid_inst_src) |
| 3954 | return irb->codegen->invalid_inst_src; | 3954 | return ag->codegen->invalid_inst_src; |
| 3955 | | 3955 | |
| 3956 | return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr); | 3956 | return ir_build_overflow_op_src(ag, scope, node, op, type_value, op1, op2, result_ptr); |
| 3957 | } | 3957 | } |
| 3958 | | 3958 | |
| 3959 | static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 3959 | static IrInstSrc *ir_gen_mul_add(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 3960 | assert(node->type == NodeTypeFnCallExpr); | 3960 | assert(node->type == NodeTypeFnCallExpr); |
| 3961 | | 3961 | |
| 3962 | AstNode *type_node = node->data.fn_call_expr.params.at(0); | 3962 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -3964,63 +3964,63 @@ static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) | ... | @@ -3964,63 +3964,63 @@ static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) |
| 3964 | AstNode *op2_node = node->data.fn_call_expr.params.at(2); | 3964 | AstNode *op2_node = node->data.fn_call_expr.params.at(2); |
| 3965 | AstNode *op3_node = node->data.fn_call_expr.params.at(3); | 3965 | AstNode *op3_node = node->data.fn_call_expr.params.at(3); |
| 3966 | | 3966 | |
| 3967 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); | 3967 | IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); |
| 3968 | if (type_value == irb->codegen->invalid_inst_src) | 3968 | if (type_value == ag->codegen->invalid_inst_src) |
| 3969 | return irb->codegen->invalid_inst_src; | 3969 | return ag->codegen->invalid_inst_src; |
| 3970 | | 3970 | |
| 3971 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); | 3971 | IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope); |
| 3972 | if (op1 == irb->codegen->invalid_inst_src) | 3972 | if (op1 == ag->codegen->invalid_inst_src) |
| 3973 | return irb->codegen->invalid_inst_src; | 3973 | return ag->codegen->invalid_inst_src; |
| 3974 | | 3974 | |
| 3975 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); | 3975 | IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope); |
| 3976 | if (op2 == irb->codegen->invalid_inst_src) | 3976 | if (op2 == ag->codegen->invalid_inst_src) |
| 3977 | return irb->codegen->invalid_inst_src; | 3977 | return ag->codegen->invalid_inst_src; |
| 3978 | | 3978 | |
| 3979 | IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope); | 3979 | IrInstSrc *op3 = ir_gen_node(ag, op3_node, scope); |
| 3980 | if (op3 == irb->codegen->invalid_inst_src) | 3980 | if (op3 == ag->codegen->invalid_inst_src) |
| 3981 | return irb->codegen->invalid_inst_src; | 3981 | return ag->codegen->invalid_inst_src; |
| 3982 | | 3982 | |
| 3983 | return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3); | 3983 | return ir_build_mul_add_src(ag, scope, node, type_value, op1, op2, op3); |
| 3984 | } | 3984 | } |
| 3985 | | 3985 | |
| 3986 | static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) { | 3986 | static IrInstSrc *ir_gen_this(Stage1AstGen *ag, Scope *orig_scope, AstNode *node) { |
| 3987 | for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { | 3987 | for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { |
| 3988 | if (it_scope->id == ScopeIdDecls) { | 3988 | if (it_scope->id == ScopeIdDecls) { |
| 3989 | ScopeDecls *decls_scope = (ScopeDecls *)it_scope; | 3989 | ScopeDecls *decls_scope = (ScopeDecls *)it_scope; |
| 3990 | ZigType *container_type = decls_scope->container_type; | 3990 | ZigType *container_type = decls_scope->container_type; |
| 3991 | if (container_type != nullptr) { | 3991 | if (container_type != nullptr) { |
| 3992 | return ir_build_const_type(irb, orig_scope, node, container_type); | 3992 | return ir_build_const_type(ag, orig_scope, node, container_type); |
| 3993 | } else { | 3993 | } else { |
| 3994 | return ir_build_const_import(irb, orig_scope, node, decls_scope->import); | 3994 | return ir_build_const_import(ag, orig_scope, node, decls_scope->import); |
| 3995 | } | 3995 | } |
| 3996 | } | 3996 | } |
| 3997 | } | 3997 | } |
| 3998 | zig_unreachable(); | 3998 | zig_unreachable(); |
| 3999 | } | 3999 | } |
| 4000 | | 4000 | |
| 4001 | static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node, | 4001 | static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *await_node, AstNode *call_node, |
| 4002 | LVal lval, ResultLoc *result_loc) | 4002 | LVal lval, ResultLoc *result_loc) |
| 4003 | { | 4003 | { |
| 4004 | if (call_node->data.fn_call_expr.params.length != 4) { | 4004 | if (call_node->data.fn_call_expr.params.length != 4) { |
| 4005 | add_node_error(irb->codegen, call_node, | 4005 | add_node_error(ag->codegen, call_node, |
| 4006 | buf_sprintf("expected 4 arguments, found %" ZIG_PRI_usize, | 4006 | buf_sprintf("expected 4 arguments, found %" ZIG_PRI_usize, |
| 4007 | call_node->data.fn_call_expr.params.length)); | 4007 | call_node->data.fn_call_expr.params.length)); |
| 4008 | return irb->codegen->invalid_inst_src; | 4008 | return ag->codegen->invalid_inst_src; |
| 4009 | } | 4009 | } |
| 4010 | | 4010 | |
| 4011 | AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0); | 4011 | AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0); |
| 4012 | IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope); | 4012 | IrInstSrc *bytes = ir_gen_node(ag, bytes_node, scope); |
| 4013 | if (bytes == irb->codegen->invalid_inst_src) | 4013 | if (bytes == ag->codegen->invalid_inst_src) |
| 4014 | return bytes; | 4014 | return bytes; |
| 4015 | | 4015 | |
| 4016 | AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1); | 4016 | AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1); |
| 4017 | IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope); | 4017 | IrInstSrc *ret_ptr = ir_gen_node(ag, ret_ptr_node, scope); |
| 4018 | if (ret_ptr == irb->codegen->invalid_inst_src) | 4018 | if (ret_ptr == ag->codegen->invalid_inst_src) |
| 4019 | return ret_ptr; | 4019 | return ret_ptr; |
| 4020 | | 4020 | |
| 4021 | AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2); | 4021 | AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2); |
| 4022 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); | 4022 | IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); |
| 4023 | if (fn_ref == irb->codegen->invalid_inst_src) | 4023 | if (fn_ref == ag->codegen->invalid_inst_src) |
| 4024 | return fn_ref; | 4024 | return fn_ref; |
| 4025 | | 4025 | |
| 4026 | CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone; | 4026 | CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone; |
| ... | @@ -4034,89 +4034,89 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw | ... | @@ -4034,89 +4034,89 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw |
| 4034 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count); | 4034 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count); |
| 4035 | for (size_t i = 0; i < arg_count; i += 1) { | 4035 | for (size_t i = 0; i < arg_count; i += 1) { |
| 4036 | AstNode *arg_node = args_node->data.container_init_expr.entries.at(i); | 4036 | AstNode *arg_node = args_node->data.container_init_expr.entries.at(i); |
| 4037 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); | 4037 | IrInstSrc *arg = ir_gen_node(ag, arg_node, scope); |
| 4038 | if (arg == irb->codegen->invalid_inst_src) | 4038 | if (arg == ag->codegen->invalid_inst_src) |
| 4039 | return arg; | 4039 | return arg; |
| 4040 | args[i] = arg; | 4040 | args[i] = arg; |
| 4041 | } | 4041 | } |
| 4042 | | 4042 | |
| 4043 | IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, | 4043 | IrInstSrc *call = ir_build_call_src(ag, scope, call_node, nullptr, fn_ref, arg_count, args, |
| 4044 | ret_ptr, modifier, is_async_call_builtin, bytes, result_loc); | 4044 | ret_ptr, modifier, is_async_call_builtin, bytes, result_loc); |
| 4045 | return ir_lval_wrap(irb, scope, call, lval, result_loc); | 4045 | return ir_lval_wrap(ag, scope, call, lval, result_loc); |
| 4046 | } else { | 4046 | } else { |
| 4047 | exec_add_error_node(irb->codegen, irb->exec, args_node, | 4047 | exec_add_error_node(ag->codegen, ag->exec, args_node, |
| 4048 | buf_sprintf("TODO: @asyncCall with anon struct literal")); | 4048 | buf_sprintf("TODO: @asyncCall with anon struct literal")); |
| 4049 | return irb->codegen->invalid_inst_src; | 4049 | return ag->codegen->invalid_inst_src; |
| 4050 | } | 4050 | } |
| 4051 | } | 4051 | } |
| 4052 | IrInstSrc *args = ir_gen_node(irb, args_node, scope); | 4052 | IrInstSrc *args = ir_gen_node(ag, args_node, scope); |
| 4053 | if (args == irb->codegen->invalid_inst_src) | 4053 | if (args == ag->codegen->invalid_inst_src) |
| 4054 | return args; | 4054 | return args; |
| 4055 | | 4055 | |
| 4056 | IrInstSrc *call = ir_build_async_call_extra(irb, scope, call_node, modifier, fn_ref, ret_ptr, bytes, args, result_loc); | 4056 | IrInstSrc *call = ir_build_async_call_extra(ag, scope, call_node, modifier, fn_ref, ret_ptr, bytes, args, result_loc); |
| 4057 | return ir_lval_wrap(irb, scope, call, lval, result_loc); | 4057 | return ir_lval_wrap(ag, scope, call, lval, result_loc); |
| 4058 | } | 4058 | } |
| 4059 | | 4059 | |
| 4060 | static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 4060 | static IrInstSrc *ir_gen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 4061 | AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options, | 4061 | AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options, |
| 4062 | AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc) | 4062 | AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc) |
| 4063 | { | 4063 | { |
| 4064 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); | 4064 | IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); |
| 4065 | if (fn_ref == irb->codegen->invalid_inst_src) | 4065 | if (fn_ref == ag->codegen->invalid_inst_src) |
| 4066 | return fn_ref; | 4066 | return fn_ref; |
| 4067 | | 4067 | |
| 4068 | IrInstSrc *fn_type = ir_build_typeof_1(irb, scope, source_node, fn_ref); | 4068 | IrInstSrc *fn_type = ir_build_typeof_1(ag, scope, source_node, fn_ref); |
| 4069 | | 4069 | |
| 4070 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(args_len); | 4070 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(args_len); |
| 4071 | for (size_t i = 0; i < args_len; i += 1) { | 4071 | for (size_t i = 0; i < args_len; i += 1) { |
| 4072 | AstNode *arg_node = args_ptr[i]; | 4072 | AstNode *arg_node = args_ptr[i]; |
| 4073 | | 4073 | |
| 4074 | IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i); | 4074 | IrInstSrc *arg_index = ir_build_const_usize(ag, scope, arg_node, i); |
| 4075 | IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true); | 4075 | IrInstSrc *arg_type = ir_build_arg_type(ag, scope, source_node, fn_type, arg_index, true); |
| 4076 | ResultLoc *no_result = no_result_loc(); | 4076 | ResultLoc *no_result = no_result_loc(); |
| 4077 | ir_build_reset_result(irb, scope, source_node, no_result); | 4077 | ir_build_reset_result(ag, scope, source_node, no_result); |
| 4078 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result); | 4078 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, arg_type, no_result); |
| 4079 | | 4079 | |
| 4080 | IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base); | 4080 | IrInstSrc *arg = ir_gen_node_extra(ag, arg_node, scope, LValNone, &result_loc_cast->base); |
| 4081 | if (arg == irb->codegen->invalid_inst_src) | 4081 | if (arg == ag->codegen->invalid_inst_src) |
| 4082 | return arg; | 4082 | return arg; |
| 4083 | | 4083 | |
| 4084 | args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast); | 4084 | args[i] = ir_build_implicit_cast(ag, scope, arg_node, arg, result_loc_cast); |
| 4085 | } | 4085 | } |
| 4086 | | 4086 | |
| 4087 | IrInstSrc *fn_call; | 4087 | IrInstSrc *fn_call; |
| 4088 | if (options != nullptr) { | 4088 | if (options != nullptr) { |
| 4089 | fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc); | 4089 | fn_call = ir_build_call_args(ag, scope, source_node, options, fn_ref, args, args_len, result_loc); |
| 4090 | } else { | 4090 | } else { |
| 4091 | fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr, | 4091 | fn_call = ir_build_call_src(ag, scope, source_node, nullptr, fn_ref, args_len, args, nullptr, |
| 4092 | modifier, false, nullptr, result_loc); | 4092 | modifier, false, nullptr, result_loc); |
| 4093 | } | 4093 | } |
| 4094 | return ir_lval_wrap(irb, scope, fn_call, lval, result_loc); | 4094 | return ir_lval_wrap(ag, scope, fn_call, lval, result_loc); |
| 4095 | } | 4095 | } |
| 4096 | | 4096 | |
| 4097 | static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 4097 | static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 4098 | ResultLoc *result_loc) | 4098 | ResultLoc *result_loc) |
| 4099 | { | 4099 | { |
| 4100 | assert(node->type == NodeTypeFnCallExpr); | 4100 | assert(node->type == NodeTypeFnCallExpr); |
| 4101 | | 4101 | |
| 4102 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; | 4102 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; |
| 4103 | Buf *name = node_identifier_buf(fn_ref_expr); | 4103 | Buf *name = node_identifier_buf(fn_ref_expr); |
| 4104 | auto entry = irb->codegen->builtin_fn_table.maybe_get(name); | 4104 | auto entry = ag->codegen->builtin_fn_table.maybe_get(name); |
| 4105 | | 4105 | |
| 4106 | if (!entry) { | 4106 | if (!entry) { |
| 4107 | add_node_error(irb->codegen, node, | 4107 | add_node_error(ag->codegen, node, |
| 4108 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); | 4108 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); |
| 4109 | return irb->codegen->invalid_inst_src; | 4109 | return ag->codegen->invalid_inst_src; |
| 4110 | } | 4110 | } |
| 4111 | | 4111 | |
| 4112 | BuiltinFnEntry *builtin_fn = entry->value; | 4112 | BuiltinFnEntry *builtin_fn = entry->value; |
| 4113 | size_t actual_param_count = node->data.fn_call_expr.params.length; | 4113 | size_t actual_param_count = node->data.fn_call_expr.params.length; |
| 4114 | | 4114 | |
| 4115 | if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) { | 4115 | if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) { |
| 4116 | add_node_error(irb->codegen, node, | 4116 | add_node_error(ag->codegen, node, |
| 4117 | buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize, | 4117 | buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize, |
| 4118 | builtin_fn->param_count, actual_param_count)); | 4118 | builtin_fn->param_count, actual_param_count)); |
| 4119 | return irb->codegen->invalid_inst_src; | 4119 | return ag->codegen->invalid_inst_src; |
| 4120 | } | 4120 | } |
| 4121 | | 4121 | |
| 4122 | switch (builtin_fn->id) { | 4122 | switch (builtin_fn->id) { |
| ... | @@ -4124,152 +4124,152 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -4124,152 +4124,152 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 4124 | zig_unreachable(); | 4124 | zig_unreachable(); |
| 4125 | case BuiltinFnIdTypeof: | 4125 | case BuiltinFnIdTypeof: |
| 4126 | { | 4126 | { |
| 4127 | Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope); | 4127 | Scope *sub_scope = create_typeof_scope(ag->codegen, node, scope); |
| 4128 | | 4128 | |
| 4129 | size_t arg_count = node->data.fn_call_expr.params.length; | 4129 | size_t arg_count = node->data.fn_call_expr.params.length; |
| 4130 | | 4130 | |
| 4131 | IrInstSrc *type_of; | 4131 | IrInstSrc *type_of; |
| 4132 | | 4132 | |
| 4133 | if (arg_count == 0) { | 4133 | if (arg_count == 0) { |
| 4134 | add_node_error(irb->codegen, node, | 4134 | add_node_error(ag->codegen, node, |
| 4135 | buf_sprintf("expected at least 1 argument, found 0")); | 4135 | buf_sprintf("expected at least 1 argument, found 0")); |
| 4136 | return irb->codegen->invalid_inst_src; | 4136 | return ag->codegen->invalid_inst_src; |
| 4137 | } else if (arg_count == 1) { | 4137 | } else if (arg_count == 1) { |
| 4138 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4138 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4139 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, sub_scope); | 4139 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, sub_scope); |
| 4140 | if (arg0_value == irb->codegen->invalid_inst_src) | 4140 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4141 | return arg0_value; | 4141 | return arg0_value; |
| 4142 | | 4142 | |
| 4143 | type_of = ir_build_typeof_1(irb, scope, node, arg0_value); | 4143 | type_of = ir_build_typeof_1(ag, scope, node, arg0_value); |
| 4144 | } else { | 4144 | } else { |
| 4145 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count); | 4145 | IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count); |
| 4146 | for (size_t i = 0; i < arg_count; i += 1) { | 4146 | for (size_t i = 0; i < arg_count; i += 1) { |
| 4147 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); | 4147 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); |
| 4148 | IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope); | 4148 | IrInstSrc *arg = ir_gen_node(ag, arg_node, sub_scope); |
| 4149 | if (arg == irb->codegen->invalid_inst_src) | 4149 | if (arg == ag->codegen->invalid_inst_src) |
| 4150 | return irb->codegen->invalid_inst_src; | 4150 | return ag->codegen->invalid_inst_src; |
| 4151 | args[i] = arg; | 4151 | args[i] = arg; |
| 4152 | } | 4152 | } |
| 4153 | | 4153 | |
| 4154 | type_of = ir_build_typeof_n(irb, scope, node, args, arg_count); | 4154 | type_of = ir_build_typeof_n(ag, scope, node, args, arg_count); |
| 4155 | } | 4155 | } |
| 4156 | return ir_lval_wrap(irb, scope, type_of, lval, result_loc); | 4156 | return ir_lval_wrap(ag, scope, type_of, lval, result_loc); |
| 4157 | } | 4157 | } |
| 4158 | case BuiltinFnIdSetCold: | 4158 | case BuiltinFnIdSetCold: |
| 4159 | { | 4159 | { |
| 4160 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4160 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4161 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4161 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4162 | if (arg0_value == irb->codegen->invalid_inst_src) | 4162 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4163 | return arg0_value; | 4163 | return arg0_value; |
| 4164 | | 4164 | |
| 4165 | IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); | 4165 | IrInstSrc *set_cold = ir_build_set_cold(ag, scope, node, arg0_value); |
| 4166 | return ir_lval_wrap(irb, scope, set_cold, lval, result_loc); | 4166 | return ir_lval_wrap(ag, scope, set_cold, lval, result_loc); |
| 4167 | } | 4167 | } |
| 4168 | case BuiltinFnIdSetRuntimeSafety: | 4168 | case BuiltinFnIdSetRuntimeSafety: |
| 4169 | { | 4169 | { |
| 4170 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4170 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4171 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4171 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4172 | if (arg0_value == irb->codegen->invalid_inst_src) | 4172 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4173 | return arg0_value; | 4173 | return arg0_value; |
| 4174 | | 4174 | |
| 4175 | IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); | 4175 | IrInstSrc *set_safety = ir_build_set_runtime_safety(ag, scope, node, arg0_value); |
| 4176 | return ir_lval_wrap(irb, scope, set_safety, lval, result_loc); | 4176 | return ir_lval_wrap(ag, scope, set_safety, lval, result_loc); |
| 4177 | } | 4177 | } |
| 4178 | case BuiltinFnIdSetFloatMode: | 4178 | case BuiltinFnIdSetFloatMode: |
| 4179 | { | 4179 | { |
| 4180 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4180 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4181 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4181 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4182 | if (arg0_value == irb->codegen->invalid_inst_src) | 4182 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4183 | return arg0_value; | 4183 | return arg0_value; |
| 4184 | | 4184 | |
| 4185 | IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); | 4185 | IrInstSrc *set_float_mode = ir_build_set_float_mode(ag, scope, node, arg0_value); |
| 4186 | return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc); | 4186 | return ir_lval_wrap(ag, scope, set_float_mode, lval, result_loc); |
| 4187 | } | 4187 | } |
| 4188 | case BuiltinFnIdSizeof: | 4188 | case BuiltinFnIdSizeof: |
| 4189 | case BuiltinFnIdBitSizeof: | 4189 | case BuiltinFnIdBitSizeof: |
| 4190 | { | 4190 | { |
| 4191 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4191 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4192 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4192 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4193 | if (arg0_value == irb->codegen->invalid_inst_src) | 4193 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4194 | return arg0_value; | 4194 | return arg0_value; |
| 4195 | | 4195 | |
| 4196 | IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); | 4196 | IrInstSrc *size_of = ir_build_size_of(ag, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); |
| 4197 | return ir_lval_wrap(irb, scope, size_of, lval, result_loc); | 4197 | return ir_lval_wrap(ag, scope, size_of, lval, result_loc); |
| 4198 | } | 4198 | } |
| 4199 | case BuiltinFnIdImport: | 4199 | case BuiltinFnIdImport: |
| 4200 | { | 4200 | { |
| 4201 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4201 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4202 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4202 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4203 | if (arg0_value == irb->codegen->invalid_inst_src) | 4203 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4204 | return arg0_value; | 4204 | return arg0_value; |
| 4205 | | 4205 | |
| 4206 | IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value); | 4206 | IrInstSrc *import = ir_build_import(ag, scope, node, arg0_value); |
| 4207 | return ir_lval_wrap(irb, scope, import, lval, result_loc); | 4207 | return ir_lval_wrap(ag, scope, import, lval, result_loc); |
| 4208 | } | 4208 | } |
| 4209 | case BuiltinFnIdCImport: | 4209 | case BuiltinFnIdCImport: |
| 4210 | { | 4210 | { |
| 4211 | IrInstSrc *c_import = ir_build_c_import(irb, scope, node); | 4211 | IrInstSrc *c_import = ir_build_c_import(ag, scope, node); |
| 4212 | return ir_lval_wrap(irb, scope, c_import, lval, result_loc); | 4212 | return ir_lval_wrap(ag, scope, c_import, lval, result_loc); |
| 4213 | } | 4213 | } |
| 4214 | case BuiltinFnIdCInclude: | 4214 | case BuiltinFnIdCInclude: |
| 4215 | { | 4215 | { |
| 4216 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4216 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4217 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4217 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4218 | if (arg0_value == irb->codegen->invalid_inst_src) | 4218 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4219 | return arg0_value; | 4219 | return arg0_value; |
| 4220 | | 4220 | |
| 4221 | if (!exec_c_import_buf(irb->exec)) { | 4221 | if (!exec_c_import_buf(ag->exec)) { |
| 4222 | add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block")); | 4222 | add_node_error(ag->codegen, node, buf_sprintf("C include valid only inside C import block")); |
| 4223 | return irb->codegen->invalid_inst_src; | 4223 | return ag->codegen->invalid_inst_src; |
| 4224 | } | 4224 | } |
| 4225 | | 4225 | |
| 4226 | IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value); | 4226 | IrInstSrc *c_include = ir_build_c_include(ag, scope, node, arg0_value); |
| 4227 | return ir_lval_wrap(irb, scope, c_include, lval, result_loc); | 4227 | return ir_lval_wrap(ag, scope, c_include, lval, result_loc); |
| 4228 | } | 4228 | } |
| 4229 | case BuiltinFnIdCDefine: | 4229 | case BuiltinFnIdCDefine: |
| 4230 | { | 4230 | { |
| 4231 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4231 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4232 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4232 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4233 | if (arg0_value == irb->codegen->invalid_inst_src) | 4233 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4234 | return arg0_value; | 4234 | return arg0_value; |
| 4235 | | 4235 | |
| 4236 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4236 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4237 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4237 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4238 | if (arg1_value == irb->codegen->invalid_inst_src) | 4238 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4239 | return arg1_value; | 4239 | return arg1_value; |
| 4240 | | 4240 | |
| 4241 | if (!exec_c_import_buf(irb->exec)) { | 4241 | if (!exec_c_import_buf(ag->exec)) { |
| 4242 | add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block")); | 4242 | add_node_error(ag->codegen, node, buf_sprintf("C define valid only inside C import block")); |
| 4243 | return irb->codegen->invalid_inst_src; | 4243 | return ag->codegen->invalid_inst_src; |
| 4244 | } | 4244 | } |
| 4245 | | 4245 | |
| 4246 | IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); | 4246 | IrInstSrc *c_define = ir_build_c_define(ag, scope, node, arg0_value, arg1_value); |
| 4247 | return ir_lval_wrap(irb, scope, c_define, lval, result_loc); | 4247 | return ir_lval_wrap(ag, scope, c_define, lval, result_loc); |
| 4248 | } | 4248 | } |
| 4249 | case BuiltinFnIdCUndef: | 4249 | case BuiltinFnIdCUndef: |
| 4250 | { | 4250 | { |
| 4251 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4251 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4252 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4252 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4253 | if (arg0_value == irb->codegen->invalid_inst_src) | 4253 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4254 | return arg0_value; | 4254 | return arg0_value; |
| 4255 | | 4255 | |
| 4256 | if (!exec_c_import_buf(irb->exec)) { | 4256 | if (!exec_c_import_buf(ag->exec)) { |
| 4257 | add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block")); | 4257 | add_node_error(ag->codegen, node, buf_sprintf("C undef valid only inside C import block")); |
| 4258 | return irb->codegen->invalid_inst_src; | 4258 | return ag->codegen->invalid_inst_src; |
| 4259 | } | 4259 | } |
| 4260 | | 4260 | |
| 4261 | IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); | 4261 | IrInstSrc *c_undef = ir_build_c_undef(ag, scope, node, arg0_value); |
| 4262 | return ir_lval_wrap(irb, scope, c_undef, lval, result_loc); | 4262 | return ir_lval_wrap(ag, scope, c_undef, lval, result_loc); |
| 4263 | } | 4263 | } |
| 4264 | case BuiltinFnIdCompileErr: | 4264 | case BuiltinFnIdCompileErr: |
| 4265 | { | 4265 | { |
| 4266 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4266 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4267 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4267 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4268 | if (arg0_value == irb->codegen->invalid_inst_src) | 4268 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4269 | return arg0_value; | 4269 | return arg0_value; |
| 4270 | | 4270 | |
| 4271 | IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); | 4271 | IrInstSrc *compile_err = ir_build_compile_err(ag, scope, node, arg0_value); |
| 4272 | return ir_lval_wrap(irb, scope, compile_err, lval, result_loc); | 4272 | return ir_lval_wrap(ag, scope, compile_err, lval, result_loc); |
| 4273 | } | 4273 | } |
| 4274 | case BuiltinFnIdCompileLog: | 4274 | case BuiltinFnIdCompileLog: |
| 4275 | { | 4275 | { |
| ... | @@ -4277,171 +4277,171 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -4277,171 +4277,171 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 4277 | | 4277 | |
| 4278 | for (size_t i = 0; i < actual_param_count; i += 1) { | 4278 | for (size_t i = 0; i < actual_param_count; i += 1) { |
| 4279 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); | 4279 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); |
| 4280 | args[i] = ir_gen_node(irb, arg_node, scope); | 4280 | args[i] = ir_gen_node(ag, arg_node, scope); |
| 4281 | if (args[i] == irb->codegen->invalid_inst_src) | 4281 | if (args[i] == ag->codegen->invalid_inst_src) |
| 4282 | return irb->codegen->invalid_inst_src; | 4282 | return ag->codegen->invalid_inst_src; |
| 4283 | } | 4283 | } |
| 4284 | | 4284 | |
| 4285 | IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); | 4285 | IrInstSrc *compile_log = ir_build_compile_log(ag, scope, node, actual_param_count, args); |
| 4286 | return ir_lval_wrap(irb, scope, compile_log, lval, result_loc); | 4286 | return ir_lval_wrap(ag, scope, compile_log, lval, result_loc); |
| 4287 | } | 4287 | } |
| 4288 | case BuiltinFnIdErrName: | 4288 | case BuiltinFnIdErrName: |
| 4289 | { | 4289 | { |
| 4290 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4290 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4291 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4291 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4292 | if (arg0_value == irb->codegen->invalid_inst_src) | 4292 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4293 | return arg0_value; | 4293 | return arg0_value; |
| 4294 | | 4294 | |
| 4295 | IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value); | 4295 | IrInstSrc *err_name = ir_build_err_name(ag, scope, node, arg0_value); |
| 4296 | return ir_lval_wrap(irb, scope, err_name, lval, result_loc); | 4296 | return ir_lval_wrap(ag, scope, err_name, lval, result_loc); |
| 4297 | } | 4297 | } |
| 4298 | case BuiltinFnIdEmbedFile: | 4298 | case BuiltinFnIdEmbedFile: |
| 4299 | { | 4299 | { |
| 4300 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4300 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4301 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4301 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4302 | if (arg0_value == irb->codegen->invalid_inst_src) | 4302 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4303 | return arg0_value; | 4303 | return arg0_value; |
| 4304 | | 4304 | |
| 4305 | IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); | 4305 | IrInstSrc *embed_file = ir_build_embed_file(ag, scope, node, arg0_value); |
| 4306 | return ir_lval_wrap(irb, scope, embed_file, lval, result_loc); | 4306 | return ir_lval_wrap(ag, scope, embed_file, lval, result_loc); |
| 4307 | } | 4307 | } |
| 4308 | case BuiltinFnIdCmpxchgWeak: | 4308 | case BuiltinFnIdCmpxchgWeak: |
| 4309 | case BuiltinFnIdCmpxchgStrong: | 4309 | case BuiltinFnIdCmpxchgStrong: |
| 4310 | { | 4310 | { |
| 4311 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4311 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4312 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4312 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4313 | if (arg0_value == irb->codegen->invalid_inst_src) | 4313 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4314 | return arg0_value; | 4314 | return arg0_value; |
| 4315 | | 4315 | |
| 4316 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4316 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4317 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4317 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4318 | if (arg1_value == irb->codegen->invalid_inst_src) | 4318 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4319 | return arg1_value; | 4319 | return arg1_value; |
| 4320 | | 4320 | |
| 4321 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 4321 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 4322 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 4322 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 4323 | if (arg2_value == irb->codegen->invalid_inst_src) | 4323 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 4324 | return arg2_value; | 4324 | return arg2_value; |
| 4325 | | 4325 | |
| 4326 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); | 4326 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 4327 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); | 4327 | IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); |
| 4328 | if (arg3_value == irb->codegen->invalid_inst_src) | 4328 | if (arg3_value == ag->codegen->invalid_inst_src) |
| 4329 | return arg3_value; | 4329 | return arg3_value; |
| 4330 | | 4330 | |
| 4331 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); | 4331 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); |
| 4332 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); | 4332 | IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope); |
| 4333 | if (arg4_value == irb->codegen->invalid_inst_src) | 4333 | if (arg4_value == ag->codegen->invalid_inst_src) |
| 4334 | return arg4_value; | 4334 | return arg4_value; |
| 4335 | | 4335 | |
| 4336 | AstNode *arg5_node = node->data.fn_call_expr.params.at(5); | 4336 | AstNode *arg5_node = node->data.fn_call_expr.params.at(5); |
| 4337 | IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope); | 4337 | IrInstSrc *arg5_value = ir_gen_node(ag, arg5_node, scope); |
| 4338 | if (arg5_value == irb->codegen->invalid_inst_src) | 4338 | if (arg5_value == ag->codegen->invalid_inst_src) |
| 4339 | return arg5_value; | 4339 | return arg5_value; |
| 4340 | | 4340 | |
| 4341 | IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, | 4341 | IrInstSrc *cmpxchg = ir_build_cmpxchg_src(ag, scope, node, arg0_value, arg1_value, |
| 4342 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak), | 4342 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak), |
| 4343 | result_loc); | 4343 | result_loc); |
| 4344 | return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc); | 4344 | return ir_lval_wrap(ag, scope, cmpxchg, lval, result_loc); |
| 4345 | } | 4345 | } |
| 4346 | case BuiltinFnIdFence: | 4346 | case BuiltinFnIdFence: |
| 4347 | { | 4347 | { |
| 4348 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4348 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4349 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4349 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4350 | if (arg0_value == irb->codegen->invalid_inst_src) | 4350 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4351 | return arg0_value; | 4351 | return arg0_value; |
| 4352 | | 4352 | |
| 4353 | IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value); | 4353 | IrInstSrc *fence = ir_build_fence(ag, scope, node, arg0_value); |
| 4354 | return ir_lval_wrap(irb, scope, fence, lval, result_loc); | 4354 | return ir_lval_wrap(ag, scope, fence, lval, result_loc); |
| 4355 | } | 4355 | } |
| 4356 | case BuiltinFnIdReduce: | 4356 | case BuiltinFnIdReduce: |
| 4357 | { | 4357 | { |
| 4358 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4358 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4359 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4359 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4360 | if (arg0_value == irb->codegen->invalid_inst_src) | 4360 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4361 | return arg0_value; | 4361 | return arg0_value; |
| 4362 | | 4362 | |
| 4363 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4363 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4364 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4364 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4365 | if (arg1_value == irb->codegen->invalid_inst_src) | 4365 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4366 | return arg1_value; | 4366 | return arg1_value; |
| 4367 | | 4367 | |
| 4368 | IrInstSrc *reduce = ir_build_reduce(irb, scope, node, arg0_value, arg1_value); | 4368 | IrInstSrc *reduce = ir_build_reduce(ag, scope, node, arg0_value, arg1_value); |
| 4369 | return ir_lval_wrap(irb, scope, reduce, lval, result_loc); | 4369 | return ir_lval_wrap(ag, scope, reduce, lval, result_loc); |
| 4370 | } | 4370 | } |
| 4371 | case BuiltinFnIdDivExact: | 4371 | case BuiltinFnIdDivExact: |
| 4372 | { | 4372 | { |
| 4373 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4373 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4374 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4374 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4375 | if (arg0_value == irb->codegen->invalid_inst_src) | 4375 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4376 | return arg0_value; | 4376 | return arg0_value; |
| 4377 | | 4377 | |
| 4378 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4378 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4379 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4379 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4380 | if (arg1_value == irb->codegen->invalid_inst_src) | 4380 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4381 | return arg1_value; | 4381 | return arg1_value; |
| 4382 | | 4382 | |
| 4383 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); | 4383 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 4384 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 4384 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 4385 | } | 4385 | } |
| 4386 | case BuiltinFnIdDivTrunc: | 4386 | case BuiltinFnIdDivTrunc: |
| 4387 | { | 4387 | { |
| 4388 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4388 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4389 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4389 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4390 | if (arg0_value == irb->codegen->invalid_inst_src) | 4390 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4391 | return arg0_value; | 4391 | return arg0_value; |
| 4392 | | 4392 | |
| 4393 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4393 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4394 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4394 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4395 | if (arg1_value == irb->codegen->invalid_inst_src) | 4395 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4396 | return arg1_value; | 4396 | return arg1_value; |
| 4397 | | 4397 | |
| 4398 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); | 4398 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 4399 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 4399 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 4400 | } | 4400 | } |
| 4401 | case BuiltinFnIdDivFloor: | 4401 | case BuiltinFnIdDivFloor: |
| 4402 | { | 4402 | { |
| 4403 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4403 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4404 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4404 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4405 | if (arg0_value == irb->codegen->invalid_inst_src) | 4405 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4406 | return arg0_value; | 4406 | return arg0_value; |
| 4407 | | 4407 | |
| 4408 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4408 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4409 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4409 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4410 | if (arg1_value == irb->codegen->invalid_inst_src) | 4410 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4411 | return arg1_value; | 4411 | return arg1_value; |
| 4412 | | 4412 | |
| 4413 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); | 4413 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 4414 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 4414 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 4415 | } | 4415 | } |
| 4416 | case BuiltinFnIdRem: | 4416 | case BuiltinFnIdRem: |
| 4417 | { | 4417 | { |
| 4418 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4418 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4419 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4419 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4420 | if (arg0_value == irb->codegen->invalid_inst_src) | 4420 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4421 | return arg0_value; | 4421 | return arg0_value; |
| 4422 | | 4422 | |
| 4423 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4423 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4424 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4424 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4425 | if (arg1_value == irb->codegen->invalid_inst_src) | 4425 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4426 | return arg1_value; | 4426 | return arg1_value; |
| 4427 | | 4427 | |
| 4428 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); | 4428 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 4429 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 4429 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 4430 | } | 4430 | } |
| 4431 | case BuiltinFnIdMod: | 4431 | case BuiltinFnIdMod: |
| 4432 | { | 4432 | { |
| 4433 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4433 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4434 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4434 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4435 | if (arg0_value == irb->codegen->invalid_inst_src) | 4435 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4436 | return arg0_value; | 4436 | return arg0_value; |
| 4437 | | 4437 | |
| 4438 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4438 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4439 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4439 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4440 | if (arg1_value == irb->codegen->invalid_inst_src) | 4440 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4441 | return arg1_value; | 4441 | return arg1_value; |
| 4442 | | 4442 | |
| 4443 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); | 4443 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 4444 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 4444 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 4445 | } | 4445 | } |
| 4446 | case BuiltinFnIdSqrt: | 4446 | case BuiltinFnIdSqrt: |
| 4447 | case BuiltinFnIdSin: | 4447 | case BuiltinFnIdSin: |
| ... | @@ -4459,537 +4459,537 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -4459,537 +4459,537 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 4459 | case BuiltinFnIdRound: | 4459 | case BuiltinFnIdRound: |
| 4460 | { | 4460 | { |
| 4461 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4461 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4462 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4462 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4463 | if (arg0_value == irb->codegen->invalid_inst_src) | 4463 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4464 | return arg0_value; | 4464 | return arg0_value; |
| 4465 | | 4465 | |
| 4466 | IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id); | 4466 | IrInstSrc *inst = ir_build_float_op_src(ag, scope, node, arg0_value, builtin_fn->id); |
| 4467 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); | 4467 | return ir_lval_wrap(ag, scope, inst, lval, result_loc); |
| 4468 | } | 4468 | } |
| 4469 | case BuiltinFnIdTruncate: | 4469 | case BuiltinFnIdTruncate: |
| 4470 | { | 4470 | { |
| 4471 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4471 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4472 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4472 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4473 | if (arg0_value == irb->codegen->invalid_inst_src) | 4473 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4474 | return arg0_value; | 4474 | return arg0_value; |
| 4475 | | 4475 | |
| 4476 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4476 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4477 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4477 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4478 | if (arg1_value == irb->codegen->invalid_inst_src) | 4478 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4479 | return arg1_value; | 4479 | return arg1_value; |
| 4480 | | 4480 | |
| 4481 | IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); | 4481 | IrInstSrc *truncate = ir_build_truncate(ag, scope, node, arg0_value, arg1_value); |
| 4482 | return ir_lval_wrap(irb, scope, truncate, lval, result_loc); | 4482 | return ir_lval_wrap(ag, scope, truncate, lval, result_loc); |
| 4483 | } | 4483 | } |
| 4484 | case BuiltinFnIdIntCast: | 4484 | case BuiltinFnIdIntCast: |
| 4485 | { | 4485 | { |
| 4486 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4486 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4487 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4487 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4488 | if (arg0_value == irb->codegen->invalid_inst_src) | 4488 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4489 | return arg0_value; | 4489 | return arg0_value; |
| 4490 | | 4490 | |
| 4491 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4491 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4492 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4492 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4493 | if (arg1_value == irb->codegen->invalid_inst_src) | 4493 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4494 | return arg1_value; | 4494 | return arg1_value; |
| 4495 | | 4495 | |
| 4496 | IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); | 4496 | IrInstSrc *result = ir_build_int_cast(ag, scope, node, arg0_value, arg1_value); |
| 4497 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4497 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4498 | } | 4498 | } |
| 4499 | case BuiltinFnIdFloatCast: | 4499 | case BuiltinFnIdFloatCast: |
| 4500 | { | 4500 | { |
| 4501 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4501 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4502 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4502 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4503 | if (arg0_value == irb->codegen->invalid_inst_src) | 4503 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4504 | return arg0_value; | 4504 | return arg0_value; |
| 4505 | | 4505 | |
| 4506 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4506 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4507 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4507 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4508 | if (arg1_value == irb->codegen->invalid_inst_src) | 4508 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4509 | return arg1_value; | 4509 | return arg1_value; |
| 4510 | | 4510 | |
| 4511 | IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); | 4511 | IrInstSrc *result = ir_build_float_cast(ag, scope, node, arg0_value, arg1_value); |
| 4512 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4512 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4513 | } | 4513 | } |
| 4514 | case BuiltinFnIdErrSetCast: | 4514 | case BuiltinFnIdErrSetCast: |
| 4515 | { | 4515 | { |
| 4516 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4516 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4517 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4517 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4518 | if (arg0_value == irb->codegen->invalid_inst_src) | 4518 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4519 | return arg0_value; | 4519 | return arg0_value; |
| 4520 | | 4520 | |
| 4521 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4521 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4522 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4522 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4523 | if (arg1_value == irb->codegen->invalid_inst_src) | 4523 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4524 | return arg1_value; | 4524 | return arg1_value; |
| 4525 | | 4525 | |
| 4526 | IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); | 4526 | IrInstSrc *result = ir_build_err_set_cast(ag, scope, node, arg0_value, arg1_value); |
| 4527 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4527 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4528 | } | 4528 | } |
| 4529 | case BuiltinFnIdIntToFloat: | 4529 | case BuiltinFnIdIntToFloat: |
| 4530 | { | 4530 | { |
| 4531 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4531 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4532 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4532 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4533 | if (arg0_value == irb->codegen->invalid_inst_src) | 4533 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4534 | return arg0_value; | 4534 | return arg0_value; |
| 4535 | | 4535 | |
| 4536 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4536 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4537 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4537 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4538 | if (arg1_value == irb->codegen->invalid_inst_src) | 4538 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4539 | return arg1_value; | 4539 | return arg1_value; |
| 4540 | | 4540 | |
| 4541 | IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); | 4541 | IrInstSrc *result = ir_build_int_to_float(ag, scope, node, arg0_value, arg1_value); |
| 4542 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4542 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4543 | } | 4543 | } |
| 4544 | case BuiltinFnIdFloatToInt: | 4544 | case BuiltinFnIdFloatToInt: |
| 4545 | { | 4545 | { |
| 4546 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4546 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4547 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4547 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4548 | if (arg0_value == irb->codegen->invalid_inst_src) | 4548 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4549 | return arg0_value; | 4549 | return arg0_value; |
| 4550 | | 4550 | |
| 4551 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4551 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4552 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4552 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4553 | if (arg1_value == irb->codegen->invalid_inst_src) | 4553 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4554 | return arg1_value; | 4554 | return arg1_value; |
| 4555 | | 4555 | |
| 4556 | IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); | 4556 | IrInstSrc *result = ir_build_float_to_int(ag, scope, node, arg0_value, arg1_value); |
| 4557 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4557 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4558 | } | 4558 | } |
| 4559 | case BuiltinFnIdErrToInt: | 4559 | case BuiltinFnIdErrToInt: |
| 4560 | { | 4560 | { |
| 4561 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4561 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4562 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4562 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4563 | if (arg0_value == irb->codegen->invalid_inst_src) | 4563 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4564 | return arg0_value; | 4564 | return arg0_value; |
| 4565 | | 4565 | |
| 4566 | IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value); | 4566 | IrInstSrc *result = ir_build_err_to_int_src(ag, scope, node, arg0_value); |
| 4567 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4567 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4568 | } | 4568 | } |
| 4569 | case BuiltinFnIdIntToErr: | 4569 | case BuiltinFnIdIntToErr: |
| 4570 | { | 4570 | { |
| 4571 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4571 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4572 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4572 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4573 | if (arg0_value == irb->codegen->invalid_inst_src) | 4573 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4574 | return arg0_value; | 4574 | return arg0_value; |
| 4575 | | 4575 | |
| 4576 | IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value); | 4576 | IrInstSrc *result = ir_build_int_to_err_src(ag, scope, node, arg0_value); |
| 4577 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4577 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4578 | } | 4578 | } |
| 4579 | case BuiltinFnIdBoolToInt: | 4579 | case BuiltinFnIdBoolToInt: |
| 4580 | { | 4580 | { |
| 4581 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4581 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4582 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4582 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4583 | if (arg0_value == irb->codegen->invalid_inst_src) | 4583 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4584 | return arg0_value; | 4584 | return arg0_value; |
| 4585 | | 4585 | |
| 4586 | IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value); | 4586 | IrInstSrc *result = ir_build_bool_to_int(ag, scope, node, arg0_value); |
| 4587 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4587 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4588 | } | 4588 | } |
| 4589 | case BuiltinFnIdVectorType: | 4589 | case BuiltinFnIdVectorType: |
| 4590 | { | 4590 | { |
| 4591 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4591 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4592 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4592 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4593 | if (arg0_value == irb->codegen->invalid_inst_src) | 4593 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4594 | return arg0_value; | 4594 | return arg0_value; |
| 4595 | | 4595 | |
| 4596 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4596 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4597 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4597 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4598 | if (arg1_value == irb->codegen->invalid_inst_src) | 4598 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4599 | return arg1_value; | 4599 | return arg1_value; |
| 4600 | | 4600 | |
| 4601 | IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); | 4601 | IrInstSrc *vector_type = ir_build_vector_type(ag, scope, node, arg0_value, arg1_value); |
| 4602 | return ir_lval_wrap(irb, scope, vector_type, lval, result_loc); | 4602 | return ir_lval_wrap(ag, scope, vector_type, lval, result_loc); |
| 4603 | } | 4603 | } |
| 4604 | case BuiltinFnIdShuffle: | 4604 | case BuiltinFnIdShuffle: |
| 4605 | { | 4605 | { |
| 4606 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4606 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4607 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4607 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4608 | if (arg0_value == irb->codegen->invalid_inst_src) | 4608 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4609 | return arg0_value; | 4609 | return arg0_value; |
| 4610 | | 4610 | |
| 4611 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4611 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4612 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4612 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4613 | if (arg1_value == irb->codegen->invalid_inst_src) | 4613 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4614 | return arg1_value; | 4614 | return arg1_value; |
| 4615 | | 4615 | |
| 4616 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 4616 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 4617 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 4617 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 4618 | if (arg2_value == irb->codegen->invalid_inst_src) | 4618 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 4619 | return arg2_value; | 4619 | return arg2_value; |
| 4620 | | 4620 | |
| 4621 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); | 4621 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 4622 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); | 4622 | IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); |
| 4623 | if (arg3_value == irb->codegen->invalid_inst_src) | 4623 | if (arg3_value == ag->codegen->invalid_inst_src) |
| 4624 | return arg3_value; | 4624 | return arg3_value; |
| 4625 | | 4625 | |
| 4626 | IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node, | 4626 | IrInstSrc *shuffle_vector = ir_build_shuffle_vector(ag, scope, node, |
| 4627 | arg0_value, arg1_value, arg2_value, arg3_value); | 4627 | arg0_value, arg1_value, arg2_value, arg3_value); |
| 4628 | return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc); | 4628 | return ir_lval_wrap(ag, scope, shuffle_vector, lval, result_loc); |
| 4629 | } | 4629 | } |
| 4630 | case BuiltinFnIdSplat: | 4630 | case BuiltinFnIdSplat: |
| 4631 | { | 4631 | { |
| 4632 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4632 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4633 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4633 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4634 | if (arg0_value == irb->codegen->invalid_inst_src) | 4634 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4635 | return arg0_value; | 4635 | return arg0_value; |
| 4636 | | 4636 | |
| 4637 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4637 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4638 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4638 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4639 | if (arg1_value == irb->codegen->invalid_inst_src) | 4639 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4640 | return arg1_value; | 4640 | return arg1_value; |
| 4641 | | 4641 | |
| 4642 | IrInstSrc *splat = ir_build_splat_src(irb, scope, node, | 4642 | IrInstSrc *splat = ir_build_splat_src(ag, scope, node, |
| 4643 | arg0_value, arg1_value); | 4643 | arg0_value, arg1_value); |
| 4644 | return ir_lval_wrap(irb, scope, splat, lval, result_loc); | 4644 | return ir_lval_wrap(ag, scope, splat, lval, result_loc); |
| 4645 | } | 4645 | } |
| 4646 | case BuiltinFnIdMemcpy: | 4646 | case BuiltinFnIdMemcpy: |
| 4647 | { | 4647 | { |
| 4648 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4648 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4649 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4649 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4650 | if (arg0_value == irb->codegen->invalid_inst_src) | 4650 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4651 | return arg0_value; | 4651 | return arg0_value; |
| 4652 | | 4652 | |
| 4653 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4653 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4654 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4654 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4655 | if (arg1_value == irb->codegen->invalid_inst_src) | 4655 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4656 | return arg1_value; | 4656 | return arg1_value; |
| 4657 | | 4657 | |
| 4658 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 4658 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 4659 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 4659 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 4660 | if (arg2_value == irb->codegen->invalid_inst_src) | 4660 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 4661 | return arg2_value; | 4661 | return arg2_value; |
| 4662 | | 4662 | |
| 4663 | IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value); | 4663 | IrInstSrc *ir_memcpy = ir_build_memcpy_src(ag, scope, node, arg0_value, arg1_value, arg2_value); |
| 4664 | return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc); | 4664 | return ir_lval_wrap(ag, scope, ir_memcpy, lval, result_loc); |
| 4665 | } | 4665 | } |
| 4666 | case BuiltinFnIdMemset: | 4666 | case BuiltinFnIdMemset: |
| 4667 | { | 4667 | { |
| 4668 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4668 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4669 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4669 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4670 | if (arg0_value == irb->codegen->invalid_inst_src) | 4670 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4671 | return arg0_value; | 4671 | return arg0_value; |
| 4672 | | 4672 | |
| 4673 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4673 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4674 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4674 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4675 | if (arg1_value == irb->codegen->invalid_inst_src) | 4675 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4676 | return arg1_value; | 4676 | return arg1_value; |
| 4677 | | 4677 | |
| 4678 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 4678 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 4679 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 4679 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 4680 | if (arg2_value == irb->codegen->invalid_inst_src) | 4680 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 4681 | return arg2_value; | 4681 | return arg2_value; |
| 4682 | | 4682 | |
| 4683 | IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value); | 4683 | IrInstSrc *ir_memset = ir_build_memset_src(ag, scope, node, arg0_value, arg1_value, arg2_value); |
| 4684 | return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc); | 4684 | return ir_lval_wrap(ag, scope, ir_memset, lval, result_loc); |
| 4685 | } | 4685 | } |
| 4686 | case BuiltinFnIdWasmMemorySize: | 4686 | case BuiltinFnIdWasmMemorySize: |
| 4687 | { | 4687 | { |
| 4688 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4688 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4689 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4689 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4690 | if (arg0_value == irb->codegen->invalid_inst_src) | 4690 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4691 | return arg0_value; | 4691 | return arg0_value; |
| 4692 | | 4692 | |
| 4693 | IrInstSrc *ir_wasm_memory_size = ir_build_wasm_memory_size_src(irb, scope, node, arg0_value); | 4693 | IrInstSrc *ir_wasm_memory_size = ir_build_wasm_memory_size_src(ag, scope, node, arg0_value); |
| 4694 | return ir_lval_wrap(irb, scope, ir_wasm_memory_size, lval, result_loc); | 4694 | return ir_lval_wrap(ag, scope, ir_wasm_memory_size, lval, result_loc); |
| 4695 | } | 4695 | } |
| 4696 | case BuiltinFnIdWasmMemoryGrow: | 4696 | case BuiltinFnIdWasmMemoryGrow: |
| 4697 | { | 4697 | { |
| 4698 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4698 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4699 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4699 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4700 | if (arg0_value == irb->codegen->invalid_inst_src) | 4700 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4701 | return arg0_value; | 4701 | return arg0_value; |
| 4702 | | 4702 | |
| 4703 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4703 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4704 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4704 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4705 | if (arg1_value == irb->codegen->invalid_inst_src) | 4705 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4706 | return arg1_value; | 4706 | return arg1_value; |
| 4707 | | 4707 | |
| 4708 | IrInstSrc *ir_wasm_memory_grow = ir_build_wasm_memory_grow_src(irb, scope, node, arg0_value, arg1_value); | 4708 | IrInstSrc *ir_wasm_memory_grow = ir_build_wasm_memory_grow_src(ag, scope, node, arg0_value, arg1_value); |
| 4709 | return ir_lval_wrap(irb, scope, ir_wasm_memory_grow, lval, result_loc); | 4709 | return ir_lval_wrap(ag, scope, ir_wasm_memory_grow, lval, result_loc); |
| 4710 | } | 4710 | } |
| 4711 | case BuiltinFnIdField: | 4711 | case BuiltinFnIdField: |
| 4712 | { | 4712 | { |
| 4713 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4713 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4714 | IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr); | 4714 | IrInstSrc *arg0_value = ir_gen_node_extra(ag, arg0_node, scope, LValPtr, nullptr); |
| 4715 | if (arg0_value == irb->codegen->invalid_inst_src) | 4715 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4716 | return arg0_value; | 4716 | return arg0_value; |
| 4717 | | 4717 | |
| 4718 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4718 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4719 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4719 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4720 | if (arg1_value == irb->codegen->invalid_inst_src) | 4720 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4721 | return arg1_value; | 4721 | return arg1_value; |
| 4722 | | 4722 | |
| 4723 | IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, | 4723 | IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(ag, scope, node, |
| 4724 | arg0_value, arg1_value, false); | 4724 | arg0_value, arg1_value, false); |
| 4725 | | 4725 | |
| 4726 | if (lval == LValPtr || lval == LValAssign) | 4726 | if (lval == LValPtr || lval == LValAssign) |
| 4727 | return ptr_instruction; | 4727 | return ptr_instruction; |
| 4728 | | 4728 | |
| 4729 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); | 4729 | IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction); |
| 4730 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); | 4730 | return ir_expr_wrap(ag, scope, load_ptr, result_loc); |
| 4731 | } | 4731 | } |
| 4732 | case BuiltinFnIdHasField: | 4732 | case BuiltinFnIdHasField: |
| 4733 | { | 4733 | { |
| 4734 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4734 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4735 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4735 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4736 | if (arg0_value == irb->codegen->invalid_inst_src) | 4736 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4737 | return arg0_value; | 4737 | return arg0_value; |
| 4738 | | 4738 | |
| 4739 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4739 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4740 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4740 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4741 | if (arg1_value == irb->codegen->invalid_inst_src) | 4741 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4742 | return arg1_value; | 4742 | return arg1_value; |
| 4743 | | 4743 | |
| 4744 | IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value); | 4744 | IrInstSrc *type_info = ir_build_has_field(ag, scope, node, arg0_value, arg1_value); |
| 4745 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); | 4745 | return ir_lval_wrap(ag, scope, type_info, lval, result_loc); |
| 4746 | } | 4746 | } |
| 4747 | case BuiltinFnIdTypeInfo: | 4747 | case BuiltinFnIdTypeInfo: |
| 4748 | { | 4748 | { |
| 4749 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4749 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4750 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4750 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4751 | if (arg0_value == irb->codegen->invalid_inst_src) | 4751 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4752 | return arg0_value; | 4752 | return arg0_value; |
| 4753 | | 4753 | |
| 4754 | IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value); | 4754 | IrInstSrc *type_info = ir_build_type_info(ag, scope, node, arg0_value); |
| 4755 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); | 4755 | return ir_lval_wrap(ag, scope, type_info, lval, result_loc); |
| 4756 | } | 4756 | } |
| 4757 | case BuiltinFnIdType: | 4757 | case BuiltinFnIdType: |
| 4758 | { | 4758 | { |
| 4759 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); | 4759 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); |
| 4760 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); | 4760 | IrInstSrc *arg = ir_gen_node(ag, arg_node, scope); |
| 4761 | if (arg == irb->codegen->invalid_inst_src) | 4761 | if (arg == ag->codegen->invalid_inst_src) |
| 4762 | return arg; | 4762 | return arg; |
| 4763 | | 4763 | |
| 4764 | IrInstSrc *type = ir_build_type(irb, scope, node, arg); | 4764 | IrInstSrc *type = ir_build_type(ag, scope, node, arg); |
| 4765 | return ir_lval_wrap(irb, scope, type, lval, result_loc); | 4765 | return ir_lval_wrap(ag, scope, type, lval, result_loc); |
| 4766 | } | 4766 | } |
| 4767 | case BuiltinFnIdBreakpoint: | 4767 | case BuiltinFnIdBreakpoint: |
| 4768 | return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc); | 4768 | return ir_lval_wrap(ag, scope, ir_build_breakpoint(ag, scope, node), lval, result_loc); |
| 4769 | case BuiltinFnIdReturnAddress: | 4769 | case BuiltinFnIdReturnAddress: |
| 4770 | return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc); | 4770 | return ir_lval_wrap(ag, scope, ir_build_return_address_src(ag, scope, node), lval, result_loc); |
| 4771 | case BuiltinFnIdFrameAddress: | 4771 | case BuiltinFnIdFrameAddress: |
| 4772 | return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc); | 4772 | return ir_lval_wrap(ag, scope, ir_build_frame_address_src(ag, scope, node), lval, result_loc); |
| 4773 | case BuiltinFnIdFrameHandle: | 4773 | case BuiltinFnIdFrameHandle: |
| 4774 | if (!irb->exec->fn_entry) { | 4774 | if (!ag->exec->fn_entry) { |
| 4775 | add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition")); | 4775 | add_node_error(ag->codegen, node, buf_sprintf("@frame() called outside of function definition")); |
| 4776 | return irb->codegen->invalid_inst_src; | 4776 | return ag->codegen->invalid_inst_src; |
| 4777 | } | 4777 | } |
| 4778 | return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc); | 4778 | return ir_lval_wrap(ag, scope, ir_build_handle_src(ag, scope, node), lval, result_loc); |
| 4779 | case BuiltinFnIdFrameType: { | 4779 | case BuiltinFnIdFrameType: { |
| 4780 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4780 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4781 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4781 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4782 | if (arg0_value == irb->codegen->invalid_inst_src) | 4782 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4783 | return arg0_value; | 4783 | return arg0_value; |
| 4784 | | 4784 | |
| 4785 | IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value); | 4785 | IrInstSrc *frame_type = ir_build_frame_type(ag, scope, node, arg0_value); |
| 4786 | return ir_lval_wrap(irb, scope, frame_type, lval, result_loc); | 4786 | return ir_lval_wrap(ag, scope, frame_type, lval, result_loc); |
| 4787 | } | 4787 | } |
| 4788 | case BuiltinFnIdFrameSize: { | 4788 | case BuiltinFnIdFrameSize: { |
| 4789 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4789 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4790 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4790 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4791 | if (arg0_value == irb->codegen->invalid_inst_src) | 4791 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4792 | return arg0_value; | 4792 | return arg0_value; |
| 4793 | | 4793 | |
| 4794 | IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value); | 4794 | IrInstSrc *frame_size = ir_build_frame_size_src(ag, scope, node, arg0_value); |
| 4795 | return ir_lval_wrap(irb, scope, frame_size, lval, result_loc); | 4795 | return ir_lval_wrap(ag, scope, frame_size, lval, result_loc); |
| 4796 | } | 4796 | } |
| 4797 | case BuiltinFnIdAlignOf: | 4797 | case BuiltinFnIdAlignOf: |
| 4798 | { | 4798 | { |
| 4799 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4799 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4800 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4800 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4801 | if (arg0_value == irb->codegen->invalid_inst_src) | 4801 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4802 | return arg0_value; | 4802 | return arg0_value; |
| 4803 | | 4803 | |
| 4804 | IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value); | 4804 | IrInstSrc *align_of = ir_build_align_of(ag, scope, node, arg0_value); |
| 4805 | return ir_lval_wrap(irb, scope, align_of, lval, result_loc); | 4805 | return ir_lval_wrap(ag, scope, align_of, lval, result_loc); |
| 4806 | } | 4806 | } |
| 4807 | case BuiltinFnIdAddWithOverflow: | 4807 | case BuiltinFnIdAddWithOverflow: |
| 4808 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpAdd), lval, result_loc); | 4808 | return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpAdd), lval, result_loc); |
| 4809 | case BuiltinFnIdSubWithOverflow: | 4809 | case BuiltinFnIdSubWithOverflow: |
| 4810 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpSub), lval, result_loc); | 4810 | return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpSub), lval, result_loc); |
| 4811 | case BuiltinFnIdMulWithOverflow: | 4811 | case BuiltinFnIdMulWithOverflow: |
| 4812 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpMul), lval, result_loc); | 4812 | return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpMul), lval, result_loc); |
| 4813 | case BuiltinFnIdShlWithOverflow: | 4813 | case BuiltinFnIdShlWithOverflow: |
| 4814 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpShl), lval, result_loc); | 4814 | return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpShl), lval, result_loc); |
| 4815 | case BuiltinFnIdMulAdd: | 4815 | case BuiltinFnIdMulAdd: |
| 4816 | return ir_lval_wrap(irb, scope, ir_gen_mul_add(irb, scope, node), lval, result_loc); | 4816 | return ir_lval_wrap(ag, scope, ir_gen_mul_add(ag, scope, node), lval, result_loc); |
| 4817 | case BuiltinFnIdTypeName: | 4817 | case BuiltinFnIdTypeName: |
| 4818 | { | 4818 | { |
| 4819 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4819 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4820 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4820 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4821 | if (arg0_value == irb->codegen->invalid_inst_src) | 4821 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4822 | return arg0_value; | 4822 | return arg0_value; |
| 4823 | | 4823 | |
| 4824 | IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value); | 4824 | IrInstSrc *type_name = ir_build_type_name(ag, scope, node, arg0_value); |
| 4825 | return ir_lval_wrap(irb, scope, type_name, lval, result_loc); | 4825 | return ir_lval_wrap(ag, scope, type_name, lval, result_loc); |
| 4826 | } | 4826 | } |
| 4827 | case BuiltinFnIdPanic: | 4827 | case BuiltinFnIdPanic: |
| 4828 | { | 4828 | { |
| 4829 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4829 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4830 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4830 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4831 | if (arg0_value == irb->codegen->invalid_inst_src) | 4831 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4832 | return arg0_value; | 4832 | return arg0_value; |
| 4833 | | 4833 | |
| 4834 | IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value); | 4834 | IrInstSrc *panic = ir_build_panic_src(ag, scope, node, arg0_value); |
| 4835 | return ir_lval_wrap(irb, scope, panic, lval, result_loc); | 4835 | return ir_lval_wrap(ag, scope, panic, lval, result_loc); |
| 4836 | } | 4836 | } |
| 4837 | case BuiltinFnIdPtrCast: | 4837 | case BuiltinFnIdPtrCast: |
| 4838 | { | 4838 | { |
| 4839 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4839 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4840 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4840 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4841 | if (arg0_value == irb->codegen->invalid_inst_src) | 4841 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4842 | return arg0_value; | 4842 | return arg0_value; |
| 4843 | | 4843 | |
| 4844 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4844 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4845 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4845 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4846 | if (arg1_value == irb->codegen->invalid_inst_src) | 4846 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4847 | return arg1_value; | 4847 | return arg1_value; |
| 4848 | | 4848 | |
| 4849 | IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); | 4849 | IrInstSrc *ptr_cast = ir_build_ptr_cast_src(ag, scope, node, arg0_value, arg1_value, true); |
| 4850 | return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc); | 4850 | return ir_lval_wrap(ag, scope, ptr_cast, lval, result_loc); |
| 4851 | } | 4851 | } |
| 4852 | case BuiltinFnIdBitCast: | 4852 | case BuiltinFnIdBitCast: |
| 4853 | { | 4853 | { |
| 4854 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); | 4854 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); |
| 4855 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); | 4855 | IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope); |
| 4856 | if (dest_type == irb->codegen->invalid_inst_src) | 4856 | if (dest_type == ag->codegen->invalid_inst_src) |
| 4857 | return dest_type; | 4857 | return dest_type; |
| 4858 | | 4858 | |
| 4859 | ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>(); | 4859 | ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>(); |
| 4860 | result_loc_bit_cast->base.id = ResultLocIdBitCast; | 4860 | result_loc_bit_cast->base.id = ResultLocIdBitCast; |
| 4861 | result_loc_bit_cast->base.source_instruction = dest_type; | 4861 | result_loc_bit_cast->base.source_instruction = dest_type; |
| 4862 | result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const; | 4862 | result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const; |
| 4863 | ir_ref_instruction(dest_type, irb->current_basic_block); | 4863 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 4864 | result_loc_bit_cast->parent = result_loc; | 4864 | result_loc_bit_cast->parent = result_loc; |
| 4865 | | 4865 | |
| 4866 | ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base); | 4866 | ir_build_reset_result(ag, scope, node, &result_loc_bit_cast->base); |
| 4867 | | 4867 | |
| 4868 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4868 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4869 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, | 4869 | IrInstSrc *arg1_value = ir_gen_node_extra(ag, arg1_node, scope, LValNone, |
| 4870 | &result_loc_bit_cast->base); | 4870 | &result_loc_bit_cast->base); |
| 4871 | if (arg1_value == irb->codegen->invalid_inst_src) | 4871 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4872 | return arg1_value; | 4872 | return arg1_value; |
| 4873 | | 4873 | |
| 4874 | IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); | 4874 | IrInstSrc *bitcast = ir_build_bit_cast_src(ag, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 4875 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); | 4875 | return ir_lval_wrap(ag, scope, bitcast, lval, result_loc); |
| 4876 | } | 4876 | } |
| 4877 | case BuiltinFnIdAs: | 4877 | case BuiltinFnIdAs: |
| 4878 | { | 4878 | { |
| 4879 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); | 4879 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); |
| 4880 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); | 4880 | IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope); |
| 4881 | if (dest_type == irb->codegen->invalid_inst_src) | 4881 | if (dest_type == ag->codegen->invalid_inst_src) |
| 4882 | return dest_type; | 4882 | return dest_type; |
| 4883 | | 4883 | |
| 4884 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc); | 4884 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, dest_type, result_loc); |
| 4885 | | 4885 | |
| 4886 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4886 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4887 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, | 4887 | IrInstSrc *arg1_value = ir_gen_node_extra(ag, arg1_node, scope, LValNone, |
| 4888 | &result_loc_cast->base); | 4888 | &result_loc_cast->base); |
| 4889 | if (arg1_value == irb->codegen->invalid_inst_src) | 4889 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4890 | return arg1_value; | 4890 | return arg1_value; |
| 4891 | | 4891 | |
| 4892 | IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); | 4892 | IrInstSrc *result = ir_build_implicit_cast(ag, scope, node, arg1_value, result_loc_cast); |
| 4893 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 4893 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 4894 | } | 4894 | } |
| 4895 | case BuiltinFnIdIntToPtr: | 4895 | case BuiltinFnIdIntToPtr: |
| 4896 | { | 4896 | { |
| 4897 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4897 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4898 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4898 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4899 | if (arg0_value == irb->codegen->invalid_inst_src) | 4899 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4900 | return arg0_value; | 4900 | return arg0_value; |
| 4901 | | 4901 | |
| 4902 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4902 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4903 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4903 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4904 | if (arg1_value == irb->codegen->invalid_inst_src) | 4904 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4905 | return arg1_value; | 4905 | return arg1_value; |
| 4906 | | 4906 | |
| 4907 | IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value); | 4907 | IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(ag, scope, node, arg0_value, arg1_value); |
| 4908 | return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc); | 4908 | return ir_lval_wrap(ag, scope, int_to_ptr, lval, result_loc); |
| 4909 | } | 4909 | } |
| 4910 | case BuiltinFnIdPtrToInt: | 4910 | case BuiltinFnIdPtrToInt: |
| 4911 | { | 4911 | { |
| 4912 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4912 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4913 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4913 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4914 | if (arg0_value == irb->codegen->invalid_inst_src) | 4914 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4915 | return arg0_value; | 4915 | return arg0_value; |
| 4916 | | 4916 | |
| 4917 | IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value); | 4917 | IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(ag, scope, node, arg0_value); |
| 4918 | return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc); | 4918 | return ir_lval_wrap(ag, scope, ptr_to_int, lval, result_loc); |
| 4919 | } | 4919 | } |
| 4920 | case BuiltinFnIdTagName: | 4920 | case BuiltinFnIdTagName: |
| 4921 | { | 4921 | { |
| 4922 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4922 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4923 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4923 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4924 | if (arg0_value == irb->codegen->invalid_inst_src) | 4924 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4925 | return arg0_value; | 4925 | return arg0_value; |
| 4926 | | 4926 | |
| 4927 | IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value); | 4927 | IrInstSrc *tag_name = ir_build_tag_name_src(ag, scope, node, arg0_value); |
| 4928 | return ir_lval_wrap(irb, scope, tag_name, lval, result_loc); | 4928 | return ir_lval_wrap(ag, scope, tag_name, lval, result_loc); |
| 4929 | } | 4929 | } |
| 4930 | case BuiltinFnIdFieldParentPtr: | 4930 | case BuiltinFnIdFieldParentPtr: |
| 4931 | { | 4931 | { |
| 4932 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4932 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4933 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4933 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4934 | if (arg0_value == irb->codegen->invalid_inst_src) | 4934 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4935 | return arg0_value; | 4935 | return arg0_value; |
| 4936 | | 4936 | |
| 4937 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4937 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4938 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4938 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4939 | if (arg1_value == irb->codegen->invalid_inst_src) | 4939 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4940 | return arg1_value; | 4940 | return arg1_value; |
| 4941 | | 4941 | |
| 4942 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 4942 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 4943 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 4943 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 4944 | if (arg2_value == irb->codegen->invalid_inst_src) | 4944 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 4945 | return arg2_value; | 4945 | return arg2_value; |
| 4946 | | 4946 | |
| 4947 | IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node, | 4947 | IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(ag, scope, node, |
| 4948 | arg0_value, arg1_value, arg2_value); | 4948 | arg0_value, arg1_value, arg2_value); |
| 4949 | return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc); | 4949 | return ir_lval_wrap(ag, scope, field_parent_ptr, lval, result_loc); |
| 4950 | } | 4950 | } |
| 4951 | case BuiltinFnIdByteOffsetOf: | 4951 | case BuiltinFnIdByteOffsetOf: |
| 4952 | { | 4952 | { |
| 4953 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4953 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4954 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4954 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4955 | if (arg0_value == irb->codegen->invalid_inst_src) | 4955 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4956 | return arg0_value; | 4956 | return arg0_value; |
| 4957 | | 4957 | |
| 4958 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4958 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4959 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4959 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4960 | if (arg1_value == irb->codegen->invalid_inst_src) | 4960 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4961 | return arg1_value; | 4961 | return arg1_value; |
| 4962 | | 4962 | |
| 4963 | IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); | 4963 | IrInstSrc *offset_of = ir_build_byte_offset_of(ag, scope, node, arg0_value, arg1_value); |
| 4964 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); | 4964 | return ir_lval_wrap(ag, scope, offset_of, lval, result_loc); |
| 4965 | } | 4965 | } |
| 4966 | case BuiltinFnIdBitOffsetOf: | 4966 | case BuiltinFnIdBitOffsetOf: |
| 4967 | { | 4967 | { |
| 4968 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4968 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4969 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 4969 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 4970 | if (arg0_value == irb->codegen->invalid_inst_src) | 4970 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 4971 | return arg0_value; | 4971 | return arg0_value; |
| 4972 | | 4972 | |
| 4973 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 4973 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 4974 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 4974 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 4975 | if (arg1_value == irb->codegen->invalid_inst_src) | 4975 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 4976 | return arg1_value; | 4976 | return arg1_value; |
| 4977 | | 4977 | |
| 4978 | IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); | 4978 | IrInstSrc *offset_of = ir_build_bit_offset_of(ag, scope, node, arg0_value, arg1_value); |
| 4979 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); | 4979 | return ir_lval_wrap(ag, scope, offset_of, lval, result_loc); |
| 4980 | } | 4980 | } |
| 4981 | case BuiltinFnIdCall: { | 4981 | case BuiltinFnIdCall: { |
| 4982 | // Cast the options parameter to the options type | 4982 | // Cast the options parameter to the options type |
| 4983 | ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions"); | 4983 | ZigType *options_type = get_builtin_type(ag->codegen, "CallOptions"); |
| 4984 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); | 4984 | IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type); |
| 4985 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); | 4985 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); |
| 4986 | | 4986 | |
| 4987 | AstNode *options_node = node->data.fn_call_expr.params.at(0); | 4987 | AstNode *options_node = node->data.fn_call_expr.params.at(0); |
| 4988 | IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope, | 4988 | IrInstSrc *options_inner = ir_gen_node_extra(ag, options_node, scope, |
| 4989 | LValNone, &result_loc_cast->base); | 4989 | LValNone, &result_loc_cast->base); |
| 4990 | if (options_inner == irb->codegen->invalid_inst_src) | 4990 | if (options_inner == ag->codegen->invalid_inst_src) |
| 4991 | return options_inner; | 4991 | return options_inner; |
| 4992 | IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast); | 4992 | IrInstSrc *options = ir_build_implicit_cast(ag, scope, options_node, options_inner, result_loc_cast); |
| 4993 | | 4993 | |
| 4994 | AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1); | 4994 | AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1); |
| 4995 | AstNode *args_node = node->data.fn_call_expr.params.at(2); | 4995 | AstNode *args_node = node->data.fn_call_expr.params.at(2); |
| ... | @@ -4997,256 +4997,256 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -4997,256 +4997,256 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 4997 | if (args_node->data.container_init_expr.kind == ContainerInitKindArray || | 4997 | if (args_node->data.container_init_expr.kind == ContainerInitKindArray || |
| 4998 | args_node->data.container_init_expr.entries.length == 0) | 4998 | args_node->data.container_init_expr.entries.length == 0) |
| 4999 | { | 4999 | { |
| 5000 | return ir_gen_fn_call_with_args(irb, scope, node, | 5000 | return ir_gen_fn_call_with_args(ag, scope, node, |
| 5001 | fn_ref_node, CallModifierNone, options, | 5001 | fn_ref_node, CallModifierNone, options, |
| 5002 | args_node->data.container_init_expr.entries.items, | 5002 | args_node->data.container_init_expr.entries.items, |
| 5003 | args_node->data.container_init_expr.entries.length, | 5003 | args_node->data.container_init_expr.entries.length, |
| 5004 | lval, result_loc); | 5004 | lval, result_loc); |
| 5005 | } else { | 5005 | } else { |
| 5006 | exec_add_error_node(irb->codegen, irb->exec, args_node, | 5006 | exec_add_error_node(ag->codegen, ag->exec, args_node, |
| 5007 | buf_sprintf("TODO: @call with anon struct literal")); | 5007 | buf_sprintf("TODO: @call with anon struct literal")); |
| 5008 | return irb->codegen->invalid_inst_src; | 5008 | return ag->codegen->invalid_inst_src; |
| 5009 | } | 5009 | } |
| 5010 | } else { | 5010 | } else { |
| 5011 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); | 5011 | IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); |
| 5012 | if (fn_ref == irb->codegen->invalid_inst_src) | 5012 | if (fn_ref == ag->codegen->invalid_inst_src) |
| 5013 | return fn_ref; | 5013 | return fn_ref; |
| 5014 | | 5014 | |
| 5015 | IrInstSrc *args = ir_gen_node(irb, args_node, scope); | 5015 | IrInstSrc *args = ir_gen_node(ag, args_node, scope); |
| 5016 | if (args == irb->codegen->invalid_inst_src) | 5016 | if (args == ag->codegen->invalid_inst_src) |
| 5017 | return args; | 5017 | return args; |
| 5018 | | 5018 | |
| 5019 | IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc); | 5019 | IrInstSrc *call = ir_build_call_extra(ag, scope, node, options, fn_ref, args, result_loc); |
| 5020 | return ir_lval_wrap(irb, scope, call, lval, result_loc); | 5020 | return ir_lval_wrap(ag, scope, call, lval, result_loc); |
| 5021 | } | 5021 | } |
| 5022 | } | 5022 | } |
| 5023 | case BuiltinFnIdAsyncCall: | 5023 | case BuiltinFnIdAsyncCall: |
| 5024 | return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc); | 5024 | return ir_gen_async_call(ag, scope, nullptr, node, lval, result_loc); |
| 5025 | case BuiltinFnIdShlExact: | 5025 | case BuiltinFnIdShlExact: |
| 5026 | { | 5026 | { |
| 5027 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5027 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5028 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5028 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5029 | if (arg0_value == irb->codegen->invalid_inst_src) | 5029 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5030 | return arg0_value; | 5030 | return arg0_value; |
| 5031 | | 5031 | |
| 5032 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5032 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5033 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5033 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5034 | if (arg1_value == irb->codegen->invalid_inst_src) | 5034 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5035 | return arg1_value; | 5035 | return arg1_value; |
| 5036 | | 5036 | |
| 5037 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); | 5037 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 5038 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 5038 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 5039 | } | 5039 | } |
| 5040 | case BuiltinFnIdShrExact: | 5040 | case BuiltinFnIdShrExact: |
| 5041 | { | 5041 | { |
| 5042 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5042 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5043 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5043 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5044 | if (arg0_value == irb->codegen->invalid_inst_src) | 5044 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5045 | return arg0_value; | 5045 | return arg0_value; |
| 5046 | | 5046 | |
| 5047 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5047 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5048 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5048 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5049 | if (arg1_value == irb->codegen->invalid_inst_src) | 5049 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5050 | return arg1_value; | 5050 | return arg1_value; |
| 5051 | | 5051 | |
| 5052 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); | 5052 | IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 5053 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); | 5053 | return ir_lval_wrap(ag, scope, bin_op, lval, result_loc); |
| 5054 | } | 5054 | } |
| 5055 | case BuiltinFnIdSetEvalBranchQuota: | 5055 | case BuiltinFnIdSetEvalBranchQuota: |
| 5056 | { | 5056 | { |
| 5057 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5057 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5058 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5058 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5059 | if (arg0_value == irb->codegen->invalid_inst_src) | 5059 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5060 | return arg0_value; | 5060 | return arg0_value; |
| 5061 | | 5061 | |
| 5062 | IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); | 5062 | IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(ag, scope, node, arg0_value); |
| 5063 | return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc); | 5063 | return ir_lval_wrap(ag, scope, set_eval_branch_quota, lval, result_loc); |
| 5064 | } | 5064 | } |
| 5065 | case BuiltinFnIdAlignCast: | 5065 | case BuiltinFnIdAlignCast: |
| 5066 | { | 5066 | { |
| 5067 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5067 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5068 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5068 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5069 | if (arg0_value == irb->codegen->invalid_inst_src) | 5069 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5070 | return arg0_value; | 5070 | return arg0_value; |
| 5071 | | 5071 | |
| 5072 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5072 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5073 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5073 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5074 | if (arg1_value == irb->codegen->invalid_inst_src) | 5074 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5075 | return arg1_value; | 5075 | return arg1_value; |
| 5076 | | 5076 | |
| 5077 | IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value); | 5077 | IrInstSrc *align_cast = ir_build_align_cast_src(ag, scope, node, arg0_value, arg1_value); |
| 5078 | return ir_lval_wrap(irb, scope, align_cast, lval, result_loc); | 5078 | return ir_lval_wrap(ag, scope, align_cast, lval, result_loc); |
| 5079 | } | 5079 | } |
| 5080 | case BuiltinFnIdThis: | 5080 | case BuiltinFnIdThis: |
| 5081 | { | 5081 | { |
| 5082 | IrInstSrc *this_inst = ir_gen_this(irb, scope, node); | 5082 | IrInstSrc *this_inst = ir_gen_this(ag, scope, node); |
| 5083 | return ir_lval_wrap(irb, scope, this_inst, lval, result_loc); | 5083 | return ir_lval_wrap(ag, scope, this_inst, lval, result_loc); |
| 5084 | } | 5084 | } |
| 5085 | case BuiltinFnIdSetAlignStack: | 5085 | case BuiltinFnIdSetAlignStack: |
| 5086 | { | 5086 | { |
| 5087 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5087 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5088 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5088 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5089 | if (arg0_value == irb->codegen->invalid_inst_src) | 5089 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5090 | return arg0_value; | 5090 | return arg0_value; |
| 5091 | | 5091 | |
| 5092 | IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); | 5092 | IrInstSrc *set_align_stack = ir_build_set_align_stack(ag, scope, node, arg0_value); |
| 5093 | return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc); | 5093 | return ir_lval_wrap(ag, scope, set_align_stack, lval, result_loc); |
| 5094 | } | 5094 | } |
| 5095 | case BuiltinFnIdExport: | 5095 | case BuiltinFnIdExport: |
| 5096 | { | 5096 | { |
| 5097 | // Cast the options parameter to the options type | 5097 | // Cast the options parameter to the options type |
| 5098 | ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions"); | 5098 | ZigType *options_type = get_builtin_type(ag->codegen, "ExportOptions"); |
| 5099 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); | 5099 | IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type); |
| 5100 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); | 5100 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); |
| 5101 | | 5101 | |
| 5102 | AstNode *target_node = node->data.fn_call_expr.params.at(0); | 5102 | AstNode *target_node = node->data.fn_call_expr.params.at(0); |
| 5103 | IrInstSrc *target_value = ir_gen_node(irb, target_node, scope); | 5103 | IrInstSrc *target_value = ir_gen_node(ag, target_node, scope); |
| 5104 | if (target_value == irb->codegen->invalid_inst_src) | 5104 | if (target_value == ag->codegen->invalid_inst_src) |
| 5105 | return target_value; | 5105 | return target_value; |
| 5106 | | 5106 | |
| 5107 | AstNode *options_node = node->data.fn_call_expr.params.at(1); | 5107 | AstNode *options_node = node->data.fn_call_expr.params.at(1); |
| 5108 | IrInstSrc *options_value = ir_gen_node_extra(irb, options_node, | 5108 | IrInstSrc *options_value = ir_gen_node_extra(ag, options_node, |
| 5109 | scope, LValNone, &result_loc_cast->base); | 5109 | scope, LValNone, &result_loc_cast->base); |
| 5110 | if (options_value == irb->codegen->invalid_inst_src) | 5110 | if (options_value == ag->codegen->invalid_inst_src) |
| 5111 | return options_value; | 5111 | return options_value; |
| 5112 | | 5112 | |
| 5113 | IrInstSrc *casted_options_value = ir_build_implicit_cast( | 5113 | IrInstSrc *casted_options_value = ir_build_implicit_cast( |
| 5114 | irb, scope, options_node, options_value, result_loc_cast); | 5114 | ag, scope, options_node, options_value, result_loc_cast); |
| 5115 | | 5115 | |
| 5116 | IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value); | 5116 | IrInstSrc *ir_export = ir_build_export(ag, scope, node, target_value, casted_options_value); |
| 5117 | return ir_lval_wrap(irb, scope, ir_export, lval, result_loc); | 5117 | return ir_lval_wrap(ag, scope, ir_export, lval, result_loc); |
| 5118 | } | 5118 | } |
| 5119 | case BuiltinFnIdExtern: | 5119 | case BuiltinFnIdExtern: |
| 5120 | { | 5120 | { |
| 5121 | // Cast the options parameter to the options type | 5121 | // Cast the options parameter to the options type |
| 5122 | ZigType *options_type = get_builtin_type(irb->codegen, "ExternOptions"); | 5122 | ZigType *options_type = get_builtin_type(ag->codegen, "ExternOptions"); |
| 5123 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); | 5123 | IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type); |
| 5124 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); | 5124 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); |
| 5125 | | 5125 | |
| 5126 | AstNode *type_node = node->data.fn_call_expr.params.at(0); | 5126 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| 5127 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); | 5127 | IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); |
| 5128 | if (type_value == irb->codegen->invalid_inst_src) | 5128 | if (type_value == ag->codegen->invalid_inst_src) |
| 5129 | return type_value; | 5129 | return type_value; |
| 5130 | | 5130 | |
| 5131 | AstNode *options_node = node->data.fn_call_expr.params.at(1); | 5131 | AstNode *options_node = node->data.fn_call_expr.params.at(1); |
| 5132 | IrInstSrc *options_value = ir_gen_node_extra(irb, options_node, | 5132 | IrInstSrc *options_value = ir_gen_node_extra(ag, options_node, |
| 5133 | scope, LValNone, &result_loc_cast->base); | 5133 | scope, LValNone, &result_loc_cast->base); |
| 5134 | if (options_value == irb->codegen->invalid_inst_src) | 5134 | if (options_value == ag->codegen->invalid_inst_src) |
| 5135 | return options_value; | 5135 | return options_value; |
| 5136 | | 5136 | |
| 5137 | IrInstSrc *casted_options_value = ir_build_implicit_cast( | 5137 | IrInstSrc *casted_options_value = ir_build_implicit_cast( |
| 5138 | irb, scope, options_node, options_value, result_loc_cast); | 5138 | ag, scope, options_node, options_value, result_loc_cast); |
| 5139 | | 5139 | |
| 5140 | IrInstSrc *ir_extern = ir_build_extern(irb, scope, node, type_value, casted_options_value); | 5140 | IrInstSrc *ir_extern = ir_build_extern(ag, scope, node, type_value, casted_options_value); |
| 5141 | return ir_lval_wrap(irb, scope, ir_extern, lval, result_loc); | 5141 | return ir_lval_wrap(ag, scope, ir_extern, lval, result_loc); |
| 5142 | } | 5142 | } |
| 5143 | case BuiltinFnIdErrorReturnTrace: | 5143 | case BuiltinFnIdErrorReturnTrace: |
| 5144 | { | 5144 | { |
| 5145 | IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node, | 5145 | IrInstSrc *error_return_trace = ir_build_error_return_trace_src(ag, scope, node, |
| 5146 | IrInstErrorReturnTraceNull); | 5146 | IrInstErrorReturnTraceNull); |
| 5147 | return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc); | 5147 | return ir_lval_wrap(ag, scope, error_return_trace, lval, result_loc); |
| 5148 | } | 5148 | } |
| 5149 | case BuiltinFnIdAtomicRmw: | 5149 | case BuiltinFnIdAtomicRmw: |
| 5150 | { | 5150 | { |
| 5151 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5151 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5152 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5152 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5153 | if (arg0_value == irb->codegen->invalid_inst_src) | 5153 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5154 | return arg0_value; | 5154 | return arg0_value; |
| 5155 | | 5155 | |
| 5156 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5156 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5157 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5157 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5158 | if (arg1_value == irb->codegen->invalid_inst_src) | 5158 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5159 | return arg1_value; | 5159 | return arg1_value; |
| 5160 | | 5160 | |
| 5161 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 5161 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5162 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 5162 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 5163 | if (arg2_value == irb->codegen->invalid_inst_src) | 5163 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 5164 | return arg2_value; | 5164 | return arg2_value; |
| 5165 | | 5165 | |
| 5166 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); | 5166 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 5167 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); | 5167 | IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); |
| 5168 | if (arg3_value == irb->codegen->invalid_inst_src) | 5168 | if (arg3_value == ag->codegen->invalid_inst_src) |
| 5169 | return arg3_value; | 5169 | return arg3_value; |
| 5170 | | 5170 | |
| 5171 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); | 5171 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); |
| 5172 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); | 5172 | IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope); |
| 5173 | if (arg4_value == irb->codegen->invalid_inst_src) | 5173 | if (arg4_value == ag->codegen->invalid_inst_src) |
| 5174 | return arg4_value; | 5174 | return arg4_value; |
| 5175 | | 5175 | |
| 5176 | IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node, | 5176 | IrInstSrc *inst = ir_build_atomic_rmw_src(ag, scope, node, |
| 5177 | arg0_value, arg1_value, arg2_value, arg3_value, arg4_value); | 5177 | arg0_value, arg1_value, arg2_value, arg3_value, arg4_value); |
| 5178 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); | 5178 | return ir_lval_wrap(ag, scope, inst, lval, result_loc); |
| 5179 | } | 5179 | } |
| 5180 | case BuiltinFnIdAtomicLoad: | 5180 | case BuiltinFnIdAtomicLoad: |
| 5181 | { | 5181 | { |
| 5182 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5182 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5183 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5183 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5184 | if (arg0_value == irb->codegen->invalid_inst_src) | 5184 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5185 | return arg0_value; | 5185 | return arg0_value; |
| 5186 | | 5186 | |
| 5187 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5187 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5188 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5188 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5189 | if (arg1_value == irb->codegen->invalid_inst_src) | 5189 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5190 | return arg1_value; | 5190 | return arg1_value; |
| 5191 | | 5191 | |
| 5192 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 5192 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5193 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 5193 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 5194 | if (arg2_value == irb->codegen->invalid_inst_src) | 5194 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 5195 | return arg2_value; | 5195 | return arg2_value; |
| 5196 | | 5196 | |
| 5197 | IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value); | 5197 | IrInstSrc *inst = ir_build_atomic_load_src(ag, scope, node, arg0_value, arg1_value, arg2_value); |
| 5198 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); | 5198 | return ir_lval_wrap(ag, scope, inst, lval, result_loc); |
| 5199 | } | 5199 | } |
| 5200 | case BuiltinFnIdAtomicStore: | 5200 | case BuiltinFnIdAtomicStore: |
| 5201 | { | 5201 | { |
| 5202 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5202 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5203 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5203 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5204 | if (arg0_value == irb->codegen->invalid_inst_src) | 5204 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5205 | return arg0_value; | 5205 | return arg0_value; |
| 5206 | | 5206 | |
| 5207 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5207 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5208 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5208 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5209 | if (arg1_value == irb->codegen->invalid_inst_src) | 5209 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5210 | return arg1_value; | 5210 | return arg1_value; |
| 5211 | | 5211 | |
| 5212 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); | 5212 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5213 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); | 5213 | IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); |
| 5214 | if (arg2_value == irb->codegen->invalid_inst_src) | 5214 | if (arg2_value == ag->codegen->invalid_inst_src) |
| 5215 | return arg2_value; | 5215 | return arg2_value; |
| 5216 | | 5216 | |
| 5217 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); | 5217 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 5218 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); | 5218 | IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); |
| 5219 | if (arg3_value == irb->codegen->invalid_inst_src) | 5219 | if (arg3_value == ag->codegen->invalid_inst_src) |
| 5220 | return arg3_value; | 5220 | return arg3_value; |
| 5221 | | 5221 | |
| 5222 | IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value, | 5222 | IrInstSrc *inst = ir_build_atomic_store_src(ag, scope, node, arg0_value, arg1_value, |
| 5223 | arg2_value, arg3_value); | 5223 | arg2_value, arg3_value); |
| 5224 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); | 5224 | return ir_lval_wrap(ag, scope, inst, lval, result_loc); |
| 5225 | } | 5225 | } |
| 5226 | case BuiltinFnIdIntToEnum: | 5226 | case BuiltinFnIdIntToEnum: |
| 5227 | { | 5227 | { |
| 5228 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5228 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5229 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5229 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5230 | if (arg0_value == irb->codegen->invalid_inst_src) | 5230 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5231 | return arg0_value; | 5231 | return arg0_value; |
| 5232 | | 5232 | |
| 5233 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5233 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5234 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5234 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5235 | if (arg1_value == irb->codegen->invalid_inst_src) | 5235 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5236 | return arg1_value; | 5236 | return arg1_value; |
| 5237 | | 5237 | |
| 5238 | IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value); | 5238 | IrInstSrc *result = ir_build_int_to_enum_src(ag, scope, node, arg0_value, arg1_value); |
| 5239 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 5239 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 5240 | } | 5240 | } |
| 5241 | case BuiltinFnIdEnumToInt: | 5241 | case BuiltinFnIdEnumToInt: |
| 5242 | { | 5242 | { |
| 5243 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5243 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5244 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5244 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5245 | if (arg0_value == irb->codegen->invalid_inst_src) | 5245 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5246 | return arg0_value; | 5246 | return arg0_value; |
| 5247 | | 5247 | |
| 5248 | IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value); | 5248 | IrInstSrc *result = ir_build_enum_to_int(ag, scope, node, arg0_value); |
| 5249 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 5249 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 5250 | } | 5250 | } |
| 5251 | case BuiltinFnIdCtz: | 5251 | case BuiltinFnIdCtz: |
| 5252 | case BuiltinFnIdPopCount: | 5252 | case BuiltinFnIdPopCount: |
| ... | @@ -5255,73 +5255,73 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -5255,73 +5255,73 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 5255 | case BuiltinFnIdBitReverse: | 5255 | case BuiltinFnIdBitReverse: |
| 5256 | { | 5256 | { |
| 5257 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5257 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5258 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5258 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5259 | if (arg0_value == irb->codegen->invalid_inst_src) | 5259 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5260 | return arg0_value; | 5260 | return arg0_value; |
| 5261 | | 5261 | |
| 5262 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5262 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5263 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5263 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5264 | if (arg1_value == irb->codegen->invalid_inst_src) | 5264 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5265 | return arg1_value; | 5265 | return arg1_value; |
| 5266 | | 5266 | |
| 5267 | IrInstSrc *result; | 5267 | IrInstSrc *result; |
| 5268 | switch (builtin_fn->id) { | 5268 | switch (builtin_fn->id) { |
| 5269 | case BuiltinFnIdCtz: | 5269 | case BuiltinFnIdCtz: |
| 5270 | result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value); | 5270 | result = ir_build_ctz(ag, scope, node, arg0_value, arg1_value); |
| 5271 | break; | 5271 | break; |
| 5272 | case BuiltinFnIdPopCount: | 5272 | case BuiltinFnIdPopCount: |
| 5273 | result = ir_build_pop_count(irb, scope, node, arg0_value, arg1_value); | 5273 | result = ir_build_pop_count(ag, scope, node, arg0_value, arg1_value); |
| 5274 | break; | 5274 | break; |
| 5275 | case BuiltinFnIdClz: | 5275 | case BuiltinFnIdClz: |
| 5276 | result = ir_build_clz(irb, scope, node, arg0_value, arg1_value); | 5276 | result = ir_build_clz(ag, scope, node, arg0_value, arg1_value); |
| 5277 | break; | 5277 | break; |
| 5278 | case BuiltinFnIdBswap: | 5278 | case BuiltinFnIdBswap: |
| 5279 | result = ir_build_bswap(irb, scope, node, arg0_value, arg1_value); | 5279 | result = ir_build_bswap(ag, scope, node, arg0_value, arg1_value); |
| 5280 | break; | 5280 | break; |
| 5281 | case BuiltinFnIdBitReverse: | 5281 | case BuiltinFnIdBitReverse: |
| 5282 | result = ir_build_bit_reverse(irb, scope, node, arg0_value, arg1_value); | 5282 | result = ir_build_bit_reverse(ag, scope, node, arg0_value, arg1_value); |
| 5283 | break; | 5283 | break; |
| 5284 | default: | 5284 | default: |
| 5285 | zig_unreachable(); | 5285 | zig_unreachable(); |
| 5286 | } | 5286 | } |
| 5287 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | 5287 | return ir_lval_wrap(ag, scope, result, lval, result_loc); |
| 5288 | } | 5288 | } |
| 5289 | case BuiltinFnIdHasDecl: | 5289 | case BuiltinFnIdHasDecl: |
| 5290 | { | 5290 | { |
| 5291 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5291 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5292 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); | 5292 | IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); |
| 5293 | if (arg0_value == irb->codegen->invalid_inst_src) | 5293 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5294 | return arg0_value; | 5294 | return arg0_value; |
| 5295 | | 5295 | |
| 5296 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5296 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5297 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); | 5297 | IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); |
| 5298 | if (arg1_value == irb->codegen->invalid_inst_src) | 5298 | if (arg1_value == ag->codegen->invalid_inst_src) |
| 5299 | return arg1_value; | 5299 | return arg1_value; |
| 5300 | | 5300 | |
| 5301 | IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); | 5301 | IrInstSrc *has_decl = ir_build_has_decl(ag, scope, node, arg0_value, arg1_value); |
| 5302 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); | 5302 | return ir_lval_wrap(ag, scope, has_decl, lval, result_loc); |
| 5303 | } | 5303 | } |
| 5304 | case BuiltinFnIdUnionInit: | 5304 | case BuiltinFnIdUnionInit: |
| 5305 | { | 5305 | { |
| 5306 | AstNode *union_type_node = node->data.fn_call_expr.params.at(0); | 5306 | AstNode *union_type_node = node->data.fn_call_expr.params.at(0); |
| 5307 | IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope); | 5307 | IrInstSrc *union_type_inst = ir_gen_node(ag, union_type_node, scope); |
| 5308 | if (union_type_inst == irb->codegen->invalid_inst_src) | 5308 | if (union_type_inst == ag->codegen->invalid_inst_src) |
| 5309 | return union_type_inst; | 5309 | return union_type_inst; |
| 5310 | | 5310 | |
| 5311 | AstNode *name_node = node->data.fn_call_expr.params.at(1); | 5311 | AstNode *name_node = node->data.fn_call_expr.params.at(1); |
| 5312 | IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope); | 5312 | IrInstSrc *name_inst = ir_gen_node(ag, name_node, scope); |
| 5313 | if (name_inst == irb->codegen->invalid_inst_src) | 5313 | if (name_inst == ag->codegen->invalid_inst_src) |
| 5314 | return name_inst; | 5314 | return name_inst; |
| 5315 | | 5315 | |
| 5316 | AstNode *init_node = node->data.fn_call_expr.params.at(2); | 5316 | AstNode *init_node = node->data.fn_call_expr.params.at(2); |
| 5317 | | 5317 | |
| 5318 | return ir_gen_union_init_expr(irb, scope, node, union_type_inst, name_inst, init_node, | 5318 | return ir_gen_union_init_expr(ag, scope, node, union_type_inst, name_inst, init_node, |
| 5319 | lval, result_loc); | 5319 | lval, result_loc); |
| 5320 | } | 5320 | } |
| 5321 | case BuiltinFnIdSrc: | 5321 | case BuiltinFnIdSrc: |
| 5322 | { | 5322 | { |
| 5323 | IrInstSrc *src_inst = ir_build_src(irb, scope, node); | 5323 | IrInstSrc *src_inst = ir_build_src(ag, scope, node); |
| 5324 | return ir_lval_wrap(irb, scope, src_inst, lval, result_loc); | 5324 | return ir_lval_wrap(ag, scope, src_inst, lval, result_loc); |
| 5325 | } | 5325 | } |
| 5326 | } | 5326 | } |
| 5327 | zig_unreachable(); | 5327 | zig_unreachable(); |
| ... | @@ -5339,13 +5339,13 @@ static ScopeNoSuspend *get_scope_nosuspend(Scope *scope) { | ... | @@ -5339,13 +5339,13 @@ static ScopeNoSuspend *get_scope_nosuspend(Scope *scope) { |
| 5339 | return nullptr; | 5339 | return nullptr; |
| 5340 | } | 5340 | } |
| 5341 | | 5341 | |
| 5342 | static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 5342 | static IrInstSrc *ir_gen_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 5343 | ResultLoc *result_loc) | 5343 | ResultLoc *result_loc) |
| 5344 | { | 5344 | { |
| 5345 | assert(node->type == NodeTypeFnCallExpr); | 5345 | assert(node->type == NodeTypeFnCallExpr); |
| 5346 | | 5346 | |
| 5347 | if (node->data.fn_call_expr.modifier == CallModifierBuiltin) | 5347 | if (node->data.fn_call_expr.modifier == CallModifierBuiltin) |
| 5348 | return ir_gen_builtin_fn_call(irb, scope, node, lval, result_loc); | 5348 | return ir_gen_builtin_fn_call(ag, scope, node, lval, result_loc); |
| 5349 | | 5349 | |
| 5350 | bool is_nosuspend = get_scope_nosuspend(scope) != nullptr; | 5350 | bool is_nosuspend = get_scope_nosuspend(scope) != nullptr; |
| 5351 | CallModifier modifier = node->data.fn_call_expr.modifier; | 5351 | CallModifier modifier = node->data.fn_call_expr.modifier; |
| ... | @@ -5354,64 +5354,64 @@ static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, | ... | @@ -5354,64 +5354,64 @@ static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, |
| 5354 | } | 5354 | } |
| 5355 | | 5355 | |
| 5356 | AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr; | 5356 | AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr; |
| 5357 | return ir_gen_fn_call_with_args(irb, scope, node, fn_ref_node, modifier, | 5357 | return ir_gen_fn_call_with_args(ag, scope, node, fn_ref_node, modifier, |
| 5358 | nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc); | 5358 | nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc); |
| 5359 | } | 5359 | } |
| 5360 | | 5360 | |
| 5361 | static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 5361 | static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 5362 | ResultLoc *result_loc) | 5362 | ResultLoc *result_loc) |
| 5363 | { | 5363 | { |
| 5364 | assert(node->type == NodeTypeIfBoolExpr); | 5364 | assert(node->type == NodeTypeIfBoolExpr); |
| 5365 | | 5365 | |
| 5366 | IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); | 5366 | IrInstSrc *condition = ir_gen_node(ag, node->data.if_bool_expr.condition, scope); |
| 5367 | if (condition == irb->codegen->invalid_inst_src) | 5367 | if (condition == ag->codegen->invalid_inst_src) |
| 5368 | return irb->codegen->invalid_inst_src; | 5368 | return ag->codegen->invalid_inst_src; |
| 5369 | | 5369 | |
| 5370 | IrInstSrc *is_comptime; | 5370 | IrInstSrc *is_comptime; |
| 5371 | if (ir_should_inline(irb->exec, scope)) { | 5371 | if (ir_should_inline(ag->exec, scope)) { |
| 5372 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 5372 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 5373 | } else { | 5373 | } else { |
| 5374 | is_comptime = ir_build_test_comptime(irb, scope, node, condition); | 5374 | is_comptime = ir_build_test_comptime(ag, scope, node, condition); |
| 5375 | } | 5375 | } |
| 5376 | | 5376 | |
| 5377 | AstNode *then_node = node->data.if_bool_expr.then_block; | 5377 | AstNode *then_node = node->data.if_bool_expr.then_block; |
| 5378 | AstNode *else_node = node->data.if_bool_expr.else_node; | 5378 | AstNode *else_node = node->data.if_bool_expr.else_node; |
| 5379 | | 5379 | |
| 5380 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then"); | 5380 | IrBasicBlockSrc *then_block = ir_create_basic_block(ag, scope, "Then"); |
| 5381 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else"); | 5381 | IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "Else"); |
| 5382 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf"); | 5382 | IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "EndIf"); |
| 5383 | | 5383 | |
| 5384 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition, | 5384 | IrInstSrc *cond_br_inst = ir_build_cond_br(ag, scope, node, condition, |
| 5385 | then_block, else_block, is_comptime); | 5385 | then_block, else_block, is_comptime); |
| 5386 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, | 5386 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(ag, cond_br_inst, else_block, endif_block, |
| 5387 | result_loc, is_comptime); | 5387 | result_loc, is_comptime); |
| 5388 | | 5388 | |
| 5389 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 5389 | ir_set_cursor_at_end_and_append_block(ag, then_block); |
| 5390 | | 5390 | |
| 5391 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 5391 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 5392 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval, | 5392 | IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, subexpr_scope, lval, |
| 5393 | &peer_parent->peers.at(0)->base); | 5393 | &peer_parent->peers.at(0)->base); |
| 5394 | if (then_expr_result == irb->codegen->invalid_inst_src) | 5394 | if (then_expr_result == ag->codegen->invalid_inst_src) |
| 5395 | return irb->codegen->invalid_inst_src; | 5395 | return ag->codegen->invalid_inst_src; |
| 5396 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; | 5396 | IrBasicBlockSrc *after_then_block = ag->current_basic_block; |
| 5397 | if (!instr_is_unreachable(then_expr_result)) | 5397 | if (!instr_is_unreachable(then_expr_result)) |
| 5398 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 5398 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 5399 | | 5399 | |
| 5400 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 5400 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 5401 | IrInstSrc *else_expr_result; | 5401 | IrInstSrc *else_expr_result; |
| 5402 | if (else_node) { | 5402 | if (else_node) { |
| 5403 | else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); | 5403 | else_expr_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); |
| 5404 | if (else_expr_result == irb->codegen->invalid_inst_src) | 5404 | if (else_expr_result == ag->codegen->invalid_inst_src) |
| 5405 | return irb->codegen->invalid_inst_src; | 5405 | return ag->codegen->invalid_inst_src; |
| 5406 | } else { | 5406 | } else { |
| 5407 | else_expr_result = ir_build_const_void(irb, scope, node); | 5407 | else_expr_result = ir_build_const_void(ag, scope, node); |
| 5408 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); | 5408 | ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 5409 | } | 5409 | } |
| 5410 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 5410 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 5411 | if (!instr_is_unreachable(else_expr_result)) | 5411 | if (!instr_is_unreachable(else_expr_result)) |
| 5412 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 5412 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 5413 | | 5413 | |
| 5414 | ir_set_cursor_at_end_and_append_block(irb, endif_block); | 5414 | ir_set_cursor_at_end_and_append_block(ag, endif_block); |
| 5415 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 5415 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 5416 | incoming_values[0] = then_expr_result; | 5416 | incoming_values[0] = then_expr_result; |
| 5417 | incoming_values[1] = else_expr_result; | 5417 | incoming_values[1] = else_expr_result; |
| ... | @@ -5419,37 +5419,37 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode * | ... | @@ -5419,37 +5419,37 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode * |
| 5419 | incoming_blocks[0] = after_then_block; | 5419 | incoming_blocks[0] = after_then_block; |
| 5420 | incoming_blocks[1] = after_else_block; | 5420 | incoming_blocks[1] = after_else_block; |
| 5421 | | 5421 | |
| 5422 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); | 5422 | IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 5423 | return ir_expr_wrap(irb, scope, phi, result_loc); | 5423 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 5424 | } | 5424 | } |
| 5425 | | 5425 | |
| 5426 | static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { | 5426 | static IrInstSrc *ir_gen_prefix_op_id_lval(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| 5427 | assert(node->type == NodeTypePrefixOpExpr); | 5427 | assert(node->type == NodeTypePrefixOpExpr); |
| 5428 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | 5428 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 5429 | | 5429 | |
| 5430 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); | 5430 | IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, lval, nullptr); |
| 5431 | if (value == irb->codegen->invalid_inst_src) | 5431 | if (value == ag->codegen->invalid_inst_src) |
| 5432 | return value; | 5432 | return value; |
| 5433 | | 5433 | |
| 5434 | return ir_build_un_op(irb, scope, node, op_id, value); | 5434 | return ir_build_un_op(ag, scope, node, op_id, value); |
| 5435 | } | 5435 | } |
| 5436 | | 5436 | |
| 5437 | static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) { | 5437 | static IrInstSrc *ir_gen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 5438 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone); | 5438 | return ir_gen_prefix_op_id_lval(ag, scope, node, op_id, LValNone); |
| 5439 | } | 5439 | } |
| 5440 | | 5440 | |
| 5441 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) { | 5441 | static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) { |
| 5442 | if (inst == irb->codegen->invalid_inst_src) return inst; | 5442 | if (inst == ag->codegen->invalid_inst_src) return inst; |
| 5443 | ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc); | 5443 | ir_build_end_expr(ag, scope, inst->base.source_node, inst, result_loc); |
| 5444 | return inst; | 5444 | return inst; |
| 5445 | } | 5445 | } |
| 5446 | | 5446 | |
| 5447 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, | 5447 | static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value, LVal lval, |
| 5448 | ResultLoc *result_loc) | 5448 | ResultLoc *result_loc) |
| 5449 | { | 5449 | { |
| 5450 | // This logic must be kept in sync with | 5450 | // This logic must be kept in sync with |
| 5451 | // [STMT_EXPR_TEST_THING] <--- (search this token) | 5451 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 5452 | if (value == irb->codegen->invalid_inst_src || | 5452 | if (value == ag->codegen->invalid_inst_src || |
| 5453 | instr_is_unreachable(value) || | 5453 | instr_is_unreachable(value) || |
| 5454 | value->base.source_node->type == NodeTypeDefer || | 5454 | value->base.source_node->type == NodeTypeDefer || |
| 5455 | value->id == IrInstSrcIdDeclVar) | 5455 | value->id == IrInstSrcIdDeclVar) |
| ... | @@ -5461,9 +5461,9 @@ static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value | ... | @@ -5461,9 +5461,9 @@ static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value |
| 5461 | if (lval == LValPtr) { | 5461 | if (lval == LValPtr) { |
| 5462 | // We needed a pointer to a value, but we got a value. So we create | 5462 | // We needed a pointer to a value, but we got a value. So we create |
| 5463 | // an instruction which just makes a pointer of it. | 5463 | // an instruction which just makes a pointer of it. |
| 5464 | return ir_build_ref_src(irb, scope, value->base.source_node, value); | 5464 | return ir_build_ref_src(ag, scope, value->base.source_node, value); |
| 5465 | } else if (result_loc != nullptr) { | 5465 | } else if (result_loc != nullptr) { |
| 5466 | return ir_expr_wrap(irb, scope, value, result_loc); | 5466 | return ir_expr_wrap(ag, scope, value, result_loc); |
| 5467 | } else { | 5467 | } else { |
| 5468 | return value; | 5468 | return value; |
| 5469 | } | 5469 | } |
| ... | @@ -5484,7 +5484,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) { | ... | @@ -5484,7 +5484,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) { |
| 5484 | } | 5484 | } |
| 5485 | } | 5485 | } |
| 5486 | | 5486 | |
| 5487 | static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node, | 5487 | static Error token_number_literal_u32(Stage1AstGen *ag, AstNode *source_node, |
| 5488 | RootStruct *root_struct, uint32_t *result, TokenIndex token) | 5488 | RootStruct *root_struct, uint32_t *result, TokenIndex token) |
| 5489 | { | 5489 | { |
| 5490 | BigInt bigint; | 5490 | BigInt bigint; |
| ... | @@ -5493,7 +5493,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node, | ... | @@ -5493,7 +5493,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node, |
| 5493 | if (!bigint_fits_in_bits(&bigint, 32, false)) { | 5493 | if (!bigint_fits_in_bits(&bigint, 32, false)) { |
| 5494 | Buf *val_buf = buf_alloc(); | 5494 | Buf *val_buf = buf_alloc(); |
| 5495 | bigint_append_buf(val_buf, &bigint, 10); | 5495 | bigint_append_buf(val_buf, &bigint, 10); |
| 5496 | exec_add_error_node(irb->codegen, irb->exec, source_node, | 5496 | exec_add_error_node(ag->codegen, ag->exec, source_node, |
| 5497 | buf_sprintf("value %s too large for u32", buf_ptr(val_buf))); | 5497 | buf_sprintf("value %s too large for u32", buf_ptr(val_buf))); |
| 5498 | bigint_deinit(&bigint); | 5498 | bigint_deinit(&bigint); |
| 5499 | return ErrorSemanticAnalyzeFail; | 5499 | return ErrorSemanticAnalyzeFail; |
| ... | @@ -5504,7 +5504,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node, | ... | @@ -5504,7 +5504,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node, |
| 5504 | | 5504 | |
| 5505 | } | 5505 | } |
| 5506 | | 5506 | |
| 5507 | static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 5507 | static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 5508 | Error err; | 5508 | Error err; |
| 5509 | assert(node->type == NodeTypePointerType); | 5509 | assert(node->type == NodeTypePointerType); |
| 5510 | | 5510 | |
| ... | @@ -5521,8 +5521,8 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode * | ... | @@ -5521,8 +5521,8 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode * |
| 5521 | | 5521 | |
| 5522 | IrInstSrc *sentinel; | 5522 | IrInstSrc *sentinel; |
| 5523 | if (sentinel_expr != nullptr) { | 5523 | if (sentinel_expr != nullptr) { |
| 5524 | sentinel = ir_gen_node(irb, sentinel_expr, scope); | 5524 | sentinel = ir_gen_node(ag, sentinel_expr, scope); |
| 5525 | if (sentinel == irb->codegen->invalid_inst_src) | 5525 | if (sentinel == ag->codegen->invalid_inst_src) |
| 5526 | return sentinel; | 5526 | return sentinel; |
| 5527 | } else { | 5527 | } else { |
| 5528 | sentinel = nullptr; | 5528 | sentinel = nullptr; |
| ... | @@ -5530,75 +5530,75 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode * | ... | @@ -5530,75 +5530,75 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode * |
| 5530 | | 5530 | |
| 5531 | IrInstSrc *align_value; | 5531 | IrInstSrc *align_value; |
| 5532 | if (align_expr != nullptr) { | 5532 | if (align_expr != nullptr) { |
| 5533 | align_value = ir_gen_node(irb, align_expr, scope); | 5533 | align_value = ir_gen_node(ag, align_expr, scope); |
| 5534 | if (align_value == irb->codegen->invalid_inst_src) | 5534 | if (align_value == ag->codegen->invalid_inst_src) |
| 5535 | return align_value; | 5535 | return align_value; |
| 5536 | } else { | 5536 | } else { |
| 5537 | align_value = nullptr; | 5537 | align_value = nullptr; |
| 5538 | } | 5538 | } |
| 5539 | | 5539 | |
| 5540 | IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope); | 5540 | IrInstSrc *child_type = ir_gen_node(ag, expr_node, scope); |
| 5541 | if (child_type == irb->codegen->invalid_inst_src) | 5541 | if (child_type == ag->codegen->invalid_inst_src) |
| 5542 | return child_type; | 5542 | return child_type; |
| 5543 | | 5543 | |
| 5544 | uint32_t bit_offset_start = 0; | 5544 | uint32_t bit_offset_start = 0; |
| 5545 | if (node->data.pointer_type.bit_offset_start != 0) { | 5545 | if (node->data.pointer_type.bit_offset_start != 0) { |
| 5546 | if ((err = token_number_literal_u32(irb, node, root_struct, &bit_offset_start, | 5546 | if ((err = token_number_literal_u32(ag, node, root_struct, &bit_offset_start, |
| 5547 | node->data.pointer_type.bit_offset_start))) | 5547 | node->data.pointer_type.bit_offset_start))) |
| 5548 | { | 5548 | { |
| 5549 | return irb->codegen->invalid_inst_src; | 5549 | return ag->codegen->invalid_inst_src; |
| 5550 | } | 5550 | } |
| 5551 | } | 5551 | } |
| 5552 | | 5552 | |
| 5553 | uint32_t host_int_bytes = 0; | 5553 | uint32_t host_int_bytes = 0; |
| 5554 | if (node->data.pointer_type.host_int_bytes != 0) { | 5554 | if (node->data.pointer_type.host_int_bytes != 0) { |
| 5555 | if ((err = token_number_literal_u32(irb, node, root_struct, &host_int_bytes, | 5555 | if ((err = token_number_literal_u32(ag, node, root_struct, &host_int_bytes, |
| 5556 | node->data.pointer_type.host_int_bytes))) | 5556 | node->data.pointer_type.host_int_bytes))) |
| 5557 | { | 5557 | { |
| 5558 | return irb->codegen->invalid_inst_src; | 5558 | return ag->codegen->invalid_inst_src; |
| 5559 | } | 5559 | } |
| 5560 | } | 5560 | } |
| 5561 | | 5561 | |
| 5562 | if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) { | 5562 | if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) { |
| 5563 | exec_add_error_node(irb->codegen, irb->exec, node, | 5563 | exec_add_error_node(ag->codegen, ag->exec, node, |
| 5564 | buf_sprintf("bit offset starts after end of host integer")); | 5564 | buf_sprintf("bit offset starts after end of host integer")); |
| 5565 | return irb->codegen->invalid_inst_src; | 5565 | return ag->codegen->invalid_inst_src; |
| 5566 | } | 5566 | } |
| 5567 | | 5567 | |
| 5568 | return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile, | 5568 | return ir_build_ptr_type(ag, scope, node, child_type, is_const, is_volatile, |
| 5569 | ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero); | 5569 | ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero); |
| 5570 | } | 5570 | } |
| 5571 | | 5571 | |
| 5572 | static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 5572 | static IrInstSrc *ir_gen_catch_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 5573 | AstNode *expr_node, LVal lval, ResultLoc *result_loc) | 5573 | AstNode *expr_node, LVal lval, ResultLoc *result_loc) |
| 5574 | { | 5574 | { |
| 5575 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); | 5575 | IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); |
| 5576 | if (err_union_ptr == irb->codegen->invalid_inst_src) | 5576 | if (err_union_ptr == ag->codegen->invalid_inst_src) |
| 5577 | return irb->codegen->invalid_inst_src; | 5577 | return ag->codegen->invalid_inst_src; |
| 5578 | | 5578 | |
| 5579 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false); | 5579 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(ag, scope, source_node, err_union_ptr, true, false); |
| 5580 | if (payload_ptr == irb->codegen->invalid_inst_src) | 5580 | if (payload_ptr == ag->codegen->invalid_inst_src) |
| 5581 | return irb->codegen->invalid_inst_src; | 5581 | return ag->codegen->invalid_inst_src; |
| 5582 | | 5582 | |
| 5583 | if (lval == LValPtr) | 5583 | if (lval == LValPtr) |
| 5584 | return payload_ptr; | 5584 | return payload_ptr; |
| 5585 | | 5585 | |
| 5586 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); | 5586 | IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, source_node, payload_ptr); |
| 5587 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); | 5587 | return ir_expr_wrap(ag, scope, load_ptr, result_loc); |
| 5588 | } | 5588 | } |
| 5589 | | 5589 | |
| 5590 | static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 5590 | static IrInstSrc *ir_gen_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 5591 | assert(node->type == NodeTypePrefixOpExpr); | 5591 | assert(node->type == NodeTypePrefixOpExpr); |
| 5592 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | 5592 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 5593 | | 5593 | |
| 5594 | IrInstSrc *value = ir_gen_node(irb, expr_node, scope); | 5594 | IrInstSrc *value = ir_gen_node(ag, expr_node, scope); |
| 5595 | if (value == irb->codegen->invalid_inst_src) | 5595 | if (value == ag->codegen->invalid_inst_src) |
| 5596 | return irb->codegen->invalid_inst_src; | 5596 | return ag->codegen->invalid_inst_src; |
| 5597 | | 5597 | |
| 5598 | return ir_build_bool_not(irb, scope, node, value); | 5598 | return ir_build_bool_not(ag, scope, node, value); |
| 5599 | } | 5599 | } |
| 5600 | | 5600 | |
| 5601 | static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 5601 | static IrInstSrc *ir_gen_prefix_op_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 5602 | ResultLoc *result_loc) | 5602 | ResultLoc *result_loc) |
| 5603 | { | 5603 | { |
| 5604 | assert(node->type == NodeTypePrefixOpExpr); | 5604 | assert(node->type == NodeTypePrefixOpExpr); |
| ... | @@ -5609,49 +5609,49 @@ static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode | ... | @@ -5609,49 +5609,49 @@ static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode |
| 5609 | case PrefixOpInvalid: | 5609 | case PrefixOpInvalid: |
| 5610 | zig_unreachable(); | 5610 | zig_unreachable(); |
| 5611 | case PrefixOpBoolNot: | 5611 | case PrefixOpBoolNot: |
| 5612 | return ir_lval_wrap(irb, scope, ir_gen_bool_not(irb, scope, node), lval, result_loc); | 5612 | return ir_lval_wrap(ag, scope, ir_gen_bool_not(ag, scope, node), lval, result_loc); |
| 5613 | case PrefixOpBinNot: | 5613 | case PrefixOpBinNot: |
| 5614 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpBinNot), lval, result_loc); | 5614 | return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpBinNot), lval, result_loc); |
| 5615 | case PrefixOpNegation: | 5615 | case PrefixOpNegation: |
| 5616 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval, result_loc); | 5616 | return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpNegation), lval, result_loc); |
| 5617 | case PrefixOpNegationWrap: | 5617 | case PrefixOpNegationWrap: |
| 5618 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval, result_loc); | 5618 | return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpNegationWrap), lval, result_loc); |
| 5619 | case PrefixOpOptional: | 5619 | case PrefixOpOptional: |
| 5620 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval, result_loc); | 5620 | return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpOptional), lval, result_loc); |
| 5621 | case PrefixOpAddrOf: { | 5621 | case PrefixOpAddrOf: { |
| 5622 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | 5622 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 5623 | return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr), lval, result_loc); | 5623 | return ir_lval_wrap(ag, scope, ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr), lval, result_loc); |
| 5624 | } | 5624 | } |
| 5625 | } | 5625 | } |
| 5626 | zig_unreachable(); | 5626 | zig_unreachable(); |
| 5627 | } | 5627 | } |
| 5628 | | 5628 | |
| 5629 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, | 5629 | static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 5630 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, | 5630 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 5631 | LVal lval, ResultLoc *parent_result_loc) | 5631 | LVal lval, ResultLoc *parent_result_loc) |
| 5632 | { | 5632 | { |
| 5633 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type); | 5633 | IrInstSrc *container_ptr = ir_build_resolve_result(ag, scope, source_node, parent_result_loc, union_type); |
| 5634 | IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr, | 5634 | IrInstSrc *field_ptr = ir_build_field_ptr_instruction(ag, scope, source_node, container_ptr, |
| 5635 | field_name, true); | 5635 | field_name, true); |
| 5636 | | 5636 | |
| 5637 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); | 5637 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); |
| 5638 | result_loc_inst->base.id = ResultLocIdInstruction; | 5638 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5639 | result_loc_inst->base.source_instruction = field_ptr; | 5639 | result_loc_inst->base.source_instruction = field_ptr; |
| 5640 | ir_ref_instruction(field_ptr, irb->current_basic_block); | 5640 | ir_ref_instruction(field_ptr, ag->current_basic_block); |
| 5641 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); | 5641 | ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); |
| 5642 | | 5642 | |
| 5643 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, | 5643 | IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, |
| 5644 | &result_loc_inst->base); | 5644 | &result_loc_inst->base); |
| 5645 | if (expr_value == irb->codegen->invalid_inst_src) | 5645 | if (expr_value == ag->codegen->invalid_inst_src) |
| 5646 | return expr_value; | 5646 | return expr_value; |
| 5647 | | 5647 | |
| 5648 | IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type, | 5648 | IrInstSrc *init_union = ir_build_union_init_named_field(ag, scope, source_node, union_type, |
| 5649 | field_name, field_ptr, container_ptr); | 5649 | field_name, field_ptr, container_ptr); |
| 5650 | | 5650 | |
| 5651 | return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc); | 5651 | return ir_lval_wrap(ag, scope, init_union, lval, parent_result_loc); |
| 5652 | } | 5652 | } |
| 5653 | | 5653 | |
| 5654 | static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 5654 | static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 5655 | ResultLoc *parent_result_loc) | 5655 | ResultLoc *parent_result_loc) |
| 5656 | { | 5656 | { |
| 5657 | assert(node->type == NodeTypeContainerInitExpr); | 5657 | assert(node->type == NodeTypeContainerInitExpr); |
| ... | @@ -5666,33 +5666,33 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As | ... | @@ -5666,33 +5666,33 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As |
| 5666 | IrInstSrc *container_type; | 5666 | IrInstSrc *container_type; |
| 5667 | if (container_init_expr->type->type == NodeTypeInferredArrayType) { | 5667 | if (container_init_expr->type->type == NodeTypeInferredArrayType) { |
| 5668 | if (kind == ContainerInitKindStruct) { | 5668 | if (kind == ContainerInitKindStruct) { |
| 5669 | add_node_error(irb->codegen, container_init_expr->type, | 5669 | add_node_error(ag->codegen, container_init_expr->type, |
| 5670 | buf_sprintf("initializing array with struct syntax")); | 5670 | buf_sprintf("initializing array with struct syntax")); |
| 5671 | return irb->codegen->invalid_inst_src; | 5671 | return ag->codegen->invalid_inst_src; |
| 5672 | } | 5672 | } |
| 5673 | IrInstSrc *sentinel; | 5673 | IrInstSrc *sentinel; |
| 5674 | if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) { | 5674 | if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) { |
| 5675 | sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope); | 5675 | sentinel = ir_gen_node(ag, container_init_expr->type->data.inferred_array_type.sentinel, scope); |
| 5676 | if (sentinel == irb->codegen->invalid_inst_src) | 5676 | if (sentinel == ag->codegen->invalid_inst_src) |
| 5677 | return sentinel; | 5677 | return sentinel; |
| 5678 | } else { | 5678 | } else { |
| 5679 | sentinel = nullptr; | 5679 | sentinel = nullptr; |
| 5680 | } | 5680 | } |
| 5681 | | 5681 | |
| 5682 | IrInstSrc *elem_type = ir_gen_node(irb, | 5682 | IrInstSrc *elem_type = ir_gen_node(ag, |
| 5683 | container_init_expr->type->data.inferred_array_type.child_type, scope); | 5683 | container_init_expr->type->data.inferred_array_type.child_type, scope); |
| 5684 | if (elem_type == irb->codegen->invalid_inst_src) | 5684 | if (elem_type == ag->codegen->invalid_inst_src) |
| 5685 | return elem_type; | 5685 | return elem_type; |
| 5686 | size_t item_count = container_init_expr->entries.length; | 5686 | size_t item_count = container_init_expr->entries.length; |
| 5687 | IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); | 5687 | IrInstSrc *item_count_inst = ir_build_const_usize(ag, scope, node, item_count); |
| 5688 | container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type); | 5688 | container_type = ir_build_array_type(ag, scope, node, item_count_inst, sentinel, elem_type); |
| 5689 | } else { | 5689 | } else { |
| 5690 | container_type = ir_gen_node(irb, container_init_expr->type, scope); | 5690 | container_type = ir_gen_node(ag, container_init_expr->type, scope); |
| 5691 | if (container_type == irb->codegen->invalid_inst_src) | 5691 | if (container_type == ag->codegen->invalid_inst_src) |
| 5692 | return container_type; | 5692 | return container_type; |
| 5693 | } | 5693 | } |
| 5694 | | 5694 | |
| 5695 | result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc); | 5695 | result_loc_cast = ir_build_cast_result_loc(ag, container_type, parent_result_loc); |
| 5696 | child_result_loc = &result_loc_cast->base; | 5696 | child_result_loc = &result_loc_cast->base; |
| 5697 | init_array_type_source_node = container_type->base.source_node; | 5697 | init_array_type_source_node = container_type->base.source_node; |
| 5698 | } else { | 5698 | } else { |
| ... | @@ -5706,7 +5706,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As | ... | @@ -5706,7 +5706,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As |
| 5706 | | 5706 | |
| 5707 | switch (kind) { | 5707 | switch (kind) { |
| 5708 | case ContainerInitKindStruct: { | 5708 | case ContainerInitKindStruct: { |
| 5709 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, | 5709 | IrInstSrc *container_ptr = ir_build_resolve_result(ag, scope, node, child_result_loc, |
| 5710 | nullptr); | 5710 | nullptr); |
| 5711 | | 5711 | |
| 5712 | size_t field_count = container_init_expr->entries.length; | 5712 | size_t field_count = container_init_expr->entries.length; |
| ... | @@ -5718,122 +5718,122 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As | ... | @@ -5718,122 +5718,122 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As |
| 5718 | Buf *name = entry_node->data.struct_val_field.name; | 5718 | Buf *name = entry_node->data.struct_val_field.name; |
| 5719 | AstNode *expr_node = entry_node->data.struct_val_field.expr; | 5719 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 5720 | | 5720 | |
| 5721 | IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true); | 5721 | IrInstSrc *field_ptr = ir_build_field_ptr(ag, scope, entry_node, container_ptr, name, true); |
| 5722 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); | 5722 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); |
| 5723 | result_loc_inst->base.id = ResultLocIdInstruction; | 5723 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5724 | result_loc_inst->base.source_instruction = field_ptr; | 5724 | result_loc_inst->base.source_instruction = field_ptr; |
| 5725 | result_loc_inst->base.allow_write_through_const = true; | 5725 | result_loc_inst->base.allow_write_through_const = true; |
| 5726 | ir_ref_instruction(field_ptr, irb->current_basic_block); | 5726 | ir_ref_instruction(field_ptr, ag->current_basic_block); |
| 5727 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); | 5727 | ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); |
| 5728 | | 5728 | |
| 5729 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, | 5729 | IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, |
| 5730 | &result_loc_inst->base); | 5730 | &result_loc_inst->base); |
| 5731 | if (expr_value == irb->codegen->invalid_inst_src) | 5731 | if (expr_value == ag->codegen->invalid_inst_src) |
| 5732 | return expr_value; | 5732 | return expr_value; |
| 5733 | | 5733 | |
| 5734 | fields[i].name = name; | 5734 | fields[i].name = name; |
| 5735 | fields[i].source_node = entry_node; | 5735 | fields[i].source_node = entry_node; |
| 5736 | fields[i].result_loc = field_ptr; | 5736 | fields[i].result_loc = field_ptr; |
| 5737 | } | 5737 | } |
| 5738 | IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count, | 5738 | IrInstSrc *result = ir_build_container_init_fields(ag, scope, node, field_count, |
| 5739 | fields, container_ptr); | 5739 | fields, container_ptr); |
| 5740 | | 5740 | |
| 5741 | if (result_loc_cast != nullptr) { | 5741 | if (result_loc_cast != nullptr) { |
| 5742 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); | 5742 | result = ir_build_implicit_cast(ag, scope, node, result, result_loc_cast); |
| 5743 | } | 5743 | } |
| 5744 | return ir_lval_wrap(irb, scope, result, lval, parent_result_loc); | 5744 | return ir_lval_wrap(ag, scope, result, lval, parent_result_loc); |
| 5745 | } | 5745 | } |
| 5746 | case ContainerInitKindArray: { | 5746 | case ContainerInitKindArray: { |
| 5747 | size_t item_count = container_init_expr->entries.length; | 5747 | size_t item_count = container_init_expr->entries.length; |
| 5748 | | 5748 | |
| 5749 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, | 5749 | IrInstSrc *container_ptr = ir_build_resolve_result(ag, scope, node, child_result_loc, |
| 5750 | nullptr); | 5750 | nullptr); |
| 5751 | | 5751 | |
| 5752 | IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count); | 5752 | IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count); |
| 5753 | for (size_t i = 0; i < item_count; i += 1) { | 5753 | for (size_t i = 0; i < item_count; i += 1) { |
| 5754 | AstNode *expr_node = container_init_expr->entries.at(i); | 5754 | AstNode *expr_node = container_init_expr->entries.at(i); |
| 5755 | | 5755 | |
| 5756 | IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i); | 5756 | IrInstSrc *elem_index = ir_build_const_usize(ag, scope, expr_node, i); |
| 5757 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, | 5757 | IrInstSrc *elem_ptr = ir_build_elem_ptr(ag, scope, expr_node, container_ptr, |
| 5758 | elem_index, false, PtrLenSingle, init_array_type_source_node); | 5758 | elem_index, false, PtrLenSingle, init_array_type_source_node); |
| 5759 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); | 5759 | ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>(); |
| 5760 | result_loc_inst->base.id = ResultLocIdInstruction; | 5760 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5761 | result_loc_inst->base.source_instruction = elem_ptr; | 5761 | result_loc_inst->base.source_instruction = elem_ptr; |
| 5762 | result_loc_inst->base.allow_write_through_const = true; | 5762 | result_loc_inst->base.allow_write_through_const = true; |
| 5763 | ir_ref_instruction(elem_ptr, irb->current_basic_block); | 5763 | ir_ref_instruction(elem_ptr, ag->current_basic_block); |
| 5764 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); | 5764 | ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); |
| 5765 | | 5765 | |
| 5766 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, | 5766 | IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, |
| 5767 | &result_loc_inst->base); | 5767 | &result_loc_inst->base); |
| 5768 | if (expr_value == irb->codegen->invalid_inst_src) | 5768 | if (expr_value == ag->codegen->invalid_inst_src) |
| 5769 | return expr_value; | 5769 | return expr_value; |
| 5770 | | 5770 | |
| 5771 | result_locs[i] = elem_ptr; | 5771 | result_locs[i] = elem_ptr; |
| 5772 | } | 5772 | } |
| 5773 | IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count, | 5773 | IrInstSrc *result = ir_build_container_init_list(ag, scope, node, item_count, |
| 5774 | result_locs, container_ptr, init_array_type_source_node); | 5774 | result_locs, container_ptr, init_array_type_source_node); |
| 5775 | if (result_loc_cast != nullptr) { | 5775 | if (result_loc_cast != nullptr) { |
| 5776 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); | 5776 | result = ir_build_implicit_cast(ag, scope, node, result, result_loc_cast); |
| 5777 | } | 5777 | } |
| 5778 | return ir_lval_wrap(irb, scope, result, lval, parent_result_loc); | 5778 | return ir_lval_wrap(ag, scope, result, lval, parent_result_loc); |
| 5779 | } | 5779 | } |
| 5780 | } | 5780 | } |
| 5781 | zig_unreachable(); | 5781 | zig_unreachable(); |
| 5782 | } | 5782 | } |
| 5783 | | 5783 | |
| 5784 | static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) { | 5784 | static ResultLocVar *ir_build_var_result_loc(Stage1AstGen *ag, IrInstSrc *alloca, ZigVar *var) { |
| 5785 | ResultLocVar *result_loc_var = heap::c_allocator.create<ResultLocVar>(); | 5785 | ResultLocVar *result_loc_var = heap::c_allocator.create<ResultLocVar>(); |
| 5786 | result_loc_var->base.id = ResultLocIdVar; | 5786 | result_loc_var->base.id = ResultLocIdVar; |
| 5787 | result_loc_var->base.source_instruction = alloca; | 5787 | result_loc_var->base.source_instruction = alloca; |
| 5788 | result_loc_var->base.allow_write_through_const = true; | 5788 | result_loc_var->base.allow_write_through_const = true; |
| 5789 | result_loc_var->var = var; | 5789 | result_loc_var->var = var; |
| 5790 | | 5790 | |
| 5791 | ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base); | 5791 | ir_build_reset_result(ag, alloca->base.scope, alloca->base.source_node, &result_loc_var->base); |
| 5792 | | 5792 | |
| 5793 | return result_loc_var; | 5793 | return result_loc_var; |
| 5794 | } | 5794 | } |
| 5795 | | 5795 | |
| 5796 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, | 5796 | static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest_type, |
| 5797 | ResultLoc *parent_result_loc) | 5797 | ResultLoc *parent_result_loc) |
| 5798 | { | 5798 | { |
| 5799 | ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>(); | 5799 | ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>(); |
| 5800 | result_loc_cast->base.id = ResultLocIdCast; | 5800 | result_loc_cast->base.id = ResultLocIdCast; |
| 5801 | result_loc_cast->base.source_instruction = dest_type; | 5801 | result_loc_cast->base.source_instruction = dest_type; |
| 5802 | result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const; | 5802 | result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const; |
| 5803 | ir_ref_instruction(dest_type, irb->current_basic_block); | 5803 | ir_ref_instruction(dest_type, ag->current_basic_block); |
| 5804 | result_loc_cast->parent = parent_result_loc; | 5804 | result_loc_cast->parent = parent_result_loc; |
| 5805 | | 5805 | |
| 5806 | ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base); | 5806 | ir_build_reset_result(ag, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base); |
| 5807 | | 5807 | |
| 5808 | return result_loc_cast; | 5808 | return result_loc_cast; |
| 5809 | } | 5809 | } |
| 5810 | | 5810 | |
| 5811 | static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, | 5811 | static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var, |
| 5812 | IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime) | 5812 | IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime) |
| 5813 | { | 5813 | { |
| 5814 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); | 5814 | IrInstSrc *alloca = ir_build_alloca_src(ag, scope, source_node, nullptr, name_hint, is_comptime); |
| 5815 | ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var); | 5815 | ResultLocVar *var_result_loc = ir_build_var_result_loc(ag, alloca, var); |
| 5816 | ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base); | 5816 | ir_build_end_expr(ag, scope, source_node, init, &var_result_loc->base); |
| 5817 | ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca); | 5817 | ir_build_var_decl_src(ag, scope, source_node, var, nullptr, alloca); |
| 5818 | } | 5818 | } |
| 5819 | | 5819 | |
| 5820 | static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 5820 | static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 5821 | assert(node->type == NodeTypeVariableDeclaration); | 5821 | assert(node->type == NodeTypeVariableDeclaration); |
| 5822 | | 5822 | |
| 5823 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; | 5823 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; |
| 5824 | | 5824 | |
| 5825 | if (buf_eql_str(variable_declaration->symbol, "_")) { | 5825 | if (buf_eql_str(variable_declaration->symbol, "_")) { |
| 5826 | add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol")); | 5826 | add_node_error(ag->codegen, node, buf_sprintf("`_` is not a declarable symbol")); |
| 5827 | return irb->codegen->invalid_inst_src; | 5827 | return ag->codegen->invalid_inst_src; |
| 5828 | } | 5828 | } |
| 5829 | | 5829 | |
| 5830 | // Used for the type expr and the align expr | 5830 | // Used for the type expr and the align expr |
| 5831 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); | 5831 | Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope); |
| 5832 | | 5832 | |
| 5833 | IrInstSrc *type_instruction; | 5833 | IrInstSrc *type_instruction; |
| 5834 | if (variable_declaration->type != nullptr) { | 5834 | if (variable_declaration->type != nullptr) { |
| 5835 | type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope); | 5835 | type_instruction = ir_gen_node(ag, variable_declaration->type, comptime_scope); |
| 5836 | if (type_instruction == irb->codegen->invalid_inst_src) | 5836 | if (type_instruction == ag->codegen->invalid_inst_src) |
| 5837 | return type_instruction; | 5837 | return type_instruction; |
| 5838 | } else { | 5838 | } else { |
| 5839 | type_instruction = nullptr; | 5839 | type_instruction = nullptr; |
| ... | @@ -5843,43 +5843,43 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node | ... | @@ -5843,43 +5843,43 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node |
| 5843 | bool is_const = variable_declaration->is_const; | 5843 | bool is_const = variable_declaration->is_const; |
| 5844 | bool is_extern = variable_declaration->is_extern; | 5844 | bool is_extern = variable_declaration->is_extern; |
| 5845 | | 5845 | |
| 5846 | bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime; | 5846 | bool is_comptime_scalar = ir_should_inline(ag->exec, scope) || variable_declaration->is_comptime; |
| 5847 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar); | 5847 | IrInstSrc *is_comptime = ir_build_const_bool(ag, scope, node, is_comptime_scalar); |
| 5848 | ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol, | 5848 | ZigVar *var = ir_create_var(ag, node, scope, variable_declaration->symbol, |
| 5849 | is_const, is_const, is_shadowable, is_comptime); | 5849 | is_const, is_const, is_shadowable, is_comptime); |
| 5850 | // we detect IrInstSrcDeclVar in gen_block to make sure the next node | 5850 | // we detect IrInstSrcDeclVar in gen_block to make sure the next node |
| 5851 | // is inside var->child_scope | 5851 | // is inside var->child_scope |
| 5852 | | 5852 | |
| 5853 | if (!is_extern && !variable_declaration->expr) { | 5853 | if (!is_extern && !variable_declaration->expr) { |
| 5854 | var->var_type = irb->codegen->builtin_types.entry_invalid; | 5854 | var->var_type = ag->codegen->builtin_types.entry_invalid; |
| 5855 | add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized")); | 5855 | add_node_error(ag->codegen, node, buf_sprintf("variables must be initialized")); |
| 5856 | return irb->codegen->invalid_inst_src; | 5856 | return ag->codegen->invalid_inst_src; |
| 5857 | } | 5857 | } |
| 5858 | | 5858 | |
| 5859 | IrInstSrc *align_value = nullptr; | 5859 | IrInstSrc *align_value = nullptr; |
| 5860 | if (variable_declaration->align_expr != nullptr) { | 5860 | if (variable_declaration->align_expr != nullptr) { |
| 5861 | align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope); | 5861 | align_value = ir_gen_node(ag, variable_declaration->align_expr, comptime_scope); |
| 5862 | if (align_value == irb->codegen->invalid_inst_src) | 5862 | if (align_value == ag->codegen->invalid_inst_src) |
| 5863 | return align_value; | 5863 | return align_value; |
| 5864 | } | 5864 | } |
| 5865 | | 5865 | |
| 5866 | if (variable_declaration->section_expr != nullptr) { | 5866 | if (variable_declaration->section_expr != nullptr) { |
| 5867 | add_node_error(irb->codegen, variable_declaration->section_expr, | 5867 | add_node_error(ag->codegen, variable_declaration->section_expr, |
| 5868 | buf_sprintf("cannot set section of local variable '%s'", buf_ptr(variable_declaration->symbol))); | 5868 | buf_sprintf("cannot set section of local variable '%s'", buf_ptr(variable_declaration->symbol))); |
| 5869 | } | 5869 | } |
| 5870 | | 5870 | |
| 5871 | // Parser should ensure that this never happens | 5871 | // Parser should ensure that this never happens |
| 5872 | assert(variable_declaration->threadlocal_tok == 0); | 5872 | assert(variable_declaration->threadlocal_tok == 0); |
| 5873 | | 5873 | |
| 5874 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value, | 5874 | IrInstSrc *alloca = ir_build_alloca_src(ag, scope, node, align_value, |
| 5875 | buf_ptr(variable_declaration->symbol), is_comptime); | 5875 | buf_ptr(variable_declaration->symbol), is_comptime); |
| 5876 | | 5876 | |
| 5877 | // Create a result location for the initialization expression. | 5877 | // Create a result location for the initialization expression. |
| 5878 | ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var); | 5878 | ResultLocVar *result_loc_var = ir_build_var_result_loc(ag, alloca, var); |
| 5879 | ResultLoc *init_result_loc; | 5879 | ResultLoc *init_result_loc; |
| 5880 | ResultLocCast *result_loc_cast; | 5880 | ResultLocCast *result_loc_cast; |
| 5881 | if (type_instruction != nullptr) { | 5881 | if (type_instruction != nullptr) { |
| 5882 | result_loc_cast = ir_build_cast_result_loc(irb, type_instruction, &result_loc_var->base); | 5882 | result_loc_cast = ir_build_cast_result_loc(ag, type_instruction, &result_loc_var->base); |
| 5883 | init_result_loc = &result_loc_cast->base; | 5883 | init_result_loc = &result_loc_cast->base; |
| 5884 | } else { | 5884 | } else { |
| 5885 | result_loc_cast = nullptr; | 5885 | result_loc_cast = nullptr; |
| ... | @@ -5887,29 +5887,29 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node | ... | @@ -5887,29 +5887,29 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node |
| 5887 | } | 5887 | } |
| 5888 | | 5888 | |
| 5889 | Scope *init_scope = is_comptime_scalar ? | 5889 | Scope *init_scope = is_comptime_scalar ? |
| 5890 | create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope; | 5890 | create_comptime_scope(ag->codegen, variable_declaration->expr, scope) : scope; |
| 5891 | | 5891 | |
| 5892 | // Temporarily set the name of the Stage1Zir to the VariableDeclaration | 5892 | // Temporarily set the name of the Stage1Zir to the VariableDeclaration |
| 5893 | // so that the struct or enum from the init expression inherits the name. | 5893 | // so that the struct or enum from the init expression inherits the name. |
| 5894 | Buf *old_exec_name = irb->exec->name; | 5894 | Buf *old_exec_name = ag->exec->name; |
| 5895 | irb->exec->name = variable_declaration->symbol; | 5895 | ag->exec->name = variable_declaration->symbol; |
| 5896 | IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope, | 5896 | IrInstSrc *init_value = ir_gen_node_extra(ag, variable_declaration->expr, init_scope, |
| 5897 | LValNone, init_result_loc); | 5897 | LValNone, init_result_loc); |
| 5898 | irb->exec->name = old_exec_name; | 5898 | ag->exec->name = old_exec_name; |
| 5899 | | 5899 | |
| 5900 | if (init_value == irb->codegen->invalid_inst_src) | 5900 | if (init_value == ag->codegen->invalid_inst_src) |
| 5901 | return irb->codegen->invalid_inst_src; | 5901 | return ag->codegen->invalid_inst_src; |
| 5902 | | 5902 | |
| 5903 | if (result_loc_cast != nullptr) { | 5903 | if (result_loc_cast != nullptr) { |
| 5904 | IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node, | 5904 | IrInstSrc *implicit_cast = ir_build_implicit_cast(ag, scope, init_value->base.source_node, |
| 5905 | init_value, result_loc_cast); | 5905 | init_value, result_loc_cast); |
| 5906 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); | 5906 | ir_build_end_expr(ag, scope, node, implicit_cast, &result_loc_var->base); |
| 5907 | } | 5907 | } |
| 5908 | | 5908 | |
| 5909 | return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca); | 5909 | return ir_build_var_decl_src(ag, scope, node, var, align_value, alloca); |
| 5910 | } | 5910 | } |
| 5911 | | 5911 | |
| 5912 | static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 5912 | static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 5913 | ResultLoc *result_loc) | 5913 | ResultLoc *result_loc) |
| 5914 | { | 5914 | { |
| 5915 | assert(node->type == NodeTypeWhileExpr); | 5915 | assert(node->type == NodeTypeWhileExpr); |
| ... | @@ -5917,73 +5917,73 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -5917,73 +5917,73 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 5917 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; | 5917 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; |
| 5918 | AstNode *else_node = node->data.while_expr.else_node; | 5918 | AstNode *else_node = node->data.while_expr.else_node; |
| 5919 | | 5919 | |
| 5920 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond"); | 5920 | IrBasicBlockSrc *cond_block = ir_create_basic_block(ag, scope, "WhileCond"); |
| 5921 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody"); | 5921 | IrBasicBlockSrc *body_block = ir_create_basic_block(ag, scope, "WhileBody"); |
| 5922 | IrBasicBlockSrc *continue_block = continue_expr_node ? | 5922 | IrBasicBlockSrc *continue_block = continue_expr_node ? |
| 5923 | ir_create_basic_block(irb, scope, "WhileContinue") : cond_block; | 5923 | ir_create_basic_block(ag, scope, "WhileContinue") : cond_block; |
| 5924 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd"); | 5924 | IrBasicBlockSrc *end_block = ir_create_basic_block(ag, scope, "WhileEnd"); |
| 5925 | IrBasicBlockSrc *else_block = else_node ? | 5925 | IrBasicBlockSrc *else_block = else_node ? |
| 5926 | ir_create_basic_block(irb, scope, "WhileElse") : end_block; | 5926 | ir_create_basic_block(ag, scope, "WhileElse") : end_block; |
| 5927 | | 5927 | |
| 5928 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, | 5928 | IrInstSrc *is_comptime = ir_build_const_bool(ag, scope, node, |
| 5929 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); | 5929 | ir_should_inline(ag->exec, scope) || node->data.while_expr.is_inline); |
| 5930 | ir_build_br(irb, scope, node, cond_block, is_comptime); | 5930 | ir_build_br(ag, scope, node, cond_block, is_comptime); |
| 5931 | | 5931 | |
| 5932 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 5932 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 5933 | Buf *var_symbol = node->data.while_expr.var_symbol; | 5933 | Buf *var_symbol = node->data.while_expr.var_symbol; |
| 5934 | Buf *err_symbol = node->data.while_expr.err_symbol; | 5934 | Buf *err_symbol = node->data.while_expr.err_symbol; |
| 5935 | if (err_symbol != nullptr) { | 5935 | if (err_symbol != nullptr) { |
| 5936 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 5936 | ir_set_cursor_at_end_and_append_block(ag, cond_block); |
| 5937 | | 5937 | |
| 5938 | Scope *payload_scope; | 5938 | Scope *payload_scope; |
| 5939 | AstNode *symbol_node = node; // TODO make more accurate | 5939 | AstNode *symbol_node = node; // TODO make more accurate |
| 5940 | ZigVar *payload_var; | 5940 | ZigVar *payload_var; |
| 5941 | if (var_symbol) { | 5941 | if (var_symbol) { |
| 5942 | // TODO make it an error to write to payload variable | 5942 | // TODO make it an error to write to payload variable |
| 5943 | payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, | 5943 | payload_var = ir_create_var(ag, symbol_node, subexpr_scope, var_symbol, |
| 5944 | true, false, false, is_comptime); | 5944 | true, false, false, is_comptime); |
| 5945 | payload_scope = payload_var->child_scope; | 5945 | payload_scope = payload_var->child_scope; |
| 5946 | } else { | 5946 | } else { |
| 5947 | payload_scope = subexpr_scope; | 5947 | payload_scope = subexpr_scope; |
| 5948 | } | 5948 | } |
| 5949 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, payload_scope); | 5949 | ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, payload_scope); |
| 5950 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, | 5950 | IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, |
| 5951 | LValPtr, nullptr); | 5951 | LValPtr, nullptr); |
| 5952 | if (err_val_ptr == irb->codegen->invalid_inst_src) | 5952 | if (err_val_ptr == ag->codegen->invalid_inst_src) |
| 5953 | return err_val_ptr; | 5953 | return err_val_ptr; |
| 5954 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, | 5954 | IrInstSrc *is_err = ir_build_test_err_src(ag, scope, node->data.while_expr.condition, err_val_ptr, |
| 5955 | true, false); | 5955 | true, false); |
| 5956 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; | 5956 | IrBasicBlockSrc *after_cond_block = ag->current_basic_block; |
| 5957 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); | 5957 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node)); |
| 5958 | IrInstSrc *cond_br_inst; | 5958 | IrInstSrc *cond_br_inst; |
| 5959 | if (!instr_is_unreachable(is_err)) { | 5959 | if (!instr_is_unreachable(is_err)) { |
| 5960 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err, | 5960 | cond_br_inst = ir_build_cond_br(ag, scope, node->data.while_expr.condition, is_err, |
| 5961 | else_block, body_block, is_comptime); | 5961 | else_block, body_block, is_comptime); |
| 5962 | cond_br_inst->is_gen = true; | 5962 | cond_br_inst->is_gen = true; |
| 5963 | } else { | 5963 | } else { |
| 5964 | // for the purposes of the source instruction to ir_build_result_peers | 5964 | // for the purposes of the source instruction to ir_build_result_peers |
| 5965 | cond_br_inst = irb->current_basic_block->instruction_list.last(); | 5965 | cond_br_inst = ag->current_basic_block->instruction_list.last(); |
| 5966 | } | 5966 | } |
| 5967 | | 5967 | |
| 5968 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, | 5968 | ResultLocPeerParent *peer_parent = ir_build_result_peers(ag, cond_br_inst, end_block, result_loc, |
| 5969 | is_comptime); | 5969 | is_comptime); |
| 5970 | | 5970 | |
| 5971 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 5971 | ir_set_cursor_at_end_and_append_block(ag, body_block); |
| 5972 | if (var_symbol) { | 5972 | if (var_symbol) { |
| 5973 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, &spill_scope->base, symbol_node, | 5973 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(ag, &spill_scope->base, symbol_node, |
| 5974 | err_val_ptr, false, false); | 5974 | err_val_ptr, false, false); |
| 5975 | IrInstSrc *var_value = node->data.while_expr.var_is_ptr ? | 5975 | IrInstSrc *var_value = node->data.while_expr.var_is_ptr ? |
| 5976 | payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, symbol_node, payload_ptr); | 5976 | payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, symbol_node, payload_ptr); |
| 5977 | build_decl_var_and_init(irb, payload_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime); | 5977 | build_decl_var_and_init(ag, payload_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime); |
| 5978 | } | 5978 | } |
| 5979 | | 5979 | |
| 5980 | ZigList<IrInstSrc *> incoming_values = {0}; | 5980 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 5981 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; | 5981 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 5982 | | 5982 | |
| 5983 | if (is_duplicate_label(irb->codegen, payload_scope, node, node->data.while_expr.name)) | 5983 | if (is_duplicate_label(ag->codegen, payload_scope, node, node->data.while_expr.name)) |
| 5984 | return irb->codegen->invalid_inst_src; | 5984 | return ag->codegen->invalid_inst_src; |
| 5985 | | 5985 | |
| 5986 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope); | 5986 | ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, payload_scope); |
| 5987 | loop_scope->break_block = end_block; | 5987 | loop_scope->break_block = end_block; |
| 5988 | loop_scope->continue_block = continue_block; | 5988 | loop_scope->continue_block = continue_block; |
| 5989 | loop_scope->is_comptime = is_comptime; | 5989 | loop_scope->is_comptime = is_comptime; |
| ... | @@ -5996,54 +5996,54 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -5996,54 +5996,54 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 5996 | // Note the body block of the loop is not the place that lval and result_loc are used - | 5996 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 5997 | // it's actually in break statements, handled similarly to return statements. | 5997 | // it's actually in break statements, handled similarly to return statements. |
| 5998 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. | 5998 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 5999 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); | 5999 | IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); |
| 6000 | if (body_result == irb->codegen->invalid_inst_src) | 6000 | if (body_result == ag->codegen->invalid_inst_src) |
| 6001 | return body_result; | 6001 | return body_result; |
| 6002 | | 6002 | |
| 6003 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { | 6003 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { |
| 6004 | add_node_error(irb->codegen, node, buf_sprintf("unused while label")); | 6004 | add_node_error(ag->codegen, node, buf_sprintf("unused while label")); |
| 6005 | } | 6005 | } |
| 6006 | | 6006 | |
| 6007 | if (!instr_is_unreachable(body_result)) { | 6007 | if (!instr_is_unreachable(body_result)) { |
| 6008 | ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, node->data.while_expr.body, body_result)); | 6008 | ir_mark_gen(ir_build_check_statement_is_void(ag, payload_scope, node->data.while_expr.body, body_result)); |
| 6009 | ir_mark_gen(ir_build_br(irb, payload_scope, node, continue_block, is_comptime)); | 6009 | ir_mark_gen(ir_build_br(ag, payload_scope, node, continue_block, is_comptime)); |
| 6010 | } | 6010 | } |
| 6011 | | 6011 | |
| 6012 | if (continue_expr_node) { | 6012 | if (continue_expr_node) { |
| 6013 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 6013 | ir_set_cursor_at_end_and_append_block(ag, continue_block); |
| 6014 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); | 6014 | IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, payload_scope); |
| 6015 | if (expr_result == irb->codegen->invalid_inst_src) | 6015 | if (expr_result == ag->codegen->invalid_inst_src) |
| 6016 | return expr_result; | 6016 | return expr_result; |
| 6017 | if (!instr_is_unreachable(expr_result)) { | 6017 | if (!instr_is_unreachable(expr_result)) { |
| 6018 | ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result)); | 6018 | ir_mark_gen(ir_build_check_statement_is_void(ag, payload_scope, continue_expr_node, expr_result)); |
| 6019 | ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime)); | 6019 | ir_mark_gen(ir_build_br(ag, payload_scope, node, cond_block, is_comptime)); |
| 6020 | } | 6020 | } |
| 6021 | } | 6021 | } |
| 6022 | | 6022 | |
| 6023 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6023 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6024 | assert(else_node != nullptr); | 6024 | assert(else_node != nullptr); |
| 6025 | | 6025 | |
| 6026 | // TODO make it an error to write to error variable | 6026 | // TODO make it an error to write to error variable |
| 6027 | AstNode *err_symbol_node = else_node; // TODO make more accurate | 6027 | AstNode *err_symbol_node = else_node; // TODO make more accurate |
| 6028 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, | 6028 | ZigVar *err_var = ir_create_var(ag, err_symbol_node, scope, err_symbol, |
| 6029 | true, false, false, is_comptime); | 6029 | true, false, false, is_comptime); |
| 6030 | Scope *err_scope = err_var->child_scope; | 6030 | Scope *err_scope = err_var->child_scope; |
| 6031 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr); | 6031 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(ag, err_scope, err_symbol_node, err_val_ptr); |
| 6032 | IrInstSrc *err_value = ir_build_load_ptr(irb, err_scope, err_symbol_node, err_ptr); | 6032 | IrInstSrc *err_value = ir_build_load_ptr(ag, err_scope, err_symbol_node, err_ptr); |
| 6033 | build_decl_var_and_init(irb, err_scope, err_symbol_node, err_var, err_value, buf_ptr(err_symbol), is_comptime); | 6033 | build_decl_var_and_init(ag, err_scope, err_symbol_node, err_var, err_value, buf_ptr(err_symbol), is_comptime); |
| 6034 | | 6034 | |
| 6035 | if (peer_parent->peers.length != 0) { | 6035 | if (peer_parent->peers.length != 0) { |
| 6036 | peer_parent->peers.last()->next_bb = else_block; | 6036 | peer_parent->peers.last()->next_bb = else_block; |
| 6037 | } | 6037 | } |
| 6038 | ResultLocPeer *peer_result = create_peer_result(peer_parent); | 6038 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 6039 | peer_parent->peers.append(peer_result); | 6039 | peer_parent->peers.append(peer_result); |
| 6040 | IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base); | 6040 | IrInstSrc *else_result = ir_gen_node_extra(ag, else_node, err_scope, lval, &peer_result->base); |
| 6041 | if (else_result == irb->codegen->invalid_inst_src) | 6041 | if (else_result == ag->codegen->invalid_inst_src) |
| 6042 | return else_result; | 6042 | return else_result; |
| 6043 | if (!instr_is_unreachable(else_result)) | 6043 | if (!instr_is_unreachable(else_result)) |
| 6044 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 6044 | ir_mark_gen(ir_build_br(ag, scope, node, end_block, is_comptime)); |
| 6045 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6045 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6046 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 6046 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 6047 | if (else_result) { | 6047 | if (else_result) { |
| 6048 | incoming_blocks.append(after_else_block); | 6048 | incoming_blocks.append(after_else_block); |
| 6049 | incoming_values.append(else_result); | 6049 | incoming_values.append(else_result); |
| ... | @@ -6055,53 +6055,53 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6055,53 +6055,53 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6055 | peer_parent->peers.last()->next_bb = end_block; | 6055 | peer_parent->peers.last()->next_bb = end_block; |
| 6056 | } | 6056 | } |
| 6057 | | 6057 | |
| 6058 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, | 6058 | IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6059 | incoming_blocks.items, incoming_values.items, peer_parent); | 6059 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6060 | return ir_expr_wrap(irb, scope, phi, result_loc); | 6060 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6061 | } else if (var_symbol != nullptr) { | 6061 | } else if (var_symbol != nullptr) { |
| 6062 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 6062 | ir_set_cursor_at_end_and_append_block(ag, cond_block); |
| 6063 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 6063 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 6064 | // TODO make it an error to write to payload variable | 6064 | // TODO make it an error to write to payload variable |
| 6065 | AstNode *symbol_node = node; // TODO make more accurate | 6065 | AstNode *symbol_node = node; // TODO make more accurate |
| 6066 | | 6066 | |
| 6067 | ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, | 6067 | ZigVar *payload_var = ir_create_var(ag, symbol_node, subexpr_scope, var_symbol, |
| 6068 | true, false, false, is_comptime); | 6068 | true, false, false, is_comptime); |
| 6069 | Scope *child_scope = payload_var->child_scope; | 6069 | Scope *child_scope = payload_var->child_scope; |
| 6070 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, child_scope); | 6070 | ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, child_scope); |
| 6071 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, | 6071 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, |
| 6072 | LValPtr, nullptr); | 6072 | LValPtr, nullptr); |
| 6073 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) | 6073 | if (maybe_val_ptr == ag->codegen->invalid_inst_src) |
| 6074 | return maybe_val_ptr; | 6074 | return maybe_val_ptr; |
| 6075 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); | 6075 | IrInstSrc *maybe_val = ir_build_load_ptr(ag, scope, node->data.while_expr.condition, maybe_val_ptr); |
| 6076 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val); | 6076 | IrInstSrc *is_non_null = ir_build_test_non_null_src(ag, scope, node->data.while_expr.condition, maybe_val); |
| 6077 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; | 6077 | IrBasicBlockSrc *after_cond_block = ag->current_basic_block; |
| 6078 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); | 6078 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node)); |
| 6079 | IrInstSrc *cond_br_inst; | 6079 | IrInstSrc *cond_br_inst; |
| 6080 | if (!instr_is_unreachable(is_non_null)) { | 6080 | if (!instr_is_unreachable(is_non_null)) { |
| 6081 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null, | 6081 | cond_br_inst = ir_build_cond_br(ag, scope, node->data.while_expr.condition, is_non_null, |
| 6082 | body_block, else_block, is_comptime); | 6082 | body_block, else_block, is_comptime); |
| 6083 | cond_br_inst->is_gen = true; | 6083 | cond_br_inst->is_gen = true; |
| 6084 | } else { | 6084 | } else { |
| 6085 | // for the purposes of the source instruction to ir_build_result_peers | 6085 | // for the purposes of the source instruction to ir_build_result_peers |
| 6086 | cond_br_inst = irb->current_basic_block->instruction_list.last(); | 6086 | cond_br_inst = ag->current_basic_block->instruction_list.last(); |
| 6087 | } | 6087 | } |
| 6088 | | 6088 | |
| 6089 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, | 6089 | ResultLocPeerParent *peer_parent = ir_build_result_peers(ag, cond_br_inst, end_block, result_loc, |
| 6090 | is_comptime); | 6090 | is_comptime); |
| 6091 | | 6091 | |
| 6092 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6092 | ir_set_cursor_at_end_and_append_block(ag, body_block); |
| 6093 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, &spill_scope->base, symbol_node, maybe_val_ptr, false); | 6093 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(ag, &spill_scope->base, symbol_node, maybe_val_ptr, false); |
| 6094 | IrInstSrc *var_value = node->data.while_expr.var_is_ptr ? | 6094 | IrInstSrc *var_value = node->data.while_expr.var_is_ptr ? |
| 6095 | payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, symbol_node, payload_ptr); | 6095 | payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, symbol_node, payload_ptr); |
| 6096 | build_decl_var_and_init(irb, child_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime); | 6096 | build_decl_var_and_init(ag, child_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime); |
| 6097 | | 6097 | |
| 6098 | ZigList<IrInstSrc *> incoming_values = {0}; | 6098 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 6099 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; | 6099 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 6100 | | 6100 | |
| 6101 | if (is_duplicate_label(irb->codegen, child_scope, node, node->data.while_expr.name)) | 6101 | if (is_duplicate_label(ag->codegen, child_scope, node, node->data.while_expr.name)) |
| 6102 | return irb->codegen->invalid_inst_src; | 6102 | return ag->codegen->invalid_inst_src; |
| 6103 | | 6103 | |
| 6104 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); | 6104 | ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, child_scope); |
| 6105 | loop_scope->break_block = end_block; | 6105 | loop_scope->break_block = end_block; |
| 6106 | loop_scope->continue_block = continue_block; | 6106 | loop_scope->continue_block = continue_block; |
| 6107 | loop_scope->is_comptime = is_comptime; | 6107 | loop_scope->is_comptime = is_comptime; |
| ... | @@ -6114,47 +6114,47 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6114,47 +6114,47 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6114 | // Note the body block of the loop is not the place that lval and result_loc are used - | 6114 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 6115 | // it's actually in break statements, handled similarly to return statements. | 6115 | // it's actually in break statements, handled similarly to return statements. |
| 6116 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. | 6116 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 6117 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); | 6117 | IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); |
| 6118 | if (body_result == irb->codegen->invalid_inst_src) | 6118 | if (body_result == ag->codegen->invalid_inst_src) |
| 6119 | return body_result; | 6119 | return body_result; |
| 6120 | | 6120 | |
| 6121 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { | 6121 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { |
| 6122 | add_node_error(irb->codegen, node, buf_sprintf("unused while label")); | 6122 | add_node_error(ag->codegen, node, buf_sprintf("unused while label")); |
| 6123 | } | 6123 | } |
| 6124 | | 6124 | |
| 6125 | if (!instr_is_unreachable(body_result)) { | 6125 | if (!instr_is_unreachable(body_result)) { |
| 6126 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.while_expr.body, body_result)); | 6126 | ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, node->data.while_expr.body, body_result)); |
| 6127 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); | 6127 | ir_mark_gen(ir_build_br(ag, child_scope, node, continue_block, is_comptime)); |
| 6128 | } | 6128 | } |
| 6129 | | 6129 | |
| 6130 | if (continue_expr_node) { | 6130 | if (continue_expr_node) { |
| 6131 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 6131 | ir_set_cursor_at_end_and_append_block(ag, continue_block); |
| 6132 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); | 6132 | IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, child_scope); |
| 6133 | if (expr_result == irb->codegen->invalid_inst_src) | 6133 | if (expr_result == ag->codegen->invalid_inst_src) |
| 6134 | return expr_result; | 6134 | return expr_result; |
| 6135 | if (!instr_is_unreachable(expr_result)) { | 6135 | if (!instr_is_unreachable(expr_result)) { |
| 6136 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result)); | 6136 | ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, continue_expr_node, expr_result)); |
| 6137 | ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime)); | 6137 | ir_mark_gen(ir_build_br(ag, child_scope, node, cond_block, is_comptime)); |
| 6138 | } | 6138 | } |
| 6139 | } | 6139 | } |
| 6140 | | 6140 | |
| 6141 | IrInstSrc *else_result = nullptr; | 6141 | IrInstSrc *else_result = nullptr; |
| 6142 | if (else_node) { | 6142 | if (else_node) { |
| 6143 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6143 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6144 | | 6144 | |
| 6145 | if (peer_parent->peers.length != 0) { | 6145 | if (peer_parent->peers.length != 0) { |
| 6146 | peer_parent->peers.last()->next_bb = else_block; | 6146 | peer_parent->peers.last()->next_bb = else_block; |
| 6147 | } | 6147 | } |
| 6148 | ResultLocPeer *peer_result = create_peer_result(peer_parent); | 6148 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 6149 | peer_parent->peers.append(peer_result); | 6149 | peer_parent->peers.append(peer_result); |
| 6150 | else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base); | 6150 | else_result = ir_gen_node_extra(ag, else_node, scope, lval, &peer_result->base); |
| 6151 | if (else_result == irb->codegen->invalid_inst_src) | 6151 | if (else_result == ag->codegen->invalid_inst_src) |
| 6152 | return else_result; | 6152 | return else_result; |
| 6153 | if (!instr_is_unreachable(else_result)) | 6153 | if (!instr_is_unreachable(else_result)) |
| 6154 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 6154 | ir_mark_gen(ir_build_br(ag, scope, node, end_block, is_comptime)); |
| 6155 | } | 6155 | } |
| 6156 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6156 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6157 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 6157 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 6158 | if (else_result) { | 6158 | if (else_result) { |
| 6159 | incoming_blocks.append(after_else_block); | 6159 | incoming_blocks.append(after_else_block); |
| 6160 | incoming_values.append(else_result); | 6160 | incoming_values.append(else_result); |
| ... | @@ -6166,39 +6166,39 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6166,39 +6166,39 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6166 | peer_parent->peers.last()->next_bb = end_block; | 6166 | peer_parent->peers.last()->next_bb = end_block; |
| 6167 | } | 6167 | } |
| 6168 | | 6168 | |
| 6169 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, | 6169 | IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6170 | incoming_blocks.items, incoming_values.items, peer_parent); | 6170 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6171 | return ir_expr_wrap(irb, scope, phi, result_loc); | 6171 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6172 | } else { | 6172 | } else { |
| 6173 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 6173 | ir_set_cursor_at_end_and_append_block(ag, cond_block); |
| 6174 | IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); | 6174 | IrInstSrc *cond_val = ir_gen_node(ag, node->data.while_expr.condition, scope); |
| 6175 | if (cond_val == irb->codegen->invalid_inst_src) | 6175 | if (cond_val == ag->codegen->invalid_inst_src) |
| 6176 | return cond_val; | 6176 | return cond_val; |
| 6177 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; | 6177 | IrBasicBlockSrc *after_cond_block = ag->current_basic_block; |
| 6178 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); | 6178 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node)); |
| 6179 | IrInstSrc *cond_br_inst; | 6179 | IrInstSrc *cond_br_inst; |
| 6180 | if (!instr_is_unreachable(cond_val)) { | 6180 | if (!instr_is_unreachable(cond_val)) { |
| 6181 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, | 6181 | cond_br_inst = ir_build_cond_br(ag, scope, node->data.while_expr.condition, cond_val, |
| 6182 | body_block, else_block, is_comptime); | 6182 | body_block, else_block, is_comptime); |
| 6183 | cond_br_inst->is_gen = true; | 6183 | cond_br_inst->is_gen = true; |
| 6184 | } else { | 6184 | } else { |
| 6185 | // for the purposes of the source instruction to ir_build_result_peers | 6185 | // for the purposes of the source instruction to ir_build_result_peers |
| 6186 | cond_br_inst = irb->current_basic_block->instruction_list.last(); | 6186 | cond_br_inst = ag->current_basic_block->instruction_list.last(); |
| 6187 | } | 6187 | } |
| 6188 | | 6188 | |
| 6189 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, | 6189 | ResultLocPeerParent *peer_parent = ir_build_result_peers(ag, cond_br_inst, end_block, result_loc, |
| 6190 | is_comptime); | 6190 | is_comptime); |
| 6191 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6191 | ir_set_cursor_at_end_and_append_block(ag, body_block); |
| 6192 | | 6192 | |
| 6193 | ZigList<IrInstSrc *> incoming_values = {0}; | 6193 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 6194 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; | 6194 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 6195 | | 6195 | |
| 6196 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 6196 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 6197 | | 6197 | |
| 6198 | if (is_duplicate_label(irb->codegen, subexpr_scope, node, node->data.while_expr.name)) | 6198 | if (is_duplicate_label(ag->codegen, subexpr_scope, node, node->data.while_expr.name)) |
| 6199 | return irb->codegen->invalid_inst_src; | 6199 | return ag->codegen->invalid_inst_src; |
| 6200 | | 6200 | |
| 6201 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, subexpr_scope); | 6201 | ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, subexpr_scope); |
| 6202 | loop_scope->break_block = end_block; | 6202 | loop_scope->break_block = end_block; |
| 6203 | loop_scope->continue_block = continue_block; | 6203 | loop_scope->continue_block = continue_block; |
| 6204 | loop_scope->is_comptime = is_comptime; | 6204 | loop_scope->is_comptime = is_comptime; |
| ... | @@ -6210,33 +6210,33 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6210,33 +6210,33 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6210 | // Note the body block of the loop is not the place that lval and result_loc are used - | 6210 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 6211 | // it's actually in break statements, handled similarly to return statements. | 6211 | // it's actually in break statements, handled similarly to return statements. |
| 6212 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. | 6212 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 6213 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); | 6213 | IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); |
| 6214 | if (body_result == irb->codegen->invalid_inst_src) | 6214 | if (body_result == ag->codegen->invalid_inst_src) |
| 6215 | return body_result; | 6215 | return body_result; |
| 6216 | | 6216 | |
| 6217 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { | 6217 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { |
| 6218 | add_node_error(irb->codegen, node, buf_sprintf("unused while label")); | 6218 | add_node_error(ag->codegen, node, buf_sprintf("unused while label")); |
| 6219 | } | 6219 | } |
| 6220 | | 6220 | |
| 6221 | if (!instr_is_unreachable(body_result)) { | 6221 | if (!instr_is_unreachable(body_result)) { |
| 6222 | ir_mark_gen(ir_build_check_statement_is_void(irb, scope, node->data.while_expr.body, body_result)); | 6222 | ir_mark_gen(ir_build_check_statement_is_void(ag, scope, node->data.while_expr.body, body_result)); |
| 6223 | ir_mark_gen(ir_build_br(irb, scope, node, continue_block, is_comptime)); | 6223 | ir_mark_gen(ir_build_br(ag, scope, node, continue_block, is_comptime)); |
| 6224 | } | 6224 | } |
| 6225 | | 6225 | |
| 6226 | if (continue_expr_node) { | 6226 | if (continue_expr_node) { |
| 6227 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 6227 | ir_set_cursor_at_end_and_append_block(ag, continue_block); |
| 6228 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope); | 6228 | IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, subexpr_scope); |
| 6229 | if (expr_result == irb->codegen->invalid_inst_src) | 6229 | if (expr_result == ag->codegen->invalid_inst_src) |
| 6230 | return expr_result; | 6230 | return expr_result; |
| 6231 | if (!instr_is_unreachable(expr_result)) { | 6231 | if (!instr_is_unreachable(expr_result)) { |
| 6232 | ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result)); | 6232 | ir_mark_gen(ir_build_check_statement_is_void(ag, scope, continue_expr_node, expr_result)); |
| 6233 | ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime)); | 6233 | ir_mark_gen(ir_build_br(ag, scope, node, cond_block, is_comptime)); |
| 6234 | } | 6234 | } |
| 6235 | } | 6235 | } |
| 6236 | | 6236 | |
| 6237 | IrInstSrc *else_result = nullptr; | 6237 | IrInstSrc *else_result = nullptr; |
| 6238 | if (else_node) { | 6238 | if (else_node) { |
| 6239 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6239 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6240 | | 6240 | |
| 6241 | if (peer_parent->peers.length != 0) { | 6241 | if (peer_parent->peers.length != 0) { |
| 6242 | peer_parent->peers.last()->next_bb = else_block; | 6242 | peer_parent->peers.last()->next_bb = else_block; |
| ... | @@ -6244,14 +6244,14 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6244,14 +6244,14 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6244 | ResultLocPeer *peer_result = create_peer_result(peer_parent); | 6244 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 6245 | peer_parent->peers.append(peer_result); | 6245 | peer_parent->peers.append(peer_result); |
| 6246 | | 6246 | |
| 6247 | else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base); | 6247 | else_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_result->base); |
| 6248 | if (else_result == irb->codegen->invalid_inst_src) | 6248 | if (else_result == ag->codegen->invalid_inst_src) |
| 6249 | return else_result; | 6249 | return else_result; |
| 6250 | if (!instr_is_unreachable(else_result)) | 6250 | if (!instr_is_unreachable(else_result)) |
| 6251 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 6251 | ir_mark_gen(ir_build_br(ag, scope, node, end_block, is_comptime)); |
| 6252 | } | 6252 | } |
| 6253 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6253 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6254 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 6254 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 6255 | if (else_result) { | 6255 | if (else_result) { |
| 6256 | incoming_blocks.append(after_else_block); | 6256 | incoming_blocks.append(after_else_block); |
| 6257 | incoming_values.append(else_result); | 6257 | incoming_values.append(else_result); |
| ... | @@ -6263,13 +6263,13 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6263,13 +6263,13 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6263 | peer_parent->peers.last()->next_bb = end_block; | 6263 | peer_parent->peers.last()->next_bb = end_block; |
| 6264 | } | 6264 | } |
| 6265 | | 6265 | |
| 6266 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, | 6266 | IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6267 | incoming_blocks.items, incoming_values.items, peer_parent); | 6267 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6268 | return ir_expr_wrap(irb, scope, phi, result_loc); | 6268 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6269 | } | 6269 | } |
| 6270 | } | 6270 | } |
| 6271 | | 6271 | |
| 6272 | static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, | 6272 | static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, |
| 6273 | ResultLoc *result_loc) | 6273 | ResultLoc *result_loc) |
| 6274 | { | 6274 | { |
| 6275 | assert(node->type == NodeTypeForExpr); | 6275 | assert(node->type == NodeTypeForExpr); |
| ... | @@ -6281,19 +6281,19 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -6281,19 +6281,19 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 6281 | AstNode *else_node = node->data.for_expr.else_node; | 6281 | AstNode *else_node = node->data.for_expr.else_node; |
| 6282 | | 6282 | |
| 6283 | if (!elem_node) { | 6283 | if (!elem_node) { |
| 6284 | add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter")); | 6284 | add_node_error(ag->codegen, node, buf_sprintf("for loop expression missing element parameter")); |
| 6285 | return irb->codegen->invalid_inst_src; | 6285 | return ag->codegen->invalid_inst_src; |
| 6286 | } | 6286 | } |
| 6287 | assert(elem_node->type == NodeTypeIdentifier); | 6287 | assert(elem_node->type == NodeTypeIdentifier); |
| 6288 | | 6288 | |
| 6289 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope); | 6289 | ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, parent_scope); |
| 6290 | | 6290 | |
| 6291 | IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr); | 6291 | IrInstSrc *array_val_ptr = ir_gen_node_extra(ag, array_node, &spill_scope->base, LValPtr, nullptr); |
| 6292 | if (array_val_ptr == irb->codegen->invalid_inst_src) | 6292 | if (array_val_ptr == ag->codegen->invalid_inst_src) |
| 6293 | return array_val_ptr; | 6293 | return array_val_ptr; |
| 6294 | | 6294 | |
| 6295 | IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node, | 6295 | IrInstSrc *is_comptime = ir_build_const_bool(ag, parent_scope, node, |
| 6296 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); | 6296 | ir_should_inline(ag->exec, parent_scope) || node->data.for_expr.is_inline); |
| 6297 | | 6297 | |
| 6298 | AstNode *index_var_source_node; | 6298 | AstNode *index_var_source_node; |
| 6299 | ZigVar *index_var; | 6299 | ZigVar *index_var; |
| ... | @@ -6301,61 +6301,61 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -6301,61 +6301,61 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 6301 | if (index_node) { | 6301 | if (index_node) { |
| 6302 | index_var_source_node = index_node; | 6302 | index_var_source_node = index_node; |
| 6303 | Buf *index_var_name_buf = node_identifier_buf(index_node); | 6303 | Buf *index_var_name_buf = node_identifier_buf(index_node); |
| 6304 | index_var = ir_create_var(irb, index_node, parent_scope, index_var_name_buf, true, false, false, is_comptime); | 6304 | index_var = ir_create_var(ag, index_node, parent_scope, index_var_name_buf, true, false, false, is_comptime); |
| 6305 | index_var_name = buf_ptr(index_var_name_buf); | 6305 | index_var_name = buf_ptr(index_var_name_buf); |
| 6306 | } else { | 6306 | } else { |
| 6307 | index_var_source_node = node; | 6307 | index_var_source_node = node; |
| 6308 | index_var = ir_create_var(irb, node, parent_scope, nullptr, true, false, true, is_comptime); | 6308 | index_var = ir_create_var(ag, node, parent_scope, nullptr, true, false, true, is_comptime); |
| 6309 | index_var_name = "i"; | 6309 | index_var_name = "i"; |
| 6310 | } | 6310 | } |
| 6311 | | 6311 | |
| 6312 | IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0); | 6312 | IrInstSrc *zero = ir_build_const_usize(ag, parent_scope, node, 0); |
| 6313 | build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime); | 6313 | build_decl_var_and_init(ag, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime); |
| 6314 | parent_scope = index_var->child_scope; | 6314 | parent_scope = index_var->child_scope; |
| 6315 | | 6315 | |
| 6316 | IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1); | 6316 | IrInstSrc *one = ir_build_const_usize(ag, parent_scope, node, 1); |
| 6317 | IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var); | 6317 | IrInstSrc *index_ptr = ir_build_var_ptr(ag, parent_scope, node, index_var); |
| 6318 | | 6318 | |
| 6319 | | 6319 | |
| 6320 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond"); | 6320 | IrBasicBlockSrc *cond_block = ir_create_basic_block(ag, parent_scope, "ForCond"); |
| 6321 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody"); | 6321 | IrBasicBlockSrc *body_block = ir_create_basic_block(ag, parent_scope, "ForBody"); |
| 6322 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd"); | 6322 | IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "ForEnd"); |
| 6323 | IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block; | 6323 | IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(ag, parent_scope, "ForElse") : end_block; |
| 6324 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); | 6324 | IrBasicBlockSrc *continue_block = ir_create_basic_block(ag, parent_scope, "ForContinue"); |
| 6325 | | 6325 | |
| 6326 | Buf *len_field_name = buf_create_from_str("len"); | 6326 | Buf *len_field_name = buf_create_from_str("len"); |
| 6327 | IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false); | 6327 | IrInstSrc *len_ref = ir_build_field_ptr(ag, parent_scope, node, array_val_ptr, len_field_name, false); |
| 6328 | IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref); | 6328 | IrInstSrc *len_val = ir_build_load_ptr(ag, &spill_scope->base, node, len_ref); |
| 6329 | ir_build_br(irb, parent_scope, node, cond_block, is_comptime); | 6329 | ir_build_br(ag, parent_scope, node, cond_block, is_comptime); |
| 6330 | | 6330 | |
| 6331 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 6331 | ir_set_cursor_at_end_and_append_block(ag, cond_block); |
| 6332 | IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr); | 6332 | IrInstSrc *index_val = ir_build_load_ptr(ag, &spill_scope->base, node, index_ptr); |
| 6333 | IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); | 6333 | IrInstSrc *cond = ir_build_bin_op(ag, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 6334 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; | 6334 | IrBasicBlockSrc *after_cond_block = ag->current_basic_block; |
| 6335 | IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); | 6335 | IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, parent_scope, node)); |
| 6336 | IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, | 6336 | IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(ag, parent_scope, node, cond, |
| 6337 | body_block, else_block, is_comptime)); | 6337 | body_block, else_block, is_comptime)); |
| 6338 | | 6338 | |
| 6339 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime); | 6339 | ResultLocPeerParent *peer_parent = ir_build_result_peers(ag, cond_br_inst, end_block, result_loc, is_comptime); |
| 6340 | | 6340 | |
| 6341 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6341 | ir_set_cursor_at_end_and_append_block(ag, body_block); |
| 6342 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, &spill_scope->base, node, array_val_ptr, index_val, | 6342 | IrInstSrc *elem_ptr = ir_build_elem_ptr(ag, &spill_scope->base, node, array_val_ptr, index_val, |
| 6343 | false, PtrLenSingle, nullptr); | 6343 | false, PtrLenSingle, nullptr); |
| 6344 | // TODO make it an error to write to element variable or i variable. | 6344 | // TODO make it an error to write to element variable or i variable. |
| 6345 | Buf *elem_var_name = node_identifier_buf(elem_node); | 6345 | Buf *elem_var_name = node_identifier_buf(elem_node); |
| 6346 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); | 6346 | ZigVar *elem_var = ir_create_var(ag, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| 6347 | Scope *child_scope = elem_var->child_scope; | 6347 | Scope *child_scope = elem_var->child_scope; |
| 6348 | | 6348 | |
| 6349 | IrInstSrc *elem_value = node->data.for_expr.elem_is_ptr ? | 6349 | IrInstSrc *elem_value = node->data.for_expr.elem_is_ptr ? |
| 6350 | elem_ptr : ir_build_load_ptr(irb, &spill_scope->base, elem_node, elem_ptr); | 6350 | elem_ptr : ir_build_load_ptr(ag, &spill_scope->base, elem_node, elem_ptr); |
| 6351 | build_decl_var_and_init(irb, parent_scope, elem_node, elem_var, elem_value, buf_ptr(elem_var_name), is_comptime); | 6351 | build_decl_var_and_init(ag, parent_scope, elem_node, elem_var, elem_value, buf_ptr(elem_var_name), is_comptime); |
| 6352 | | 6352 | |
| 6353 | if (is_duplicate_label(irb->codegen, child_scope, node, node->data.for_expr.name)) | 6353 | if (is_duplicate_label(ag->codegen, child_scope, node, node->data.for_expr.name)) |
| 6354 | return irb->codegen->invalid_inst_src; | 6354 | return ag->codegen->invalid_inst_src; |
| 6355 | | 6355 | |
| 6356 | ZigList<IrInstSrc *> incoming_values = {0}; | 6356 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 6357 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; | 6357 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 6358 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); | 6358 | ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, child_scope); |
| 6359 | loop_scope->break_block = end_block; | 6359 | loop_scope->break_block = end_block; |
| 6360 | loop_scope->continue_block = continue_block; | 6360 | loop_scope->continue_block = continue_block; |
| 6361 | loop_scope->is_comptime = is_comptime; | 6361 | loop_scope->is_comptime = is_comptime; |
| ... | @@ -6368,41 +6368,41 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -6368,41 +6368,41 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 6368 | // Note the body block of the loop is not the place that lval and result_loc are used - | 6368 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 6369 | // it's actually in break statements, handled similarly to return statements. | 6369 | // it's actually in break statements, handled similarly to return statements. |
| 6370 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. | 6370 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 6371 | IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base); | 6371 | IrInstSrc *body_result = ir_gen_node(ag, body_node, &loop_scope->base); |
| 6372 | if (body_result == irb->codegen->invalid_inst_src) | 6372 | if (body_result == ag->codegen->invalid_inst_src) |
| 6373 | return irb->codegen->invalid_inst_src; | 6373 | return ag->codegen->invalid_inst_src; |
| 6374 | | 6374 | |
| 6375 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { | 6375 | if (loop_scope->name != nullptr && loop_scope->name_used == false) { |
| 6376 | add_node_error(irb->codegen, node, buf_sprintf("unused for label")); | 6376 | add_node_error(ag->codegen, node, buf_sprintf("unused for label")); |
| 6377 | } | 6377 | } |
| 6378 | | 6378 | |
| 6379 | if (!instr_is_unreachable(body_result)) { | 6379 | if (!instr_is_unreachable(body_result)) { |
| 6380 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result)); | 6380 | ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, node->data.for_expr.body, body_result)); |
| 6381 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); | 6381 | ir_mark_gen(ir_build_br(ag, child_scope, node, continue_block, is_comptime)); |
| 6382 | } | 6382 | } |
| 6383 | | 6383 | |
| 6384 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 6384 | ir_set_cursor_at_end_and_append_block(ag, continue_block); |
| 6385 | IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); | 6385 | IrInstSrc *new_index_val = ir_build_bin_op(ag, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 6386 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; | 6386 | ir_build_store_ptr(ag, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; |
| 6387 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); | 6387 | ir_build_br(ag, child_scope, node, cond_block, is_comptime); |
| 6388 | | 6388 | |
| 6389 | IrInstSrc *else_result = nullptr; | 6389 | IrInstSrc *else_result = nullptr; |
| 6390 | if (else_node) { | 6390 | if (else_node) { |
| 6391 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6391 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6392 | | 6392 | |
| 6393 | if (peer_parent->peers.length != 0) { | 6393 | if (peer_parent->peers.length != 0) { |
| 6394 | peer_parent->peers.last()->next_bb = else_block; | 6394 | peer_parent->peers.last()->next_bb = else_block; |
| 6395 | } | 6395 | } |
| 6396 | ResultLocPeer *peer_result = create_peer_result(peer_parent); | 6396 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 6397 | peer_parent->peers.append(peer_result); | 6397 | peer_parent->peers.append(peer_result); |
| 6398 | else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base); | 6398 | else_result = ir_gen_node_extra(ag, else_node, parent_scope, LValNone, &peer_result->base); |
| 6399 | if (else_result == irb->codegen->invalid_inst_src) | 6399 | if (else_result == ag->codegen->invalid_inst_src) |
| 6400 | return else_result; | 6400 | return else_result; |
| 6401 | if (!instr_is_unreachable(else_result)) | 6401 | if (!instr_is_unreachable(else_result)) |
| 6402 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); | 6402 | ir_mark_gen(ir_build_br(ag, parent_scope, node, end_block, is_comptime)); |
| 6403 | } | 6403 | } |
| 6404 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6404 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6405 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 6405 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 6406 | | 6406 | |
| 6407 | if (else_result) { | 6407 | if (else_result) { |
| 6408 | incoming_blocks.append(after_else_block); | 6408 | incoming_blocks.append(after_else_block); |
| ... | @@ -6415,24 +6415,24 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -6415,24 +6415,24 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 6415 | peer_parent->peers.last()->next_bb = end_block; | 6415 | peer_parent->peers.last()->next_bb = end_block; |
| 6416 | } | 6416 | } |
| 6417 | | 6417 | |
| 6418 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, | 6418 | IrInstSrc *phi = ir_build_phi(ag, parent_scope, node, incoming_blocks.length, |
| 6419 | incoming_blocks.items, incoming_values.items, peer_parent); | 6419 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6420 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); | 6420 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 6421 | } | 6421 | } |
| 6422 | | 6422 | |
| 6423 | static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6423 | static IrInstSrc *ir_gen_bool_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6424 | assert(node->type == NodeTypeBoolLiteral); | 6424 | assert(node->type == NodeTypeBoolLiteral); |
| 6425 | return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value); | 6425 | return ir_build_const_bool(ag, scope, node, node->data.bool_literal.value); |
| 6426 | } | 6426 | } |
| 6427 | | 6427 | |
| 6428 | static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6428 | static IrInstSrc *ir_gen_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6429 | assert(node->type == NodeTypeEnumLiteral); | 6429 | assert(node->type == NodeTypeEnumLiteral); |
| 6430 | RootStruct *root_struct = node->owner->data.structure.root_struct; | 6430 | RootStruct *root_struct = node->owner->data.structure.root_struct; |
| 6431 | Buf *name = token_identifier_buf(root_struct, node->main_token + 1); | 6431 | Buf *name = token_identifier_buf(root_struct, node->main_token + 1); |
| 6432 | return ir_build_const_enum_literal(irb, scope, node, name); | 6432 | return ir_build_const_enum_literal(ag, scope, node, name); |
| 6433 | } | 6433 | } |
| 6434 | | 6434 | |
| 6435 | static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6435 | static IrInstSrc *ir_gen_string_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6436 | Error err; | 6436 | Error err; |
| 6437 | assert(node->type == NodeTypeStringLiteral); | 6437 | assert(node->type == NodeTypeStringLiteral); |
| 6438 | | 6438 | |
| ... | @@ -6446,7 +6446,7 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode | ... | @@ -6446,7 +6446,7 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode |
| 6446 | size_t byte_offset = root_struct->token_locs[node->main_token].offset; | 6446 | size_t byte_offset = root_struct->token_locs[node->main_token].offset; |
| 6447 | size_t bad_index; | 6447 | size_t bad_index; |
| 6448 | if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { | 6448 | if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { |
| 6449 | add_token_error_offset(irb->codegen, node->owner, node->main_token, | 6449 | add_token_error_offset(ag->codegen, node->owner, node->main_token, |
| 6450 | buf_create_from_str("invalid string literal character"), bad_index); | 6450 | buf_create_from_str("invalid string literal character"), bad_index); |
| 6451 | } | 6451 | } |
| 6452 | src_assert(source[byte_offset] == '"', node); | 6452 | src_assert(source[byte_offset] == '"', node); |
| ... | @@ -6470,10 +6470,10 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode | ... | @@ -6470,10 +6470,10 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode |
| 6470 | } else { | 6470 | } else { |
| 6471 | zig_unreachable(); | 6471 | zig_unreachable(); |
| 6472 | } | 6472 | } |
| 6473 | return ir_build_const_str_lit(irb, scope, node, str); | 6473 | return ir_build_const_str_lit(ag, scope, node, str); |
| 6474 | } | 6474 | } |
| 6475 | | 6475 | |
| 6476 | static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6476 | static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6477 | assert(node->type == NodeTypeArrayType); | 6477 | assert(node->type == NodeTypeArrayType); |
| 6478 | | 6478 | |
| 6479 | AstNode *size_node = node->data.array_type.size; | 6479 | AstNode *size_node = node->data.array_type.size; |
| ... | @@ -6484,12 +6484,12 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6484,12 +6484,12 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6484 | AstNode *sentinel_expr = node->data.array_type.sentinel; | 6484 | AstNode *sentinel_expr = node->data.array_type.sentinel; |
| 6485 | AstNode *align_expr = node->data.array_type.align_expr; | 6485 | AstNode *align_expr = node->data.array_type.align_expr; |
| 6486 | | 6486 | |
| 6487 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); | 6487 | Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope); |
| 6488 | | 6488 | |
| 6489 | IrInstSrc *sentinel; | 6489 | IrInstSrc *sentinel; |
| 6490 | if (sentinel_expr != nullptr) { | 6490 | if (sentinel_expr != nullptr) { |
| 6491 | sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope); | 6491 | sentinel = ir_gen_node(ag, sentinel_expr, comptime_scope); |
| 6492 | if (sentinel == irb->codegen->invalid_inst_src) | 6492 | if (sentinel == ag->codegen->invalid_inst_src) |
| 6493 | return sentinel; | 6493 | return sentinel; |
| 6494 | } else { | 6494 | } else { |
| 6495 | sentinel = nullptr; | 6495 | sentinel = nullptr; |
| ... | @@ -6497,98 +6497,98 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -6497,98 +6497,98 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 6497 | | 6497 | |
| 6498 | if (size_node) { | 6498 | if (size_node) { |
| 6499 | if (is_const) { | 6499 | if (is_const) { |
| 6500 | add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type")); | 6500 | add_node_error(ag->codegen, node, buf_create_from_str("const qualifier invalid on array type")); |
| 6501 | return irb->codegen->invalid_inst_src; | 6501 | return ag->codegen->invalid_inst_src; |
| 6502 | } | 6502 | } |
| 6503 | if (is_volatile) { | 6503 | if (is_volatile) { |
| 6504 | add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); | 6504 | add_node_error(ag->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); |
| 6505 | return irb->codegen->invalid_inst_src; | 6505 | return ag->codegen->invalid_inst_src; |
| 6506 | } | 6506 | } |
| 6507 | if (is_allow_zero) { | 6507 | if (is_allow_zero) { |
| 6508 | add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type")); | 6508 | add_node_error(ag->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type")); |
| 6509 | return irb->codegen->invalid_inst_src; | 6509 | return ag->codegen->invalid_inst_src; |
| 6510 | } | 6510 | } |
| 6511 | if (align_expr != nullptr) { | 6511 | if (align_expr != nullptr) { |
| 6512 | add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type")); | 6512 | add_node_error(ag->codegen, node, buf_create_from_str("align qualifier invalid on array type")); |
| 6513 | return irb->codegen->invalid_inst_src; | 6513 | return ag->codegen->invalid_inst_src; |
| 6514 | } | 6514 | } |
| 6515 | | 6515 | |
| 6516 | IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope); | 6516 | IrInstSrc *size_value = ir_gen_node(ag, size_node, comptime_scope); |
| 6517 | if (size_value == irb->codegen->invalid_inst_src) | 6517 | if (size_value == ag->codegen->invalid_inst_src) |
| 6518 | return size_value; | 6518 | return size_value; |
| 6519 | | 6519 | |
| 6520 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); | 6520 | IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope); |
| 6521 | if (child_type == irb->codegen->invalid_inst_src) | 6521 | if (child_type == ag->codegen->invalid_inst_src) |
| 6522 | return child_type; | 6522 | return child_type; |
| 6523 | | 6523 | |
| 6524 | return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type); | 6524 | return ir_build_array_type(ag, scope, node, size_value, sentinel, child_type); |
| 6525 | } else { | 6525 | } else { |
| 6526 | IrInstSrc *align_value; | 6526 | IrInstSrc *align_value; |
| 6527 | if (align_expr != nullptr) { | 6527 | if (align_expr != nullptr) { |
| 6528 | align_value = ir_gen_node(irb, align_expr, comptime_scope); | 6528 | align_value = ir_gen_node(ag, align_expr, comptime_scope); |
| 6529 | if (align_value == irb->codegen->invalid_inst_src) | 6529 | if (align_value == ag->codegen->invalid_inst_src) |
| 6530 | return align_value; | 6530 | return align_value; |
| 6531 | } else { | 6531 | } else { |
| 6532 | align_value = nullptr; | 6532 | align_value = nullptr; |
| 6533 | } | 6533 | } |
| 6534 | | 6534 | |
| 6535 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); | 6535 | IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope); |
| 6536 | if (child_type == irb->codegen->invalid_inst_src) | 6536 | if (child_type == ag->codegen->invalid_inst_src) |
| 6537 | return child_type; | 6537 | return child_type; |
| 6538 | | 6538 | |
| 6539 | return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel, | 6539 | return ir_build_slice_type(ag, scope, node, child_type, is_const, is_volatile, sentinel, |
| 6540 | align_value, is_allow_zero); | 6540 | align_value, is_allow_zero); |
| 6541 | } | 6541 | } |
| 6542 | } | 6542 | } |
| 6543 | | 6543 | |
| 6544 | static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6544 | static IrInstSrc *ir_gen_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6545 | assert(node->type == NodeTypeAnyFrameType); | 6545 | assert(node->type == NodeTypeAnyFrameType); |
| 6546 | | 6546 | |
| 6547 | AstNode *payload_type_node = node->data.anyframe_type.payload_type; | 6547 | AstNode *payload_type_node = node->data.anyframe_type.payload_type; |
| 6548 | IrInstSrc *payload_type_value = nullptr; | 6548 | IrInstSrc *payload_type_value = nullptr; |
| 6549 | | 6549 | |
| 6550 | if (payload_type_node != nullptr) { | 6550 | if (payload_type_node != nullptr) { |
| 6551 | payload_type_value = ir_gen_node(irb, payload_type_node, scope); | 6551 | payload_type_value = ir_gen_node(ag, payload_type_node, scope); |
| 6552 | if (payload_type_value == irb->codegen->invalid_inst_src) | 6552 | if (payload_type_value == ag->codegen->invalid_inst_src) |
| 6553 | return payload_type_value; | 6553 | return payload_type_value; |
| 6554 | | 6554 | |
| 6555 | } | 6555 | } |
| 6556 | | 6556 | |
| 6557 | return ir_build_anyframe_type(irb, scope, node, payload_type_value); | 6557 | return ir_build_anyframe_type(ag, scope, node, payload_type_value); |
| 6558 | } | 6558 | } |
| 6559 | | 6559 | |
| 6560 | static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6560 | static IrInstSrc *ir_gen_undefined_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6561 | assert(node->type == NodeTypeUndefinedLiteral); | 6561 | assert(node->type == NodeTypeUndefinedLiteral); |
| 6562 | return ir_build_const_undefined(irb, scope, node); | 6562 | return ir_build_const_undefined(ag, scope, node); |
| 6563 | } | 6563 | } |
| 6564 | | 6564 | |
| 6565 | static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 6565 | static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 6566 | assert(node->type == NodeTypeAsmExpr); | 6566 | assert(node->type == NodeTypeAsmExpr); |
| 6567 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; | 6567 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; |
| 6568 | | 6568 | |
| 6569 | IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope); | 6569 | IrInstSrc *asm_template = ir_gen_node(ag, asm_expr->asm_template, scope); |
| 6570 | if (asm_template == irb->codegen->invalid_inst_src) | 6570 | if (asm_template == ag->codegen->invalid_inst_src) |
| 6571 | return irb->codegen->invalid_inst_src; | 6571 | return ag->codegen->invalid_inst_src; |
| 6572 | | 6572 | |
| 6573 | bool is_volatile = asm_expr->volatile_token != 0; | 6573 | bool is_volatile = asm_expr->volatile_token != 0; |
| 6574 | bool in_fn_scope = (scope_fn_entry(scope) != nullptr); | 6574 | bool in_fn_scope = (scope_fn_entry(scope) != nullptr); |
| 6575 | | 6575 | |
| 6576 | if (!in_fn_scope) { | 6576 | if (!in_fn_scope) { |
| 6577 | if (is_volatile) { | 6577 | if (is_volatile) { |
| 6578 | add_token_error(irb->codegen, node->owner, asm_expr->volatile_token, | 6578 | add_token_error(ag->codegen, node->owner, asm_expr->volatile_token, |
| 6579 | buf_sprintf("volatile is meaningless on global assembly")); | 6579 | buf_sprintf("volatile is meaningless on global assembly")); |
| 6580 | return irb->codegen->invalid_inst_src; | 6580 | return ag->codegen->invalid_inst_src; |
| 6581 | } | 6581 | } |
| 6582 | | 6582 | |
| 6583 | if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 || | 6583 | if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 || |
| 6584 | asm_expr->clobber_list.length != 0) | 6584 | asm_expr->clobber_list.length != 0) |
| 6585 | { | 6585 | { |
| 6586 | add_node_error(irb->codegen, node, | 6586 | add_node_error(ag->codegen, node, |
| 6587 | buf_sprintf("global assembly cannot have inputs, outputs, or clobbers")); | 6587 | buf_sprintf("global assembly cannot have inputs, outputs, or clobbers")); |
| 6588 | return irb->codegen->invalid_inst_src; | 6588 | return ag->codegen->invalid_inst_src; |
| 6589 | } | 6589 | } |
| 6590 | | 6590 | |
| 6591 | return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr, | 6591 | return ir_build_asm_src(ag, scope, node, asm_template, nullptr, nullptr, |
| 6592 | nullptr, 0, is_volatile, true); | 6592 | nullptr, 0, is_volatile, true); |
| 6593 | } | 6593 | } |
| 6594 | | 6594 | |
| ... | @@ -6597,61 +6597,61 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node | ... | @@ -6597,61 +6597,61 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node |
| 6597 | ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length); | 6597 | ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length); |
| 6598 | size_t return_count = 0; | 6598 | size_t return_count = 0; |
| 6599 | if (!is_volatile && asm_expr->output_list.length == 0) { | 6599 | if (!is_volatile && asm_expr->output_list.length == 0) { |
| 6600 | add_node_error(irb->codegen, node, | 6600 | add_node_error(ag->codegen, node, |
| 6601 | buf_sprintf("assembly expression with no output must be marked volatile")); | 6601 | buf_sprintf("assembly expression with no output must be marked volatile")); |
| 6602 | return irb->codegen->invalid_inst_src; | 6602 | return ag->codegen->invalid_inst_src; |
| 6603 | } | 6603 | } |
| 6604 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { | 6604 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 6605 | AsmOutput *asm_output = asm_expr->output_list.at(i); | 6605 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 6606 | if (asm_output->return_type) { | 6606 | if (asm_output->return_type) { |
| 6607 | return_count += 1; | 6607 | return_count += 1; |
| 6608 | | 6608 | |
| 6609 | IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope); | 6609 | IrInstSrc *return_type = ir_gen_node(ag, asm_output->return_type, scope); |
| 6610 | if (return_type == irb->codegen->invalid_inst_src) | 6610 | if (return_type == ag->codegen->invalid_inst_src) |
| 6611 | return irb->codegen->invalid_inst_src; | 6611 | return ag->codegen->invalid_inst_src; |
| 6612 | if (return_count > 1) { | 6612 | if (return_count > 1) { |
| 6613 | add_node_error(irb->codegen, node, | 6613 | add_node_error(ag->codegen, node, |
| 6614 | buf_sprintf("inline assembly allows up to one output value")); | 6614 | buf_sprintf("inline assembly allows up to one output value")); |
| 6615 | return irb->codegen->invalid_inst_src; | 6615 | return ag->codegen->invalid_inst_src; |
| 6616 | } | 6616 | } |
| 6617 | output_types[i] = return_type; | 6617 | output_types[i] = return_type; |
| 6618 | } else { | 6618 | } else { |
| 6619 | Buf *variable_name = asm_output->variable_name; | 6619 | Buf *variable_name = asm_output->variable_name; |
| 6620 | // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how | 6620 | // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how |
| 6621 | // inline assembly works. https://github.com/ziglang/zig/issues/215 | 6621 | // inline assembly works. https://github.com/ziglang/zig/issues/215 |
| 6622 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, nullptr); | 6622 | ZigVar *var = find_variable(ag->codegen, scope, variable_name, nullptr); |
| 6623 | if (var) { | 6623 | if (var) { |
| 6624 | output_vars[i] = var; | 6624 | output_vars[i] = var; |
| 6625 | } else { | 6625 | } else { |
| 6626 | add_node_error(irb->codegen, node, | 6626 | add_node_error(ag->codegen, node, |
| 6627 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); | 6627 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); |
| 6628 | return irb->codegen->invalid_inst_src; | 6628 | return ag->codegen->invalid_inst_src; |
| 6629 | } | 6629 | } |
| 6630 | } | 6630 | } |
| 6631 | | 6631 | |
| 6632 | const char modifier = *buf_ptr(asm_output->constraint); | 6632 | const char modifier = *buf_ptr(asm_output->constraint); |
| 6633 | if (modifier != '=') { | 6633 | if (modifier != '=') { |
| 6634 | add_node_error(irb->codegen, node, | 6634 | add_node_error(ag->codegen, node, |
| 6635 | buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported." | 6635 | buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported." |
| 6636 | " Compiler TODO: see https://github.com/ziglang/zig/issues/215", | 6636 | " Compiler TODO: see https://github.com/ziglang/zig/issues/215", |
| 6637 | buf_ptr(asm_output->asm_symbolic_name), modifier)); | 6637 | buf_ptr(asm_output->asm_symbolic_name), modifier)); |
| 6638 | return irb->codegen->invalid_inst_src; | 6638 | return ag->codegen->invalid_inst_src; |
| 6639 | } | 6639 | } |
| 6640 | } | 6640 | } |
| 6641 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { | 6641 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 6642 | AsmInput *asm_input = asm_expr->input_list.at(i); | 6642 | AsmInput *asm_input = asm_expr->input_list.at(i); |
| 6643 | IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope); | 6643 | IrInstSrc *input_value = ir_gen_node(ag, asm_input->expr, scope); |
| 6644 | if (input_value == irb->codegen->invalid_inst_src) | 6644 | if (input_value == ag->codegen->invalid_inst_src) |
| 6645 | return irb->codegen->invalid_inst_src; | 6645 | return ag->codegen->invalid_inst_src; |
| 6646 | | 6646 | |
| 6647 | input_list[i] = input_value; | 6647 | input_list[i] = input_value; |
| 6648 | } | 6648 | } |
| 6649 | | 6649 | |
| 6650 | return ir_build_asm_src(irb, scope, node, asm_template, input_list, output_types, | 6650 | return ir_build_asm_src(ag, scope, node, asm_template, input_list, output_types, |
| 6651 | output_vars, return_count, is_volatile, false); | 6651 | output_vars, return_count, is_volatile, false); |
| 6652 | } | 6652 | } |
| 6653 | | 6653 | |
| 6654 | static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 6654 | static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 6655 | ResultLoc *result_loc) | 6655 | ResultLoc *result_loc) |
| 6656 | { | 6656 | { |
| 6657 | assert(node->type == NodeTypeIfOptional); | 6657 | assert(node->type == NodeTypeIfOptional); |
| ... | @@ -6662,73 +6662,73 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo | ... | @@ -6662,73 +6662,73 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo |
| 6662 | AstNode *else_node = node->data.test_expr.else_node; | 6662 | AstNode *else_node = node->data.test_expr.else_node; |
| 6663 | bool var_is_ptr = node->data.test_expr.var_is_ptr; | 6663 | bool var_is_ptr = node->data.test_expr.var_is_ptr; |
| 6664 | | 6664 | |
| 6665 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, expr_node, scope); | 6665 | ScopeExpr *spill_scope = create_expr_scope(ag->codegen, expr_node, scope); |
| 6666 | spill_scope->spill_harder = true; | 6666 | spill_scope->spill_harder = true; |
| 6667 | | 6667 | |
| 6668 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, &spill_scope->base, LValPtr, nullptr); | 6668 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, expr_node, &spill_scope->base, LValPtr, nullptr); |
| 6669 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) | 6669 | if (maybe_val_ptr == ag->codegen->invalid_inst_src) |
| 6670 | return maybe_val_ptr; | 6670 | return maybe_val_ptr; |
| 6671 | | 6671 | |
| 6672 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); | 6672 | IrInstSrc *maybe_val = ir_build_load_ptr(ag, scope, node, maybe_val_ptr); |
| 6673 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val); | 6673 | IrInstSrc *is_non_null = ir_build_test_non_null_src(ag, scope, node, maybe_val); |
| 6674 | | 6674 | |
| 6675 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen"); | 6675 | IrBasicBlockSrc *then_block = ir_create_basic_block(ag, scope, "OptionalThen"); |
| 6676 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse"); | 6676 | IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "OptionalElse"); |
| 6677 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf"); | 6677 | IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "OptionalEndIf"); |
| 6678 | | 6678 | |
| 6679 | IrInstSrc *is_comptime; | 6679 | IrInstSrc *is_comptime; |
| 6680 | if (ir_should_inline(irb->exec, scope)) { | 6680 | if (ir_should_inline(ag->exec, scope)) { |
| 6681 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 6681 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 6682 | } else { | 6682 | } else { |
| 6683 | is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null); | 6683 | is_comptime = ir_build_test_comptime(ag, scope, node, is_non_null); |
| 6684 | } | 6684 | } |
| 6685 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, | 6685 | IrInstSrc *cond_br_inst = ir_build_cond_br(ag, scope, node, is_non_null, |
| 6686 | then_block, else_block, is_comptime); | 6686 | then_block, else_block, is_comptime); |
| 6687 | | 6687 | |
| 6688 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, | 6688 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(ag, cond_br_inst, else_block, endif_block, |
| 6689 | result_loc, is_comptime); | 6689 | result_loc, is_comptime); |
| 6690 | | 6690 | |
| 6691 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 6691 | ir_set_cursor_at_end_and_append_block(ag, then_block); |
| 6692 | | 6692 | |
| 6693 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, &spill_scope->base, is_comptime); | 6693 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, &spill_scope->base, is_comptime); |
| 6694 | Scope *var_scope; | 6694 | Scope *var_scope; |
| 6695 | if (var_symbol) { | 6695 | if (var_symbol) { |
| 6696 | bool is_shadowable = false; | 6696 | bool is_shadowable = false; |
| 6697 | bool is_const = true; | 6697 | bool is_const = true; |
| 6698 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, | 6698 | ZigVar *var = ir_create_var(ag, node, subexpr_scope, |
| 6699 | var_symbol, is_const, is_const, is_shadowable, is_comptime); | 6699 | var_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 6700 | | 6700 | |
| 6701 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false); | 6701 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(ag, subexpr_scope, node, maybe_val_ptr, false); |
| 6702 | IrInstSrc *var_value = var_is_ptr ? | 6702 | IrInstSrc *var_value = var_is_ptr ? |
| 6703 | payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, node, payload_ptr); | 6703 | payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, node, payload_ptr); |
| 6704 | build_decl_var_and_init(irb, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), is_comptime); | 6704 | build_decl_var_and_init(ag, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), is_comptime); |
| 6705 | var_scope = var->child_scope; | 6705 | var_scope = var->child_scope; |
| 6706 | } else { | 6706 | } else { |
| 6707 | var_scope = subexpr_scope; | 6707 | var_scope = subexpr_scope; |
| 6708 | } | 6708 | } |
| 6709 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, | 6709 | IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, var_scope, lval, |
| 6710 | &peer_parent->peers.at(0)->base); | 6710 | &peer_parent->peers.at(0)->base); |
| 6711 | if (then_expr_result == irb->codegen->invalid_inst_src) | 6711 | if (then_expr_result == ag->codegen->invalid_inst_src) |
| 6712 | return then_expr_result; | 6712 | return then_expr_result; |
| 6713 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; | 6713 | IrBasicBlockSrc *after_then_block = ag->current_basic_block; |
| 6714 | if (!instr_is_unreachable(then_expr_result)) | 6714 | if (!instr_is_unreachable(then_expr_result)) |
| 6715 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 6715 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 6716 | | 6716 | |
| 6717 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6717 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6718 | IrInstSrc *else_expr_result; | 6718 | IrInstSrc *else_expr_result; |
| 6719 | if (else_node) { | 6719 | if (else_node) { |
| 6720 | else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); | 6720 | else_expr_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); |
| 6721 | if (else_expr_result == irb->codegen->invalid_inst_src) | 6721 | if (else_expr_result == ag->codegen->invalid_inst_src) |
| 6722 | return else_expr_result; | 6722 | return else_expr_result; |
| 6723 | } else { | 6723 | } else { |
| 6724 | else_expr_result = ir_build_const_void(irb, scope, node); | 6724 | else_expr_result = ir_build_const_void(ag, scope, node); |
| 6725 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); | 6725 | ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 6726 | } | 6726 | } |
| 6727 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6727 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6728 | if (!instr_is_unreachable(else_expr_result)) | 6728 | if (!instr_is_unreachable(else_expr_result)) |
| 6729 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 6729 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 6730 | | 6730 | |
| 6731 | ir_set_cursor_at_end_and_append_block(irb, endif_block); | 6731 | ir_set_cursor_at_end_and_append_block(ag, endif_block); |
| 6732 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 6732 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 6733 | incoming_values[0] = then_expr_result; | 6733 | incoming_values[0] = then_expr_result; |
| 6734 | incoming_values[1] = else_expr_result; | 6734 | incoming_values[1] = else_expr_result; |
| ... | @@ -6736,11 +6736,11 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo | ... | @@ -6736,11 +6736,11 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo |
| 6736 | incoming_blocks[0] = after_then_block; | 6736 | incoming_blocks[0] = after_then_block; |
| 6737 | incoming_blocks[1] = after_else_block; | 6737 | incoming_blocks[1] = after_else_block; |
| 6738 | | 6738 | |
| 6739 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); | 6739 | IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 6740 | return ir_expr_wrap(irb, scope, phi, result_loc); | 6740 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6741 | } | 6741 | } |
| 6742 | | 6742 | |
| 6743 | static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 6743 | static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 6744 | ResultLoc *result_loc) | 6744 | ResultLoc *result_loc) |
| 6745 | { | 6745 | { |
| 6746 | assert(node->type == NodeTypeIfErrorExpr); | 6746 | assert(node->type == NodeTypeIfErrorExpr); |
| ... | @@ -6753,51 +6753,51 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -6753,51 +6753,51 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 6753 | Buf *var_symbol = node->data.if_err_expr.var_symbol; | 6753 | Buf *var_symbol = node->data.if_err_expr.var_symbol; |
| 6754 | Buf *err_symbol = node->data.if_err_expr.err_symbol; | 6754 | Buf *err_symbol = node->data.if_err_expr.err_symbol; |
| 6755 | | 6755 | |
| 6756 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); | 6756 | IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr); |
| 6757 | if (err_val_ptr == irb->codegen->invalid_inst_src) | 6757 | if (err_val_ptr == ag->codegen->invalid_inst_src) |
| 6758 | return err_val_ptr; | 6758 | return err_val_ptr; |
| 6759 | | 6759 | |
| 6760 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); | 6760 | IrInstSrc *err_val = ir_build_load_ptr(ag, scope, node, err_val_ptr); |
| 6761 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false); | 6761 | IrInstSrc *is_err = ir_build_test_err_src(ag, scope, node, err_val_ptr, true, false); |
| 6762 | | 6762 | |
| 6763 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk"); | 6763 | IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, scope, "TryOk"); |
| 6764 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse"); | 6764 | IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "TryElse"); |
| 6765 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd"); | 6765 | IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "TryEnd"); |
| 6766 | | 6766 | |
| 6767 | bool force_comptime = ir_should_inline(irb->exec, scope); | 6767 | bool force_comptime = ir_should_inline(ag->exec, scope); |
| 6768 | IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); | 6768 | IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(ag, scope, node, true) : ir_build_test_comptime(ag, scope, node, is_err); |
| 6769 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); | 6769 | IrInstSrc *cond_br_inst = ir_build_cond_br(ag, scope, node, is_err, else_block, ok_block, is_comptime); |
| 6770 | | 6770 | |
| 6771 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, | 6771 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(ag, cond_br_inst, else_block, endif_block, |
| 6772 | result_loc, is_comptime); | 6772 | result_loc, is_comptime); |
| 6773 | | 6773 | |
| 6774 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 6774 | ir_set_cursor_at_end_and_append_block(ag, ok_block); |
| 6775 | | 6775 | |
| 6776 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 6776 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 6777 | Scope *var_scope; | 6777 | Scope *var_scope; |
| 6778 | if (var_symbol) { | 6778 | if (var_symbol) { |
| 6779 | bool is_shadowable = false; | 6779 | bool is_shadowable = false; |
| 6780 | IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); | 6780 | IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(ag, subexpr_scope, node, true) : ir_build_test_comptime(ag, subexpr_scope, node, err_val); |
| 6781 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, | 6781 | ZigVar *var = ir_create_var(ag, node, subexpr_scope, |
| 6782 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); | 6782 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); |
| 6783 | | 6783 | |
| 6784 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false); | 6784 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(ag, subexpr_scope, node, err_val_ptr, false, false); |
| 6785 | IrInstSrc *var_value = var_is_ptr ? | 6785 | IrInstSrc *var_value = var_is_ptr ? |
| 6786 | payload_ptr : ir_build_load_ptr(irb, subexpr_scope, node, payload_ptr); | 6786 | payload_ptr : ir_build_load_ptr(ag, subexpr_scope, node, payload_ptr); |
| 6787 | build_decl_var_and_init(irb, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), var_is_comptime); | 6787 | build_decl_var_and_init(ag, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), var_is_comptime); |
| 6788 | var_scope = var->child_scope; | 6788 | var_scope = var->child_scope; |
| 6789 | } else { | 6789 | } else { |
| 6790 | var_scope = subexpr_scope; | 6790 | var_scope = subexpr_scope; |
| 6791 | } | 6791 | } |
| 6792 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, | 6792 | IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, var_scope, lval, |
| 6793 | &peer_parent->peers.at(0)->base); | 6793 | &peer_parent->peers.at(0)->base); |
| 6794 | if (then_expr_result == irb->codegen->invalid_inst_src) | 6794 | if (then_expr_result == ag->codegen->invalid_inst_src) |
| 6795 | return then_expr_result; | 6795 | return then_expr_result; |
| 6796 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; | 6796 | IrBasicBlockSrc *after_then_block = ag->current_basic_block; |
| 6797 | if (!instr_is_unreachable(then_expr_result)) | 6797 | if (!instr_is_unreachable(then_expr_result)) |
| 6798 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 6798 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 6799 | | 6799 | |
| 6800 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6800 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 6801 | | 6801 | |
| 6802 | IrInstSrc *else_expr_result; | 6802 | IrInstSrc *else_expr_result; |
| 6803 | if (else_node) { | 6803 | if (else_node) { |
| ... | @@ -6805,28 +6805,28 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -6805,28 +6805,28 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 6805 | if (err_symbol) { | 6805 | if (err_symbol) { |
| 6806 | bool is_shadowable = false; | 6806 | bool is_shadowable = false; |
| 6807 | bool is_const = true; | 6807 | bool is_const = true; |
| 6808 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, | 6808 | ZigVar *var = ir_create_var(ag, node, subexpr_scope, |
| 6809 | err_symbol, is_const, is_const, is_shadowable, is_comptime); | 6809 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 6810 | | 6810 | |
| 6811 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr); | 6811 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(ag, subexpr_scope, node, err_val_ptr); |
| 6812 | IrInstSrc *err_value = ir_build_load_ptr(irb, subexpr_scope, node, err_ptr); | 6812 | IrInstSrc *err_value = ir_build_load_ptr(ag, subexpr_scope, node, err_ptr); |
| 6813 | build_decl_var_and_init(irb, subexpr_scope, node, var, err_value, buf_ptr(err_symbol), is_comptime); | 6813 | build_decl_var_and_init(ag, subexpr_scope, node, var, err_value, buf_ptr(err_symbol), is_comptime); |
| 6814 | err_var_scope = var->child_scope; | 6814 | err_var_scope = var->child_scope; |
| 6815 | } else { | 6815 | } else { |
| 6816 | err_var_scope = subexpr_scope; | 6816 | err_var_scope = subexpr_scope; |
| 6817 | } | 6817 | } |
| 6818 | else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base); | 6818 | else_expr_result = ir_gen_node_extra(ag, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base); |
| 6819 | if (else_expr_result == irb->codegen->invalid_inst_src) | 6819 | if (else_expr_result == ag->codegen->invalid_inst_src) |
| 6820 | return else_expr_result; | 6820 | return else_expr_result; |
| 6821 | } else { | 6821 | } else { |
| 6822 | else_expr_result = ir_build_const_void(irb, scope, node); | 6822 | else_expr_result = ir_build_const_void(ag, scope, node); |
| 6823 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); | 6823 | ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 6824 | } | 6824 | } |
| 6825 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; | 6825 | IrBasicBlockSrc *after_else_block = ag->current_basic_block; |
| 6826 | if (!instr_is_unreachable(else_expr_result)) | 6826 | if (!instr_is_unreachable(else_expr_result)) |
| 6827 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 6827 | ir_mark_gen(ir_build_br(ag, scope, node, endif_block, is_comptime)); |
| 6828 | | 6828 | |
| 6829 | ir_set_cursor_at_end_and_append_block(irb, endif_block); | 6829 | ir_set_cursor_at_end_and_append_block(ag, endif_block); |
| 6830 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 6830 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 6831 | incoming_values[0] = then_expr_result; | 6831 | incoming_values[0] = then_expr_result; |
| 6832 | incoming_values[1] = else_expr_result; | 6832 | incoming_values[1] = else_expr_result; |
| ... | @@ -6834,11 +6834,11 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -6834,11 +6834,11 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 6834 | incoming_blocks[0] = after_then_block; | 6834 | incoming_blocks[0] = after_then_block; |
| 6835 | incoming_blocks[1] = after_else_block; | 6835 | incoming_blocks[1] = after_else_block; |
| 6836 | | 6836 | |
| 6837 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); | 6837 | IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 6838 | return ir_expr_wrap(irb, scope, phi, result_loc); | 6838 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6839 | } | 6839 | } |
| 6840 | | 6840 | |
| 6841 | static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node, | 6841 | static bool ir_gen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *switch_node, AstNode *prong_node, |
| 6842 | IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime, | 6842 | IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime, |
| 6843 | IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len, | 6843 | IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len, |
| 6844 | ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values, | 6844 | ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values, |
| ... | @@ -6857,66 +6857,66 @@ static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *s | ... | @@ -6857,66 +6857,66 @@ static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *s |
| 6857 | | 6857 | |
| 6858 | bool is_shadowable = false; | 6858 | bool is_shadowable = false; |
| 6859 | bool is_const = true; | 6859 | bool is_const = true; |
| 6860 | ZigVar *var = ir_create_var(irb, var_symbol_node, scope, | 6860 | ZigVar *var = ir_create_var(ag, var_symbol_node, scope, |
| 6861 | var_name, is_const, is_const, is_shadowable, var_is_comptime); | 6861 | var_name, is_const, is_const, is_shadowable, var_is_comptime); |
| 6862 | child_scope = var->child_scope; | 6862 | child_scope = var->child_scope; |
| 6863 | IrInstSrc *var_value; | 6863 | IrInstSrc *var_value; |
| 6864 | if (out_switch_else_var != nullptr) { | 6864 | if (out_switch_else_var != nullptr) { |
| 6865 | IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node, | 6865 | IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(ag, scope, var_symbol_node, |
| 6866 | target_value_ptr); | 6866 | target_value_ptr); |
| 6867 | *out_switch_else_var = switch_else_var; | 6867 | *out_switch_else_var = switch_else_var; |
| 6868 | IrInstSrc *payload_ptr = &switch_else_var->base; | 6868 | IrInstSrc *payload_ptr = &switch_else_var->base; |
| 6869 | var_value = var_is_ptr ? | 6869 | var_value = var_is_ptr ? |
| 6870 | payload_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, payload_ptr); | 6870 | payload_ptr : ir_build_load_ptr(ag, scope, var_symbol_node, payload_ptr); |
| 6871 | } else if (prong_values != nullptr) { | 6871 | } else if (prong_values != nullptr) { |
| 6872 | IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, | 6872 | IrInstSrc *payload_ptr = ir_build_switch_var(ag, scope, var_symbol_node, target_value_ptr, |
| 6873 | prong_values, prong_values_len); | 6873 | prong_values, prong_values_len); |
| 6874 | var_value = var_is_ptr ? | 6874 | var_value = var_is_ptr ? |
| 6875 | payload_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, payload_ptr); | 6875 | payload_ptr : ir_build_load_ptr(ag, scope, var_symbol_node, payload_ptr); |
| 6876 | } else { | 6876 | } else { |
| 6877 | var_value = var_is_ptr ? | 6877 | var_value = var_is_ptr ? |
| 6878 | target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, target_value_ptr); | 6878 | target_value_ptr : ir_build_load_ptr(ag, scope, var_symbol_node, target_value_ptr); |
| 6879 | } | 6879 | } |
| 6880 | build_decl_var_and_init(irb, scope, var_symbol_node, var, var_value, buf_ptr(var_name), var_is_comptime); | 6880 | build_decl_var_and_init(ag, scope, var_symbol_node, var, var_value, buf_ptr(var_name), var_is_comptime); |
| 6881 | } else { | 6881 | } else { |
| 6882 | child_scope = scope; | 6882 | child_scope = scope; |
| 6883 | } | 6883 | } |
| 6884 | | 6884 | |
| 6885 | IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc); | 6885 | IrInstSrc *expr_result = ir_gen_node_extra(ag, expr_node, child_scope, lval, result_loc); |
| 6886 | if (expr_result == irb->codegen->invalid_inst_src) | 6886 | if (expr_result == ag->codegen->invalid_inst_src) |
| 6887 | return false; | 6887 | return false; |
| 6888 | if (!instr_is_unreachable(expr_result)) | 6888 | if (!instr_is_unreachable(expr_result)) |
| 6889 | ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime)); | 6889 | ir_mark_gen(ir_build_br(ag, scope, switch_node, end_block, is_comptime)); |
| 6890 | incoming_blocks->append(irb->current_basic_block); | 6890 | incoming_blocks->append(ag->current_basic_block); |
| 6891 | incoming_values->append(expr_result); | 6891 | incoming_values->append(expr_result); |
| 6892 | return true; | 6892 | return true; |
| 6893 | } | 6893 | } |
| 6894 | | 6894 | |
| 6895 | static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 6895 | static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 6896 | ResultLoc *result_loc) | 6896 | ResultLoc *result_loc) |
| 6897 | { | 6897 | { |
| 6898 | assert(node->type == NodeTypeSwitchExpr); | 6898 | assert(node->type == NodeTypeSwitchExpr); |
| 6899 | | 6899 | |
| 6900 | AstNode *target_node = node->data.switch_expr.expr; | 6900 | AstNode *target_node = node->data.switch_expr.expr; |
| 6901 | IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); | 6901 | IrInstSrc *target_value_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr); |
| 6902 | if (target_value_ptr == irb->codegen->invalid_inst_src) | 6902 | if (target_value_ptr == ag->codegen->invalid_inst_src) |
| 6903 | return target_value_ptr; | 6903 | return target_value_ptr; |
| 6904 | IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); | 6904 | IrInstSrc *target_value = ir_build_switch_target(ag, scope, node, target_value_ptr); |
| 6905 | | 6905 | |
| 6906 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); | 6906 | IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "SwitchElse"); |
| 6907 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); | 6907 | IrBasicBlockSrc *end_block = ir_create_basic_block(ag, scope, "SwitchEnd"); |
| 6908 | | 6908 | |
| 6909 | size_t prong_count = node->data.switch_expr.prongs.length; | 6909 | size_t prong_count = node->data.switch_expr.prongs.length; |
| 6910 | ZigList<IrInstSrcSwitchBrCase> cases = {0}; | 6910 | ZigList<IrInstSrcSwitchBrCase> cases = {0}; |
| 6911 | | 6911 | |
| 6912 | IrInstSrc *is_comptime; | 6912 | IrInstSrc *is_comptime; |
| 6913 | IrInstSrc *var_is_comptime; | 6913 | IrInstSrc *var_is_comptime; |
| 6914 | if (ir_should_inline(irb->exec, scope)) { | 6914 | if (ir_should_inline(ag->exec, scope)) { |
| 6915 | is_comptime = ir_build_const_bool(irb, scope, node, true); | 6915 | is_comptime = ir_build_const_bool(ag, scope, node, true); |
| 6916 | var_is_comptime = is_comptime; | 6916 | var_is_comptime = is_comptime; |
| 6917 | } else { | 6917 | } else { |
| 6918 | is_comptime = ir_build_test_comptime(irb, scope, node, target_value); | 6918 | is_comptime = ir_build_test_comptime(ag, scope, node, target_value); |
| 6919 | var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr); | 6919 | var_is_comptime = ir_build_test_comptime(ag, scope, node, target_value_ptr); |
| 6920 | } | 6920 | } |
| 6921 | | 6921 | |
| 6922 | ZigList<IrInstSrc *> incoming_values = {0}; | 6922 | ZigList<IrInstSrc *> incoming_values = {0}; |
| ... | @@ -6932,11 +6932,11 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -6932,11 +6932,11 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 6932 | peer_parent->is_comptime = is_comptime; | 6932 | peer_parent->is_comptime = is_comptime; |
| 6933 | peer_parent->parent = result_loc; | 6933 | peer_parent->parent = result_loc; |
| 6934 | | 6934 | |
| 6935 | ir_build_reset_result(irb, scope, node, &peer_parent->base); | 6935 | ir_build_reset_result(ag, scope, node, &peer_parent->base); |
| 6936 | | 6936 | |
| 6937 | // First do the else and the ranges | 6937 | // First do the else and the ranges |
| 6938 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 6938 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); |
| 6939 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); | 6939 | Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope); |
| 6940 | AstNode *else_prong = nullptr; | 6940 | AstNode *else_prong = nullptr; |
| 6941 | AstNode *underscore_prong = nullptr; | 6941 | AstNode *underscore_prong = nullptr; |
| 6942 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { | 6942 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { |
| ... | @@ -6954,54 +6954,54 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -6954,54 +6954,54 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 6954 | AstNode *start_node = item_node->data.switch_range.start; | 6954 | AstNode *start_node = item_node->data.switch_range.start; |
| 6955 | AstNode *end_node = item_node->data.switch_range.end; | 6955 | AstNode *end_node = item_node->data.switch_range.end; |
| 6956 | | 6956 | |
| 6957 | IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope); | 6957 | IrInstSrc *start_value = ir_gen_node(ag, start_node, comptime_scope); |
| 6958 | if (start_value == irb->codegen->invalid_inst_src) | 6958 | if (start_value == ag->codegen->invalid_inst_src) |
| 6959 | return irb->codegen->invalid_inst_src; | 6959 | return ag->codegen->invalid_inst_src; |
| 6960 | | 6960 | |
| 6961 | IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope); | 6961 | IrInstSrc *end_value = ir_gen_node(ag, end_node, comptime_scope); |
| 6962 | if (end_value == irb->codegen->invalid_inst_src) | 6962 | if (end_value == ag->codegen->invalid_inst_src) |
| 6963 | return irb->codegen->invalid_inst_src; | 6963 | return ag->codegen->invalid_inst_src; |
| 6964 | | 6964 | |
| 6965 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); | 6965 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 6966 | check_range->start = start_value; | 6966 | check_range->start = start_value; |
| 6967 | check_range->end = end_value; | 6967 | check_range->end = end_value; |
| 6968 | | 6968 | |
| 6969 | IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, | 6969 | IrInstSrc *lower_range_ok = ir_build_bin_op(ag, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 6970 | target_value, start_value, false); | 6970 | target_value, start_value, false); |
| 6971 | IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, | 6971 | IrInstSrc *upper_range_ok = ir_build_bin_op(ag, scope, item_node, IrBinOpCmpLessOrEq, |
| 6972 | target_value, end_value, false); | 6972 | target_value, end_value, false); |
| 6973 | IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, | 6973 | IrInstSrc *both_ok = ir_build_bin_op(ag, scope, item_node, IrBinOpBoolAnd, |
| 6974 | lower_range_ok, upper_range_ok, false); | 6974 | lower_range_ok, upper_range_ok, false); |
| 6975 | if (ok_bit) { | 6975 | if (ok_bit) { |
| 6976 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); | 6976 | ok_bit = ir_build_bin_op(ag, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); |
| 6977 | } else { | 6977 | } else { |
| 6978 | ok_bit = both_ok; | 6978 | ok_bit = both_ok; |
| 6979 | } | 6979 | } |
| 6980 | } else { | 6980 | } else { |
| 6981 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); | 6981 | IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope); |
| 6982 | if (item_value == irb->codegen->invalid_inst_src) | 6982 | if (item_value == ag->codegen->invalid_inst_src) |
| 6983 | return irb->codegen->invalid_inst_src; | 6983 | return ag->codegen->invalid_inst_src; |
| 6984 | | 6984 | |
| 6985 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); | 6985 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 6986 | check_range->start = item_value; | 6986 | check_range->start = item_value; |
| 6987 | check_range->end = item_value; | 6987 | check_range->end = item_value; |
| 6988 | | 6988 | |
| 6989 | IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, | 6989 | IrInstSrc *cmp_ok = ir_build_bin_op(ag, scope, item_node, IrBinOpCmpEq, |
| 6990 | item_value, target_value, false); | 6990 | item_value, target_value, false); |
| 6991 | if (ok_bit) { | 6991 | if (ok_bit) { |
| 6992 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); | 6992 | ok_bit = ir_build_bin_op(ag, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); |
| 6993 | } else { | 6993 | } else { |
| 6994 | ok_bit = cmp_ok; | 6994 | ok_bit = cmp_ok; |
| 6995 | } | 6995 | } |
| 6996 | } | 6996 | } |
| 6997 | } | 6997 | } |
| 6998 | | 6998 | |
| 6999 | IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); | 6999 | IrBasicBlockSrc *range_block_yes = ir_create_basic_block(ag, scope, "SwitchRangeYes"); |
| 7000 | IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); | 7000 | IrBasicBlockSrc *range_block_no = ir_create_basic_block(ag, scope, "SwitchRangeNo"); |
| 7001 | | 7001 | |
| 7002 | assert(ok_bit); | 7002 | assert(ok_bit); |
| 7003 | assert(last_item_node); | 7003 | assert(last_item_node); |
| 7004 | IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, | 7004 | IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(ag, scope, last_item_node, ok_bit, |
| 7005 | range_block_yes, range_block_no, is_comptime)); | 7005 | range_block_yes, range_block_no, is_comptime)); |
| 7006 | if (peer_parent->base.source_instruction == nullptr) { | 7006 | if (peer_parent->base.source_instruction == nullptr) { |
| 7007 | peer_parent->base.source_instruction = br_inst; | 7007 | peer_parent->base.source_instruction = br_inst; |
| ... | @@ -7011,65 +7011,65 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -7011,65 +7011,65 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 7011 | peer_parent->peers.last()->next_bb = range_block_yes; | 7011 | peer_parent->peers.last()->next_bb = range_block_yes; |
| 7012 | } | 7012 | } |
| 7013 | peer_parent->peers.append(this_peer_result_loc); | 7013 | peer_parent->peers.append(this_peer_result_loc); |
| 7014 | ir_set_cursor_at_end_and_append_block(irb, range_block_yes); | 7014 | ir_set_cursor_at_end_and_append_block(ag, range_block_yes); |
| 7015 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, | 7015 | if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, |
| 7016 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, | 7016 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, |
| 7017 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) | 7017 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 7018 | { | 7018 | { |
| 7019 | return irb->codegen->invalid_inst_src; | 7019 | return ag->codegen->invalid_inst_src; |
| 7020 | } | 7020 | } |
| 7021 | | 7021 | |
| 7022 | ir_set_cursor_at_end_and_append_block(irb, range_block_no); | 7022 | ir_set_cursor_at_end_and_append_block(ag, range_block_no); |
| 7023 | } else { | 7023 | } else { |
| 7024 | if (prong_item_count == 0) { | 7024 | if (prong_item_count == 0) { |
| 7025 | if (else_prong) { | 7025 | if (else_prong) { |
| 7026 | ErrorMsg *msg = add_node_error(irb->codegen, prong_node, | 7026 | ErrorMsg *msg = add_node_error(ag->codegen, prong_node, |
| 7027 | buf_sprintf("multiple else prongs in switch expression")); | 7027 | buf_sprintf("multiple else prongs in switch expression")); |
| 7028 | add_error_note(irb->codegen, msg, else_prong, | 7028 | add_error_note(ag->codegen, msg, else_prong, |
| 7029 | buf_sprintf("previous else prong is here")); | 7029 | buf_sprintf("previous else prong is here")); |
| 7030 | return irb->codegen->invalid_inst_src; | 7030 | return ag->codegen->invalid_inst_src; |
| 7031 | } | 7031 | } |
| 7032 | else_prong = prong_node; | 7032 | else_prong = prong_node; |
| 7033 | } else if (prong_item_count == 1 && | 7033 | } else if (prong_item_count == 1 && |
| 7034 | prong_node->data.switch_prong.items.at(0)->type == NodeTypeIdentifier && | 7034 | prong_node->data.switch_prong.items.at(0)->type == NodeTypeIdentifier && |
| 7035 | buf_eql_str(node_identifier_buf(prong_node->data.switch_prong.items.at(0)), "_")) { | 7035 | buf_eql_str(node_identifier_buf(prong_node->data.switch_prong.items.at(0)), "_")) { |
| 7036 | if (underscore_prong) { | 7036 | if (underscore_prong) { |
| 7037 | ErrorMsg *msg = add_node_error(irb->codegen, prong_node, | 7037 | ErrorMsg *msg = add_node_error(ag->codegen, prong_node, |
| 7038 | buf_sprintf("multiple '_' prongs in switch expression")); | 7038 | buf_sprintf("multiple '_' prongs in switch expression")); |
| 7039 | add_error_note(irb->codegen, msg, underscore_prong, | 7039 | add_error_note(ag->codegen, msg, underscore_prong, |
| 7040 | buf_sprintf("previous '_' prong is here")); | 7040 | buf_sprintf("previous '_' prong is here")); |
| 7041 | return irb->codegen->invalid_inst_src; | 7041 | return ag->codegen->invalid_inst_src; |
| 7042 | } | 7042 | } |
| 7043 | underscore_prong = prong_node; | 7043 | underscore_prong = prong_node; |
| 7044 | } else { | 7044 | } else { |
| 7045 | continue; | 7045 | continue; |
| 7046 | } | 7046 | } |
| 7047 | if (underscore_prong && else_prong) { | 7047 | if (underscore_prong && else_prong) { |
| 7048 | ErrorMsg *msg = add_node_error(irb->codegen, prong_node, | 7048 | ErrorMsg *msg = add_node_error(ag->codegen, prong_node, |
| 7049 | buf_sprintf("else and '_' prong in switch expression")); | 7049 | buf_sprintf("else and '_' prong in switch expression")); |
| 7050 | if (underscore_prong == prong_node) | 7050 | if (underscore_prong == prong_node) |
| 7051 | add_error_note(irb->codegen, msg, else_prong, | 7051 | add_error_note(ag->codegen, msg, else_prong, |
| 7052 | buf_sprintf("else prong is here")); | 7052 | buf_sprintf("else prong is here")); |
| 7053 | else | 7053 | else |
| 7054 | add_error_note(irb->codegen, msg, underscore_prong, | 7054 | add_error_note(ag->codegen, msg, underscore_prong, |
| 7055 | buf_sprintf("'_' prong is here")); | 7055 | buf_sprintf("'_' prong is here")); |
| 7056 | return irb->codegen->invalid_inst_src; | 7056 | return ag->codegen->invalid_inst_src; |
| 7057 | } | 7057 | } |
| 7058 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); | 7058 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 7059 | | 7059 | |
| 7060 | IrBasicBlockSrc *prev_block = irb->current_basic_block; | 7060 | IrBasicBlockSrc *prev_block = ag->current_basic_block; |
| 7061 | if (peer_parent->peers.length > 0) { | 7061 | if (peer_parent->peers.length > 0) { |
| 7062 | peer_parent->peers.last()->next_bb = else_block; | 7062 | peer_parent->peers.last()->next_bb = else_block; |
| 7063 | } | 7063 | } |
| 7064 | peer_parent->peers.append(this_peer_result_loc); | 7064 | peer_parent->peers.append(this_peer_result_loc); |
| 7065 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 7065 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 7066 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, | 7066 | if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, |
| 7067 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, | 7067 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, |
| 7068 | &switch_else_var, LValNone, &this_peer_result_loc->base)) | 7068 | &switch_else_var, LValNone, &this_peer_result_loc->base)) |
| 7069 | { | 7069 | { |
| 7070 | return irb->codegen->invalid_inst_src; | 7070 | return ag->codegen->invalid_inst_src; |
| 7071 | } | 7071 | } |
| 7072 | ir_set_cursor_at_end(irb, prev_block); | 7072 | ir_set_cursor_at_end(ag, prev_block); |
| 7073 | } | 7073 | } |
| 7074 | } | 7074 | } |
| 7075 | | 7075 | |
| ... | @@ -7086,16 +7086,16 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -7086,16 +7086,16 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 7086 | | 7086 | |
| 7087 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); | 7087 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 7088 | | 7088 | |
| 7089 | IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); | 7089 | IrBasicBlockSrc *prong_block = ir_create_basic_block(ag, scope, "SwitchProng"); |
| 7090 | IrInstSrc **items = heap::c_allocator.allocate<IrInstSrc *>(prong_item_count); | 7090 | IrInstSrc **items = heap::c_allocator.allocate<IrInstSrc *>(prong_item_count); |
| 7091 | | 7091 | |
| 7092 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { | 7092 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 7093 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); | 7093 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 7094 | assert(item_node->type != NodeTypeSwitchRange); | 7094 | assert(item_node->type != NodeTypeSwitchRange); |
| 7095 | | 7095 | |
| 7096 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); | 7096 | IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope); |
| 7097 | if (item_value == irb->codegen->invalid_inst_src) | 7097 | if (item_value == ag->codegen->invalid_inst_src) |
| 7098 | return irb->codegen->invalid_inst_src; | 7098 | return ag->codegen->invalid_inst_src; |
| 7099 | | 7099 | |
| 7100 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); | 7100 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 7101 | check_range->start = item_value; | 7101 | check_range->start = item_value; |
| ... | @@ -7108,31 +7108,31 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -7108,31 +7108,31 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 7108 | items[item_i] = item_value; | 7108 | items[item_i] = item_value; |
| 7109 | } | 7109 | } |
| 7110 | | 7110 | |
| 7111 | IrBasicBlockSrc *prev_block = irb->current_basic_block; | 7111 | IrBasicBlockSrc *prev_block = ag->current_basic_block; |
| 7112 | if (peer_parent->peers.length > 0) { | 7112 | if (peer_parent->peers.length > 0) { |
| 7113 | peer_parent->peers.last()->next_bb = prong_block; | 7113 | peer_parent->peers.last()->next_bb = prong_block; |
| 7114 | } | 7114 | } |
| 7115 | peer_parent->peers.append(this_peer_result_loc); | 7115 | peer_parent->peers.append(this_peer_result_loc); |
| 7116 | ir_set_cursor_at_end_and_append_block(irb, prong_block); | 7116 | ir_set_cursor_at_end_and_append_block(ag, prong_block); |
| 7117 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, | 7117 | if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, |
| 7118 | is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count, | 7118 | is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count, |
| 7119 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) | 7119 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 7120 | { | 7120 | { |
| 7121 | return irb->codegen->invalid_inst_src; | 7121 | return ag->codegen->invalid_inst_src; |
| 7122 | } | 7122 | } |
| 7123 | | 7123 | |
| 7124 | ir_set_cursor_at_end(irb, prev_block); | 7124 | ir_set_cursor_at_end(ag, prev_block); |
| 7125 | | 7125 | |
| 7126 | } | 7126 | } |
| 7127 | | 7127 | |
| 7128 | IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, | 7128 | IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(ag, scope, node, target_value, |
| 7129 | check_ranges.items, check_ranges.length, else_prong, underscore_prong != nullptr); | 7129 | check_ranges.items, check_ranges.length, else_prong, underscore_prong != nullptr); |
| 7130 | | 7130 | |
| 7131 | IrInstSrc *br_instruction; | 7131 | IrInstSrc *br_instruction; |
| 7132 | if (cases.length == 0) { | 7132 | if (cases.length == 0) { |
| 7133 | br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime); | 7133 | br_instruction = ir_build_br(ag, scope, node, else_block, is_comptime); |
| 7134 | } else { | 7134 | } else { |
| 7135 | IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block, | 7135 | IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(ag, scope, node, target_value, else_block, |
| 7136 | cases.length, cases.items, is_comptime, switch_prongs_void); | 7136 | cases.length, cases.items, is_comptime, switch_prongs_void); |
| 7137 | if (switch_else_var != nullptr) { | 7137 | if (switch_else_var != nullptr) { |
| 7138 | switch_else_var->switch_br = switch_br; | 7138 | switch_else_var->switch_br = switch_br; |
| ... | @@ -7150,46 +7150,46 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n | ... | @@ -7150,46 +7150,46 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n |
| 7150 | if (peer_parent->peers.length != 0) { | 7150 | if (peer_parent->peers.length != 0) { |
| 7151 | peer_parent->peers.last()->next_bb = else_block; | 7151 | peer_parent->peers.last()->next_bb = else_block; |
| 7152 | } | 7152 | } |
| 7153 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 7153 | ir_set_cursor_at_end_and_append_block(ag, else_block); |
| 7154 | ir_build_unreachable(irb, scope, node); | 7154 | ir_build_unreachable(ag, scope, node); |
| 7155 | } else { | 7155 | } else { |
| 7156 | if (peer_parent->peers.length != 0) { | 7156 | if (peer_parent->peers.length != 0) { |
| 7157 | peer_parent->peers.last()->next_bb = end_block; | 7157 | peer_parent->peers.last()->next_bb = end_block; |
| 7158 | } | 7158 | } |
| 7159 | } | 7159 | } |
| 7160 | | 7160 | |
| 7161 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 7161 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 7162 | assert(incoming_blocks.length == incoming_values.length); | 7162 | assert(incoming_blocks.length == incoming_values.length); |
| 7163 | IrInstSrc *result_instruction; | 7163 | IrInstSrc *result_instruction; |
| 7164 | if (incoming_blocks.length == 0) { | 7164 | if (incoming_blocks.length == 0) { |
| 7165 | result_instruction = ir_build_const_void(irb, scope, node); | 7165 | result_instruction = ir_build_const_void(ag, scope, node); |
| 7166 | } else { | 7166 | } else { |
| 7167 | result_instruction = ir_build_phi(irb, scope, node, incoming_blocks.length, | 7167 | result_instruction = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 7168 | incoming_blocks.items, incoming_values.items, peer_parent); | 7168 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7169 | } | 7169 | } |
| 7170 | return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc); | 7170 | return ir_lval_wrap(ag, scope, result_instruction, lval, result_loc); |
| 7171 | } | 7171 | } |
| 7172 | | 7172 | |
| 7173 | static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) { | 7173 | static IrInstSrc *ir_gen_comptime(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { |
| 7174 | assert(node->type == NodeTypeCompTime); | 7174 | assert(node->type == NodeTypeCompTime); |
| 7175 | | 7175 | |
| 7176 | Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope); | 7176 | Scope *child_scope = create_comptime_scope(ag->codegen, node, parent_scope); |
| 7177 | // purposefully pass null for result_loc and let EndExpr handle it | 7177 | // purposefully pass null for result_loc and let EndExpr handle it |
| 7178 | return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr); | 7178 | return ir_gen_node_extra(ag, node->data.comptime_expr.expr, child_scope, lval, nullptr); |
| 7179 | } | 7179 | } |
| 7180 | | 7180 | |
| 7181 | static IrInstSrc *ir_gen_nosuspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) { | 7181 | static IrInstSrc *ir_gen_nosuspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { |
| 7182 | assert(node->type == NodeTypeNoSuspend); | 7182 | assert(node->type == NodeTypeNoSuspend); |
| 7183 | | 7183 | |
| 7184 | Scope *child_scope = create_nosuspend_scope(irb->codegen, node, parent_scope); | 7184 | Scope *child_scope = create_nosuspend_scope(ag->codegen, node, parent_scope); |
| 7185 | // purposefully pass null for result_loc and let EndExpr handle it | 7185 | // purposefully pass null for result_loc and let EndExpr handle it |
| 7186 | return ir_gen_node_extra(irb, node->data.nosuspend_expr.expr, child_scope, lval, nullptr); | 7186 | return ir_gen_node_extra(ag, node->data.nosuspend_expr.expr, child_scope, lval, nullptr); |
| 7187 | } | 7187 | } |
| 7188 | | 7188 | |
| 7189 | static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { | 7189 | static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { |
| 7190 | IrInstSrc *is_comptime; | 7190 | IrInstSrc *is_comptime; |
| 7191 | if (ir_should_inline(irb->exec, break_scope)) { | 7191 | if (ir_should_inline(ag->exec, break_scope)) { |
| 7192 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); | 7192 | is_comptime = ir_build_const_bool(ag, break_scope, node, true); |
| 7193 | } else { | 7193 | } else { |
| 7194 | is_comptime = block_scope->is_comptime; | 7194 | is_comptime = block_scope->is_comptime; |
| 7195 | } | 7195 | } |
| ... | @@ -7199,24 +7199,24 @@ static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope | ... | @@ -7199,24 +7199,24 @@ static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope |
| 7199 | ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent); | 7199 | ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent); |
| 7200 | block_scope->peer_parent->peers.append(peer_result); | 7200 | block_scope->peer_parent->peers.append(peer_result); |
| 7201 | | 7201 | |
| 7202 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval, | 7202 | result_value = ir_gen_node_extra(ag, node->data.break_expr.expr, break_scope, block_scope->lval, |
| 7203 | &peer_result->base); | 7203 | &peer_result->base); |
| 7204 | if (result_value == irb->codegen->invalid_inst_src) | 7204 | if (result_value == ag->codegen->invalid_inst_src) |
| 7205 | return irb->codegen->invalid_inst_src; | 7205 | return ag->codegen->invalid_inst_src; |
| 7206 | } else { | 7206 | } else { |
| 7207 | result_value = ir_build_const_void(irb, break_scope, node); | 7207 | result_value = ir_build_const_void(ag, break_scope, node); |
| 7208 | } | 7208 | } |
| 7209 | | 7209 | |
| 7210 | IrBasicBlockSrc *dest_block = block_scope->end_block; | 7210 | IrBasicBlockSrc *dest_block = block_scope->end_block; |
| 7211 | if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr)) | 7211 | if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) |
| 7212 | return irb->codegen->invalid_inst_src; | 7212 | return ag->codegen->invalid_inst_src; |
| 7213 | | 7213 | |
| 7214 | block_scope->incoming_blocks->append(irb->current_basic_block); | 7214 | block_scope->incoming_blocks->append(ag->current_basic_block); |
| 7215 | block_scope->incoming_values->append(result_value); | 7215 | block_scope->incoming_values->append(result_value); |
| 7216 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); | 7216 | return ir_build_br(ag, break_scope, node, dest_block, is_comptime); |
| 7217 | } | 7217 | } |
| 7218 | | 7218 | |
| 7219 | static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) { | 7219 | static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *node) { |
| 7220 | assert(node->type == NodeTypeBreak); | 7220 | assert(node->type == NodeTypeBreak); |
| 7221 | | 7221 | |
| 7222 | // Search up the scope. We'll find one of these things first: | 7222 | // Search up the scope. We'll find one of these things first: |
| ... | @@ -7230,15 +7230,15 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n | ... | @@ -7230,15 +7230,15 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n |
| 7230 | for (;;) { | 7230 | for (;;) { |
| 7231 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { | 7231 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 7232 | if (node->data.break_expr.name != nullptr) { | 7232 | if (node->data.break_expr.name != nullptr) { |
| 7233 | add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name))); | 7233 | add_node_error(ag->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name))); |
| 7234 | return irb->codegen->invalid_inst_src; | 7234 | return ag->codegen->invalid_inst_src; |
| 7235 | } else { | 7235 | } else { |
| 7236 | add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop")); | 7236 | add_node_error(ag->codegen, node, buf_sprintf("break expression outside loop")); |
| 7237 | return irb->codegen->invalid_inst_src; | 7237 | return ag->codegen->invalid_inst_src; |
| 7238 | } | 7238 | } |
| 7239 | } else if (search_scope->id == ScopeIdDeferExpr) { | 7239 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 7240 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression")); | 7240 | add_node_error(ag->codegen, node, buf_sprintf("cannot break out of defer expression")); |
| 7241 | return irb->codegen->invalid_inst_src; | 7241 | return ag->codegen->invalid_inst_src; |
| 7242 | } else if (search_scope->id == ScopeIdLoop) { | 7242 | } else if (search_scope->id == ScopeIdLoop) { |
| 7243 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; | 7243 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 7244 | if (node->data.break_expr.name == nullptr || | 7244 | if (node->data.break_expr.name == nullptr || |
| ... | @@ -7255,18 +7255,18 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n | ... | @@ -7255,18 +7255,18 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n |
| 7255 | { | 7255 | { |
| 7256 | assert(this_block_scope->end_block != nullptr); | 7256 | assert(this_block_scope->end_block != nullptr); |
| 7257 | this_block_scope->name_used = true; | 7257 | this_block_scope->name_used = true; |
| 7258 | return ir_gen_return_from_block(irb, break_scope, node, this_block_scope); | 7258 | return ir_gen_return_from_block(ag, break_scope, node, this_block_scope); |
| 7259 | } | 7259 | } |
| 7260 | } else if (search_scope->id == ScopeIdSuspend) { | 7260 | } else if (search_scope->id == ScopeIdSuspend) { |
| 7261 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block")); | 7261 | add_node_error(ag->codegen, node, buf_sprintf("cannot break out of suspend block")); |
| 7262 | return irb->codegen->invalid_inst_src; | 7262 | return ag->codegen->invalid_inst_src; |
| 7263 | } | 7263 | } |
| 7264 | search_scope = search_scope->parent; | 7264 | search_scope = search_scope->parent; |
| 7265 | } | 7265 | } |
| 7266 | | 7266 | |
| 7267 | IrInstSrc *is_comptime; | 7267 | IrInstSrc *is_comptime; |
| 7268 | if (ir_should_inline(irb->exec, break_scope)) { | 7268 | if (ir_should_inline(ag->exec, break_scope)) { |
| 7269 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); | 7269 | is_comptime = ir_build_const_bool(ag, break_scope, node, true); |
| 7270 | } else { | 7270 | } else { |
| 7271 | is_comptime = loop_scope->is_comptime; | 7271 | is_comptime = loop_scope->is_comptime; |
| 7272 | } | 7272 | } |
| ... | @@ -7276,24 +7276,24 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n | ... | @@ -7276,24 +7276,24 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n |
| 7276 | ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent); | 7276 | ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent); |
| 7277 | loop_scope->peer_parent->peers.append(peer_result); | 7277 | loop_scope->peer_parent->peers.append(peer_result); |
| 7278 | | 7278 | |
| 7279 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, | 7279 | result_value = ir_gen_node_extra(ag, node->data.break_expr.expr, break_scope, |
| 7280 | loop_scope->lval, &peer_result->base); | 7280 | loop_scope->lval, &peer_result->base); |
| 7281 | if (result_value == irb->codegen->invalid_inst_src) | 7281 | if (result_value == ag->codegen->invalid_inst_src) |
| 7282 | return irb->codegen->invalid_inst_src; | 7282 | return ag->codegen->invalid_inst_src; |
| 7283 | } else { | 7283 | } else { |
| 7284 | result_value = ir_build_const_void(irb, break_scope, node); | 7284 | result_value = ir_build_const_void(ag, break_scope, node); |
| 7285 | } | 7285 | } |
| 7286 | | 7286 | |
| 7287 | IrBasicBlockSrc *dest_block = loop_scope->break_block; | 7287 | IrBasicBlockSrc *dest_block = loop_scope->break_block; |
| 7288 | if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr)) | 7288 | if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) |
| 7289 | return irb->codegen->invalid_inst_src; | 7289 | return ag->codegen->invalid_inst_src; |
| 7290 | | 7290 | |
| 7291 | loop_scope->incoming_blocks->append(irb->current_basic_block); | 7291 | loop_scope->incoming_blocks->append(ag->current_basic_block); |
| 7292 | loop_scope->incoming_values->append(result_value); | 7292 | loop_scope->incoming_values->append(result_value); |
| 7293 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); | 7293 | return ir_build_br(ag, break_scope, node, dest_block, is_comptime); |
| 7294 | } | 7294 | } |
| 7295 | | 7295 | |
| 7296 | static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) { | 7296 | static IrInstSrc *ir_gen_continue(Stage1AstGen *ag, Scope *continue_scope, AstNode *node) { |
| 7297 | assert(node->type == NodeTypeContinue); | 7297 | assert(node->type == NodeTypeContinue); |
| 7298 | | 7298 | |
| 7299 | // Search up the scope. We'll find one of these things first: | 7299 | // Search up the scope. We'll find one of these things first: |
| ... | @@ -7308,15 +7308,15 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN | ... | @@ -7308,15 +7308,15 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN |
| 7308 | for (;;) { | 7308 | for (;;) { |
| 7309 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { | 7309 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 7310 | if (node->data.continue_expr.name != nullptr) { | 7310 | if (node->data.continue_expr.name != nullptr) { |
| 7311 | add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name))); | 7311 | add_node_error(ag->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name))); |
| 7312 | return irb->codegen->invalid_inst_src; | 7312 | return ag->codegen->invalid_inst_src; |
| 7313 | } else { | 7313 | } else { |
| 7314 | add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop")); | 7314 | add_node_error(ag->codegen, node, buf_sprintf("continue expression outside loop")); |
| 7315 | return irb->codegen->invalid_inst_src; | 7315 | return ag->codegen->invalid_inst_src; |
| 7316 | } | 7316 | } |
| 7317 | } else if (search_scope->id == ScopeIdDeferExpr) { | 7317 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 7318 | add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression")); | 7318 | add_node_error(ag->codegen, node, buf_sprintf("cannot continue out of defer expression")); |
| 7319 | return irb->codegen->invalid_inst_src; | 7319 | return ag->codegen->invalid_inst_src; |
| 7320 | } else if (search_scope->id == ScopeIdLoop) { | 7320 | } else if (search_scope->id == ScopeIdLoop) { |
| 7321 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; | 7321 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 7322 | if (node->data.continue_expr.name == nullptr || | 7322 | if (node->data.continue_expr.name == nullptr || |
| ... | @@ -7334,42 +7334,42 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN | ... | @@ -7334,42 +7334,42 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN |
| 7334 | } | 7334 | } |
| 7335 | | 7335 | |
| 7336 | IrInstSrc *is_comptime; | 7336 | IrInstSrc *is_comptime; |
| 7337 | if (ir_should_inline(irb->exec, continue_scope)) { | 7337 | if (ir_should_inline(ag->exec, continue_scope)) { |
| 7338 | is_comptime = ir_build_const_bool(irb, continue_scope, node, true); | 7338 | is_comptime = ir_build_const_bool(ag, continue_scope, node, true); |
| 7339 | } else { | 7339 | } else { |
| 7340 | is_comptime = loop_scope->is_comptime; | 7340 | is_comptime = loop_scope->is_comptime; |
| 7341 | } | 7341 | } |
| 7342 | | 7342 | |
| 7343 | for (size_t i = 0; i < runtime_scopes.length; i += 1) { | 7343 | for (size_t i = 0; i < runtime_scopes.length; i += 1) { |
| 7344 | ScopeRuntime *scope_runtime = runtime_scopes.at(i); | 7344 | ScopeRuntime *scope_runtime = runtime_scopes.at(i); |
| 7345 | ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime)); | 7345 | ir_mark_gen(ir_build_check_runtime_scope(ag, continue_scope, node, scope_runtime->is_comptime, is_comptime)); |
| 7346 | } | 7346 | } |
| 7347 | runtime_scopes.deinit(); | 7347 | runtime_scopes.deinit(); |
| 7348 | | 7348 | |
| 7349 | IrBasicBlockSrc *dest_block = loop_scope->continue_block; | 7349 | IrBasicBlockSrc *dest_block = loop_scope->continue_block; |
| 7350 | if (!ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, nullptr, nullptr)) | 7350 | if (!ir_gen_defers_for_block(ag, continue_scope, dest_block->scope, nullptr, nullptr)) |
| 7351 | return irb->codegen->invalid_inst_src; | 7351 | return ag->codegen->invalid_inst_src; |
| 7352 | return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime)); | 7352 | return ir_mark_gen(ir_build_br(ag, continue_scope, node, dest_block, is_comptime)); |
| 7353 | } | 7353 | } |
| 7354 | | 7354 | |
| 7355 | static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 7355 | static IrInstSrc *ir_gen_error_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 7356 | assert(node->type == NodeTypeErrorType); | 7356 | assert(node->type == NodeTypeErrorType); |
| 7357 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set); | 7357 | return ir_build_const_type(ag, scope, node, ag->codegen->builtin_types.entry_global_error_set); |
| 7358 | } | 7358 | } |
| 7359 | | 7359 | |
| 7360 | static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 7360 | static IrInstSrc *ir_gen_defer(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 7361 | assert(node->type == NodeTypeDefer); | 7361 | assert(node->type == NodeTypeDefer); |
| 7362 | | 7362 | |
| 7363 | ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope); | 7363 | ScopeDefer *defer_child_scope = create_defer_scope(ag->codegen, node, parent_scope); |
| 7364 | node->data.defer.child_scope = &defer_child_scope->base; | 7364 | node->data.defer.child_scope = &defer_child_scope->base; |
| 7365 | | 7365 | |
| 7366 | ScopeDeferExpr *defer_expr_scope = create_defer_expr_scope(irb->codegen, node, parent_scope); | 7366 | ScopeDeferExpr *defer_expr_scope = create_defer_expr_scope(ag->codegen, node, parent_scope); |
| 7367 | node->data.defer.expr_scope = &defer_expr_scope->base; | 7367 | node->data.defer.expr_scope = &defer_expr_scope->base; |
| 7368 | | 7368 | |
| 7369 | return ir_build_const_void(irb, parent_scope, node); | 7369 | return ir_build_const_void(ag, parent_scope, node); |
| 7370 | } | 7370 | } |
| 7371 | | 7371 | |
| 7372 | static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 7372 | static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 7373 | assert(node->type == NodeTypeSliceExpr); | 7373 | assert(node->type == NodeTypeSliceExpr); |
| 7374 | | 7374 | |
| 7375 | AstNodeSliceExpr *slice_expr = &node->data.slice_expr; | 7375 | AstNodeSliceExpr *slice_expr = &node->data.slice_expr; |
| ... | @@ -7378,38 +7378,38 @@ static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, L | ... | @@ -7378,38 +7378,38 @@ static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, L |
| 7378 | AstNode *end_node = slice_expr->end; | 7378 | AstNode *end_node = slice_expr->end; |
| 7379 | AstNode *sentinel_node = slice_expr->sentinel; | 7379 | AstNode *sentinel_node = slice_expr->sentinel; |
| 7380 | | 7380 | |
| 7381 | IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr); | 7381 | IrInstSrc *ptr_value = ir_gen_node_extra(ag, array_node, scope, LValPtr, nullptr); |
| 7382 | if (ptr_value == irb->codegen->invalid_inst_src) | 7382 | if (ptr_value == ag->codegen->invalid_inst_src) |
| 7383 | return irb->codegen->invalid_inst_src; | 7383 | return ag->codegen->invalid_inst_src; |
| 7384 | | 7384 | |
| 7385 | IrInstSrc *start_value = ir_gen_node(irb, start_node, scope); | 7385 | IrInstSrc *start_value = ir_gen_node(ag, start_node, scope); |
| 7386 | if (start_value == irb->codegen->invalid_inst_src) | 7386 | if (start_value == ag->codegen->invalid_inst_src) |
| 7387 | return irb->codegen->invalid_inst_src; | 7387 | return ag->codegen->invalid_inst_src; |
| 7388 | | 7388 | |
| 7389 | IrInstSrc *end_value; | 7389 | IrInstSrc *end_value; |
| 7390 | if (end_node) { | 7390 | if (end_node) { |
| 7391 | end_value = ir_gen_node(irb, end_node, scope); | 7391 | end_value = ir_gen_node(ag, end_node, scope); |
| 7392 | if (end_value == irb->codegen->invalid_inst_src) | 7392 | if (end_value == ag->codegen->invalid_inst_src) |
| 7393 | return irb->codegen->invalid_inst_src; | 7393 | return ag->codegen->invalid_inst_src; |
| 7394 | } else { | 7394 | } else { |
| 7395 | end_value = nullptr; | 7395 | end_value = nullptr; |
| 7396 | } | 7396 | } |
| 7397 | | 7397 | |
| 7398 | IrInstSrc *sentinel_value; | 7398 | IrInstSrc *sentinel_value; |
| 7399 | if (sentinel_node) { | 7399 | if (sentinel_node) { |
| 7400 | sentinel_value = ir_gen_node(irb, sentinel_node, scope); | 7400 | sentinel_value = ir_gen_node(ag, sentinel_node, scope); |
| 7401 | if (sentinel_value == irb->codegen->invalid_inst_src) | 7401 | if (sentinel_value == ag->codegen->invalid_inst_src) |
| 7402 | return irb->codegen->invalid_inst_src; | 7402 | return ag->codegen->invalid_inst_src; |
| 7403 | } else { | 7403 | } else { |
| 7404 | sentinel_value = nullptr; | 7404 | sentinel_value = nullptr; |
| 7405 | } | 7405 | } |
| 7406 | | 7406 | |
| 7407 | IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value, | 7407 | IrInstSrc *slice = ir_build_slice_src(ag, scope, node, ptr_value, start_value, end_value, |
| 7408 | sentinel_value, true, result_loc); | 7408 | sentinel_value, true, result_loc); |
| 7409 | return ir_lval_wrap(irb, scope, slice, lval, result_loc); | 7409 | return ir_lval_wrap(ag, scope, slice, lval, result_loc); |
| 7410 | } | 7410 | } |
| 7411 | | 7411 | |
| 7412 | static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, | 7412 | static IrInstSrc *ir_gen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, |
| 7413 | ResultLoc *result_loc) | 7413 | ResultLoc *result_loc) |
| 7414 | { | 7414 | { |
| 7415 | assert(node->type == NodeTypeCatchExpr); | 7415 | assert(node->type == NodeTypeCatchExpr); |
| ... | @@ -7422,77 +7422,77 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -7422,77 +7422,77 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 7422 | if (var_node != nullptr) { | 7422 | if (var_node != nullptr) { |
| 7423 | assert(var_node->type == NodeTypeIdentifier); | 7423 | assert(var_node->type == NodeTypeIdentifier); |
| 7424 | Buf *var_name = node_identifier_buf(var_node); | 7424 | Buf *var_name = node_identifier_buf(var_node); |
| 7425 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); | 7425 | add_node_error(ag->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 7426 | return irb->codegen->invalid_inst_src; | 7426 | return ag->codegen->invalid_inst_src; |
| 7427 | } | 7427 | } |
| 7428 | return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc); | 7428 | return ir_gen_catch_unreachable(ag, parent_scope, node, op1_node, lval, result_loc); |
| 7429 | } | 7429 | } |
| 7430 | | 7430 | |
| 7431 | | 7431 | |
| 7432 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, op1_node, parent_scope); | 7432 | ScopeExpr *spill_scope = create_expr_scope(ag->codegen, op1_node, parent_scope); |
| 7433 | spill_scope->spill_harder = true; | 7433 | spill_scope->spill_harder = true; |
| 7434 | | 7434 | |
| 7435 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, &spill_scope->base, LValPtr, nullptr); | 7435 | IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, op1_node, &spill_scope->base, LValPtr, nullptr); |
| 7436 | if (err_union_ptr == irb->codegen->invalid_inst_src) | 7436 | if (err_union_ptr == ag->codegen->invalid_inst_src) |
| 7437 | return irb->codegen->invalid_inst_src; | 7437 | return ag->codegen->invalid_inst_src; |
| 7438 | | 7438 | |
| 7439 | IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false); | 7439 | IrInstSrc *is_err = ir_build_test_err_src(ag, parent_scope, node, err_union_ptr, true, false); |
| 7440 | | 7440 | |
| 7441 | IrInstSrc *is_comptime; | 7441 | IrInstSrc *is_comptime; |
| 7442 | if (ir_should_inline(irb->exec, parent_scope)) { | 7442 | if (ir_should_inline(ag->exec, parent_scope)) { |
| 7443 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); | 7443 | is_comptime = ir_build_const_bool(ag, parent_scope, node, true); |
| 7444 | } else { | 7444 | } else { |
| 7445 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err); | 7445 | is_comptime = ir_build_test_comptime(ag, parent_scope, node, is_err); |
| 7446 | } | 7446 | } |
| 7447 | | 7447 | |
| 7448 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); | 7448 | IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrOk"); |
| 7449 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); | 7449 | IrBasicBlockSrc *err_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrError"); |
| 7450 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); | 7450 | IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrEnd"); |
| 7451 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); | 7451 | IrInstSrc *cond_br_inst = ir_build_cond_br(ag, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 7452 | | 7452 | |
| 7453 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc, | 7453 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(ag, cond_br_inst, ok_block, end_block, result_loc, |
| 7454 | is_comptime); | 7454 | is_comptime); |
| 7455 | | 7455 | |
| 7456 | ir_set_cursor_at_end_and_append_block(irb, err_block); | 7456 | ir_set_cursor_at_end_and_append_block(ag, err_block); |
| 7457 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, &spill_scope->base, is_comptime); | 7457 | Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, &spill_scope->base, is_comptime); |
| 7458 | Scope *err_scope; | 7458 | Scope *err_scope; |
| 7459 | if (var_node) { | 7459 | if (var_node) { |
| 7460 | assert(var_node->type == NodeTypeIdentifier); | 7460 | assert(var_node->type == NodeTypeIdentifier); |
| 7461 | Buf *var_name = node_identifier_buf(var_node); | 7461 | Buf *var_name = node_identifier_buf(var_node); |
| 7462 | bool is_const = true; | 7462 | bool is_const = true; |
| 7463 | bool is_shadowable = false; | 7463 | bool is_shadowable = false; |
| 7464 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name, | 7464 | ZigVar *var = ir_create_var(ag, node, subexpr_scope, var_name, |
| 7465 | is_const, is_const, is_shadowable, is_comptime); | 7465 | is_const, is_const, is_shadowable, is_comptime); |
| 7466 | err_scope = var->child_scope; | 7466 | err_scope = var->child_scope; |
| 7467 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr); | 7467 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(ag, err_scope, node, err_union_ptr); |
| 7468 | IrInstSrc *err_value = ir_build_load_ptr(irb, err_scope, var_node, err_ptr); | 7468 | IrInstSrc *err_value = ir_build_load_ptr(ag, err_scope, var_node, err_ptr); |
| 7469 | build_decl_var_and_init(irb, err_scope, var_node, var, err_value, buf_ptr(var_name), is_comptime); | 7469 | build_decl_var_and_init(ag, err_scope, var_node, var, err_value, buf_ptr(var_name), is_comptime); |
| 7470 | } else { | 7470 | } else { |
| 7471 | err_scope = subexpr_scope; | 7471 | err_scope = subexpr_scope; |
| 7472 | } | 7472 | } |
| 7473 | IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); | 7473 | IrInstSrc *err_result = ir_gen_node_extra(ag, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); |
| 7474 | if (err_result == irb->codegen->invalid_inst_src) | 7474 | if (err_result == ag->codegen->invalid_inst_src) |
| 7475 | return irb->codegen->invalid_inst_src; | 7475 | return ag->codegen->invalid_inst_src; |
| 7476 | IrBasicBlockSrc *after_err_block = irb->current_basic_block; | 7476 | IrBasicBlockSrc *after_err_block = ag->current_basic_block; |
| 7477 | if (!instr_is_unreachable(err_result)) | 7477 | if (!instr_is_unreachable(err_result)) |
| 7478 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); | 7478 | ir_mark_gen(ir_build_br(ag, parent_scope, node, end_block, is_comptime)); |
| 7479 | | 7479 | |
| 7480 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 7480 | ir_set_cursor_at_end_and_append_block(ag, ok_block); |
| 7481 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false); | 7481 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(ag, parent_scope, node, err_union_ptr, false, false); |
| 7482 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); | 7482 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(ag, parent_scope, node, unwrapped_ptr); |
| 7483 | ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); | 7483 | ir_build_end_expr(ag, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); |
| 7484 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; | 7484 | IrBasicBlockSrc *after_ok_block = ag->current_basic_block; |
| 7485 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); | 7485 | ir_build_br(ag, parent_scope, node, end_block, is_comptime); |
| 7486 | | 7486 | |
| 7487 | ir_set_cursor_at_end_and_append_block(irb, end_block); | 7487 | ir_set_cursor_at_end_and_append_block(ag, end_block); |
| 7488 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); | 7488 | IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2); |
| 7489 | incoming_values[0] = err_result; | 7489 | incoming_values[0] = err_result; |
| 7490 | incoming_values[1] = unwrapped_payload; | 7490 | incoming_values[1] = unwrapped_payload; |
| 7491 | IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2); | 7491 | IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2); |
| 7492 | incoming_blocks[0] = after_err_block; | 7492 | incoming_blocks[0] = after_err_block; |
| 7493 | incoming_blocks[1] = after_ok_block; | 7493 | incoming_blocks[1] = after_ok_block; |
| 7494 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); | 7494 | IrInstSrc *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7495 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); | 7495 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 7496 | } | 7496 | } |
| 7497 | | 7497 | |
| 7498 | static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *outer_scope, Scope *inner_scope) { | 7498 | static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *outer_scope, Scope *inner_scope) { |
| ... | @@ -7540,51 +7540,51 @@ Buf *get_anon_type_name(CodeGen *codegen, Stage1Zir *exec, const char *kind_name | ... | @@ -7540,51 +7540,51 @@ Buf *get_anon_type_name(CodeGen *codegen, Stage1Zir *exec, const char *kind_name |
| 7540 | } | 7540 | } |
| 7541 | } | 7541 | } |
| 7542 | | 7542 | |
| 7543 | static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 7543 | static IrInstSrc *ir_gen_container_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 7544 | assert(node->type == NodeTypeContainerDecl); | 7544 | assert(node->type == NodeTypeContainerDecl); |
| 7545 | | 7545 | |
| 7546 | ContainerKind kind = node->data.container_decl.kind; | 7546 | ContainerKind kind = node->data.container_decl.kind; |
| 7547 | Buf *bare_name = buf_alloc(); | 7547 | Buf *bare_name = buf_alloc(); |
| 7548 | Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), parent_scope, node, bare_name); | 7548 | Buf *name = get_anon_type_name(ag->codegen, ag->exec, container_string(kind), parent_scope, node, bare_name); |
| 7549 | | 7549 | |
| 7550 | ContainerLayout layout = node->data.container_decl.layout; | 7550 | ContainerLayout layout = node->data.container_decl.layout; |
| 7551 | ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope, | 7551 | ZigType *container_type = get_partial_container_type(ag->codegen, parent_scope, |
| 7552 | kind, node, buf_ptr(name), bare_name, layout); | 7552 | kind, node, buf_ptr(name), bare_name, layout); |
| 7553 | ScopeDecls *child_scope = get_container_scope(container_type); | 7553 | ScopeDecls *child_scope = get_container_scope(container_type); |
| 7554 | | 7554 | |
| 7555 | for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) { | 7555 | for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) { |
| 7556 | AstNode *child_node = node->data.container_decl.decls.at(i); | 7556 | AstNode *child_node = node->data.container_decl.decls.at(i); |
| 7557 | scan_decls(irb->codegen, child_scope, child_node); | 7557 | scan_decls(ag->codegen, child_scope, child_node); |
| 7558 | } | 7558 | } |
| 7559 | | 7559 | |
| 7560 | TldContainer *tld_container = heap::c_allocator.create<TldContainer>(); | 7560 | TldContainer *tld_container = heap::c_allocator.create<TldContainer>(); |
| 7561 | init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope); | 7561 | init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope); |
| 7562 | tld_container->type_entry = container_type; | 7562 | tld_container->type_entry = container_type; |
| 7563 | tld_container->decls_scope = child_scope; | 7563 | tld_container->decls_scope = child_scope; |
| 7564 | irb->codegen->resolve_queue.append(&tld_container->base); | 7564 | ag->codegen->resolve_queue.append(&tld_container->base); |
| 7565 | | 7565 | |
| 7566 | // Add this to the list to mark as invalid if analyzing this exec fails. | 7566 | // Add this to the list to mark as invalid if analyzing this exec fails. |
| 7567 | irb->exec->tld_list.append(&tld_container->base); | 7567 | ag->exec->tld_list.append(&tld_container->base); |
| 7568 | | 7568 | |
| 7569 | return ir_build_const_type(irb, parent_scope, node, container_type); | 7569 | return ir_build_const_type(ag, parent_scope, node, container_type); |
| 7570 | } | 7570 | } |
| 7571 | | 7571 | |
| 7572 | static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 7572 | static IrInstSrc *ir_gen_err_set_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 7573 | assert(node->type == NodeTypeErrorSetDecl); | 7573 | assert(node->type == NodeTypeErrorSetDecl); |
| 7574 | | 7574 | |
| 7575 | uint32_t err_count = node->data.err_set_decl.decls.length; | 7575 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| 7576 | | 7576 | |
| 7577 | Buf bare_name = BUF_INIT; | 7577 | Buf bare_name = BUF_INIT; |
| 7578 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", parent_scope, node, &bare_name); | 7578 | Buf *type_name = get_anon_type_name(ag->codegen, ag->exec, "error", parent_scope, node, &bare_name); |
| 7579 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); | 7579 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 7580 | buf_init_from_buf(&err_set_type->name, type_name); | 7580 | buf_init_from_buf(&err_set_type->name, type_name); |
| 7581 | err_set_type->data.error_set.err_count = err_count; | 7581 | err_set_type->data.error_set.err_count = err_count; |
| 7582 | err_set_type->size_in_bits = irb->codegen->builtin_types.entry_global_error_set->size_in_bits; | 7582 | err_set_type->size_in_bits = ag->codegen->builtin_types.entry_global_error_set->size_in_bits; |
| 7583 | err_set_type->abi_align = irb->codegen->builtin_types.entry_global_error_set->abi_align; | 7583 | err_set_type->abi_align = ag->codegen->builtin_types.entry_global_error_set->abi_align; |
| 7584 | err_set_type->abi_size = irb->codegen->builtin_types.entry_global_error_set->abi_size; | 7584 | err_set_type->abi_size = ag->codegen->builtin_types.entry_global_error_set->abi_size; |
| 7585 | err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(err_count); | 7585 | err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(err_count); |
| 7586 | | 7586 | |
| 7587 | size_t errors_count = irb->codegen->errors_by_index.length + err_count; | 7587 | size_t errors_count = ag->codegen->errors_by_index.length + err_count; |
| 7588 | ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count); | 7588 | ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count); |
| 7589 | | 7589 | |
| 7590 | for (uint32_t i = 0; i < err_count; i += 1) { | 7590 | for (uint32_t i = 0; i < err_count; i += 1) { |
| ... | @@ -7595,32 +7595,32 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As | ... | @@ -7595,32 +7595,32 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As |
| 7595 | err->decl_node = field_node; | 7595 | err->decl_node = field_node; |
| 7596 | buf_init_from_buf(&err->name, err_name); | 7596 | buf_init_from_buf(&err->name, err_name); |
| 7597 | | 7597 | |
| 7598 | auto existing_entry = irb->codegen->error_table.put_unique(err_name, err); | 7598 | auto existing_entry = ag->codegen->error_table.put_unique(err_name, err); |
| 7599 | if (existing_entry) { | 7599 | if (existing_entry) { |
| 7600 | err->value = existing_entry->value->value; | 7600 | err->value = existing_entry->value->value; |
| 7601 | } else { | 7601 | } else { |
| 7602 | size_t error_value_count = irb->codegen->errors_by_index.length; | 7602 | size_t error_value_count = ag->codegen->errors_by_index.length; |
| 7603 | assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)irb->codegen->err_tag_type->data.integral.bit_count)); | 7603 | assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ag->codegen->err_tag_type->data.integral.bit_count)); |
| 7604 | err->value = error_value_count; | 7604 | err->value = error_value_count; |
| 7605 | irb->codegen->errors_by_index.append(err); | 7605 | ag->codegen->errors_by_index.append(err); |
| 7606 | } | 7606 | } |
| 7607 | err_set_type->data.error_set.errors[i] = err; | 7607 | err_set_type->data.error_set.errors[i] = err; |
| 7608 | | 7608 | |
| 7609 | ErrorTableEntry *prev_err = errors[err->value]; | 7609 | ErrorTableEntry *prev_err = errors[err->value]; |
| 7610 | if (prev_err != nullptr) { | 7610 | if (prev_err != nullptr) { |
| 7611 | ErrorMsg *msg = add_node_error(irb->codegen, ast_field_to_symbol_node(err->decl_node), | 7611 | ErrorMsg *msg = add_node_error(ag->codegen, ast_field_to_symbol_node(err->decl_node), |
| 7612 | buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); | 7612 | buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); |
| 7613 | add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node), | 7613 | add_error_note(ag->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node), |
| 7614 | buf_sprintf("other error here")); | 7614 | buf_sprintf("other error here")); |
| 7615 | return irb->codegen->invalid_inst_src; | 7615 | return ag->codegen->invalid_inst_src; |
| 7616 | } | 7616 | } |
| 7617 | errors[err->value] = err; | 7617 | errors[err->value] = err; |
| 7618 | } | 7618 | } |
| 7619 | heap::c_allocator.deallocate(errors, errors_count); | 7619 | heap::c_allocator.deallocate(errors, errors_count); |
| 7620 | return ir_build_const_type(irb, parent_scope, node, err_set_type); | 7620 | return ir_build_const_type(ag, parent_scope, node, err_set_type); |
| 7621 | } | 7621 | } |
| 7622 | | 7622 | |
| 7623 | static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 7623 | static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 7624 | assert(node->type == NodeTypeFnProto); | 7624 | assert(node->type == NodeTypeFnProto); |
| 7625 | | 7625 | |
| 7626 | size_t param_count = node->data.fn_proto.params.length; | 7626 | size_t param_count = node->data.fn_proto.params.length; |
| ... | @@ -7635,9 +7635,9 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -7635,9 +7635,9 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 7635 | } | 7635 | } |
| 7636 | if (param_node->data.param_decl.anytype_token == 0) { | 7636 | if (param_node->data.param_decl.anytype_token == 0) { |
| 7637 | AstNode *type_node = param_node->data.param_decl.type; | 7637 | AstNode *type_node = param_node->data.param_decl.type; |
| 7638 | IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope); | 7638 | IrInstSrc *type_value = ir_gen_node(ag, type_node, parent_scope); |
| 7639 | if (type_value == irb->codegen->invalid_inst_src) | 7639 | if (type_value == ag->codegen->invalid_inst_src) |
| 7640 | return irb->codegen->invalid_inst_src; | 7640 | return ag->codegen->invalid_inst_src; |
| 7641 | param_types[i] = type_value; | 7641 | param_types[i] = type_value; |
| 7642 | } else { | 7642 | } else { |
| 7643 | param_types[i] = nullptr; | 7643 | param_types[i] = nullptr; |
| ... | @@ -7646,41 +7646,41 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -7646,41 +7646,41 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 7646 | | 7646 | |
| 7647 | IrInstSrc *align_value = nullptr; | 7647 | IrInstSrc *align_value = nullptr; |
| 7648 | if (node->data.fn_proto.align_expr != nullptr) { | 7648 | if (node->data.fn_proto.align_expr != nullptr) { |
| 7649 | align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope); | 7649 | align_value = ir_gen_node(ag, node->data.fn_proto.align_expr, parent_scope); |
| 7650 | if (align_value == irb->codegen->invalid_inst_src) | 7650 | if (align_value == ag->codegen->invalid_inst_src) |
| 7651 | return irb->codegen->invalid_inst_src; | 7651 | return ag->codegen->invalid_inst_src; |
| 7652 | } | 7652 | } |
| 7653 | | 7653 | |
| 7654 | IrInstSrc *callconv_value = nullptr; | 7654 | IrInstSrc *callconv_value = nullptr; |
| 7655 | if (node->data.fn_proto.callconv_expr != nullptr) { | 7655 | if (node->data.fn_proto.callconv_expr != nullptr) { |
| 7656 | callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope); | 7656 | callconv_value = ir_gen_node(ag, node->data.fn_proto.callconv_expr, parent_scope); |
| 7657 | if (callconv_value == irb->codegen->invalid_inst_src) | 7657 | if (callconv_value == ag->codegen->invalid_inst_src) |
| 7658 | return irb->codegen->invalid_inst_src; | 7658 | return ag->codegen->invalid_inst_src; |
| 7659 | } | 7659 | } |
| 7660 | | 7660 | |
| 7661 | IrInstSrc *return_type; | 7661 | IrInstSrc *return_type; |
| 7662 | if (node->data.fn_proto.return_type == nullptr) { | 7662 | if (node->data.fn_proto.return_type == nullptr) { |
| 7663 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | 7663 | return_type = ir_build_const_type(ag, parent_scope, node, ag->codegen->builtin_types.entry_void); |
| 7664 | } else { | 7664 | } else { |
| 7665 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | 7665 | return_type = ir_gen_node(ag, node->data.fn_proto.return_type, parent_scope); |
| 7666 | if (return_type == irb->codegen->invalid_inst_src) | 7666 | if (return_type == ag->codegen->invalid_inst_src) |
| 7667 | return irb->codegen->invalid_inst_src; | 7667 | return ag->codegen->invalid_inst_src; |
| 7668 | } | 7668 | } |
| 7669 | | 7669 | |
| 7670 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); | 7670 | return ir_build_fn_proto(ag, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); |
| 7671 | } | 7671 | } |
| 7672 | | 7672 | |
| 7673 | static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) { | 7673 | static IrInstSrc *ir_gen_resume(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| 7674 | assert(node->type == NodeTypeResume); | 7674 | assert(node->type == NodeTypeResume); |
| 7675 | | 7675 | |
| 7676 | IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr); | 7676 | IrInstSrc *target_inst = ir_gen_node_extra(ag, node->data.resume_expr.expr, scope, LValPtr, nullptr); |
| 7677 | if (target_inst == irb->codegen->invalid_inst_src) | 7677 | if (target_inst == ag->codegen->invalid_inst_src) |
| 7678 | return irb->codegen->invalid_inst_src; | 7678 | return ag->codegen->invalid_inst_src; |
| 7679 | | 7679 | |
| 7680 | return ir_build_resume_src(irb, scope, node, target_inst); | 7680 | return ir_build_resume_src(ag, scope, node, target_inst); |
| 7681 | } | 7681 | } |
| 7682 | | 7682 | |
| 7683 | static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, | 7683 | static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, |
| 7684 | ResultLoc *result_loc) | 7684 | ResultLoc *result_loc) |
| 7685 | { | 7685 | { |
| 7686 | assert(node->type == NodeTypeAwaitExpr); | 7686 | assert(node->type == NodeTypeAwaitExpr); |
| ... | @@ -7691,73 +7691,73 @@ static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no | ... | @@ -7691,73 +7691,73 @@ static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no |
| 7691 | if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.modifier == CallModifierBuiltin) { | 7691 | if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.modifier == CallModifierBuiltin) { |
| 7692 | AstNode *fn_ref_expr = expr_node->data.fn_call_expr.fn_ref_expr; | 7692 | AstNode *fn_ref_expr = expr_node->data.fn_call_expr.fn_ref_expr; |
| 7693 | Buf *name = node_identifier_buf(fn_ref_expr); | 7693 | Buf *name = node_identifier_buf(fn_ref_expr); |
| 7694 | auto entry = irb->codegen->builtin_fn_table.maybe_get(name); | 7694 | auto entry = ag->codegen->builtin_fn_table.maybe_get(name); |
| 7695 | if (entry != nullptr) { | 7695 | if (entry != nullptr) { |
| 7696 | BuiltinFnEntry *builtin_fn = entry->value; | 7696 | BuiltinFnEntry *builtin_fn = entry->value; |
| 7697 | if (builtin_fn->id == BuiltinFnIdAsyncCall) { | 7697 | if (builtin_fn->id == BuiltinFnIdAsyncCall) { |
| 7698 | return ir_gen_async_call(irb, scope, node, expr_node, lval, result_loc); | 7698 | return ir_gen_async_call(ag, scope, node, expr_node, lval, result_loc); |
| 7699 | } | 7699 | } |
| 7700 | } | 7700 | } |
| 7701 | } | 7701 | } |
| 7702 | | 7702 | |
| 7703 | ZigFn *fn_entry = exec_fn_entry(irb->exec); | 7703 | ZigFn *fn_entry = exec_fn_entry(ag->exec); |
| 7704 | if (!fn_entry) { | 7704 | if (!fn_entry) { |
| 7705 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); | 7705 | add_node_error(ag->codegen, node, buf_sprintf("await outside function definition")); |
| 7706 | return irb->codegen->invalid_inst_src; | 7706 | return ag->codegen->invalid_inst_src; |
| 7707 | } | 7707 | } |
| 7708 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope); | 7708 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope); |
| 7709 | if (existing_suspend_scope) { | 7709 | if (existing_suspend_scope) { |
| 7710 | if (!existing_suspend_scope->reported_err) { | 7710 | if (!existing_suspend_scope->reported_err) { |
| 7711 | ErrorMsg *msg = add_node_error(irb->codegen, node, buf_sprintf("cannot await inside suspend block")); | 7711 | ErrorMsg *msg = add_node_error(ag->codegen, node, buf_sprintf("cannot await inside suspend block")); |
| 7712 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here")); | 7712 | add_error_note(ag->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here")); |
| 7713 | existing_suspend_scope->reported_err = true; | 7713 | existing_suspend_scope->reported_err = true; |
| 7714 | } | 7714 | } |
| 7715 | return irb->codegen->invalid_inst_src; | 7715 | return ag->codegen->invalid_inst_src; |
| 7716 | } | 7716 | } |
| 7717 | | 7717 | |
| 7718 | IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); | 7718 | IrInstSrc *target_inst = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); |
| 7719 | if (target_inst == irb->codegen->invalid_inst_src) | 7719 | if (target_inst == ag->codegen->invalid_inst_src) |
| 7720 | return irb->codegen->invalid_inst_src; | 7720 | return ag->codegen->invalid_inst_src; |
| 7721 | | 7721 | |
| 7722 | IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc, is_nosuspend); | 7722 | IrInstSrc *await_inst = ir_build_await_src(ag, scope, node, target_inst, result_loc, is_nosuspend); |
| 7723 | return ir_lval_wrap(irb, scope, await_inst, lval, result_loc); | 7723 | return ir_lval_wrap(ag, scope, await_inst, lval, result_loc); |
| 7724 | } | 7724 | } |
| 7725 | | 7725 | |
| 7726 | static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { | 7726 | static IrInstSrc *ir_gen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { |
| 7727 | assert(node->type == NodeTypeSuspend); | 7727 | assert(node->type == NodeTypeSuspend); |
| 7728 | | 7728 | |
| 7729 | ZigFn *fn_entry = exec_fn_entry(irb->exec); | 7729 | ZigFn *fn_entry = exec_fn_entry(ag->exec); |
| 7730 | if (!fn_entry) { | 7730 | if (!fn_entry) { |
| 7731 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); | 7731 | add_node_error(ag->codegen, node, buf_sprintf("suspend outside function definition")); |
| 7732 | return irb->codegen->invalid_inst_src; | 7732 | return ag->codegen->invalid_inst_src; |
| 7733 | } | 7733 | } |
| 7734 | if (get_scope_nosuspend(parent_scope) != nullptr) { | 7734 | if (get_scope_nosuspend(parent_scope) != nullptr) { |
| 7735 | add_node_error(irb->codegen, node, buf_sprintf("suspend in nosuspend scope")); | 7735 | add_node_error(ag->codegen, node, buf_sprintf("suspend in nosuspend scope")); |
| 7736 | return irb->codegen->invalid_inst_src; | 7736 | return ag->codegen->invalid_inst_src; |
| 7737 | } | 7737 | } |
| 7738 | | 7738 | |
| 7739 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope); | 7739 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope); |
| 7740 | if (existing_suspend_scope) { | 7740 | if (existing_suspend_scope) { |
| 7741 | if (!existing_suspend_scope->reported_err) { | 7741 | if (!existing_suspend_scope->reported_err) { |
| 7742 | ErrorMsg *msg = add_node_error(irb->codegen, node, buf_sprintf("cannot suspend inside suspend block")); | 7742 | ErrorMsg *msg = add_node_error(ag->codegen, node, buf_sprintf("cannot suspend inside suspend block")); |
| 7743 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here")); | 7743 | add_error_note(ag->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here")); |
| 7744 | existing_suspend_scope->reported_err = true; | 7744 | existing_suspend_scope->reported_err = true; |
| 7745 | } | 7745 | } |
| 7746 | return irb->codegen->invalid_inst_src; | 7746 | return ag->codegen->invalid_inst_src; |
| 7747 | } | 7747 | } |
| 7748 | | 7748 | |
| 7749 | IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node); | 7749 | IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(ag, parent_scope, node); |
| 7750 | ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope); | 7750 | ScopeSuspend *suspend_scope = create_suspend_scope(ag->codegen, node, parent_scope); |
| 7751 | Scope *child_scope = &suspend_scope->base; | 7751 | Scope *child_scope = &suspend_scope->base; |
| 7752 | IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope); | 7752 | IrInstSrc *susp_res = ir_gen_node(ag, node->data.suspend.block, child_scope); |
| 7753 | if (susp_res == irb->codegen->invalid_inst_src) | 7753 | if (susp_res == ag->codegen->invalid_inst_src) |
| 7754 | return irb->codegen->invalid_inst_src; | 7754 | return ag->codegen->invalid_inst_src; |
| 7755 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res)); | 7755 | ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, node->data.suspend.block, susp_res)); |
| 7756 | | 7756 | |
| 7757 | return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin)); | 7757 | return ir_mark_gen(ir_build_suspend_finish_src(ag, parent_scope, node, begin)); |
| 7758 | } | 7758 | } |
| 7759 | | 7759 | |
| 7760 | static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope, | 7760 | static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, |
| 7761 | LVal lval, ResultLoc *result_loc) | 7761 | LVal lval, ResultLoc *result_loc) |
| 7762 | { | 7762 | { |
| 7763 | assert(scope); | 7763 | assert(scope); |
| ... | @@ -7773,47 +7773,47 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope | ... | @@ -7773,47 +7773,47 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope |
| 7773 | case NodeTypeTestDecl: | 7773 | case NodeTypeTestDecl: |
| 7774 | zig_unreachable(); | 7774 | zig_unreachable(); |
| 7775 | case NodeTypeBlock: | 7775 | case NodeTypeBlock: |
| 7776 | return ir_gen_block(irb, scope, node, lval, result_loc); | 7776 | return ir_gen_block(ag, scope, node, lval, result_loc); |
| 7777 | case NodeTypeGroupedExpr: | 7777 | case NodeTypeGroupedExpr: |
| 7778 | return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval, result_loc); | 7778 | return ir_gen_node_raw(ag, node->data.grouped_expr, scope, lval, result_loc); |
| 7779 | case NodeTypeBinOpExpr: | 7779 | case NodeTypeBinOpExpr: |
| 7780 | return ir_gen_bin_op(irb, scope, node, lval, result_loc); | 7780 | return ir_gen_bin_op(ag, scope, node, lval, result_loc); |
| 7781 | case NodeTypeIntLiteral: | 7781 | case NodeTypeIntLiteral: |
| 7782 | return ir_lval_wrap(irb, scope, ir_gen_int_lit(irb, scope, node), lval, result_loc); | 7782 | return ir_lval_wrap(ag, scope, ir_gen_int_lit(ag, scope, node), lval, result_loc); |
| 7783 | case NodeTypeFloatLiteral: | 7783 | case NodeTypeFloatLiteral: |
| 7784 | return ir_lval_wrap(irb, scope, ir_gen_float_lit(irb, scope, node), lval, result_loc); | 7784 | return ir_lval_wrap(ag, scope, ir_gen_float_lit(ag, scope, node), lval, result_loc); |
| 7785 | case NodeTypeCharLiteral: | 7785 | case NodeTypeCharLiteral: |
| 7786 | return ir_lval_wrap(irb, scope, ir_gen_char_lit(irb, scope, node), lval, result_loc); | 7786 | return ir_lval_wrap(ag, scope, ir_gen_char_lit(ag, scope, node), lval, result_loc); |
| 7787 | case NodeTypeIdentifier: | 7787 | case NodeTypeIdentifier: |
| 7788 | return ir_gen_symbol(irb, scope, node, lval, result_loc); | 7788 | return ir_gen_symbol(ag, scope, node, lval, result_loc); |
| 7789 | case NodeTypeFnCallExpr: | 7789 | case NodeTypeFnCallExpr: |
| 7790 | return ir_gen_fn_call(irb, scope, node, lval, result_loc); | 7790 | return ir_gen_fn_call(ag, scope, node, lval, result_loc); |
| 7791 | case NodeTypeIfBoolExpr: | 7791 | case NodeTypeIfBoolExpr: |
| 7792 | return ir_gen_if_bool_expr(irb, scope, node, lval, result_loc); | 7792 | return ir_gen_if_bool_expr(ag, scope, node, lval, result_loc); |
| 7793 | case NodeTypePrefixOpExpr: | 7793 | case NodeTypePrefixOpExpr: |
| 7794 | return ir_gen_prefix_op_expr(irb, scope, node, lval, result_loc); | 7794 | return ir_gen_prefix_op_expr(ag, scope, node, lval, result_loc); |
| 7795 | case NodeTypeContainerInitExpr: | 7795 | case NodeTypeContainerInitExpr: |
| 7796 | return ir_gen_container_init_expr(irb, scope, node, lval, result_loc); | 7796 | return ir_gen_container_init_expr(ag, scope, node, lval, result_loc); |
| 7797 | case NodeTypeVariableDeclaration: | 7797 | case NodeTypeVariableDeclaration: |
| 7798 | return ir_gen_var_decl(irb, scope, node); | 7798 | return ir_gen_var_decl(ag, scope, node); |
| 7799 | case NodeTypeWhileExpr: | 7799 | case NodeTypeWhileExpr: |
| 7800 | return ir_gen_while_expr(irb, scope, node, lval, result_loc); | 7800 | return ir_gen_while_expr(ag, scope, node, lval, result_loc); |
| 7801 | case NodeTypeForExpr: | 7801 | case NodeTypeForExpr: |
| 7802 | return ir_gen_for_expr(irb, scope, node, lval, result_loc); | 7802 | return ir_gen_for_expr(ag, scope, node, lval, result_loc); |
| 7803 | case NodeTypeArrayAccessExpr: | 7803 | case NodeTypeArrayAccessExpr: |
| 7804 | return ir_gen_array_access(irb, scope, node, lval, result_loc); | 7804 | return ir_gen_array_access(ag, scope, node, lval, result_loc); |
| 7805 | case NodeTypeReturnExpr: | 7805 | case NodeTypeReturnExpr: |
| 7806 | return ir_gen_return(irb, scope, node, lval, result_loc); | 7806 | return ir_gen_return(ag, scope, node, lval, result_loc); |
| 7807 | case NodeTypeFieldAccessExpr: | 7807 | case NodeTypeFieldAccessExpr: |
| 7808 | { | 7808 | { |
| 7809 | IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node); | 7809 | IrInstSrc *ptr_instruction = ir_gen_field_access(ag, scope, node); |
| 7810 | if (ptr_instruction == irb->codegen->invalid_inst_src) | 7810 | if (ptr_instruction == ag->codegen->invalid_inst_src) |
| 7811 | return ptr_instruction; | 7811 | return ptr_instruction; |
| 7812 | if (lval == LValPtr || lval == LValAssign) | 7812 | if (lval == LValPtr || lval == LValAssign) |
| 7813 | return ptr_instruction; | 7813 | return ptr_instruction; |
| 7814 | | 7814 | |
| 7815 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); | 7815 | IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction); |
| 7816 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); | 7816 | return ir_expr_wrap(ag, scope, load_ptr, result_loc); |
| 7817 | } | 7817 | } |
| 7818 | case NodeTypePtrDeref: { | 7818 | case NodeTypePtrDeref: { |
| 7819 | AstNode *expr_node = node->data.ptr_deref_expr.target; | 7819 | AstNode *expr_node = node->data.ptr_deref_expr.target; |
| ... | @@ -7822,91 +7822,91 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope | ... | @@ -7822,91 +7822,91 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope |
| 7822 | if (child_lval == LValAssign) | 7822 | if (child_lval == LValAssign) |
| 7823 | child_lval = LValPtr; | 7823 | child_lval = LValPtr; |
| 7824 | | 7824 | |
| 7825 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, child_lval, nullptr); | 7825 | IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, child_lval, nullptr); |
| 7826 | if (value == irb->codegen->invalid_inst_src) | 7826 | if (value == ag->codegen->invalid_inst_src) |
| 7827 | return value; | 7827 | return value; |
| 7828 | | 7828 | |
| 7829 | // We essentially just converted any lvalue from &(x.*) to (&x).*; | 7829 | // We essentially just converted any lvalue from &(x.*) to (&x).*; |
| 7830 | // this inhibits checking that x is a pointer later, so we directly | 7830 | // this inhibits checking that x is a pointer later, so we directly |
| 7831 | // record whether the pointer check is needed | 7831 | // record whether the pointer check is needed |
| 7832 | IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc); | 7832 | IrInstSrc *un_op = ir_build_un_op_lval(ag, scope, node, IrUnOpDereference, value, lval, result_loc); |
| 7833 | return ir_expr_wrap(irb, scope, un_op, result_loc); | 7833 | return ir_expr_wrap(ag, scope, un_op, result_loc); |
| 7834 | } | 7834 | } |
| 7835 | case NodeTypeUnwrapOptional: { | 7835 | case NodeTypeUnwrapOptional: { |
| 7836 | AstNode *expr_node = node->data.unwrap_optional.expr; | 7836 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| 7837 | | 7837 | |
| 7838 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); | 7838 | IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); |
| 7839 | if (maybe_ptr == irb->codegen->invalid_inst_src) | 7839 | if (maybe_ptr == ag->codegen->invalid_inst_src) |
| 7840 | return irb->codegen->invalid_inst_src; | 7840 | return ag->codegen->invalid_inst_src; |
| 7841 | | 7841 | |
| 7842 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true ); | 7842 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(ag, scope, node, maybe_ptr, true ); |
| 7843 | if (lval == LValPtr || lval == LValAssign) | 7843 | if (lval == LValPtr || lval == LValAssign) |
| 7844 | return unwrapped_ptr; | 7844 | return unwrapped_ptr; |
| 7845 | | 7845 | |
| 7846 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr); | 7846 | IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, unwrapped_ptr); |
| 7847 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); | 7847 | return ir_expr_wrap(ag, scope, load_ptr, result_loc); |
| 7848 | } | 7848 | } |
| 7849 | case NodeTypeBoolLiteral: | 7849 | case NodeTypeBoolLiteral: |
| 7850 | return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval, result_loc); | 7850 | return ir_lval_wrap(ag, scope, ir_gen_bool_literal(ag, scope, node), lval, result_loc); |
| 7851 | case NodeTypeArrayType: | 7851 | case NodeTypeArrayType: |
| 7852 | return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval, result_loc); | 7852 | return ir_lval_wrap(ag, scope, ir_gen_array_type(ag, scope, node), lval, result_loc); |
| 7853 | case NodeTypePointerType: | 7853 | case NodeTypePointerType: |
| 7854 | return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval, result_loc); | 7854 | return ir_lval_wrap(ag, scope, ir_gen_pointer_type(ag, scope, node), lval, result_loc); |
| 7855 | case NodeTypeAnyFrameType: | 7855 | case NodeTypeAnyFrameType: |
| 7856 | return ir_lval_wrap(irb, scope, ir_gen_anyframe_type(irb, scope, node), lval, result_loc); | 7856 | return ir_lval_wrap(ag, scope, ir_gen_anyframe_type(ag, scope, node), lval, result_loc); |
| 7857 | case NodeTypeStringLiteral: | 7857 | case NodeTypeStringLiteral: |
| 7858 | return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval, result_loc); | 7858 | return ir_lval_wrap(ag, scope, ir_gen_string_literal(ag, scope, node), lval, result_loc); |
| 7859 | case NodeTypeUndefinedLiteral: | 7859 | case NodeTypeUndefinedLiteral: |
| 7860 | return ir_lval_wrap(irb, scope, ir_gen_undefined_literal(irb, scope, node), lval, result_loc); | 7860 | return ir_lval_wrap(ag, scope, ir_gen_undefined_literal(ag, scope, node), lval, result_loc); |
| 7861 | case NodeTypeAsmExpr: | 7861 | case NodeTypeAsmExpr: |
| 7862 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval, result_loc); | 7862 | return ir_lval_wrap(ag, scope, ir_gen_asm_expr(ag, scope, node), lval, result_loc); |
| 7863 | case NodeTypeNullLiteral: | 7863 | case NodeTypeNullLiteral: |
| 7864 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval, result_loc); | 7864 | return ir_lval_wrap(ag, scope, ir_gen_null_literal(ag, scope, node), lval, result_loc); |
| 7865 | case NodeTypeIfErrorExpr: | 7865 | case NodeTypeIfErrorExpr: |
| 7866 | return ir_gen_if_err_expr(irb, scope, node, lval, result_loc); | 7866 | return ir_gen_if_err_expr(ag, scope, node, lval, result_loc); |
| 7867 | case NodeTypeIfOptional: | 7867 | case NodeTypeIfOptional: |
| 7868 | return ir_gen_if_optional_expr(irb, scope, node, lval, result_loc); | 7868 | return ir_gen_if_optional_expr(ag, scope, node, lval, result_loc); |
| 7869 | case NodeTypeSwitchExpr: | 7869 | case NodeTypeSwitchExpr: |
| 7870 | return ir_gen_switch_expr(irb, scope, node, lval, result_loc); | 7870 | return ir_gen_switch_expr(ag, scope, node, lval, result_loc); |
| 7871 | case NodeTypeCompTime: | 7871 | case NodeTypeCompTime: |
| 7872 | return ir_expr_wrap(irb, scope, ir_gen_comptime(irb, scope, node, lval), result_loc); | 7872 | return ir_expr_wrap(ag, scope, ir_gen_comptime(ag, scope, node, lval), result_loc); |
| 7873 | case NodeTypeNoSuspend: | 7873 | case NodeTypeNoSuspend: |
| 7874 | return ir_expr_wrap(irb, scope, ir_gen_nosuspend(irb, scope, node, lval), result_loc); | 7874 | return ir_expr_wrap(ag, scope, ir_gen_nosuspend(ag, scope, node, lval), result_loc); |
| 7875 | case NodeTypeErrorType: | 7875 | case NodeTypeErrorType: |
| 7876 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval, result_loc); | 7876 | return ir_lval_wrap(ag, scope, ir_gen_error_type(ag, scope, node), lval, result_loc); |
| 7877 | case NodeTypeBreak: | 7877 | case NodeTypeBreak: |
| 7878 | return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval, result_loc); | 7878 | return ir_lval_wrap(ag, scope, ir_gen_break(ag, scope, node), lval, result_loc); |
| 7879 | case NodeTypeContinue: | 7879 | case NodeTypeContinue: |
| 7880 | return ir_lval_wrap(irb, scope, ir_gen_continue(irb, scope, node), lval, result_loc); | 7880 | return ir_lval_wrap(ag, scope, ir_gen_continue(ag, scope, node), lval, result_loc); |
| 7881 | case NodeTypeUnreachable: | 7881 | case NodeTypeUnreachable: |
| 7882 | return ir_build_unreachable(irb, scope, node); | 7882 | return ir_build_unreachable(ag, scope, node); |
| 7883 | case NodeTypeDefer: | 7883 | case NodeTypeDefer: |
| 7884 | return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval, result_loc); | 7884 | return ir_lval_wrap(ag, scope, ir_gen_defer(ag, scope, node), lval, result_loc); |
| 7885 | case NodeTypeSliceExpr: | 7885 | case NodeTypeSliceExpr: |
| 7886 | return ir_gen_slice(irb, scope, node, lval, result_loc); | 7886 | return ir_gen_slice(ag, scope, node, lval, result_loc); |
| 7887 | case NodeTypeCatchExpr: | 7887 | case NodeTypeCatchExpr: |
| 7888 | return ir_gen_catch(irb, scope, node, lval, result_loc); | 7888 | return ir_gen_catch(ag, scope, node, lval, result_loc); |
| 7889 | case NodeTypeContainerDecl: | 7889 | case NodeTypeContainerDecl: |
| 7890 | return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval, result_loc); | 7890 | return ir_lval_wrap(ag, scope, ir_gen_container_decl(ag, scope, node), lval, result_loc); |
| 7891 | case NodeTypeFnProto: | 7891 | case NodeTypeFnProto: |
| 7892 | return ir_lval_wrap(irb, scope, ir_gen_fn_proto(irb, scope, node), lval, result_loc); | 7892 | return ir_lval_wrap(ag, scope, ir_gen_fn_proto(ag, scope, node), lval, result_loc); |
| 7893 | case NodeTypeErrorSetDecl: | 7893 | case NodeTypeErrorSetDecl: |
| 7894 | return ir_lval_wrap(irb, scope, ir_gen_err_set_decl(irb, scope, node), lval, result_loc); | 7894 | return ir_lval_wrap(ag, scope, ir_gen_err_set_decl(ag, scope, node), lval, result_loc); |
| 7895 | case NodeTypeResume: | 7895 | case NodeTypeResume: |
| 7896 | return ir_lval_wrap(irb, scope, ir_gen_resume(irb, scope, node), lval, result_loc); | 7896 | return ir_lval_wrap(ag, scope, ir_gen_resume(ag, scope, node), lval, result_loc); |
| 7897 | case NodeTypeAwaitExpr: | 7897 | case NodeTypeAwaitExpr: |
| 7898 | return ir_gen_await_expr(irb, scope, node, lval, result_loc); | 7898 | return ir_gen_await_expr(ag, scope, node, lval, result_loc); |
| 7899 | case NodeTypeSuspend: | 7899 | case NodeTypeSuspend: |
| 7900 | return ir_lval_wrap(irb, scope, ir_gen_suspend(irb, scope, node), lval, result_loc); | 7900 | return ir_lval_wrap(ag, scope, ir_gen_suspend(ag, scope, node), lval, result_loc); |
| 7901 | case NodeTypeEnumLiteral: | 7901 | case NodeTypeEnumLiteral: |
| 7902 | return ir_lval_wrap(irb, scope, ir_gen_enum_literal(irb, scope, node), lval, result_loc); | 7902 | return ir_lval_wrap(ag, scope, ir_gen_enum_literal(ag, scope, node), lval, result_loc); |
| 7903 | case NodeTypeInferredArrayType: | 7903 | case NodeTypeInferredArrayType: |
| 7904 | add_node_error(irb->codegen, node, | 7904 | add_node_error(ag->codegen, node, |
| 7905 | buf_sprintf("inferred array size invalid here")); | 7905 | buf_sprintf("inferred array size invalid here")); |
| 7906 | return irb->codegen->invalid_inst_src; | 7906 | return ag->codegen->invalid_inst_src; |
| 7907 | case NodeTypeAnyTypeField: | 7907 | case NodeTypeAnyTypeField: |
| 7908 | return ir_lval_wrap(irb, scope, | 7908 | return ir_lval_wrap(ag, scope, |
| 7909 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_anytype), lval, result_loc); | 7909 | ir_build_const_type(ag, scope, node, ag->codegen->builtin_types.entry_anytype), lval, result_loc); |
| 7910 | } | 7910 | } |
| 7911 | zig_unreachable(); | 7911 | zig_unreachable(); |
| 7912 | } | 7912 | } |
| ... | @@ -7917,7 +7917,7 @@ ResultLoc *no_result_loc(void) { | ... | @@ -7917,7 +7917,7 @@ ResultLoc *no_result_loc(void) { |
| 7917 | return &result_loc_none->base; | 7917 | return &result_loc_none->base; |
| 7918 | } | 7918 | } |
| 7919 | | 7919 | |
| 7920 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, | 7920 | static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, |
| 7921 | ResultLoc *result_loc) | 7921 | ResultLoc *result_loc) |
| 7922 | { | 7922 | { |
| 7923 | if (lval == LValAssign) { | 7923 | if (lval == LValAssign) { |
| ... | @@ -7976,30 +7976,30 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco | ... | @@ -7976,30 +7976,30 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco |
| 7976 | case NodeTypeInferredArrayType: | 7976 | case NodeTypeInferredArrayType: |
| 7977 | case NodeTypeAnyTypeField: | 7977 | case NodeTypeAnyTypeField: |
| 7978 | case NodeTypePrefixOpExpr: | 7978 | case NodeTypePrefixOpExpr: |
| 7979 | add_node_error(irb->codegen, node, | 7979 | add_node_error(ag->codegen, node, |
| 7980 | buf_sprintf("invalid left-hand side to assignment")); | 7980 | buf_sprintf("invalid left-hand side to assignment")); |
| 7981 | return irb->codegen->invalid_inst_src; | 7981 | return ag->codegen->invalid_inst_src; |
| 7982 | | 7982 | |
| 7983 | // @field can be assigned to | 7983 | // @field can be assigned to |
| 7984 | case NodeTypeFnCallExpr: | 7984 | case NodeTypeFnCallExpr: |
| 7985 | if (node->data.fn_call_expr.modifier == CallModifierBuiltin) { | 7985 | if (node->data.fn_call_expr.modifier == CallModifierBuiltin) { |
| 7986 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; | 7986 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; |
| 7987 | Buf *name = node_identifier_buf(fn_ref_expr); | 7987 | Buf *name = node_identifier_buf(fn_ref_expr); |
| 7988 | auto entry = irb->codegen->builtin_fn_table.maybe_get(name); | 7988 | auto entry = ag->codegen->builtin_fn_table.maybe_get(name); |
| 7989 | | 7989 | |
| 7990 | if (!entry) { | 7990 | if (!entry) { |
| 7991 | add_node_error(irb->codegen, node, | 7991 | add_node_error(ag->codegen, node, |
| 7992 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); | 7992 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); |
| 7993 | return irb->codegen->invalid_inst_src; | 7993 | return ag->codegen->invalid_inst_src; |
| 7994 | } | 7994 | } |
| 7995 | | 7995 | |
| 7996 | if (entry->value->id == BuiltinFnIdField) { | 7996 | if (entry->value->id == BuiltinFnIdField) { |
| 7997 | break; | 7997 | break; |
| 7998 | } | 7998 | } |
| 7999 | } | 7999 | } |
| 8000 | add_node_error(irb->codegen, node, | 8000 | add_node_error(ag->codegen, node, |
| 8001 | buf_sprintf("invalid left-hand side to assignment")); | 8001 | buf_sprintf("invalid left-hand side to assignment")); |
| 8002 | return irb->codegen->invalid_inst_src; | 8002 | return ag->codegen->invalid_inst_src; |
| 8003 | | 8003 | |
| 8004 | | 8004 | |
| 8005 | // can be assigned to | 8005 | // can be assigned to |
| ... | @@ -8015,62 +8015,62 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco | ... | @@ -8015,62 +8015,62 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco |
| 8015 | // Create a result location indicating there is none - but if one gets created | 8015 | // Create a result location indicating there is none - but if one gets created |
| 8016 | // it will be properly distributed. | 8016 | // it will be properly distributed. |
| 8017 | result_loc = no_result_loc(); | 8017 | result_loc = no_result_loc(); |
| 8018 | ir_build_reset_result(irb, scope, node, result_loc); | 8018 | ir_build_reset_result(ag, scope, node, result_loc); |
| 8019 | } | 8019 | } |
| 8020 | Scope *child_scope; | 8020 | Scope *child_scope; |
| 8021 | if (irb->exec->is_inline || | 8021 | if (ag->exec->is_inline || |
| 8022 | (irb->exec->fn_entry != nullptr && irb->exec->fn_entry->child_scope == scope)) | 8022 | (ag->exec->fn_entry != nullptr && ag->exec->fn_entry->child_scope == scope)) |
| 8023 | { | 8023 | { |
| 8024 | child_scope = scope; | 8024 | child_scope = scope; |
| 8025 | } else { | 8025 | } else { |
| 8026 | child_scope = &create_expr_scope(irb->codegen, node, scope)->base; | 8026 | child_scope = &create_expr_scope(ag->codegen, node, scope)->base; |
| 8027 | } | 8027 | } |
| 8028 | IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc); | 8028 | IrInstSrc *result = ir_gen_node_raw(ag, node, child_scope, lval, result_loc); |
| 8029 | if (result == irb->codegen->invalid_inst_src) { | 8029 | if (result == ag->codegen->invalid_inst_src) { |
| 8030 | if (irb->exec->first_err_trace_msg == nullptr) { | 8030 | if (ag->exec->first_err_trace_msg == nullptr) { |
| 8031 | irb->exec->first_err_trace_msg = irb->codegen->trace_err; | 8031 | ag->exec->first_err_trace_msg = ag->codegen->trace_err; |
| 8032 | } | 8032 | } |
| 8033 | } | 8033 | } |
| 8034 | return result; | 8034 | return result; |
| 8035 | } | 8035 | } |
| 8036 | | 8036 | |
| 8037 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) { | 8037 | static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) { |
| 8038 | return ir_gen_node_extra(irb, node, scope, LValNone, nullptr); | 8038 | return ir_gen_node_extra(ag, node, scope, LValNone, nullptr); |
| 8039 | } | 8039 | } |
| 8040 | | 8040 | |
| 8041 | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable) { | 8041 | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable) { |
| 8042 | assert(node->owner); | 8042 | assert(node->owner); |
| 8043 | | 8043 | |
| 8044 | IrBuilderSrc ir_builder = {0}; | 8044 | Stage1AstGen ir_builder = {0}; |
| 8045 | IrBuilderSrc *irb = &ir_builder; | 8045 | Stage1AstGen *ag = &ir_builder; |
| 8046 | | 8046 | |
| 8047 | irb->codegen = codegen; | 8047 | ag->codegen = codegen; |
| 8048 | irb->exec = ir_executable; | 8048 | ag->exec = ir_executable; |
| 8049 | irb->main_block_node = node; | 8049 | ag->main_block_node = node; |
| 8050 | | 8050 | |
| 8051 | IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry"); | 8051 | IrBasicBlockSrc *entry_block = ir_create_basic_block(ag, scope, "Entry"); |
| 8052 | ir_set_cursor_at_end_and_append_block(irb, entry_block); | 8052 | ir_set_cursor_at_end_and_append_block(ag, entry_block); |
| 8053 | // Entry block gets a reference because we enter it to begin. | 8053 | // Entry block gets a reference because we enter it to begin. |
| 8054 | ir_ref_bb(irb->current_basic_block); | 8054 | ir_ref_bb(ag->current_basic_block); |
| 8055 | | 8055 | |
| 8056 | IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr); | 8056 | IrInstSrc *result = ir_gen_node_extra(ag, node, scope, LValNone, nullptr); |
| 8057 | | 8057 | |
| 8058 | if (result == irb->codegen->invalid_inst_src) | 8058 | if (result == ag->codegen->invalid_inst_src) |
| 8059 | return false; | 8059 | return false; |
| 8060 | | 8060 | |
| 8061 | if (irb->exec->first_err_trace_msg != nullptr) { | 8061 | if (ag->exec->first_err_trace_msg != nullptr) { |
| 8062 | codegen->trace_err = irb->exec->first_err_trace_msg; | 8062 | codegen->trace_err = ag->exec->first_err_trace_msg; |
| 8063 | return false; | 8063 | return false; |
| 8064 | } | 8064 | } |
| 8065 | | 8065 | |
| 8066 | if (!instr_is_unreachable(result)) { | 8066 | if (!instr_is_unreachable(result)) { |
| 8067 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr)); | 8067 | ir_mark_gen(ir_build_add_implicit_return_type(ag, scope, result->base.source_node, result, nullptr)); |
| 8068 | // no need for save_err_ret_addr because this cannot return error | 8068 | // no need for save_err_ret_addr because this cannot return error |
| 8069 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); | 8069 | ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>(); |
| 8070 | result_loc_ret->base.id = ResultLocIdReturn; | 8070 | result_loc_ret->base.id = ResultLocIdReturn; |
| 8071 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); | 8071 | ir_build_reset_result(ag, scope, node, &result_loc_ret->base); |
| 8072 | ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base)); | 8072 | ir_mark_gen(ir_build_end_expr(ag, scope, node, result, &result_loc_ret->base)); |
| 8073 | ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result)); | 8073 | ir_mark_gen(ir_build_return_src(ag, scope, result->base.source_node, result)); |
| 8074 | } | 8074 | } |
| 8075 | | 8075 | |
| 8076 | return true; | 8076 | return true; |