authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-27 20:42:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 12:58:40-07:00
log42f4ee0aebf274e74ece73157a63bbc0c6383c31
tree4feee13d9f48748243b88401c6e0ce59fa656d8c
parent2440c08ab02f7d7b82deb3bd4eeaafb33483307f

stage1: rename IrBuilderSrc to Stage1AstGen


1 files changed, 2263 insertions(+), 2263 deletions(-)

src/stage1/astgen.cpp+2263-2263
......@@ -11,7 +11,7 @@
1111#include "os.hpp"
1212#include "parser.hpp"
1313
14struct IrBuilderSrc {
14struct Stage1AstGen {
1515 CodeGen *codegen;
1616 Stage1Zir *exec;
1717 IrBasicBlockSrc *current_basic_block;
......@@ -19,22 +19,22 @@ struct IrBuilderSrc {
1919 size_t next_debug_id;
2020};
2121
22static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope);
23static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
22static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope);
23static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval,
2424 ResultLoc *result_loc);
2525
26static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval,
26static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value, LVal lval,
2727 ResultLoc *result_loc);
28static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst,
28static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst,
2929 ResultLoc *result_loc);
30static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
30static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
3131 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
3232 LVal lval, ResultLoc *parent_result_loc);
33static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
33static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest_type,
3434 ResultLoc *parent_result_loc);
35static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
35static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf *name,
3636 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime);
37static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
37static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
3838 ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime);
3939
4040static 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
362362 basic_block->instruction_list.append(instruction);
363363}
364364
365static size_t irb_next_debug_id(IrBuilderSrc *irb) {
366 size_t result = irb->next_debug_id;
367 irb->next_debug_id += 1;
365static size_t irb_next_debug_id(Stage1AstGen *ag) {
366 size_t result = ag->next_debug_id;
367 ag->next_debug_id += 1;
368368 return result;
369369}
370370
......@@ -390,11 +390,11 @@ static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb)
390390 }
391391}
392392
393static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
393static IrBasicBlockSrc *ir_create_basic_block(Stage1AstGen *ag, Scope *scope, const char *name_hint) {
394394 IrBasicBlockSrc *result = heap::c_allocator.create<IrBasicBlockSrc>();
395395 result->scope = scope;
396396 result->name_hint = name_hint;
397 result->debug_id = irb_next_debug_id(irb);
397 result->debug_id = irb_next_debug_id(ag);
398398 result->index = UINT32_MAX; // set later
399399 return result;
400400}
......@@ -932,208 +932,208 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSrc *) {
932932}
933933
934934template<typename T>
935static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
935static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
936936 T *special_instruction = heap::c_allocator.create<T>();
937937 special_instruction->base.id = ir_inst_id(special_instruction);
938938 special_instruction->base.base.scope = scope;
939939 special_instruction->base.base.source_node = source_node;
940 special_instruction->base.base.debug_id = irb_next_debug_id(irb);
941 special_instruction->base.owner_bb = irb->current_basic_block;
940 special_instruction->base.base.debug_id = irb_next_debug_id(ag);
941 special_instruction->base.owner_bb = ag->current_basic_block;
942942 return special_instruction;
943943}
944944
945945template<typename T>
946static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
947 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);
948 ir_instruction_append(irb->current_basic_block, &special_instruction->base);
946static T *ir_build_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
947 T *special_instruction = ir_create_instruction<T>(ag, scope, source_node);
948 ir_instruction_append(ag->current_basic_block, &special_instruction->base);
949949 return special_instruction;
950950}
951951
952static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition,
952static IrInstSrc *ir_build_cond_br(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *condition,
953953 IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime)
954954{
955 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node);
955 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(ag, scope, source_node);
956956 inst->base.is_noreturn = true;
957957 inst->condition = condition;
958958 inst->then_block = then_block;
959959 inst->else_block = else_block;
960960 inst->is_comptime = is_comptime;
961961
962 ir_ref_instruction(condition, irb->current_basic_block);
962 ir_ref_instruction(condition, ag->current_basic_block);
963963 ir_ref_bb(then_block);
964964 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);
966966
967967 return &inst->base;
968968}
969969
970static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) {
971 IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node);
970static IrInstSrc *ir_build_return_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *operand) {
971 IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(ag, scope, source_node);
972972 inst->base.is_noreturn = true;
973973 inst->operand = operand;
974974
975 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);
975 if (operand != nullptr) ir_ref_instruction(operand, ag->current_basic_block);
976976
977977 return &inst->base;
978978}
979979
980static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
981 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
982 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
983 const_instruction->value = irb->codegen->intern.for_void();
980static IrInstSrc *ir_build_const_void(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
981 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node);
982 ir_instruction_append(ag->current_basic_block, &const_instruction->base);
983 const_instruction->value = ag->codegen->intern.for_void();
984984 return &const_instruction->base;
985985}
986986
987static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
988 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
989 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
990 const_instruction->value = irb->codegen->intern.for_undefined();
987static IrInstSrc *ir_build_const_undefined(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
988 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node);
989 ir_instruction_append(ag->current_basic_block, &const_instruction->base);
990 const_instruction->value = ag->codegen->intern.for_undefined();
991991 const_instruction->value->special = ConstValSpecialUndef;
992992 return &const_instruction->base;
993993}
994994
995static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
996 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
997 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
998 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
995static IrInstSrc *ir_build_const_uint(Stage1AstGen *ag, Scope *scope, AstNode *source_node, uint64_t value) {
996 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
997 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
998 const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_int;
999999 const_instruction->value->special = ConstValSpecialStatic;
10001000 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
10011001 return &const_instruction->base;
10021002}
10031003
1004static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1004static IrInstSrc *ir_build_const_bigint(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
10051005 BigInt bigint)
10061006{
1007 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1008 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1009 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
1007 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1008 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1009 const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_int;
10101010 const_instruction->value->special = ConstValSpecialStatic;
10111011 const_instruction->value->data.x_bigint = bigint;
10121012 return &const_instruction->base;
10131013}
10141014
1015static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1015static IrInstSrc *ir_build_const_bigfloat(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
10161016 BigFloat bigfloat)
10171017{
1018 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1019 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1020 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
1018 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1019 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1020 const_instruction->value->type = ag->codegen->builtin_types.entry_num_lit_float;
10211021 const_instruction->value->special = ConstValSpecialStatic;
10221022 const_instruction->value->data.x_bigfloat = bigfloat;
10231023 return &const_instruction->base;
10241024}
10251025
1026static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1027 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1028 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1029 const_instruction->value = irb->codegen->intern.for_null();
1026static IrInstSrc *ir_build_const_null(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
1027 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node);
1028 ir_instruction_append(ag->current_basic_block, &const_instruction->base);
1029 const_instruction->value = ag->codegen->intern.for_null();
10301030 return &const_instruction->base;
10311031}
10321032
1033static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1034 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1035 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1036 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
1033static IrInstSrc *ir_build_const_usize(Stage1AstGen *ag, Scope *scope, AstNode *source_node, uint64_t value) {
1034 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1035 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1036 const_instruction->value->type = ag->codegen->builtin_types.entry_usize;
10371037 const_instruction->value->special = ConstValSpecialStatic;
10381038 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
10391039 return &const_instruction->base;
10401040}
10411041
1042static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1042static IrInstSrc *ir_create_const_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
10431043 ZigType *type_entry)
10441044{
1045 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1046 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1047 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1045 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node);
1046 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1047 const_instruction->value->type = ag->codegen->builtin_types.entry_type;
10481048 const_instruction->value->special = ConstValSpecialStatic;
10491049 const_instruction->value->data.x_type = type_entry;
10501050 return &const_instruction->base;
10511051}
10521052
1053static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1053static IrInstSrc *ir_build_const_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
10541054 ZigType *type_entry)
10551055{
1056 IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
1057 ir_instruction_append(irb->current_basic_block, instruction);
1056 IrInstSrc *instruction = ir_create_const_type(ag, scope, source_node, type_entry);
1057 ir_instruction_append(ag->current_basic_block, instruction);
10581058 return instruction;
10591059}
10601060
1061static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1062 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1063 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1064 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1061static IrInstSrc *ir_build_const_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigType *import) {
1062 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1063 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1064 const_instruction->value->type = ag->codegen->builtin_types.entry_type;
10651065 const_instruction->value->special = ConstValSpecialStatic;
10661066 const_instruction->value->data.x_type = import;
10671067 return &const_instruction->base;
10681068}
10691069
1070static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
1071 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1072 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1073 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
1070static IrInstSrc *ir_build_const_bool(Stage1AstGen *ag, Scope *scope, AstNode *source_node, bool value) {
1071 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1072 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1073 const_instruction->value->type = ag->codegen->builtin_types.entry_bool;
10741074 const_instruction->value->special = ConstValSpecialStatic;
10751075 const_instruction->value->data.x_bool = value;
10761076 return &const_instruction->base;
10771077}
10781078
1079static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
1080 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1081 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1082 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
1079static IrInstSrc *ir_build_const_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *name) {
1080 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, source_node);
1081 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1082 const_instruction->value->type = ag->codegen->builtin_types.entry_enum_literal;
10831083 const_instruction->value->special = ConstValSpecialStatic;
10841084 const_instruction->value->data.x_enum_literal = name;
10851085 return &const_instruction->base;
10861086}
10871087
10881088// Consumes `str`.
1089static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1090 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1091 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
1092 init_const_str_lit(irb->codegen, const_instruction->value, str, true);
1089static IrInstSrc *ir_create_const_str_lit(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *str) {
1090 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(ag, scope, source_node);
1091 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
1092 init_const_str_lit(ag->codegen, const_instruction->value, str, true);
10931093
10941094 return &const_instruction->base;
10951095}
10961096
10971097// Consumes `str`.
1098static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1099 IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
1100 ir_instruction_append(irb->current_basic_block, instruction);
1098static IrInstSrc *ir_build_const_str_lit(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *str) {
1099 IrInstSrc *instruction = ir_create_const_str_lit(ag, scope, source_node, str);
1100 ir_instruction_append(ag->current_basic_block, instruction);
11011101 return instruction;
11021102}
11031103
1104static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1104static IrInstSrc *ir_build_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrBinOp op_id,
11051105 IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on)
11061106{
1107 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node);
1107 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(ag, scope, source_node);
11081108 inst->op_id = op_id;
11091109 inst->op1 = op1;
11101110 inst->op2 = op2;
11111111 inst->safety_check_on = safety_check_on;
11121112
1113 ir_ref_instruction(op1, irb->current_basic_block);
1114 ir_ref_instruction(op2, irb->current_basic_block);
1113 ir_ref_instruction(op1, ag->current_basic_block);
1114 ir_ref_instruction(op2, ag->current_basic_block);
11151115
11161116 return &inst->base;
11171117}
11181118
1119static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1119static IrInstSrc *ir_build_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
11201120 IrInstSrc *op1, IrInstSrc *op2, Buf *type_name)
11211121{
1122 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node);
1122 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(ag, scope, source_node);
11231123 inst->op1 = op1;
11241124 inst->op2 = op2;
11251125 inst->type_name = type_name;
11261126
1127 ir_ref_instruction(op1, irb->current_basic_block);
1128 ir_ref_instruction(op2, irb->current_basic_block);
1127 ir_ref_instruction(op1, ag->current_basic_block);
1128 ir_ref_instruction(op2, ag->current_basic_block);
11291129
11301130 return &inst->base;
11311131}
11321132
1133static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
1133static IrInstSrc *ir_build_var_ptr_x(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var,
11341134 ScopeFnDef *crossed_fndef_scope)
11351135{
1136 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node);
1136 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(ag, scope, source_node);
11371137 instruction->var = var;
11381138 instruction->crossed_fndef_scope = crossed_fndef_scope;
11391139
......@@ -1142,89 +1142,89 @@ static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *s
11421142 return &instruction->base;
11431143}
11441144
1145static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
1146 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
1145static IrInstSrc *ir_build_var_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var) {
1146 return ir_build_var_ptr_x(ag, scope, source_node, var, nullptr);
11471147}
11481148
1149static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1149static IrInstSrc *ir_build_elem_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
11501150 IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len,
11511151 AstNode *init_array_type_source_node)
11521152{
1153 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node);
1153 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(ag, scope, source_node);
11541154 instruction->array_ptr = array_ptr;
11551155 instruction->elem_index = elem_index;
11561156 instruction->safety_check_on = safety_check_on;
11571157 instruction->ptr_len = ptr_len;
11581158 instruction->init_array_type_source_node = init_array_type_source_node;
11591159
1160 ir_ref_instruction(array_ptr, irb->current_basic_block);
1161 ir_ref_instruction(elem_index, irb->current_basic_block);
1160 ir_ref_instruction(array_ptr, ag->current_basic_block);
1161 ir_ref_instruction(elem_index, ag->current_basic_block);
11621162
11631163 return &instruction->base;
11641164}
11651165
1166static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1166static IrInstSrc *ir_build_field_ptr_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
11671167 IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing)
11681168{
1169 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1169 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(ag, scope, source_node);
11701170 instruction->container_ptr = container_ptr;
11711171 instruction->field_name_buffer = nullptr;
11721172 instruction->field_name_expr = field_name_expr;
11731173 instruction->initializing = initializing;
11741174
1175 ir_ref_instruction(container_ptr, irb->current_basic_block);
1176 ir_ref_instruction(field_name_expr, irb->current_basic_block);
1175 ir_ref_instruction(container_ptr, ag->current_basic_block);
1176 ir_ref_instruction(field_name_expr, ag->current_basic_block);
11771177
11781178 return &instruction->base;
11791179}
11801180
1181static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1181static IrInstSrc *ir_build_field_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
11821182 IrInstSrc *container_ptr, Buf *field_name, bool initializing)
11831183{
1184 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1184 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(ag, scope, source_node);
11851185 instruction->container_ptr = container_ptr;
11861186 instruction->field_name_buffer = field_name;
11871187 instruction->field_name_expr = nullptr;
11881188 instruction->initializing = initializing;
11891189
1190 ir_ref_instruction(container_ptr, irb->current_basic_block);
1190 ir_ref_instruction(container_ptr, ag->current_basic_block);
11911191
11921192 return &instruction->base;
11931193}
11941194
1195static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1195static IrInstSrc *ir_build_has_field(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
11961196 IrInstSrc *container_type, IrInstSrc *field_name)
11971197{
1198 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node);
1198 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(ag, scope, source_node);
11991199 instruction->container_type = container_type;
12001200 instruction->field_name = field_name;
12011201
1202 ir_ref_instruction(container_type, irb->current_basic_block);
1203 ir_ref_instruction(field_name, irb->current_basic_block);
1202 ir_ref_instruction(container_type, ag->current_basic_block);
1203 ir_ref_instruction(field_name, ag->current_basic_block);
12041204
12051205 return &instruction->base;
12061206}
12071207
1208static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1208static IrInstSrc *ir_build_call_extra(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
12091209 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc)
12101210{
1211 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node);
1211 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(ag, scope, source_node);
12121212 call_instruction->options = options;
12131213 call_instruction->fn_ref = fn_ref;
12141214 call_instruction->args = args;
12151215 call_instruction->result_loc = result_loc;
12161216
1217 ir_ref_instruction(options, irb->current_basic_block);
1218 ir_ref_instruction(fn_ref, irb->current_basic_block);
1219 ir_ref_instruction(args, irb->current_basic_block);
1217 ir_ref_instruction(options, ag->current_basic_block);
1218 ir_ref_instruction(fn_ref, ag->current_basic_block);
1219 ir_ref_instruction(args, ag->current_basic_block);
12201220
12211221 return &call_instruction->base;
12221222}
12231223
1224static IrInstSrc *ir_build_async_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1224static IrInstSrc *ir_build_async_call_extra(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
12251225 CallModifier modifier, IrInstSrc *fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstSrc *args, ResultLoc *result_loc)
12261226{
1227 IrInstSrcAsyncCallExtra *call_instruction = ir_build_instruction<IrInstSrcAsyncCallExtra>(irb, scope, source_node);
1227 IrInstSrcAsyncCallExtra *call_instruction = ir_build_instruction<IrInstSrcAsyncCallExtra>(ag, scope, source_node);
12281228 call_instruction->modifier = modifier;
12291229 call_instruction->fn_ref = fn_ref;
12301230 call_instruction->ret_ptr = ret_ptr;
......@@ -1232,39 +1232,39 @@ static IrInstSrc *ir_build_async_call_extra(IrBuilderSrc *irb, Scope *scope, Ast
12321232 call_instruction->args = args;
12331233 call_instruction->result_loc = result_loc;
12341234
1235 ir_ref_instruction(fn_ref, irb->current_basic_block);
1236 if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, irb->current_basic_block);
1237 ir_ref_instruction(new_stack, irb->current_basic_block);
1238 ir_ref_instruction(args, irb->current_basic_block);
1235 ir_ref_instruction(fn_ref, ag->current_basic_block);
1236 if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, ag->current_basic_block);
1237 ir_ref_instruction(new_stack, ag->current_basic_block);
1238 ir_ref_instruction(args, ag->current_basic_block);
12391239
12401240 return &call_instruction->base;
12411241}
12421242
1243static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1243static IrInstSrc *ir_build_call_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
12441244 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len,
12451245 ResultLoc *result_loc)
12461246{
1247 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node);
1247 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(ag, scope, source_node);
12481248 call_instruction->options = options;
12491249 call_instruction->fn_ref = fn_ref;
12501250 call_instruction->args_ptr = args_ptr;
12511251 call_instruction->args_len = args_len;
12521252 call_instruction->result_loc = result_loc;
12531253
1254 ir_ref_instruction(options, irb->current_basic_block);
1255 ir_ref_instruction(fn_ref, irb->current_basic_block);
1254 ir_ref_instruction(options, ag->current_basic_block);
1255 ir_ref_instruction(fn_ref, ag->current_basic_block);
12561256 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);
12581258
12591259 return &call_instruction->base;
12601260}
12611261
1262static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1262static IrInstSrc *ir_build_call_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
12631263 ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args,
12641264 IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
12651265 IrInstSrc *new_stack, ResultLoc *result_loc)
12661266{
1267 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node);
1267 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(ag, scope, source_node);
12681268 call_instruction->fn_entry = fn_entry;
12691269 call_instruction->fn_ref = fn_ref;
12701270 call_instruction->args = args;
......@@ -1275,23 +1275,23 @@ static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *so
12751275 call_instruction->result_loc = result_loc;
12761276 call_instruction->ret_ptr = ret_ptr;
12771277
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);
12791279 for (size_t i = 0; i < arg_count; i += 1)
1280 ir_ref_instruction(args[i], irb->current_basic_block);
1281 if (ret_ptr != nullptr) ir_ref_instruction(ret_ptr, irb->current_basic_block);
1282 if (new_stack != nullptr) ir_ref_instruction(new_stack, irb->current_basic_block);
1280 ir_ref_instruction(args[i], ag->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, ag->current_basic_block);
12831283
12841284 return &call_instruction->base;
12851285}
12861286
1287static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1287static IrInstSrc *ir_build_phi(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
12881288 size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values,
12891289 ResultLocPeerParent *peer_parent)
12901290{
12911291 assert(incoming_count != 0);
12921292 assert(incoming_count != SIZE_MAX);
12931293
1294 IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node);
1294 IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(ag, scope, source_node);
12951295 phi_instruction->incoming_count = incoming_count;
12961296 phi_instruction->incoming_blocks = incoming_blocks;
12971297 phi_instruction->incoming_values = incoming_values;
......@@ -1299,45 +1299,45 @@ static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_
12991299
13001300 for (size_t i = 0; i < incoming_count; i += 1) {
13011301 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);
13031303 }
13041304
13051305 return &phi_instruction->base;
13061306}
13071307
1308static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1308static IrInstSrc *ir_build_br(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
13091309 IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime)
13101310{
1311 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node);
1311 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(ag, scope, source_node);
13121312 inst->base.is_noreturn = true;
13131313 inst->dest_block = dest_block;
13141314 inst->is_comptime = is_comptime;
13151315
13161316 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);
13181318
13191319 return &inst->base;
13201320}
13211321
1322static IrInstSrc *ir_build_ptr_type_simple(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1322static IrInstSrc *ir_build_ptr_type_simple(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
13231323 IrInstSrc *child_type, bool is_const)
13241324{
13251325 IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>();
13261326 inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple;
13271327 inst->base.base.scope = scope;
13281328 inst->base.base.source_node = source_node;
1329 inst->base.base.debug_id = irb_next_debug_id(irb);
1330 inst->base.owner_bb = irb->current_basic_block;
1331 ir_instruction_append(irb->current_basic_block, &inst->base);
1329 inst->base.base.debug_id = irb_next_debug_id(ag);
1330 inst->base.owner_bb = ag->current_basic_block;
1331 ir_instruction_append(ag->current_basic_block, &inst->base);
13321332
13331333 inst->child_type = child_type;
13341334
1335 ir_ref_instruction(child_type, irb->current_basic_block);
1335 ir_ref_instruction(child_type, ag->current_basic_block);
13361336
13371337 return &inst->base;
13381338}
13391339
1340static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1340static IrInstSrc *ir_build_ptr_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
13411341 IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
13421342 IrInstSrc *sentinel, IrInstSrc *align_value,
13431343 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
13451345 if (!is_volatile && ptr_len == PtrLenSingle && sentinel == nullptr && align_value == nullptr &&
13461346 bit_offset_start == 0 && host_int_bytes == 0 && is_allow_zero == 0)
13471347 {
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);
13491349 }
13501350
1351 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node);
1351 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(ag, scope, source_node);
13521352 inst->sentinel = sentinel;
13531353 inst->align_value = align_value;
13541354 inst->child_type = child_type;
......@@ -1359,225 +1359,225 @@ static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *so
13591359 inst->host_int_bytes = host_int_bytes;
13601360 inst->is_allow_zero = is_allow_zero;
13611361
1362 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
1363 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
1364 ir_ref_instruction(child_type, irb->current_basic_block);
1362 if (sentinel) ir_ref_instruction(sentinel, ag->current_basic_block);
1363 if (align_value) ir_ref_instruction(align_value, ag->current_basic_block);
1364 ir_ref_instruction(child_type, ag->current_basic_block);
13651365
13661366 return &inst->base;
13671367}
13681368
1369static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
1369static IrInstSrc *ir_build_un_op_lval(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrUnOp op_id,
13701370 IrInstSrc *value, LVal lval, ResultLoc *result_loc)
13711371{
1372 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node);
1372 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(ag, scope, source_node);
13731373 instruction->op_id = op_id;
13741374 instruction->value = value;
13751375 instruction->lval = lval;
13761376 instruction->result_loc = result_loc;
13771377
1378 ir_ref_instruction(value, irb->current_basic_block);
1378 ir_ref_instruction(value, ag->current_basic_block);
13791379
13801380 return &instruction->base;
13811381}
13821382
1383static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
1383static IrInstSrc *ir_build_un_op(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrUnOp op_id,
13841384 IrInstSrc *value)
13851385{
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);
13871387}
13881388
1389static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1389static IrInstSrc *ir_build_container_init_list(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
13901390 size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc,
13911391 AstNode *init_array_type_source_node)
13921392{
13931393 IrInstSrcContainerInitList *container_init_list_instruction =
1394 ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node);
1394 ir_build_instruction<IrInstSrcContainerInitList>(ag, scope, source_node);
13951395 container_init_list_instruction->item_count = item_count;
13961396 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
13971397 container_init_list_instruction->result_loc = result_loc;
13981398 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
13991399
14001400 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);
14021402 }
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);
14041404
14051405 return &container_init_list_instruction->base;
14061406}
14071407
1408static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1408static IrInstSrc *ir_build_container_init_fields(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14091409 size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc)
14101410{
14111411 IrInstSrcContainerInitFields *container_init_fields_instruction =
1412 ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node);
1412 ir_build_instruction<IrInstSrcContainerInitFields>(ag, scope, source_node);
14131413 container_init_fields_instruction->field_count = field_count;
14141414 container_init_fields_instruction->fields = fields;
14151415 container_init_fields_instruction->result_loc = result_loc;
14161416
14171417 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);
14191419 }
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);
14211421
14221422 return &container_init_fields_instruction->base;
14231423}
14241424
1425static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1426 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node);
1425static IrInstSrc *ir_build_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
1426 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(ag, scope, source_node);
14271427 inst->base.is_noreturn = true;
14281428 return &inst->base;
14291429}
14301430
1431static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1431static IrInstSrcStorePtr *ir_build_store_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14321432 IrInstSrc *ptr, IrInstSrc *value)
14331433{
1434 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node);
1434 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(ag, scope, source_node);
14351435 instruction->ptr = ptr;
14361436 instruction->value = value;
14371437
1438 ir_ref_instruction(ptr, irb->current_basic_block);
1439 ir_ref_instruction(value, irb->current_basic_block);
1438 ir_ref_instruction(ptr, ag->current_basic_block);
1439 ir_ref_instruction(value, ag->current_basic_block);
14401440
14411441 return instruction;
14421442}
14431443
1444static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1444static IrInstSrc *ir_build_var_decl_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14451445 ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr)
14461446{
1447 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node);
1447 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(ag, scope, source_node);
14481448 inst->var = var;
14491449 inst->align_value = align_value;
14501450 inst->ptr = ptr;
14511451
1452 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
1453 ir_ref_instruction(ptr, irb->current_basic_block);
1452 if (align_value != nullptr) ir_ref_instruction(align_value, ag->current_basic_block);
1453 ir_ref_instruction(ptr, ag->current_basic_block);
14541454
14551455 return &inst->base;
14561456}
14571457
1458static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1458static IrInstSrc *ir_build_export(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14591459 IrInstSrc *target, IrInstSrc *options)
14601460{
14611461 IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>(
1462 irb, scope, source_node);
1462 ag, scope, source_node);
14631463 export_instruction->target = target;
14641464 export_instruction->options = options;
14651465
1466 ir_ref_instruction(target, irb->current_basic_block);
1467 ir_ref_instruction(options, irb->current_basic_block);
1466 ir_ref_instruction(target, ag->current_basic_block);
1467 ir_ref_instruction(options, ag->current_basic_block);
14681468
14691469 return &export_instruction->base;
14701470}
14711471
1472static IrInstSrc *ir_build_extern(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1472static IrInstSrc *ir_build_extern(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14731473 IrInstSrc *type, IrInstSrc *options)
14741474{
14751475 IrInstSrcExtern *extern_instruction = ir_build_instruction<IrInstSrcExtern>(
1476 irb, scope, source_node);
1476 ag, scope, source_node);
14771477 extern_instruction->type = type;
14781478 extern_instruction->options = options;
14791479
1480 ir_ref_instruction(type, irb->current_basic_block);
1481 ir_ref_instruction(options, irb->current_basic_block);
1480 ir_ref_instruction(type, ag->current_basic_block);
1481 ir_ref_instruction(options, ag->current_basic_block);
14821482
14831483 return &extern_instruction->base;
14841484}
14851485
1486static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
1487 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node);
1486static IrInstSrc *ir_build_load_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
1487 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(ag, scope, source_node);
14881488 instruction->ptr = ptr;
14891489
1490 ir_ref_instruction(ptr, irb->current_basic_block);
1490 ir_ref_instruction(ptr, ag->current_basic_block);
14911491
14921492 return &instruction->base;
14931493}
14941494
1495static IrInstSrc *ir_build_typeof_n(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1495static IrInstSrc *ir_build_typeof_n(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
14961496 IrInstSrc **values, size_t value_count)
14971497{
14981498 assert(value_count >= 2);
14991499
1500 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node);
1500 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(ag, scope, source_node);
15011501 instruction->value.list = values;
15021502 instruction->value_count = value_count;
15031503
15041504 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);
15061506
15071507 return &instruction->base;
15081508}
15091509
1510static IrInstSrc *ir_build_typeof_1(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1511 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node);
1510static IrInstSrc *ir_build_typeof_1(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1511 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(ag, scope, source_node);
15121512 instruction->value.scalar = value;
15131513
1514 ir_ref_instruction(value, irb->current_basic_block);
1514 ir_ref_instruction(value, ag->current_basic_block);
15151515
15161516 return &instruction->base;
15171517}
15181518
1519static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
1520 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node);
1519static IrInstSrc *ir_build_set_cold(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
1520 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(ag, scope, source_node);
15211521 instruction->is_cold = is_cold;
15221522
1523 ir_ref_instruction(is_cold, irb->current_basic_block);
1523 ir_ref_instruction(is_cold, ag->current_basic_block);
15241524
15251525 return &instruction->base;
15261526}
15271527
1528static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1528static IrInstSrc *ir_build_set_runtime_safety(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
15291529 IrInstSrc *safety_on)
15301530{
1531 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node);
1531 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(ag, scope, source_node);
15321532 inst->safety_on = safety_on;
15331533
1534 ir_ref_instruction(safety_on, irb->current_basic_block);
1534 ir_ref_instruction(safety_on, ag->current_basic_block);
15351535
15361536 return &inst->base;
15371537}
15381538
1539static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1539static IrInstSrc *ir_build_set_float_mode(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
15401540 IrInstSrc *mode_value)
15411541{
1542 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node);
1542 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(ag, scope, source_node);
15431543 instruction->mode_value = mode_value;
15441544
1545 ir_ref_instruction(mode_value, irb->current_basic_block);
1545 ir_ref_instruction(mode_value, ag->current_basic_block);
15461546
15471547 return &instruction->base;
15481548}
15491549
1550static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size,
1550static IrInstSrc *ir_build_array_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *size,
15511551 IrInstSrc *sentinel, IrInstSrc *child_type)
15521552{
1553 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node);
1553 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(ag, scope, source_node);
15541554 instruction->size = size;
15551555 instruction->sentinel = sentinel;
15561556 instruction->child_type = child_type;
15571557
1558 ir_ref_instruction(size, irb->current_basic_block);
1559 if (sentinel != nullptr) ir_ref_instruction(sentinel, irb->current_basic_block);
1560 ir_ref_instruction(child_type, irb->current_basic_block);
1558 ir_ref_instruction(size, ag->current_basic_block);
1559 if (sentinel != nullptr) ir_ref_instruction(sentinel, ag->current_basic_block);
1560 ir_ref_instruction(child_type, ag->current_basic_block);
15611561
15621562 return &instruction->base;
15631563}
15641564
1565static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1565static IrInstSrc *ir_build_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
15661566 IrInstSrc *payload_type)
15671567{
1568 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node);
1568 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(ag, scope, source_node);
15691569 instruction->payload_type = payload_type;
15701570
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);
15721572
15731573 return &instruction->base;
15741574}
15751575
1576static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1576static IrInstSrc *ir_build_slice_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
15771577 IrInstSrc *child_type, bool is_const, bool is_volatile,
15781578 IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero)
15791579{
1580 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node);
1580 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(ag, scope, source_node);
15811581 instruction->is_const = is_const;
15821582 instruction->is_volatile = is_volatile;
15831583 instruction->child_type = child_type;
......@@ -1585,18 +1585,18 @@ static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *
15851585 instruction->align_value = align_value;
15861586 instruction->is_allow_zero = is_allow_zero;
15871587
1588 if (sentinel != nullptr) ir_ref_instruction(sentinel, irb->current_basic_block);
1589 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
1590 ir_ref_instruction(child_type, 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, ag->current_basic_block);
1590 ir_ref_instruction(child_type, ag->current_basic_block);
15911591
15921592 return &instruction->base;
15931593}
15941594
1595static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1595static IrInstSrc *ir_build_asm_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
15961596 IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types,
15971597 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)
15981598{
1599 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node);
1599 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(ag, scope, source_node);
16001600 instruction->asm_template = asm_template;
16011601 instruction->input_list = input_list;
16021602 instruction->output_types = output_types;
......@@ -1608,122 +1608,122 @@ static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *sou
16081608 assert(source_node->type == NodeTypeAsmExpr);
16091609 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
16101610 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);
16121612 }
16131613
16141614 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
16151615 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);
16171617 }
16181618
16191619 return &instruction->base;
16201620}
16211621
1622static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
1622static IrInstSrc *ir_build_size_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
16231623 bool bit_size)
16241624{
1625 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node);
1625 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(ag, scope, source_node);
16261626 instruction->type_value = type_value;
16271627 instruction->bit_size = bit_size;
16281628
1629 ir_ref_instruction(type_value, irb->current_basic_block);
1629 ir_ref_instruction(type_value, ag->current_basic_block);
16301630
16311631 return &instruction->base;
16321632}
16331633
1634static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1634static IrInstSrc *ir_build_test_non_null_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
16351635 IrInstSrc *value)
16361636{
1637 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node);
1637 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(ag, scope, source_node);
16381638 instruction->value = value;
16391639
1640 ir_ref_instruction(value, irb->current_basic_block);
1640 ir_ref_instruction(value, ag->current_basic_block);
16411641
16421642 return &instruction->base;
16431643}
16441644
1645static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1645static IrInstSrc *ir_build_optional_unwrap_ptr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
16461646 IrInstSrc *base_ptr, bool safety_check_on)
16471647{
1648 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node);
1648 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(ag, scope, source_node);
16491649 instruction->base_ptr = base_ptr;
16501650 instruction->safety_check_on = safety_check_on;
16511651
1652 ir_ref_instruction(base_ptr, irb->current_basic_block);
1652 ir_ref_instruction(base_ptr, ag->current_basic_block);
16531653
16541654 return &instruction->base;
16551655}
16561656
1657static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
1657static IrInstSrc *ir_build_clz(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type,
16581658 IrInstSrc *op)
16591659{
1660 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node);
1660 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(ag, scope, source_node);
16611661 instruction->type = type;
16621662 instruction->op = op;
16631663
1664 ir_ref_instruction(type, irb->current_basic_block);
1665 ir_ref_instruction(op, irb->current_basic_block);
1664 ir_ref_instruction(type, ag->current_basic_block);
1665 ir_ref_instruction(op, ag->current_basic_block);
16661666
16671667 return &instruction->base;
16681668}
16691669
1670static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
1670static IrInstSrc *ir_build_ctz(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type,
16711671 IrInstSrc *op)
16721672{
1673 IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node);
1673 IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(ag, scope, source_node);
16741674 instruction->type = type;
16751675 instruction->op = op;
16761676
1677 ir_ref_instruction(type, irb->current_basic_block);
1678 ir_ref_instruction(op, irb->current_basic_block);
1677 ir_ref_instruction(type, ag->current_basic_block);
1678 ir_ref_instruction(op, ag->current_basic_block);
16791679
16801680 return &instruction->base;
16811681}
16821682
1683static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
1683static IrInstSrc *ir_build_pop_count(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type,
16841684 IrInstSrc *op)
16851685{
1686 IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node);
1686 IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(ag, scope, source_node);
16871687 instruction->type = type;
16881688 instruction->op = op;
16891689
1690 ir_ref_instruction(type, irb->current_basic_block);
1691 ir_ref_instruction(op, irb->current_basic_block);
1690 ir_ref_instruction(type, ag->current_basic_block);
1691 ir_ref_instruction(op, ag->current_basic_block);
16921692
16931693 return &instruction->base;
16941694}
16951695
1696static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
1696static IrInstSrc *ir_build_bswap(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type,
16971697 IrInstSrc *op)
16981698{
1699 IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node);
1699 IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(ag, scope, source_node);
17001700 instruction->type = type;
17011701 instruction->op = op;
17021702
1703 ir_ref_instruction(type, irb->current_basic_block);
1704 ir_ref_instruction(op, irb->current_basic_block);
1703 ir_ref_instruction(type, ag->current_basic_block);
1704 ir_ref_instruction(op, ag->current_basic_block);
17051705
17061706 return &instruction->base;
17071707}
17081708
1709static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
1709static IrInstSrc *ir_build_bit_reverse(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type,
17101710 IrInstSrc *op)
17111711{
1712 IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node);
1712 IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(ag, scope, source_node);
17131713 instruction->type = type;
17141714 instruction->op = op;
17151715
1716 ir_ref_instruction(type, irb->current_basic_block);
1717 ir_ref_instruction(op, irb->current_basic_block);
1716 ir_ref_instruction(type, ag->current_basic_block);
1717 ir_ref_instruction(op, ag->current_basic_block);
17181718
17191719 return &instruction->base;
17201720}
17211721
1722static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1722static IrInstSrcSwitchBr *ir_build_switch_br_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
17231723 IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases,
17241724 IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void)
17251725{
1726 IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node);
1726 IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(ag, scope, source_node);
17271727 instruction->base.is_noreturn = true;
17281728 instruction->target_value = target_value;
17291729 instruction->else_block = else_block;
......@@ -1732,156 +1732,156 @@ static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope
17321732 instruction->is_comptime = is_comptime;
17331733 instruction->switch_prongs_void = switch_prongs_void;
17341734
1735 ir_ref_instruction(target_value, irb->current_basic_block);
1736 ir_ref_instruction(is_comptime, irb->current_basic_block);
1735 ir_ref_instruction(target_value, ag->current_basic_block);
1736 ir_ref_instruction(is_comptime, ag->current_basic_block);
17371737 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);
17391739
17401740 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);
17421742 ir_ref_bb(cases[i].block);
17431743 }
17441744
17451745 return instruction;
17461746}
17471747
1748static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1748static IrInstSrc *ir_build_switch_target(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
17491749 IrInstSrc *target_value_ptr)
17501750{
1751 IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node);
1751 IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(ag, scope, source_node);
17521752 instruction->target_value_ptr = target_value_ptr;
17531753
1754 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
1754 ir_ref_instruction(target_value_ptr, ag->current_basic_block);
17551755
17561756 return &instruction->base;
17571757}
17581758
1759static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1759static IrInstSrc *ir_build_switch_var(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
17601760 IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len)
17611761{
1762 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node);
1762 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(ag, scope, source_node);
17631763 instruction->target_value_ptr = target_value_ptr;
17641764 instruction->prongs_ptr = prongs_ptr;
17651765 instruction->prongs_len = prongs_len;
17661766
1767 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
1767 ir_ref_instruction(target_value_ptr, ag->current_basic_block);
17681768 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);
17701770 }
17711771
17721772 return &instruction->base;
17731773}
17741774
17751775// For this instruction the switch_br must be set later.
1776static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1776static IrInstSrcSwitchElseVar *ir_build_switch_else_var(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
17771777 IrInstSrc *target_value_ptr)
17781778{
1779 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node);
1779 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(ag, scope, source_node);
17801780 instruction->target_value_ptr = target_value_ptr;
17811781
1782 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
1782 ir_ref_instruction(target_value_ptr, ag->current_basic_block);
17831783
17841784 return instruction;
17851785}
17861786
1787static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1788 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node);
1787static IrInstSrc *ir_build_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1788 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(ag, scope, source_node);
17891789 instruction->name = name;
17901790
1791 ir_ref_instruction(name, irb->current_basic_block);
1791 ir_ref_instruction(name, ag->current_basic_block);
17921792
17931793 return &instruction->base;
17941794}
17951795
1796static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1797 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
1796static IrInstSrc *ir_build_ref_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1797 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(ag, scope, source_node);
17981798 instruction->value = value;
17991799
1800 ir_ref_instruction(value, irb->current_basic_block);
1800 ir_ref_instruction(value, ag->current_basic_block);
18011801
18021802 return &instruction->base;
18031803}
18041804
1805static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
1806 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node);
1805static IrInstSrc *ir_build_compile_err(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
1806 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(ag, scope, source_node);
18071807 instruction->msg = msg;
18081808
1809 ir_ref_instruction(msg, irb->current_basic_block);
1809 ir_ref_instruction(msg, ag->current_basic_block);
18101810
18111811 return &instruction->base;
18121812}
18131813
1814static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1814static IrInstSrc *ir_build_compile_log(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
18151815 size_t msg_count, IrInstSrc **msg_list)
18161816{
1817 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node);
1817 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(ag, scope, source_node);
18181818 instruction->msg_count = msg_count;
18191819 instruction->msg_list = msg_list;
18201820
18211821 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);
18231823 }
18241824
18251825 return &instruction->base;
18261826}
18271827
1828static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1829 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node);
1828static IrInstSrc *ir_build_err_name(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) {
1829 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(ag, scope, source_node);
18301830 instruction->value = value;
18311831
1832 ir_ref_instruction(value, irb->current_basic_block);
1832 ir_ref_instruction(value, ag->current_basic_block);
18331833
18341834 return &instruction->base;
18351835}
18361836
1837static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1838 IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node);
1837static IrInstSrc *ir_build_c_import(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
1838 IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(ag, scope, source_node);
18391839 return &instruction->base;
18401840}
18411841
1842static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1843 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node);
1842static IrInstSrc *ir_build_c_include(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1843 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(ag, scope, source_node);
18441844 instruction->name = name;
18451845
1846 ir_ref_instruction(name, irb->current_basic_block);
1846 ir_ref_instruction(name, ag->current_basic_block);
18471847
18481848 return &instruction->base;
18491849}
18501850
1851static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
1852 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node);
1851static IrInstSrc *ir_build_c_define(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
1852 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(ag, scope, source_node);
18531853 instruction->name = name;
18541854 instruction->value = value;
18551855
1856 ir_ref_instruction(name, irb->current_basic_block);
1857 ir_ref_instruction(value, irb->current_basic_block);
1856 ir_ref_instruction(name, ag->current_basic_block);
1857 ir_ref_instruction(value, ag->current_basic_block);
18581858
18591859 return &instruction->base;
18601860}
18611861
1862static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1863 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node);
1862static IrInstSrc *ir_build_c_undef(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1863 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(ag, scope, source_node);
18641864 instruction->name = name;
18651865
1866 ir_ref_instruction(name, irb->current_basic_block);
1866 ir_ref_instruction(name, ag->current_basic_block);
18671867
18681868 return &instruction->base;
18691869}
18701870
1871static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1872 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node);
1871static IrInstSrc *ir_build_embed_file(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *name) {
1872 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(ag, scope, source_node);
18731873 instruction->name = name;
18741874
1875 ir_ref_instruction(name, irb->current_basic_block);
1875 ir_ref_instruction(name, ag->current_basic_block);
18761876
18771877 return &instruction->base;
18781878}
18791879
1880static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1880static IrInstSrc *ir_build_cmpxchg_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
18811881 IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value,
18821882 IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc)
18831883{
1884 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node);
1884 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(ag, scope, source_node);
18851885 instruction->type_value = type_value;
18861886 instruction->ptr = ptr;
18871887 instruction->cmp_value = cmp_value;
......@@ -1891,210 +1891,210 @@ static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode
18911891 instruction->is_weak = is_weak;
18921892 instruction->result_loc = result_loc;
18931893
1894 ir_ref_instruction(type_value, irb->current_basic_block);
1895 ir_ref_instruction(ptr, irb->current_basic_block);
1896 ir_ref_instruction(cmp_value, irb->current_basic_block);
1897 ir_ref_instruction(new_value, irb->current_basic_block);
1898 ir_ref_instruction(success_order_value, irb->current_basic_block);
1899 ir_ref_instruction(failure_order_value, irb->current_basic_block);
1894 ir_ref_instruction(type_value, ag->current_basic_block);
1895 ir_ref_instruction(ptr, ag->current_basic_block);
1896 ir_ref_instruction(cmp_value, ag->current_basic_block);
1897 ir_ref_instruction(new_value, ag->current_basic_block);
1898 ir_ref_instruction(success_order_value, ag->current_basic_block);
1899 ir_ref_instruction(failure_order_value, ag->current_basic_block);
19001900
19011901 return &instruction->base;
19021902}
19031903
1904static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) {
1905 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node);
1904static IrInstSrc *ir_build_fence(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *order) {
1905 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(ag, scope, source_node);
19061906 instruction->order = order;
19071907
1908 ir_ref_instruction(order, irb->current_basic_block);
1908 ir_ref_instruction(order, ag->current_basic_block);
19091909
19101910 return &instruction->base;
19111911}
19121912
1913static IrInstSrc *ir_build_reduce(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *op, IrInstSrc *value) {
1914 IrInstSrcReduce *instruction = ir_build_instruction<IrInstSrcReduce>(irb, scope, source_node);
1913static IrInstSrc *ir_build_reduce(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *op, IrInstSrc *value) {
1914 IrInstSrcReduce *instruction = ir_build_instruction<IrInstSrcReduce>(ag, scope, source_node);
19151915 instruction->op = op;
19161916 instruction->value = value;
19171917
1918 ir_ref_instruction(op, irb->current_basic_block);
1919 ir_ref_instruction(value, irb->current_basic_block);
1918 ir_ref_instruction(op, ag->current_basic_block);
1919 ir_ref_instruction(value, ag->current_basic_block);
19201920
19211921 return &instruction->base;
19221922}
19231923
1924static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1924static IrInstSrc *ir_build_truncate(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
19251925 IrInstSrc *dest_type, IrInstSrc *target)
19261926{
1927 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node);
1927 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(ag, scope, source_node);
19281928 instruction->dest_type = dest_type;
19291929 instruction->target = target;
19301930
1931 ir_ref_instruction(dest_type, irb->current_basic_block);
1932 ir_ref_instruction(target, irb->current_basic_block);
1931 ir_ref_instruction(dest_type, ag->current_basic_block);
1932 ir_ref_instruction(target, ag->current_basic_block);
19331933
19341934 return &instruction->base;
19351935}
19361936
1937static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
1937static IrInstSrc *ir_build_int_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
19381938 IrInstSrc *target)
19391939{
1940 IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node);
1940 IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(ag, scope, source_node);
19411941 instruction->dest_type = dest_type;
19421942 instruction->target = target;
19431943
1944 ir_ref_instruction(dest_type, irb->current_basic_block);
1945 ir_ref_instruction(target, irb->current_basic_block);
1944 ir_ref_instruction(dest_type, ag->current_basic_block);
1945 ir_ref_instruction(target, ag->current_basic_block);
19461946
19471947 return &instruction->base;
19481948}
19491949
1950static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
1950static IrInstSrc *ir_build_float_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
19511951 IrInstSrc *target)
19521952{
1953 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node);
1953 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(ag, scope, source_node);
19541954 instruction->dest_type = dest_type;
19551955 instruction->target = target;
19561956
1957 ir_ref_instruction(dest_type, irb->current_basic_block);
1958 ir_ref_instruction(target, irb->current_basic_block);
1957 ir_ref_instruction(dest_type, ag->current_basic_block);
1958 ir_ref_instruction(target, ag->current_basic_block);
19591959
19601960 return &instruction->base;
19611961}
19621962
1963static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1963static IrInstSrc *ir_build_err_set_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
19641964 IrInstSrc *dest_type, IrInstSrc *target)
19651965{
1966 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node);
1966 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(ag, scope, source_node);
19671967 instruction->dest_type = dest_type;
19681968 instruction->target = target;
19691969
1970 ir_ref_instruction(dest_type, irb->current_basic_block);
1971 ir_ref_instruction(target, irb->current_basic_block);
1970 ir_ref_instruction(dest_type, ag->current_basic_block);
1971 ir_ref_instruction(target, ag->current_basic_block);
19721972
19731973 return &instruction->base;
19741974}
19751975
1976static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1976static IrInstSrc *ir_build_int_to_float(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
19771977 IrInstSrc *dest_type, IrInstSrc *target)
19781978{
1979 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node);
1979 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(ag, scope, source_node);
19801980 instruction->dest_type = dest_type;
19811981 instruction->target = target;
19821982
1983 ir_ref_instruction(dest_type, irb->current_basic_block);
1984 ir_ref_instruction(target, irb->current_basic_block);
1983 ir_ref_instruction(dest_type, ag->current_basic_block);
1984 ir_ref_instruction(target, ag->current_basic_block);
19851985
19861986 return &instruction->base;
19871987}
19881988
1989static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1989static IrInstSrc *ir_build_float_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
19901990 IrInstSrc *dest_type, IrInstSrc *target)
19911991{
1992 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node);
1992 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(ag, scope, source_node);
19931993 instruction->dest_type = dest_type;
19941994 instruction->target = target;
19951995
1996 ir_ref_instruction(dest_type, irb->current_basic_block);
1997 ir_ref_instruction(target, irb->current_basic_block);
1996 ir_ref_instruction(dest_type, ag->current_basic_block);
1997 ir_ref_instruction(target, ag->current_basic_block);
19981998
19991999 return &instruction->base;
20002000}
20012001
2002static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2003 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node);
2002static IrInstSrc *ir_build_bool_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2003 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(ag, scope, source_node);
20042004 instruction->target = target;
20052005
2006 ir_ref_instruction(target, irb->current_basic_block);
2006 ir_ref_instruction(target, ag->current_basic_block);
20072007
20082008 return &instruction->base;
20092009}
20102010
2011static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
2011static IrInstSrc *ir_build_vector_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *len,
20122012 IrInstSrc *elem_type)
20132013{
2014 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node);
2014 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(ag, scope, source_node);
20152015 instruction->len = len;
20162016 instruction->elem_type = elem_type;
20172017
2018 ir_ref_instruction(len, irb->current_basic_block);
2019 ir_ref_instruction(elem_type, irb->current_basic_block);
2018 ir_ref_instruction(len, ag->current_basic_block);
2019 ir_ref_instruction(elem_type, ag->current_basic_block);
20202020
20212021 return &instruction->base;
20222022}
20232023
2024static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2024static IrInstSrc *ir_build_shuffle_vector(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
20252025 IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask)
20262026{
2027 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node);
2027 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(ag, scope, source_node);
20282028 instruction->scalar_type = scalar_type;
20292029 instruction->a = a;
20302030 instruction->b = b;
20312031 instruction->mask = mask;
20322032
2033 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block);
2034 ir_ref_instruction(a, irb->current_basic_block);
2035 ir_ref_instruction(b, irb->current_basic_block);
2036 ir_ref_instruction(mask, irb->current_basic_block);
2033 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, ag->current_basic_block);
2034 ir_ref_instruction(a, ag->current_basic_block);
2035 ir_ref_instruction(b, ag->current_basic_block);
2036 ir_ref_instruction(mask, ag->current_basic_block);
20372037
20382038 return &instruction->base;
20392039}
20402040
2041static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2041static IrInstSrc *ir_build_splat_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
20422042 IrInstSrc *len, IrInstSrc *scalar)
20432043{
2044 IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node);
2044 IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(ag, scope, source_node);
20452045 instruction->len = len;
20462046 instruction->scalar = scalar;
20472047
2048 ir_ref_instruction(len, irb->current_basic_block);
2049 ir_ref_instruction(scalar, irb->current_basic_block);
2048 ir_ref_instruction(len, ag->current_basic_block);
2049 ir_ref_instruction(scalar, ag->current_basic_block);
20502050
20512051 return &instruction->base;
20522052}
20532053
2054static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2055 IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node);
2054static IrInstSrc *ir_build_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2055 IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(ag, scope, source_node);
20562056 instruction->value = value;
20572057
2058 ir_ref_instruction(value, irb->current_basic_block);
2058 ir_ref_instruction(value, ag->current_basic_block);
20592059
20602060 return &instruction->base;
20612061}
20622062
2063static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2063static IrInstSrc *ir_build_memset_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
20642064 IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count)
20652065{
2066 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node);
2066 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(ag, scope, source_node);
20672067 instruction->dest_ptr = dest_ptr;
20682068 instruction->byte = byte;
20692069 instruction->count = count;
20702070
2071 ir_ref_instruction(dest_ptr, irb->current_basic_block);
2072 ir_ref_instruction(byte, irb->current_basic_block);
2073 ir_ref_instruction(count, irb->current_basic_block);
2071 ir_ref_instruction(dest_ptr, ag->current_basic_block);
2072 ir_ref_instruction(byte, ag->current_basic_block);
2073 ir_ref_instruction(count, ag->current_basic_block);
20742074
20752075 return &instruction->base;
20762076}
20772077
2078static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2078static IrInstSrc *ir_build_memcpy_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
20792079 IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count)
20802080{
2081 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node);
2081 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(ag, scope, source_node);
20822082 instruction->dest_ptr = dest_ptr;
20832083 instruction->src_ptr = src_ptr;
20842084 instruction->count = count;
20852085
2086 ir_ref_instruction(dest_ptr, irb->current_basic_block);
2087 ir_ref_instruction(src_ptr, irb->current_basic_block);
2088 ir_ref_instruction(count, irb->current_basic_block);
2086 ir_ref_instruction(dest_ptr, ag->current_basic_block);
2087 ir_ref_instruction(src_ptr, ag->current_basic_block);
2088 ir_ref_instruction(count, ag->current_basic_block);
20892089
20902090 return &instruction->base;
20912091}
20922092
2093static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2093static IrInstSrc *ir_build_slice_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
20942094 IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel,
20952095 bool safety_check_on, ResultLoc *result_loc)
20962096{
2097 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node);
2097 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(ag, scope, source_node);
20982098 instruction->ptr = ptr;
20992099 instruction->start = start;
21002100 instruction->end = end;
......@@ -2102,150 +2102,150 @@ static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *s
21022102 instruction->safety_check_on = safety_check_on;
21032103 instruction->result_loc = result_loc;
21042104
2105 ir_ref_instruction(ptr, irb->current_basic_block);
2106 ir_ref_instruction(start, irb->current_basic_block);
2107 if (end) ir_ref_instruction(end, irb->current_basic_block);
2108 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
2105 ir_ref_instruction(ptr, ag->current_basic_block);
2106 ir_ref_instruction(start, ag->current_basic_block);
2107 if (end) ir_ref_instruction(end, ag->current_basic_block);
2108 if (sentinel) ir_ref_instruction(sentinel, ag->current_basic_block);
21092109
21102110 return &instruction->base;
21112111}
21122112
2113static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2114 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
2113static IrInstSrc *ir_build_breakpoint(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2114 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(ag, scope, source_node);
21152115 return &instruction->base;
21162116}
21172117
2118static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2119 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node);
2118static IrInstSrc *ir_build_return_address_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2119 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(ag, scope, source_node);
21202120 return &instruction->base;
21212121}
21222122
2123static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2124 IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node);
2123static IrInstSrc *ir_build_frame_address_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2124 IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(ag, scope, source_node);
21252125 return &inst->base;
21262126}
21272127
2128static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2129 IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node);
2128static IrInstSrc *ir_build_handle_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2129 IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(ag, scope, source_node);
21302130 return &inst->base;
21312131}
21322132
2133static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
2134 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node);
2133static IrInstSrc *ir_build_frame_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
2134 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(ag, scope, source_node);
21352135 inst->fn = fn;
21362136
2137 ir_ref_instruction(fn, irb->current_basic_block);
2137 ir_ref_instruction(fn, ag->current_basic_block);
21382138
21392139 return &inst->base;
21402140}
21412141
2142static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
2143 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node);
2142static IrInstSrc *ir_build_frame_size_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
2143 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(ag, scope, source_node);
21442144 inst->fn = fn;
21452145
2146 ir_ref_instruction(fn, irb->current_basic_block);
2146 ir_ref_instruction(fn, ag->current_basic_block);
21472147
21482148 return &inst->base;
21492149}
21502150
2151static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2151static IrInstSrc *ir_build_overflow_op_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
21522152 IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr)
21532153{
2154 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node);
2154 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(ag, scope, source_node);
21552155 instruction->op = op;
21562156 instruction->type_value = type_value;
21572157 instruction->op1 = op1;
21582158 instruction->op2 = op2;
21592159 instruction->result_ptr = result_ptr;
21602160
2161 ir_ref_instruction(type_value, irb->current_basic_block);
2162 ir_ref_instruction(op1, irb->current_basic_block);
2163 ir_ref_instruction(op2, irb->current_basic_block);
2164 ir_ref_instruction(result_ptr, irb->current_basic_block);
2161 ir_ref_instruction(type_value, ag->current_basic_block);
2162 ir_ref_instruction(op1, ag->current_basic_block);
2163 ir_ref_instruction(op2, ag->current_basic_block);
2164 ir_ref_instruction(result_ptr, ag->current_basic_block);
21652165
21662166 return &instruction->base;
21672167}
21682168
2169static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand,
2169static IrInstSrc *ir_build_float_op_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *operand,
21702170 BuiltinFnId fn_id)
21712171{
2172 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node);
2172 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(ag, scope, source_node);
21732173 instruction->operand = operand;
21742174 instruction->fn_id = fn_id;
21752175
2176 ir_ref_instruction(operand, irb->current_basic_block);
2176 ir_ref_instruction(operand, ag->current_basic_block);
21772177
21782178 return &instruction->base;
21792179}
21802180
2181static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2181static IrInstSrc *ir_build_mul_add_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
21822182 IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3)
21832183{
2184 IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node);
2184 IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(ag, scope, source_node);
21852185 instruction->type_value = type_value;
21862186 instruction->op1 = op1;
21872187 instruction->op2 = op2;
21882188 instruction->op3 = op3;
21892189
2190 ir_ref_instruction(type_value, irb->current_basic_block);
2191 ir_ref_instruction(op1, irb->current_basic_block);
2192 ir_ref_instruction(op2, irb->current_basic_block);
2193 ir_ref_instruction(op3, irb->current_basic_block);
2190 ir_ref_instruction(type_value, ag->current_basic_block);
2191 ir_ref_instruction(op1, ag->current_basic_block);
2192 ir_ref_instruction(op2, ag->current_basic_block);
2193 ir_ref_instruction(op3, ag->current_basic_block);
21942194
21952195 return &instruction->base;
21962196}
21972197
2198static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
2199 IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node);
2198static IrInstSrc *ir_build_align_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
2199 IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(ag, scope, source_node);
22002200 instruction->type_value = type_value;
22012201
2202 ir_ref_instruction(type_value, irb->current_basic_block);
2202 ir_ref_instruction(type_value, ag->current_basic_block);
22032203
22042204 return &instruction->base;
22052205}
22062206
2207static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2207static IrInstSrc *ir_build_test_err_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22082208 IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
22092209{
2210 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node);
2210 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(ag, scope, source_node);
22112211 instruction->base_ptr = base_ptr;
22122212 instruction->resolve_err_set = resolve_err_set;
22132213 instruction->base_ptr_is_payload = base_ptr_is_payload;
22142214
2215 ir_ref_instruction(base_ptr, irb->current_basic_block);
2215 ir_ref_instruction(base_ptr, ag->current_basic_block);
22162216
22172217 return &instruction->base;
22182218}
22192219
2220static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2220static IrInstSrc *ir_build_unwrap_err_code_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22212221 IrInstSrc *err_union_ptr)
22222222{
2223 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node);
2223 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(ag, scope, source_node);
22242224 inst->err_union_ptr = err_union_ptr;
22252225
2226 ir_ref_instruction(err_union_ptr, irb->current_basic_block);
2226 ir_ref_instruction(err_union_ptr, ag->current_basic_block);
22272227
22282228 return &inst->base;
22292229}
22302230
2231static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2231static IrInstSrc *ir_build_unwrap_err_payload_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22322232 IrInstSrc *value, bool safety_check_on, bool initializing)
22332233{
2234 IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node);
2234 IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(ag, scope, source_node);
22352235 inst->value = value;
22362236 inst->safety_check_on = safety_check_on;
22372237 inst->initializing = initializing;
22382238
2239 ir_ref_instruction(value, irb->current_basic_block);
2239 ir_ref_instruction(value, ag->current_basic_block);
22402240
22412241 return &inst->base;
22422242}
22432243
2244static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2244static IrInstSrc *ir_build_fn_proto(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22452245 IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value,
22462246 IrInstSrc *return_type, bool is_var_args)
22472247{
2248 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node);
2248 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(ag, scope, source_node);
22492249 instruction->param_types = param_types;
22502250 instruction->align_value = align_value;
22512251 instruction->callconv_value = callconv_value;
......@@ -2256,136 +2256,136 @@ static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *so
22562256 size_t param_count = source_node->data.fn_proto.params.length;
22572257 if (is_var_args) param_count -= 1;
22582258 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);
22602260 }
2261 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
2262 if (callconv_value != nullptr) ir_ref_instruction(callconv_value, irb->current_basic_block);
2263 ir_ref_instruction(return_type, 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, ag->current_basic_block);
2263 ir_ref_instruction(return_type, ag->current_basic_block);
22642264
22652265 return &instruction->base;
22662266}
22672267
2268static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2269 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node);
2268static IrInstSrc *ir_build_test_comptime(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2269 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(ag, scope, source_node);
22702270 instruction->value = value;
22712271
2272 ir_ref_instruction(value, irb->current_basic_block);
2272 ir_ref_instruction(value, ag->current_basic_block);
22732273
22742274 return &instruction->base;
22752275}
22762276
2277static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2277static IrInstSrc *ir_build_ptr_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22782278 IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on)
22792279{
22802280 IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>(
2281 irb, scope, source_node);
2281 ag, scope, source_node);
22822282 instruction->dest_type = dest_type;
22832283 instruction->ptr = ptr;
22842284 instruction->safety_check_on = safety_check_on;
22852285
2286 ir_ref_instruction(dest_type, irb->current_basic_block);
2287 ir_ref_instruction(ptr, irb->current_basic_block);
2286 ir_ref_instruction(dest_type, ag->current_basic_block);
2287 ir_ref_instruction(ptr, ag->current_basic_block);
22882288
22892289 return &instruction->base;
22902290}
22912291
2292static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2292static IrInstSrc *ir_build_implicit_cast(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
22932293 IrInstSrc *operand, ResultLocCast *result_loc_cast)
22942294{
2295 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node);
2295 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(ag, scope, source_node);
22962296 instruction->operand = operand;
22972297 instruction->result_loc_cast = result_loc_cast;
22982298
2299 ir_ref_instruction(operand, irb->current_basic_block);
2299 ir_ref_instruction(operand, ag->current_basic_block);
23002300
23012301 return &instruction->base;
23022302}
23032303
2304static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2304static IrInstSrc *ir_build_bit_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23052305 IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast)
23062306{
2307 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node);
2307 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(ag, scope, source_node);
23082308 instruction->operand = operand;
23092309 instruction->result_loc_bit_cast = result_loc_bit_cast;
23102310
2311 ir_ref_instruction(operand, irb->current_basic_block);
2311 ir_ref_instruction(operand, ag->current_basic_block);
23122312
23132313 return &instruction->base;
23142314}
23152315
2316static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2316static IrInstSrc *ir_build_int_to_ptr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23172317 IrInstSrc *dest_type, IrInstSrc *target)
23182318{
2319 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node);
2319 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(ag, scope, source_node);
23202320 instruction->dest_type = dest_type;
23212321 instruction->target = target;
23222322
2323 ir_ref_instruction(dest_type, irb->current_basic_block);
2324 ir_ref_instruction(target, irb->current_basic_block);
2323 ir_ref_instruction(dest_type, ag->current_basic_block);
2324 ir_ref_instruction(target, ag->current_basic_block);
23252325
23262326 return &instruction->base;
23272327}
23282328
2329static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2329static IrInstSrc *ir_build_ptr_to_int_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23302330 IrInstSrc *target)
23312331{
2332 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node);
2332 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(ag, scope, source_node);
23332333 inst->target = target;
23342334
2335 ir_ref_instruction(target, irb->current_basic_block);
2335 ir_ref_instruction(target, ag->current_basic_block);
23362336
23372337 return &inst->base;
23382338}
23392339
2340static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2340static IrInstSrc *ir_build_int_to_enum_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23412341 IrInstSrc *dest_type, IrInstSrc *target)
23422342{
2343 IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node);
2343 IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(ag, scope, source_node);
23442344 instruction->dest_type = dest_type;
23452345 instruction->target = target;
23462346
2347 if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block);
2348 ir_ref_instruction(target, irb->current_basic_block);
2347 if (dest_type) ir_ref_instruction(dest_type, ag->current_basic_block);
2348 ir_ref_instruction(target, ag->current_basic_block);
23492349
23502350 return &instruction->base;
23512351}
23522352
2353static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2353static IrInstSrc *ir_build_enum_to_int(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23542354 IrInstSrc *target)
23552355{
23562356 IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>(
2357 irb, scope, source_node);
2357 ag, scope, source_node);
23582358 instruction->target = target;
23592359
2360 ir_ref_instruction(target, irb->current_basic_block);
2360 ir_ref_instruction(target, ag->current_basic_block);
23612361
23622362 return &instruction->base;
23632363}
23642364
2365static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2365static IrInstSrc *ir_build_int_to_err_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23662366 IrInstSrc *target)
23672367{
2368 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node);
2368 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(ag, scope, source_node);
23692369 instruction->target = target;
23702370
2371 ir_ref_instruction(target, irb->current_basic_block);
2371 ir_ref_instruction(target, ag->current_basic_block);
23722372
23732373 return &instruction->base;
23742374}
23752375
2376static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2376static IrInstSrc *ir_build_err_to_int_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23772377 IrInstSrc *target)
23782378{
23792379 IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>(
2380 irb, scope, source_node);
2380 ag, scope, source_node);
23812381 instruction->target = target;
23822382
2383 ir_ref_instruction(target, irb->current_basic_block);
2383 ir_ref_instruction(target, ag->current_basic_block);
23842384
23852385 return &instruction->base;
23862386}
23872387
2388static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2388static IrInstSrc *ir_build_check_switch_prongs(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
23892389 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
23902390 AstNode* else_prong, bool have_underscore_prong)
23912391{
......@@ -2394,192 +2394,192 @@ static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope,
23942394 IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo;
23952395 instruction->base.base.scope = scope;
23962396 instruction->base.base.source_node = source_node;
2397 instruction->base.base.debug_id = irb_next_debug_id(irb);
2398 instruction->base.owner_bb = irb->current_basic_block;
2399 ir_instruction_append(irb->current_basic_block, &instruction->base);
2397 instruction->base.base.debug_id = irb_next_debug_id(ag);
2398 instruction->base.owner_bb = ag->current_basic_block;
2399 ir_instruction_append(ag->current_basic_block, &instruction->base);
24002400
24012401 instruction->target_value = target_value;
24022402 instruction->ranges = ranges;
24032403 instruction->range_count = range_count;
24042404 instruction->else_prong = else_prong;
24052405
2406 ir_ref_instruction(target_value, irb->current_basic_block);
2406 ir_ref_instruction(target_value, ag->current_basic_block);
24072407 for (size_t i = 0; i < range_count; i += 1) {
2408 ir_ref_instruction(ranges[i].start, irb->current_basic_block);
2409 ir_ref_instruction(ranges[i].end, irb->current_basic_block);
2408 ir_ref_instruction(ranges[i].start, ag->current_basic_block);
2409 ir_ref_instruction(ranges[i].end, ag->current_basic_block);
24102410 }
24112411
24122412 return &instruction->base;
24132413}
24142414
2415static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2415static IrInstSrc *ir_build_check_statement_is_void(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24162416 IrInstSrc* statement_value)
24172417{
24182418 IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>(
2419 irb, scope, source_node);
2419 ag, scope, source_node);
24202420 instruction->statement_value = statement_value;
24212421
2422 ir_ref_instruction(statement_value, irb->current_basic_block);
2422 ir_ref_instruction(statement_value, ag->current_basic_block);
24232423
24242424 return &instruction->base;
24252425}
24262426
2427static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2427static IrInstSrc *ir_build_type_name(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24282428 IrInstSrc *type_value)
24292429{
2430 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node);
2430 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(ag, scope, source_node);
24312431 instruction->type_value = type_value;
24322432
2433 ir_ref_instruction(type_value, irb->current_basic_block);
2433 ir_ref_instruction(type_value, ag->current_basic_block);
24342434
24352435 return &instruction->base;
24362436}
24372437
2438static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
2439 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node);
2438static IrInstSrc *ir_build_decl_ref(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
2439 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(ag, scope, source_node);
24402440 instruction->tld = tld;
24412441 instruction->lval = lval;
24422442
24432443 return &instruction->base;
24442444}
24452445
2446static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
2447 IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node);
2446static IrInstSrc *ir_build_panic_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
2447 IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(ag, scope, source_node);
24482448 instruction->base.is_noreturn = true;
24492449 instruction->msg = msg;
24502450
2451 ir_ref_instruction(msg, irb->current_basic_block);
2451 ir_ref_instruction(msg, ag->current_basic_block);
24522452
24532453 return &instruction->base;
24542454}
24552455
2456static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2457 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node);
2456static IrInstSrc *ir_build_tag_name_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2457 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(ag, scope, source_node);
24582458 instruction->target = target;
24592459
2460 ir_ref_instruction(target, irb->current_basic_block);
2460 ir_ref_instruction(target, ag->current_basic_block);
24612461
24622462 return &instruction->base;
24632463}
24642464
2465static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2465static IrInstSrc *ir_build_field_parent_ptr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24662466 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
24672467{
24682468 IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>(
2469 irb, scope, source_node);
2469 ag, scope, source_node);
24702470 inst->type_value = type_value;
24712471 inst->field_name = field_name;
24722472 inst->field_ptr = field_ptr;
24732473
2474 ir_ref_instruction(type_value, irb->current_basic_block);
2475 ir_ref_instruction(field_name, irb->current_basic_block);
2476 ir_ref_instruction(field_ptr, irb->current_basic_block);
2474 ir_ref_instruction(type_value, ag->current_basic_block);
2475 ir_ref_instruction(field_name, ag->current_basic_block);
2476 ir_ref_instruction(field_ptr, ag->current_basic_block);
24772477
24782478 return &inst->base;
24792479}
24802480
2481static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2481static IrInstSrc *ir_build_byte_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24822482 IrInstSrc *type_value, IrInstSrc *field_name)
24832483{
2484 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node);
2484 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(ag, scope, source_node);
24852485 instruction->type_value = type_value;
24862486 instruction->field_name = field_name;
24872487
2488 ir_ref_instruction(type_value, irb->current_basic_block);
2489 ir_ref_instruction(field_name, irb->current_basic_block);
2488 ir_ref_instruction(type_value, ag->current_basic_block);
2489 ir_ref_instruction(field_name, ag->current_basic_block);
24902490
24912491 return &instruction->base;
24922492}
24932493
2494static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2494static IrInstSrc *ir_build_bit_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24952495 IrInstSrc *type_value, IrInstSrc *field_name)
24962496{
2497 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node);
2497 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(ag, scope, source_node);
24982498 instruction->type_value = type_value;
24992499 instruction->field_name = field_name;
25002500
2501 ir_ref_instruction(type_value, irb->current_basic_block);
2502 ir_ref_instruction(field_name, irb->current_basic_block);
2501 ir_ref_instruction(type_value, ag->current_basic_block);
2502 ir_ref_instruction(field_name, ag->current_basic_block);
25032503
25042504 return &instruction->base;
25052505}
25062506
2507static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
2508 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node);
2507static IrInstSrc *ir_build_type_info(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
2508 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(ag, scope, source_node);
25092509 instruction->type_value = type_value;
25102510
2511 ir_ref_instruction(type_value, irb->current_basic_block);
2511 ir_ref_instruction(type_value, ag->current_basic_block);
25122512
25132513 return &instruction->base;
25142514}
25152515
2516static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
2517 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node);
2516static IrInstSrc *ir_build_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
2517 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(ag, scope, source_node);
25182518 instruction->type_info = type_info;
25192519
2520 ir_ref_instruction(type_info, irb->current_basic_block);
2520 ir_ref_instruction(type_info, ag->current_basic_block);
25212521
25222522 return &instruction->base;
25232523}
25242524
2525static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2525static IrInstSrc *ir_build_set_eval_branch_quota(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25262526 IrInstSrc *new_quota)
25272527{
2528 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node);
2528 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(ag, scope, source_node);
25292529 instruction->new_quota = new_quota;
25302530
2531 ir_ref_instruction(new_quota, irb->current_basic_block);
2531 ir_ref_instruction(new_quota, ag->current_basic_block);
25322532
25332533 return &instruction->base;
25342534}
25352535
2536static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2536static IrInstSrc *ir_build_align_cast_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25372537 IrInstSrc *align_bytes, IrInstSrc *target)
25382538{
2539 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node);
2539 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(ag, scope, source_node);
25402540 instruction->align_bytes = align_bytes;
25412541 instruction->target = target;
25422542
2543 ir_ref_instruction(align_bytes, irb->current_basic_block);
2544 ir_ref_instruction(target, irb->current_basic_block);
2543 ir_ref_instruction(align_bytes, ag->current_basic_block);
2544 ir_ref_instruction(target, ag->current_basic_block);
25452545
25462546 return &instruction->base;
25472547}
25482548
2549static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2549static IrInstSrc *ir_build_resolve_result(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25502550 ResultLoc *result_loc, IrInstSrc *ty)
25512551{
2552 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node);
2552 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(ag, scope, source_node);
25532553 instruction->result_loc = result_loc;
25542554 instruction->ty = ty;
25552555
2556 if (ty != nullptr) ir_ref_instruction(ty, irb->current_basic_block);
2556 if (ty != nullptr) ir_ref_instruction(ty, ag->current_basic_block);
25572557
25582558 return &instruction->base;
25592559}
25602560
2561static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2561static IrInstSrc *ir_build_reset_result(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25622562 ResultLoc *result_loc)
25632563{
2564 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node);
2564 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(ag, scope, source_node);
25652565 instruction->result_loc = result_loc;
25662566 instruction->base.is_gen = true;
25672567
25682568 return &instruction->base;
25692569}
25702570
2571static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2571static IrInstSrc *ir_build_set_align_stack(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25722572 IrInstSrc *align_bytes)
25732573{
2574 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node);
2574 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(ag, scope, source_node);
25752575 instruction->align_bytes = align_bytes;
25762576
2577 ir_ref_instruction(align_bytes, irb->current_basic_block);
2577 ir_ref_instruction(align_bytes, ag->current_basic_block);
25782578
25792579 return &instruction->base;
25802580}
25812581
2582static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2582static IrInstSrc *ir_build_arg_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
25832583 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
25842584{
25852585 IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>();
......@@ -2587,273 +2587,273 @@ static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *so
25872587 IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse;
25882588 instruction->base.base.scope = scope;
25892589 instruction->base.base.source_node = source_node;
2590 instruction->base.base.debug_id = irb_next_debug_id(irb);
2591 instruction->base.owner_bb = irb->current_basic_block;
2592 ir_instruction_append(irb->current_basic_block, &instruction->base);
2590 instruction->base.base.debug_id = irb_next_debug_id(ag);
2591 instruction->base.owner_bb = ag->current_basic_block;
2592 ir_instruction_append(ag->current_basic_block, &instruction->base);
25932593
25942594 instruction->fn_type = fn_type;
25952595 instruction->arg_index = arg_index;
25962596
2597 ir_ref_instruction(fn_type, irb->current_basic_block);
2598 ir_ref_instruction(arg_index, irb->current_basic_block);
2597 ir_ref_instruction(fn_type, ag->current_basic_block);
2598 ir_ref_instruction(arg_index, ag->current_basic_block);
25992599
26002600 return &instruction->base;
26012601}
26022602
2603static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2603static IrInstSrc *ir_build_error_return_trace_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26042604 IrInstErrorReturnTraceOptional optional)
26052605{
2606 IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node);
2606 IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(ag, scope, source_node);
26072607 inst->optional = optional;
26082608
26092609 return &inst->base;
26102610}
26112611
2612static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2612static IrInstSrc *ir_build_error_union(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26132613 IrInstSrc *err_set, IrInstSrc *payload)
26142614{
2615 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node);
2615 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(ag, scope, source_node);
26162616 instruction->err_set = err_set;
26172617 instruction->payload = payload;
26182618
2619 ir_ref_instruction(err_set, irb->current_basic_block);
2620 ir_ref_instruction(payload, irb->current_basic_block);
2619 ir_ref_instruction(err_set, ag->current_basic_block);
2620 ir_ref_instruction(payload, ag->current_basic_block);
26212621
26222622 return &instruction->base;
26232623}
26242624
2625static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2625static IrInstSrc *ir_build_atomic_rmw_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26262626 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand,
26272627 IrInstSrc *ordering)
26282628{
2629 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node);
2629 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(ag, scope, source_node);
26302630 instruction->operand_type = operand_type;
26312631 instruction->ptr = ptr;
26322632 instruction->op = op;
26332633 instruction->operand = operand;
26342634 instruction->ordering = ordering;
26352635
2636 ir_ref_instruction(operand_type, irb->current_basic_block);
2637 ir_ref_instruction(ptr, irb->current_basic_block);
2638 ir_ref_instruction(op, irb->current_basic_block);
2639 ir_ref_instruction(operand, irb->current_basic_block);
2640 ir_ref_instruction(ordering, irb->current_basic_block);
2636 ir_ref_instruction(operand_type, ag->current_basic_block);
2637 ir_ref_instruction(ptr, ag->current_basic_block);
2638 ir_ref_instruction(op, ag->current_basic_block);
2639 ir_ref_instruction(operand, ag->current_basic_block);
2640 ir_ref_instruction(ordering, ag->current_basic_block);
26412641
26422642 return &instruction->base;
26432643}
26442644
2645static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2645static IrInstSrc *ir_build_atomic_load_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26462646 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering)
26472647{
2648 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node);
2648 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(ag, scope, source_node);
26492649 instruction->operand_type = operand_type;
26502650 instruction->ptr = ptr;
26512651 instruction->ordering = ordering;
26522652
2653 ir_ref_instruction(operand_type, irb->current_basic_block);
2654 ir_ref_instruction(ptr, irb->current_basic_block);
2655 ir_ref_instruction(ordering, irb->current_basic_block);
2653 ir_ref_instruction(operand_type, ag->current_basic_block);
2654 ir_ref_instruction(ptr, ag->current_basic_block);
2655 ir_ref_instruction(ordering, ag->current_basic_block);
26562656
26572657 return &instruction->base;
26582658}
26592659
2660static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2660static IrInstSrc *ir_build_atomic_store_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26612661 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering)
26622662{
2663 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node);
2663 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(ag, scope, source_node);
26642664 instruction->operand_type = operand_type;
26652665 instruction->ptr = ptr;
26662666 instruction->value = value;
26672667 instruction->ordering = ordering;
26682668
2669 ir_ref_instruction(operand_type, irb->current_basic_block);
2670 ir_ref_instruction(ptr, irb->current_basic_block);
2671 ir_ref_instruction(value, irb->current_basic_block);
2672 ir_ref_instruction(ordering, irb->current_basic_block);
2669 ir_ref_instruction(operand_type, ag->current_basic_block);
2670 ir_ref_instruction(ptr, ag->current_basic_block);
2671 ir_ref_instruction(value, ag->current_basic_block);
2672 ir_ref_instruction(ordering, ag->current_basic_block);
26732673
26742674 return &instruction->base;
26752675}
26762676
2677static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2678 IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node);
2677static IrInstSrc *ir_build_save_err_ret_addr_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2678 IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(ag, scope, source_node);
26792679 return &inst->base;
26802680}
26812681
2682static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2682static IrInstSrc *ir_build_add_implicit_return_type(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26832683 IrInstSrc *value, ResultLocReturn *result_loc_ret)
26842684{
2685 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node);
2685 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(ag, scope, source_node);
26862686 inst->value = value;
26872687 inst->result_loc_ret = result_loc_ret;
26882688
2689 ir_ref_instruction(value, irb->current_basic_block);
2689 ir_ref_instruction(value, ag->current_basic_block);
26902690
26912691 return &inst->base;
26922692}
26932693
2694static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2694static IrInstSrc *ir_build_has_decl(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
26952695 IrInstSrc *container, IrInstSrc *name)
26962696{
2697 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node);
2697 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(ag, scope, source_node);
26982698 instruction->container = container;
26992699 instruction->name = name;
27002700
2701 ir_ref_instruction(container, irb->current_basic_block);
2702 ir_ref_instruction(name, irb->current_basic_block);
2701 ir_ref_instruction(container, ag->current_basic_block);
2702 ir_ref_instruction(name, ag->current_basic_block);
27032703
27042704 return &instruction->base;
27052705}
27062706
2707static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
2708 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node);
2707static IrInstSrc *ir_build_undeclared_identifier(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Buf *name) {
2708 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(ag, scope, source_node);
27092709 instruction->name = name;
27102710
27112711 return &instruction->base;
27122712}
27132713
2714static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) {
2715 IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node);
2714static 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>(ag, scope, source_node);
27162716 instruction->scope_is_comptime = scope_is_comptime;
27172717 instruction->is_comptime = is_comptime;
27182718
2719 ir_ref_instruction(scope_is_comptime, irb->current_basic_block);
2720 ir_ref_instruction(is_comptime, irb->current_basic_block);
2719 ir_ref_instruction(scope_is_comptime, ag->current_basic_block);
2720 ir_ref_instruction(is_comptime, ag->current_basic_block);
27212721
27222722 return &instruction->base;
27232723}
27242724
2725static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2725static IrInstSrc *ir_build_union_init_named_field(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
27262726 IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc)
27272727{
2728 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node);
2728 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(ag, scope, source_node);
27292729 instruction->union_type = union_type;
27302730 instruction->field_name = field_name;
27312731 instruction->field_result_loc = field_result_loc;
27322732 instruction->result_loc = result_loc;
27332733
2734 ir_ref_instruction(union_type, irb->current_basic_block);
2735 ir_ref_instruction(field_name, irb->current_basic_block);
2736 ir_ref_instruction(field_result_loc, irb->current_basic_block);
2737 if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block);
2734 ir_ref_instruction(union_type, ag->current_basic_block);
2735 ir_ref_instruction(field_name, ag->current_basic_block);
2736 ir_ref_instruction(field_result_loc, ag->current_basic_block);
2737 if (result_loc != nullptr) ir_ref_instruction(result_loc, ag->current_basic_block);
27382738
27392739 return &instruction->base;
27402740}
27412741
2742static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2742static IrInstSrc *ir_build_alloca_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
27432743 IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime)
27442744{
2745 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node);
2745 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(ag, scope, source_node);
27462746 instruction->base.is_gen = true;
27472747 instruction->align = align;
27482748 instruction->name_hint = name_hint;
27492749 instruction->is_comptime = is_comptime;
27502750
2751 if (align != nullptr) ir_ref_instruction(align, irb->current_basic_block);
2752 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, 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, ag->current_basic_block);
27532753
27542754 return &instruction->base;
27552755}
27562756
2757static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2757static IrInstSrc *ir_build_end_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
27582758 IrInstSrc *value, ResultLoc *result_loc)
27592759{
2760 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node);
2760 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(ag, scope, source_node);
27612761 instruction->base.is_gen = true;
27622762 instruction->value = value;
27632763 instruction->result_loc = result_loc;
27642764
2765 ir_ref_instruction(value, irb->current_basic_block);
2765 ir_ref_instruction(value, ag->current_basic_block);
27662766
27672767 return &instruction->base;
27682768}
27692769
2770static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2771 return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node);
2770static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2771 return ir_build_instruction<IrInstSrcSuspendBegin>(ag, scope, source_node);
27722772}
27732773
2774static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2774static IrInstSrc *ir_build_suspend_finish_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
27752775 IrInstSrcSuspendBegin *begin)
27762776{
2777 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node);
2777 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(ag, scope, source_node);
27782778 inst->begin = begin;
27792779
2780 ir_ref_instruction(&begin->base, irb->current_basic_block);
2780 ir_ref_instruction(&begin->base, ag->current_basic_block);
27812781
27822782 return &inst->base;
27832783}
27842784
2785static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2785static IrInstSrc *ir_build_await_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
27862786 IrInstSrc *frame, ResultLoc *result_loc, bool is_nosuspend)
27872787{
2788 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
2788 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(ag, scope, source_node);
27892789 instruction->frame = frame;
27902790 instruction->result_loc = result_loc;
27912791 instruction->is_nosuspend = is_nosuspend;
27922792
2793 ir_ref_instruction(frame, irb->current_basic_block);
2793 ir_ref_instruction(frame, ag->current_basic_block);
27942794
27952795 return &instruction->base;
27962796}
27972797
2798static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
2799 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node);
2798static IrInstSrc *ir_build_resume_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
2799 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(ag, scope, source_node);
28002800 instruction->frame = frame;
28012801
2802 ir_ref_instruction(frame, irb->current_basic_block);
2802 ir_ref_instruction(frame, ag->current_basic_block);
28032803
28042804 return &instruction->base;
28052805}
28062806
2807static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2807static IrInstSrcSpillBegin *ir_build_spill_begin_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
28082808 IrInstSrc *operand, SpillId spill_id)
28092809{
2810 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node);
2810 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(ag, scope, source_node);
28112811 instruction->operand = operand;
28122812 instruction->spill_id = spill_id;
28132813
2814 ir_ref_instruction(operand, irb->current_basic_block);
2814 ir_ref_instruction(operand, ag->current_basic_block);
28152815
28162816 return instruction;
28172817}
28182818
2819static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2819static IrInstSrc *ir_build_spill_end_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
28202820 IrInstSrcSpillBegin *begin)
28212821{
2822 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node);
2822 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(ag, scope, source_node);
28232823 instruction->begin = begin;
28242824
2825 ir_ref_instruction(&begin->base, irb->current_basic_block);
2825 ir_ref_instruction(&begin->base, ag->current_basic_block);
28262826
28272827 return &instruction->base;
28282828}
28292829
2830static IrInstSrc *ir_build_wasm_memory_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *index) {
2831 IrInstSrcWasmMemorySize *instruction = ir_build_instruction<IrInstSrcWasmMemorySize>(irb, scope, source_node);
2830static IrInstSrc *ir_build_wasm_memory_size_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *index) {
2831 IrInstSrcWasmMemorySize *instruction = ir_build_instruction<IrInstSrcWasmMemorySize>(ag, scope, source_node);
28322832 instruction->index = index;
28332833
2834 ir_ref_instruction(index, irb->current_basic_block);
2834 ir_ref_instruction(index, ag->current_basic_block);
28352835
28362836 return &instruction->base;
28372837}
28382838
2839static IrInstSrc *ir_build_wasm_memory_grow_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *index, IrInstSrc *delta) {
2840 IrInstSrcWasmMemoryGrow *instruction = ir_build_instruction<IrInstSrcWasmMemoryGrow>(irb, scope, source_node);
2839static 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>(ag, scope, source_node);
28412841 instruction->index = index;
28422842 instruction->delta = delta;
28432843
2844 ir_ref_instruction(index, irb->current_basic_block);
2845 ir_ref_instruction(delta, irb->current_basic_block);
2844 ir_ref_instruction(index, ag->current_basic_block);
2845 ir_ref_instruction(delta, ag->current_basic_block);
28462846
28472847 return &instruction->base;
28482848}
28492849
2850static IrInstSrc *ir_build_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2851 IrInstSrcSrc *instruction = ir_build_instruction<IrInstSrcSrc>(irb, scope, source_node);
2850static IrInstSrc *ir_build_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
2851 IrInstSrcSrc *instruction = ir_build_instruction<IrInstSrcSrc>(ag, scope, source_node);
28522852
28532853 return &instruction->base;
28542854}
28552855
2856static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
2856static void ir_count_defers(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, size_t *results) {
28572857 results[ReturnKindUnconditional] = 0;
28582858 results[ReturnKindError] = 0;
28592859
......@@ -2896,7 +2896,7 @@ static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
28962896 return instruction;
28972897}
28982898
2899static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) {
2899static bool ir_gen_defers_for_block(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) {
29002900 Scope *scope = inner_scope;
29012901 if (is_noreturn != nullptr) *is_noreturn = false;
29022902 while (scope != outer_scope) {
......@@ -2925,36 +2925,36 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope
29252925 Buf *var_name = node_identifier_buf(defer_var_node);
29262926
29272927 if (defer_expr_node->type == NodeTypeUnreachable) {
2928 add_node_error(irb->codegen, defer_var_node,
2928 add_node_error(ag->codegen, defer_var_node,
29292929 buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
29302930 return false;
29312931 }
29322932
29332933 IrInstSrc *is_comptime;
2934 if (ir_should_inline(irb->exec, defer_expr_scope)) {
2935 is_comptime = ir_build_const_bool(irb, defer_expr_scope,
2934 if (ir_should_inline(ag->exec, defer_expr_scope)) {
2935 is_comptime = ir_build_const_bool(ag, defer_expr_scope,
29362936 defer_expr_node, true);
29372937 } else {
2938 is_comptime = ir_build_test_comptime(irb, defer_expr_scope,
2938 is_comptime = ir_build_test_comptime(ag, defer_expr_scope,
29392939 defer_expr_node, err_value);
29402940 }
29412941
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,
29432943 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,
29452945 buf_ptr(var_name), is_comptime);
29462946
29472947 defer_expr_scope = err_var->child_scope;
29482948 }
29492949
2950 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
2951 if (defer_expr_value == irb->codegen->invalid_inst_src)
2952 return irb->codegen->invalid_inst_src;
2950 IrInstSrc *defer_expr_value = ir_gen_node(ag, defer_expr_node, defer_expr_scope);
2951 if (defer_expr_value == ag->codegen->invalid_inst_src)
2952 return ag->codegen->invalid_inst_src;
29532953
29542954 if (defer_expr_value->is_noreturn) {
29552955 if (is_noreturn != nullptr) *is_noreturn = true;
29562956 } 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,
29582958 defer_expr_value));
29592959 }
29602960 scope = scope->parent;
......@@ -2982,15 +2982,15 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope
29822982 return true;
29832983}
29842984
2985static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
2985static void ir_set_cursor_at_end(Stage1AstGen *ag, IrBasicBlockSrc *basic_block) {
29862986 assert(basic_block);
2987 irb->current_basic_block = basic_block;
2987 ag->current_basic_block = basic_block;
29882988}
29892989
2990static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
2991 basic_block->index = irb->exec->basic_block_list.length;
2992 irb->exec->basic_block_list.append(basic_block);
2993 ir_set_cursor_at_end(irb, basic_block);
2990static void ir_set_cursor_at_end_and_append_block(Stage1AstGen *ag, IrBasicBlockSrc *basic_block) {
2991 basic_block->index = ag->exec->basic_block_list.length;
2992 ag->exec->basic_block_list.append(basic_block);
2993 ir_set_cursor_at_end(ag, basic_block);
29942994}
29952995
29962996static ScopeSuspend *get_scope_suspend(Scope *scope) {
......@@ -3017,19 +3017,19 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
30173017 return nullptr;
30183018}
30193019
3020static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
3020static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
30213021 assert(node->type == NodeTypeReturnExpr);
30223022
30233023 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
30243024 if (scope_defer_expr) {
30253025 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"));
30273027 scope_defer_expr->reported_err = true;
30283028 }
3029 return irb->codegen->invalid_inst_src;
3029 return ag->codegen->invalid_inst_src;
30303030 }
30313031
3032 Scope *outer_scope = irb->exec->begin_scope;
3032 Scope *outer_scope = ag->exec->begin_scope;
30333033
30343034 AstNode *expr_node = node->data.return_expr.expr;
30353035 switch (node->data.return_expr.kind) {
......@@ -3037,119 +3037,119 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
30373037 {
30383038 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
30393039 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);
30413041
30423042 IrInstSrc *return_value;
30433043 if (expr_node) {
30443044 // 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;
3046 irb->exec->name_fn = exec_fn_entry(irb->exec);
3047 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
3048 irb->exec->name_fn = prev_name_fn;
3049 if (return_value == irb->codegen->invalid_inst_src)
3050 return irb->codegen->invalid_inst_src;
3045 ZigFn *prev_name_fn = ag->exec->name_fn;
3046 ag->exec->name_fn = exec_fn_entry(ag->exec);
3047 return_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, &result_loc_ret->base);
3048 ag->exec->name_fn = prev_name_fn;
3049 if (return_value == ag->codegen->invalid_inst_src)
3050 return ag->codegen->invalid_inst_src;
30513051 } else {
3052 return_value = ir_build_const_void(irb, scope, node);
3053 ir_build_end_expr(irb, scope, node, return_value, &result_loc_ret->base);
3052 return_value = ir_build_const_void(ag, scope, node);
3053 ir_build_end_expr(ag, scope, node, return_value, &result_loc_ret->base);
30543054 }
30553055
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));
30573057
30583058 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);
30603060 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) {
30623062 // only generate unconditional defers
3063 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr))
3064 return irb->codegen->invalid_inst_src;
3065 IrInstSrc *result = ir_build_return_src(irb, scope, node, nullptr);
3063 if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr))
3064 return ag->codegen->invalid_inst_src;
3065 IrInstSrc *result = ir_build_return_src(ag, scope, node, nullptr);
30663066 result_loc_ret->base.source_instruction = result;
30673067 return result;
30683068 }
3069 bool should_inline = ir_should_inline(irb->exec, scope);
3069 bool should_inline = ir_should_inline(ag->exec, scope);
30703070
3071 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
3072 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
3071 IrBasicBlockSrc *err_block = ir_create_basic_block(ag, scope, "ErrRetErr");
3072 IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, scope, "ErrRetOk");
30733073
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);
30753075
30763076 IrInstSrc *is_comptime;
30773077 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);
30793079 } 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);
30813081 }
30823082
3083 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));
3084 IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
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(ag, scope, "RetStmt");
30853085
3086 ir_set_cursor_at_end_and_append_block(irb, err_block);
3087 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, return_value))
3088 return irb->codegen->invalid_inst_src;
3089 if (irb->codegen->have_err_ret_tracing && !should_inline) {
3090 ir_build_save_err_ret_addr_src(irb, scope, node);
3086 ir_set_cursor_at_end_and_append_block(ag, err_block);
3087 if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, return_value))
3088 return ag->codegen->invalid_inst_src;
3089 if (ag->codegen->have_err_ret_tracing && !should_inline) {
3090 ir_build_save_err_ret_addr_src(ag, scope, node);
30913091 }
3092 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
3092 ir_build_br(ag, scope, node, ret_stmt_block, is_comptime);
30933093
3094 ir_set_cursor_at_end_and_append_block(irb, ok_block);
3095 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr))
3096 return irb->codegen->invalid_inst_src;
3097 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
3094 ir_set_cursor_at_end_and_append_block(ag, ok_block);
3095 if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr))
3096 return ag->codegen->invalid_inst_src;
3097 ir_build_br(ag, scope, node, ret_stmt_block, is_comptime);
30983098
3099 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
3100 IrInstSrc *result = ir_build_return_src(irb, scope, node, nullptr);
3099 ir_set_cursor_at_end_and_append_block(ag, ret_stmt_block);
3100 IrInstSrc *result = ir_build_return_src(ag, scope, node, nullptr);
31013101 result_loc_ret->base.source_instruction = result;
31023102 return result;
31033103 }
31043104 case ReturnKindError:
31053105 {
31063106 assert(expr_node);
3107 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
3108 if (err_union_ptr == irb->codegen->invalid_inst_src)
3109 return irb->codegen->invalid_inst_src;
3110 IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
3107 IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr);
3108 if (err_union_ptr == ag->codegen->invalid_inst_src)
3109 return ag->codegen->invalid_inst_src;
3110 IrInstSrc *is_err_val = ir_build_test_err_src(ag, scope, node, err_union_ptr, true, false);
31113111
3112 IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
3113 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
3112 IrBasicBlockSrc *return_block = ir_create_basic_block(ag, scope, "ErrRetReturn");
3113 IrBasicBlockSrc *continue_block = ir_create_basic_block(ag, scope, "ErrRetContinue");
31143114 IrInstSrc *is_comptime;
3115 bool should_inline = ir_should_inline(irb->exec, scope);
3115 bool should_inline = ir_should_inline(ag->exec, scope);
31163116 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);
31183118 } 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);
31203120 }
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));
31223122
3123 ir_set_cursor_at_end_and_append_block(irb, return_block);
3124 IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr);
3125 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
3126 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
3127 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
3123 ir_set_cursor_at_end_and_append_block(ag, return_block);
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(ag, scope, node, err_val_ptr);
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(ag, scope, node, err_val,
31283128 SpillIdRetErrCode);
31293129 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
31303130 result_loc_ret->base.id = ResultLocIdReturn;
3131 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
3132 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
3131 ir_build_reset_result(ag, scope, node, &result_loc_ret->base);
3132 ir_build_end_expr(ag, scope, node, err_val, &result_loc_ret->base);
31333133
31343134 bool is_noreturn = false;
3135 if (!ir_gen_defers_for_block(irb, scope, outer_scope, &is_noreturn, err_val)) {
3136 return irb->codegen->invalid_inst_src;
3135 if (!ir_gen_defers_for_block(ag, scope, outer_scope, &is_noreturn, err_val)) {
3136 return ag->codegen->invalid_inst_src;
31373137 }
31383138 if (!is_noreturn) {
3139 if (irb->codegen->have_err_ret_tracing && !should_inline) {
3140 ir_build_save_err_ret_addr_src(irb, scope, node);
3139 if (ag->codegen->have_err_ret_tracing && !should_inline) {
3140 ir_build_save_err_ret_addr_src(ag, scope, node);
31413141 }
3142 err_val = ir_build_spill_end_src(irb, scope, node, spill_begin);
3143 IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val);
3142 err_val = ir_build_spill_end_src(ag, scope, node, spill_begin);
3143 IrInstSrc *ret_inst = ir_build_return_src(ag, scope, node, err_val);
31443144 result_loc_ret->base.source_instruction = ret_inst;
31453145 }
31463146
3147 ir_set_cursor_at_end_and_append_block(irb, continue_block);
3148 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false);
3147 ir_set_cursor_at_end_and_append_block(ag, continue_block);
3148 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(ag, scope, node, err_union_ptr, false, false);
31493149 if (lval == LValPtr)
31503150 return unwrapped_ptr;
31513151 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);
31533153 }
31543154 }
31553155 zig_unreachable();
......@@ -3227,11 +3227,11 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
32273227
32283228// Set name to nullptr to make the variable anonymous (not visible to programmer).
32293229// After you call this function var->child_scope has the variable in scope
3230static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
3230static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf *name,
32313231 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime)
32323232{
32333233 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,
32353235 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
32363236 (is_underscored ? true : is_shadowable), is_comptime, false);
32373237 assert(var->child_scope);
......@@ -3266,7 +3266,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam
32663266 return false;
32673267}
32683268
3269static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
3269static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *block_node, LVal lval,
32703270 ResultLoc *result_loc)
32713271{
32723272 assert(block_node->type == NodeTypeBlock);
......@@ -3274,10 +3274,10 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
32743274 ZigList<IrInstSrc *> incoming_values = {0};
32753275 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
32763276
3277 if (is_duplicate_label(irb->codegen, parent_scope, block_node, block_node->data.block.name))
3278 return irb->codegen->invalid_inst_src;
3277 if (is_duplicate_label(ag->codegen, parent_scope, block_node, block_node->data.block.name))
3278 return ag->codegen->invalid_inst_src;
32793279
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);
32813281
32823282 Scope *outer_block_scope = &scope_block->base;
32833283 Scope *child_scope = outer_block_scope;
......@@ -3289,19 +3289,19 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
32893289
32903290 if (block_node->data.block.statements.length == 0) {
32913291 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"));
32933293 }
32943294 // {}
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);
32963296 }
32973297
32983298 if (block_node->data.block.name != nullptr) {
32993299 scope_block->lval = lval;
33003300 scope_block->incoming_blocks = &incoming_blocks;
33013301 scope_block->incoming_values = &incoming_values;
3302 scope_block->end_block = ir_create_basic_block(irb, parent_scope, "BlockEnd");
3303 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node,
3304 ir_should_inline(irb->exec, parent_scope));
3302 scope_block->end_block = ir_create_basic_block(ag, parent_scope, "BlockEnd");
3303 scope_block->is_comptime = ir_build_const_bool(ag, parent_scope, block_node,
3304 ir_should_inline(ag->exec, parent_scope));
33053305
33063306 scope_block->peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
33073307 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
......@@ -3310,7 +3310,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
33103310 scope_block->peer_parent->end_bb = scope_block->end_block;
33113311 scope_block->peer_parent->is_comptime = scope_block->is_comptime;
33123312 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);
33143314 }
33153315
33163316 bool is_continuation_unreachable = false;
......@@ -3319,8 +3319,8 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
33193319 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
33203320 AstNode *statement_node = block_node->data.block.statements.at(i);
33213321
3322 IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope);
3323 if (statement_value == irb->codegen->invalid_inst_src) {
3322 IrInstSrc *statement_value = ir_gen_node(ag, statement_node, child_scope);
3323 if (statement_value == ag->codegen->invalid_inst_src) {
33243324 // keep generating all the elements of the block in case of error,
33253325 // we want to collect other compile errors
33263326 found_invalid_inst = true;
......@@ -3344,16 +3344,16 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
33443344 child_scope = decl_var_instruction->var->child_scope;
33453345 } else if (!is_continuation_unreachable) {
33463346 // 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));
33483348 }
33493349 }
33503350
33513351 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"));
33533353 }
33543354
33553355 if (found_invalid_inst)
3356 return irb->codegen->invalid_inst_src;
3356 return ag->codegen->invalid_inst_src;
33573357
33583358 if (is_continuation_unreachable) {
33593359 assert(noreturn_return_value != nullptr);
......@@ -3364,18 +3364,18 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
33643364 if (scope_block->peer_parent != nullptr && scope_block->peer_parent->peers.length != 0) {
33653365 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;
33663366 }
3367 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
3368 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
3367 ir_set_cursor_at_end_and_append_block(ag, scope_block->end_block);
3368 IrInstSrc *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length,
33693369 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);
33713371 } else {
3372 incoming_blocks.append(irb->current_basic_block);
3373 IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
3372 incoming_blocks.append(ag->current_basic_block);
3373 IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(ag, parent_scope, block_node));
33743374
33753375 if (scope_block->peer_parent != nullptr) {
33763376 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);
33773377 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);
33793379
33803380 if (scope_block->peer_parent->peers.length != 0) {
33813381 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 *
33853385 incoming_values.append(else_expr_result);
33863386 }
33873387
3388 bool is_return_from_fn = block_node == irb->main_block_node;
3388 bool is_return_from_fn = block_node == ag->main_block_node;
33893389 if (!is_return_from_fn) {
3390 if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr))
3391 return irb->codegen->invalid_inst_src;
3390 if (!ir_gen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr))
3391 return ag->codegen->invalid_inst_src;
33923392 }
33933393
33943394 IrInstSrc *result;
33953395 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));
3397 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
3398 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
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(ag, scope_block->end_block);
3398 IrInstSrc *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length,
33993399 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);
34013401 } else {
3402 IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
3403 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);
3402 IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(ag, child_scope, block_node));
3403 result = ir_lval_wrap(ag, parent_scope, void_inst, lval, result_loc);
34043404 }
34053405 if (!is_return_from_fn)
34063406 return result;
......@@ -3408,108 +3408,108 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
34083408 // no need for save_err_ret_addr because this cannot return error
34093409 // only generate unconditional defers
34103410
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));
34123412 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
34133413 result_loc_ret->base.id = ResultLocIdReturn;
3414 ir_build_reset_result(irb, 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));
3416 if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr))
3417 return irb->codegen->invalid_inst_src;
3418 return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result));
3414 ir_build_reset_result(ag, parent_scope, block_node, &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(ag, child_scope, outer_block_scope, nullptr, nullptr))
3417 return ag->codegen->invalid_inst_src;
3418 return ir_mark_gen(ir_build_return_src(ag, child_scope, result->base.source_node, result));
34193419}
34203420
3421static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
3421static IrInstSrc *ir_gen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) {
34223422 Scope *inner_scope = scope;
34233423 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);
34253425 }
34263426
3427 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
3428 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
3427 IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, inner_scope);
3428 IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, inner_scope);
34293429
3430 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
3431 return irb->codegen->invalid_inst_src;
3430 if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src)
3431 return ag->codegen->invalid_inst_src;
34323432
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);
34343434}
34353435
3436static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3437 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
3438 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3436static IrInstSrc *ir_gen_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *node) {
3437 IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope);
3438 IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope);
34393439
3440 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
3441 return irb->codegen->invalid_inst_src;
3440 if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src)
3441 return ag->codegen->invalid_inst_src;
34423442
34433443 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
34443444 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);
34463446
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);
34483448}
34493449
3450static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3451 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValAssign, nullptr);
3452 if (lvalue == irb->codegen->invalid_inst_src)
3453 return irb->codegen->invalid_inst_src;
3450static IrInstSrc *ir_gen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) {
3451 IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr);
3452 if (lvalue == ag->codegen->invalid_inst_src)
3453 return ag->codegen->invalid_inst_src;
34543454
34553455 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
34563456 result_loc_inst->base.id = ResultLocIdInstruction;
34573457 result_loc_inst->base.source_instruction = lvalue;
3458 ir_ref_instruction(lvalue, irb->current_basic_block);
3459 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);
3458 ir_ref_instruction(lvalue, ag->current_basic_block);
3459 ir_build_reset_result(ag, scope, node, &result_loc_inst->base);
34603460
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,
34623462 &result_loc_inst->base);
3463 if (rvalue == irb->codegen->invalid_inst_src)
3464 return irb->codegen->invalid_inst_src;
3463 if (rvalue == ag->codegen->invalid_inst_src)
3464 return ag->codegen->invalid_inst_src;
34653465
3466 return ir_build_const_void(irb, scope, node);
3466 return ir_build_const_void(ag, scope, node);
34673467}
34683468
3469static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
3470 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValAssign, nullptr);
3471 if (lvalue == irb->codegen->invalid_inst_src)
3469static IrInstSrc *ir_gen_assign_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) {
3470 IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr);
3471 if (lvalue == ag->codegen->invalid_inst_src)
34723472 return lvalue;
3473 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
3474 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3475 if (op2 == irb->codegen->invalid_inst_src)
3473 IrInstSrc *op1 = ir_build_load_ptr(ag, scope, node->data.bin_op_expr.op1, lvalue);
3474 IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope);
3475 if (op2 == ag->codegen->invalid_inst_src)
34763476 return op2;
3477 IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
3478 ir_build_store_ptr(irb, scope, node, lvalue, result);
3479 return ir_build_const_void(irb, scope, node);
3477 IrInstSrc *result = ir_build_bin_op(ag, scope, node, op_id, op1, op2, true);
3478 ir_build_store_ptr(ag, scope, node, lvalue, result);
3479 return ir_build_const_void(ag, scope, node);
34803480}
34813481
3482static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3482static IrInstSrc *ir_gen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) {
34833483 assert(node->type == NodeTypeBinOpExpr);
34843484
3485 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
3486 if (val1 == irb->codegen->invalid_inst_src)
3487 return irb->codegen->invalid_inst_src;
3488 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
3485 IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope);
3486 if (val1 == ag->codegen->invalid_inst_src)
3487 return ag->codegen->invalid_inst_src;
3488 IrBasicBlockSrc *post_val1_block = ag->current_basic_block;
34893489
34903490 IrInstSrc *is_comptime;
3491 if (ir_should_inline(irb->exec, scope)) {
3492 is_comptime = ir_build_const_bool(irb, scope, node, true);
3491 if (ir_should_inline(ag->exec, scope)) {
3492 is_comptime = ir_build_const_bool(ag, scope, node, true);
34933493 } else {
3494 is_comptime = ir_build_test_comptime(irb, scope, node, val1);
3494 is_comptime = ir_build_test_comptime(ag, scope, node, val1);
34953495 }
34963496
34973497 // 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");
34993499 // 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");
35013501
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);
35033503
3504 ir_set_cursor_at_end_and_append_block(irb, false_block);
3505 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3506 if (val2 == irb->codegen->invalid_inst_src)
3507 return irb->codegen->invalid_inst_src;
3508 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
3504 ir_set_cursor_at_end_and_append_block(ag, false_block);
3505 IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope);
3506 if (val2 == ag->codegen->invalid_inst_src)
3507 return ag->codegen->invalid_inst_src;
3508 IrBasicBlockSrc *post_val2_block = ag->current_basic_block;
35093509
3510 ir_build_br(irb, scope, node, true_block, is_comptime);
3510 ir_build_br(ag, scope, node, true_block, is_comptime);
35113511
3512 ir_set_cursor_at_end_and_append_block(irb, true_block);
3512 ir_set_cursor_at_end_and_append_block(ag, true_block);
35133513
35143514 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
35153515 incoming_values[0] = val1;
......@@ -3518,40 +3518,40 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node)
35183518 incoming_blocks[0] = post_val1_block;
35193519 incoming_blocks[1] = post_val2_block;
35203520
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);
35223522}
35233523
3524static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3524static IrInstSrc *ir_gen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) {
35253525 assert(node->type == NodeTypeBinOpExpr);
35263526
3527 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
3528 if (val1 == irb->codegen->invalid_inst_src)
3529 return irb->codegen->invalid_inst_src;
3530 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
3527 IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope);
3528 if (val1 == ag->codegen->invalid_inst_src)
3529 return ag->codegen->invalid_inst_src;
3530 IrBasicBlockSrc *post_val1_block = ag->current_basic_block;
35313531
35323532 IrInstSrc *is_comptime;
3533 if (ir_should_inline(irb->exec, scope)) {
3534 is_comptime = ir_build_const_bool(irb, scope, node, true);
3533 if (ir_should_inline(ag->exec, scope)) {
3534 is_comptime = ir_build_const_bool(ag, scope, node, true);
35353535 } else {
3536 is_comptime = ir_build_test_comptime(irb, scope, node, val1);
3536 is_comptime = ir_build_test_comptime(ag, scope, node, val1);
35373537 }
35383538
35393539 // 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");
35413541 // 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");
35433543
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);
35453545
3546 ir_set_cursor_at_end_and_append_block(irb, true_block);
3547 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3548 if (val2 == irb->codegen->invalid_inst_src)
3549 return irb->codegen->invalid_inst_src;
3550 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
3546 ir_set_cursor_at_end_and_append_block(ag, true_block);
3547 IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope);
3548 if (val2 == ag->codegen->invalid_inst_src)
3549 return ag->codegen->invalid_inst_src;
3550 IrBasicBlockSrc *post_val2_block = ag->current_basic_block;
35513551
3552 ir_build_br(irb, scope, node, false_block, is_comptime);
3552 ir_build_br(ag, scope, node, false_block, is_comptime);
35533553
3554 ir_set_cursor_at_end_and_append_block(irb, false_block);
3554 ir_set_cursor_at_end_and_append_block(ag, false_block);
35553555
35563556 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
35573557 incoming_values[0] = val1;
......@@ -3560,10 +3560,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
35603560 incoming_blocks[0] = post_val1_block;
35613561 incoming_blocks[1] = post_val2_block;
35623562
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);
35643564}
35653565
3566static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
3566static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, IrInstSrc *cond_br_inst,
35673567 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
35683568{
35693569 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
......@@ -3574,19 +3574,19 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *
35743574 peer_parent->is_comptime = is_comptime;
35753575 peer_parent->parent = parent;
35763576
3577 IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop();
3577 IrInstSrc *popped_inst = ag->current_basic_block->instruction_list.pop();
35783578 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);
35793579
3580 ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
3581 irb->current_basic_block->instruction_list.append(popped_inst);
3580 ir_build_reset_result(ag, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
3581 ag->current_basic_block->instruction_list.append(popped_inst);
35823582
35833583 return peer_parent;
35843584}
35853585
3586static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
3586static ResultLocPeerParent *ir_build_binary_result_peers(Stage1AstGen *ag, IrInstSrc *cond_br_inst,
35873587 IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
35883588{
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);
35903590
35913591 peer_parent->peers.append(create_peer_result(peer_parent));
35923592 peer_parent->peers.last()->next_bb = else_block;
......@@ -3597,7 +3597,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrIn
35973597 return peer_parent;
35983598}
35993599
3600static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
3600static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval,
36013601 ResultLoc *result_loc)
36023602{
36033603 assert(node->type == NodeTypeBinOpExpr);
......@@ -3605,73 +3605,73 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode
36053605 AstNode *op1_node = node->data.bin_op_expr.op1;
36063606 AstNode *op2_node = node->data.bin_op_expr.op2;
36073607
3608 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
3609 if (maybe_ptr == irb->codegen->invalid_inst_src)
3610 return irb->codegen->invalid_inst_src;
3608 IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, op1_node, parent_scope, LValPtr, nullptr);
3609 if (maybe_ptr == ag->codegen->invalid_inst_src)
3610 return ag->codegen->invalid_inst_src;
36113611
3612 IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
3613 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val);
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(ag, parent_scope, node, maybe_val);
36143614
36153615 IrInstSrc *is_comptime;
3616 if (ir_should_inline(irb->exec, parent_scope)) {
3617 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
3616 if (ir_should_inline(ag->exec, parent_scope)) {
3617 is_comptime = ir_build_const_bool(ag, parent_scope, node, true);
36183618 } 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);
36203620 }
36213621
3622 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
3623 IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
3624 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, 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);
3622 IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, parent_scope, "OptionalNonNull");
3623 IrBasicBlockSrc *null_block = ir_create_basic_block(ag, parent_scope, "OptionalNull");
3624 IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "OptionalEnd");
3625 IrInstSrc *cond_br_inst = ir_build_cond_br(ag, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
36263626
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,
36283628 result_loc, is_comptime);
36293629
3630 ir_set_cursor_at_end_and_append_block(irb, null_block);
3631 IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
3630 ir_set_cursor_at_end_and_append_block(ag, null_block);
3631 IrInstSrc *null_result = ir_gen_node_extra(ag, op2_node, parent_scope, LValNone,
36323632 &peer_parent->peers.at(0)->base);
3633 if (null_result == irb->codegen->invalid_inst_src)
3634 return irb->codegen->invalid_inst_src;
3635 IrBasicBlockSrc *after_null_block = irb->current_basic_block;
3633 if (null_result == ag->codegen->invalid_inst_src)
3634 return ag->codegen->invalid_inst_src;
3635 IrBasicBlockSrc *after_null_block = ag->current_basic_block;
36363636 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));
36383638
3639 ir_set_cursor_at_end_and_append_block(irb, ok_block);
3640 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false);
3641 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
3642 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
3643 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
3644 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
3639 ir_set_cursor_at_end_and_append_block(ag, ok_block);
3640 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(ag, parent_scope, node, maybe_ptr, false);
3641 IrInstSrc *unwrapped_payload = ir_build_load_ptr(ag, parent_scope, node, unwrapped_ptr);
3642 ir_build_end_expr(ag, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
3643 IrBasicBlockSrc *after_ok_block = ag->current_basic_block;
3644 ir_build_br(ag, parent_scope, node, end_block, is_comptime);
36453645
3646 ir_set_cursor_at_end_and_append_block(irb, end_block);
3646 ir_set_cursor_at_end_and_append_block(ag, end_block);
36473647 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
36483648 incoming_values[0] = null_result;
36493649 incoming_values[1] = unwrapped_payload;
36503650 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
36513651 incoming_blocks[0] = after_null_block;
36523652 incoming_blocks[1] = after_ok_block;
3653 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
3654 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
3653 IrInstSrc *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
3654 return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc);
36553655}
36563656
3657static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
3657static IrInstSrc *ir_gen_error_union(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
36583658 assert(node->type == NodeTypeBinOpExpr);
36593659
36603660 AstNode *op1_node = node->data.bin_op_expr.op1;
36613661 AstNode *op2_node = node->data.bin_op_expr.op2;
36623662
3663 IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope);
3664 if (err_set == irb->codegen->invalid_inst_src)
3665 return irb->codegen->invalid_inst_src;
3663 IrInstSrc *err_set = ir_gen_node(ag, op1_node, parent_scope);
3664 if (err_set == ag->codegen->invalid_inst_src)
3665 return ag->codegen->invalid_inst_src;
36663666
3667 IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope);
3668 if (payload == irb->codegen->invalid_inst_src)
3669 return irb->codegen->invalid_inst_src;
3667 IrInstSrc *payload = ir_gen_node(ag, op2_node, parent_scope);
3668 if (payload == ag->codegen->invalid_inst_src)
3669 return ag->codegen->invalid_inst_src;
36703670
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);
36723672}
36733673
3674static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
3674static IrInstSrc *ir_gen_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
36753675 assert(node->type == NodeTypeBinOpExpr);
36763676
36773677 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,
36793679 case BinOpTypeInvalid:
36803680 zig_unreachable();
36813681 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);
36833683 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);
36853685 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);
36873687 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);
36893689 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);
36913691 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);
36933693 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);
36953695 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);
36973697 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);
36993699 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);
37013701 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);
37033703 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);
37053705 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);
37073707 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);
37093709 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);
37113711 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);
37133713 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);
37153715 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);
37173717 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);
37193719 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);
37213721 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);
37233723 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);
37253725 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);
37273727 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);
37293729 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);
37313731 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);
37333733 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);
37353735 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);
37373737 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);
37393739 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);
37413741 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);
37433743 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);
37453745 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);
37473747 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);
37493749 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);
37513751 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);
37533753 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);
37553755 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);
37573757 case BinOpTypeUnwrapOptional:
3758 return ir_gen_orelse(irb, scope, node, lval, result_loc);
3758 return ir_gen_orelse(ag, scope, node, lval, result_loc);
37593759 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);
37613761 }
37623762 zig_unreachable();
37633763}
37643764
3765static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3765static IrInstSrc *ir_gen_int_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) {
37663766 assert(node->type == NodeTypeIntLiteral);
37673767
37683768 RootStruct *root_struct = node->owner->data.structure.root_struct;
37693769 BigInt bigint;
37703770 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);
37723772}
37733773
3774static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3774static IrInstSrc *ir_gen_float_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) {
37753775 Error err;
37763776 assert(node->type == NodeTypeFloatLiteral);
37773777
......@@ -3781,14 +3781,14 @@ static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *nod
37813781
37823782 BigFloat bigfloat;
37833783 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"));
3785 return irb->codegen->invalid_inst_src;
3784 add_node_error(ag->codegen, node, buf_sprintf("float literal out of range of any type"));
3785 return ag->codegen->invalid_inst_src;
37863786 }
37873787
3788 return ir_build_const_bigfloat(irb, scope, node, bigfloat);
3788 return ir_build_const_bigfloat(ag, scope, node, bigfloat);
37893789}
37903790
3791static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3791static IrInstSrc *ir_gen_char_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) {
37923792 Error err;
37933793 assert(node->type == NodeTypeCharLiteral);
37943794
......@@ -3802,19 +3802,19 @@ static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node
38023802 uint32_t codepoint;
38033803 size_t bad_index;
38043804 if ((err = source_char_literal(source + byte_offset, &codepoint, &bad_index))) {
3805 add_node_error(irb->codegen, node, buf_sprintf("invalid character"));
3806 return irb->codegen->invalid_inst_src;
3805 add_node_error(ag->codegen, node, buf_sprintf("invalid character"));
3806 return ag->codegen->invalid_inst_src;
38073807 }
3808 return ir_build_const_uint(irb, scope, node, codepoint);
3808 return ir_build_const_uint(ag, scope, node, codepoint);
38093809}
38103810
3811static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3811static IrInstSrc *ir_gen_null_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) {
38123812 assert(node->type == NodeTypeNullLiteral);
38133813
3814 return ir_build_const_null(irb, scope, node);
3814 return ir_build_const_null(ag, scope, node);
38153815}
38163816
3817static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
3817static IrInstSrc *ir_gen_symbol(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
38183818 Error err;
38193819 assert(node->type == NodeTypeIdentifier);
38203820
......@@ -3822,113 +3822,113 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node,
38223822
38233823 if (buf_eql_str(variable_name, "_")) {
38243824 if (lval == LValAssign) {
3825 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
3826 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
3827 const_instruction->value->type = get_pointer_to_type(irb->codegen,
3828 irb->codegen->builtin_types.entry_void, false);
3825 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(ag, scope, node);
3826 const_instruction->value = ag->codegen->pass1_arena->create<ZigValue>();
3827 const_instruction->value->type = get_pointer_to_type(ag->codegen,
3828 ag->codegen->builtin_types.entry_void, false);
38293829 const_instruction->value->special = ConstValSpecialStatic;
38303830 const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
38313831 return &const_instruction->base;
38323832 } else {
3833 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
3834 return irb->codegen->invalid_inst_src;
3833 add_node_error(ag->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
3834 return ag->codegen->invalid_inst_src;
38353835 }
38363836 }
38373837
38383838 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))) {
38403840 if (err == ErrorOverflow) {
3841 add_node_error(irb->codegen, node,
3841 add_node_error(ag->codegen, node,
38423842 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
38433843 buf_ptr(variable_name)));
3844 return irb->codegen->invalid_inst_src;
3844 return ag->codegen->invalid_inst_src;
38453845 }
38463846 assert(err == ErrorPrimitiveTypeNotFound);
38473847 } 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);
38493849 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);
38513851 } else {
3852 return ir_expr_wrap(irb, scope, value, result_loc);
3852 return ir_expr_wrap(ag, scope, value, result_loc);
38533853 }
38543854 }
38553855
38563856 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);
38583858 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);
38603860 if (lval == LValPtr || lval == LValAssign) {
38613861 return var_ptr;
38623862 } 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);
38643864 }
38653865 }
38663866
3867 Tld *tld = find_decl(irb->codegen, scope, variable_name);
3867 Tld *tld = find_decl(ag->codegen, scope, variable_name);
38683868 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);
38703870 if (lval == LValPtr || lval == LValAssign) {
38713871 return decl_ref;
38723872 } else {
3873 return ir_expr_wrap(irb, scope, decl_ref, result_loc);
3873 return ir_expr_wrap(ag, scope, decl_ref, result_loc);
38743874 }
38753875 }
38763876
38773877 if (get_container_scope(node->owner)->any_imports_failed) {
38783878 // skip the error message since we had a failing import in this file
38793879 // 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;
38813881 }
38823882
3883 return ir_build_undeclared_identifier(irb, scope, node, variable_name);
3883 return ir_build_undeclared_identifier(ag, scope, node, variable_name);
38843884}
38853885
3886static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
3886static IrInstSrc *ir_gen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
38873887 ResultLoc *result_loc)
38883888{
38893889 assert(node->type == NodeTypeArrayAccessExpr);
38903890
38913891 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);
3893 if (array_ref_instruction == irb->codegen->invalid_inst_src)
3892 IrInstSrc *array_ref_instruction = ir_gen_node_extra(ag, array_ref_node, scope, LValPtr, nullptr);
3893 if (array_ref_instruction == ag->codegen->invalid_inst_src)
38943894 return array_ref_instruction;
38953895
38963896 // Create an usize-typed result location to hold the subscript value, this
38973897 // makes it possible for the compiler to infer the subscript expression type
38983898 // if needed
3899 IrInstSrc *usize_type_inst = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
3900 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, usize_type_inst, no_result_loc());
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(ag, usize_type_inst, no_result_loc());
39013901
39023902 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);
3904 if (subscript_value == irb->codegen->invalid_inst_src)
3905 return irb->codegen->invalid_inst_src;
3903 IrInstSrc *subscript_value = ir_gen_node_extra(ag, subscript_node, scope, LValNone, &result_loc_cast->base);
3904 if (subscript_value == ag->codegen->invalid_inst_src)
3905 return ag->codegen->invalid_inst_src;
39063906
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);
39083908
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,
39103910 subscript_instruction, true, PtrLenSingle, nullptr);
39113911 if (lval == LValPtr || lval == LValAssign)
39123912 return ptr_instruction;
39133913
3914 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
3915 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
3914 IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction);
3915 return ir_expr_wrap(ag, scope, load_ptr, result_loc);
39163916}
39173917
3918static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3918static IrInstSrc *ir_gen_field_access(Stage1AstGen *ag, Scope *scope, AstNode *node) {
39193919 assert(node->type == NodeTypeFieldAccessExpr);
39203920
39213921 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
39223922 Buf *field_name = node->data.field_access_expr.field_name;
39233923
3924 IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
3925 if (container_ref_instruction == irb->codegen->invalid_inst_src)
3924 IrInstSrc *container_ref_instruction = ir_gen_node_extra(ag, container_ref_node, scope, LValPtr, nullptr);
3925 if (container_ref_instruction == ag->codegen->invalid_inst_src)
39263926 return container_ref_instruction;
39273927
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);
39293929}
39303930
3931static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
3931static IrInstSrc *ir_gen_overflow_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrOverflowOp op) {
39323932 assert(node->type == NodeTypeFnCallExpr);
39333933
39343934 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
39373937 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);
39383938
39393939
3940 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
3941 if (type_value == irb->codegen->invalid_inst_src)
3942 return irb->codegen->invalid_inst_src;
3940 IrInstSrc *type_value = ir_gen_node(ag, type_node, scope);
3941 if (type_value == ag->codegen->invalid_inst_src)
3942 return ag->codegen->invalid_inst_src;
39433943
3944 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
3945 if (op1 == irb->codegen->invalid_inst_src)
3946 return irb->codegen->invalid_inst_src;
3944 IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope);
3945 if (op1 == ag->codegen->invalid_inst_src)
3946 return ag->codegen->invalid_inst_src;
39473947
3948 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
3949 if (op2 == irb->codegen->invalid_inst_src)
3950 return irb->codegen->invalid_inst_src;
3948 IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope);
3949 if (op2 == ag->codegen->invalid_inst_src)
3950 return ag->codegen->invalid_inst_src;
39513951
3952 IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
3953 if (result_ptr == irb->codegen->invalid_inst_src)
3954 return irb->codegen->invalid_inst_src;
3952 IrInstSrc *result_ptr = ir_gen_node(ag, result_ptr_node, scope);
3953 if (result_ptr == ag->codegen->invalid_inst_src)
3954 return ag->codegen->invalid_inst_src;
39553955
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);
39573957}
39583958
3959static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
3959static IrInstSrc *ir_gen_mul_add(Stage1AstGen *ag, Scope *scope, AstNode *node) {
39603960 assert(node->type == NodeTypeFnCallExpr);
39613961
39623962 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)
39643964 AstNode *op2_node = node->data.fn_call_expr.params.at(2);
39653965 AstNode *op3_node = node->data.fn_call_expr.params.at(3);
39663966
3967 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
3968 if (type_value == irb->codegen->invalid_inst_src)
3969 return irb->codegen->invalid_inst_src;
3967 IrInstSrc *type_value = ir_gen_node(ag, type_node, scope);
3968 if (type_value == ag->codegen->invalid_inst_src)
3969 return ag->codegen->invalid_inst_src;
39703970
3971 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
3972 if (op1 == irb->codegen->invalid_inst_src)
3973 return irb->codegen->invalid_inst_src;
3971 IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope);
3972 if (op1 == ag->codegen->invalid_inst_src)
3973 return ag->codegen->invalid_inst_src;
39743974
3975 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
3976 if (op2 == irb->codegen->invalid_inst_src)
3977 return irb->codegen->invalid_inst_src;
3975 IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope);
3976 if (op2 == ag->codegen->invalid_inst_src)
3977 return ag->codegen->invalid_inst_src;
39783978
3979 IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope);
3980 if (op3 == irb->codegen->invalid_inst_src)
3981 return irb->codegen->invalid_inst_src;
3979 IrInstSrc *op3 = ir_gen_node(ag, op3_node, scope);
3980 if (op3 == ag->codegen->invalid_inst_src)
3981 return ag->codegen->invalid_inst_src;
39823982
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);
39843984}
39853985
3986static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) {
3986static IrInstSrc *ir_gen_this(Stage1AstGen *ag, Scope *orig_scope, AstNode *node) {
39873987 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
39883988 if (it_scope->id == ScopeIdDecls) {
39893989 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
39903990 ZigType *container_type = decls_scope->container_type;
39913991 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);
39933993 } 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);
39953995 }
39963996 }
39973997 }
39983998 zig_unreachable();
39993999}
40004000
4001static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
4001static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *await_node, AstNode *call_node,
40024002 LVal lval, ResultLoc *result_loc)
40034003{
40044004 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,
40064006 buf_sprintf("expected 4 arguments, found %" ZIG_PRI_usize,
40074007 call_node->data.fn_call_expr.params.length));
4008 return irb->codegen->invalid_inst_src;
4008 return ag->codegen->invalid_inst_src;
40094009 }
40104010
40114011 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);
4012 IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope);
4013 if (bytes == irb->codegen->invalid_inst_src)
4012 IrInstSrc *bytes = ir_gen_node(ag, bytes_node, scope);
4013 if (bytes == ag->codegen->invalid_inst_src)
40144014 return bytes;
40154015
40164016 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);
4018 if (ret_ptr == irb->codegen->invalid_inst_src)
4017 IrInstSrc *ret_ptr = ir_gen_node(ag, ret_ptr_node, scope);
4018 if (ret_ptr == ag->codegen->invalid_inst_src)
40194019 return ret_ptr;
40204020
40214021 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);
4023 if (fn_ref == irb->codegen->invalid_inst_src)
4022 IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope);
4023 if (fn_ref == ag->codegen->invalid_inst_src)
40244024 return fn_ref;
40254025
40264026 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
......@@ -4034,89 +4034,89 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw
40344034 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count);
40354035 for (size_t i = 0; i < arg_count; i += 1) {
40364036 AstNode *arg_node = args_node->data.container_init_expr.entries.at(i);
4037 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
4038 if (arg == irb->codegen->invalid_inst_src)
4037 IrInstSrc *arg = ir_gen_node(ag, arg_node, scope);
4038 if (arg == ag->codegen->invalid_inst_src)
40394039 return arg;
40404040 args[i] = arg;
40414041 }
40424042
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,
40444044 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);
40464046 } else {
4047 exec_add_error_node(irb->codegen, irb->exec, args_node,
4047 exec_add_error_node(ag->codegen, ag->exec, args_node,
40484048 buf_sprintf("TODO: @asyncCall with anon struct literal"));
4049 return irb->codegen->invalid_inst_src;
4049 return ag->codegen->invalid_inst_src;
40504050 }
40514051 }
4052 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
4053 if (args == irb->codegen->invalid_inst_src)
4052 IrInstSrc *args = ir_gen_node(ag, args_node, scope);
4053 if (args == ag->codegen->invalid_inst_src)
40544054 return args;
40554055
4056 IrInstSrc *call = ir_build_async_call_extra(irb, scope, call_node, modifier, fn_ref, ret_ptr, bytes, args, result_loc);
4057 return ir_lval_wrap(irb, scope, call, lval, 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(ag, scope, call, lval, result_loc);
40584058}
40594059
4060static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4060static IrInstSrc *ir_gen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
40614061 AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options,
40624062 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)
40634063{
4064 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
4065 if (fn_ref == irb->codegen->invalid_inst_src)
4064 IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope);
4065 if (fn_ref == ag->codegen->invalid_inst_src)
40664066 return fn_ref;
40674067
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);
40694069
40704070 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(args_len);
40714071 for (size_t i = 0; i < args_len; i += 1) {
40724072 AstNode *arg_node = args_ptr[i];
40734073
4074 IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
4075 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
4074 IrInstSrc *arg_index = ir_build_const_usize(ag, scope, arg_node, i);
4075 IrInstSrc *arg_type = ir_build_arg_type(ag, scope, source_node, fn_type, arg_index, true);
40764076 ResultLoc *no_result = no_result_loc();
4077 ir_build_reset_result(irb, scope, source_node, no_result);
4078 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);
4077 ir_build_reset_result(ag, scope, source_node, no_result);
4078 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, arg_type, no_result);
40794079
4080 IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
4081 if (arg == irb->codegen->invalid_inst_src)
4080 IrInstSrc *arg = ir_gen_node_extra(ag, arg_node, scope, LValNone, &result_loc_cast->base);
4081 if (arg == ag->codegen->invalid_inst_src)
40824082 return arg;
40834083
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);
40854085 }
40864086
40874087 IrInstSrc *fn_call;
40884088 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);
40904090 } 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,
40924092 modifier, false, nullptr, result_loc);
40934093 }
4094 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
4094 return ir_lval_wrap(ag, scope, fn_call, lval, result_loc);
40954095}
40964096
4097static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
4097static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
40984098 ResultLoc *result_loc)
40994099{
41004100 assert(node->type == NodeTypeFnCallExpr);
41014101
41024102 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;
41034103 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);
41054105
41064106 if (!entry) {
4107 add_node_error(irb->codegen, node,
4107 add_node_error(ag->codegen, node,
41084108 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
4109 return irb->codegen->invalid_inst_src;
4109 return ag->codegen->invalid_inst_src;
41104110 }
41114111
41124112 BuiltinFnEntry *builtin_fn = entry->value;
41134113 size_t actual_param_count = node->data.fn_call_expr.params.length;
41144114
41154115 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,
41174117 buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize,
41184118 builtin_fn->param_count, actual_param_count));
4119 return irb->codegen->invalid_inst_src;
4119 return ag->codegen->invalid_inst_src;
41204120 }
41214121
41224122 switch (builtin_fn->id) {
......@@ -4124,152 +4124,152 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
41244124 zig_unreachable();
41254125 case BuiltinFnIdTypeof:
41264126 {
4127 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);
4127 Scope *sub_scope = create_typeof_scope(ag->codegen, node, scope);
41284128
41294129 size_t arg_count = node->data.fn_call_expr.params.length;
41304130
41314131 IrInstSrc *type_of;
41324132
41334133 if (arg_count == 0) {
4134 add_node_error(irb->codegen, node,
4134 add_node_error(ag->codegen, node,
41354135 buf_sprintf("expected at least 1 argument, found 0"));
4136 return irb->codegen->invalid_inst_src;
4136 return ag->codegen->invalid_inst_src;
41374137 } else if (arg_count == 1) {
41384138 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4139 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, sub_scope);
4140 if (arg0_value == irb->codegen->invalid_inst_src)
4139 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, sub_scope);
4140 if (arg0_value == ag->codegen->invalid_inst_src)
41414141 return arg0_value;
41424142
4143 type_of = ir_build_typeof_1(irb, scope, node, arg0_value);
4143 type_of = ir_build_typeof_1(ag, scope, node, arg0_value);
41444144 } else {
41454145 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count);
41464146 for (size_t i = 0; i < arg_count; i += 1) {
41474147 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
4148 IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope);
4149 if (arg == irb->codegen->invalid_inst_src)
4150 return irb->codegen->invalid_inst_src;
4148 IrInstSrc *arg = ir_gen_node(ag, arg_node, sub_scope);
4149 if (arg == ag->codegen->invalid_inst_src)
4150 return ag->codegen->invalid_inst_src;
41514151 args[i] = arg;
41524152 }
41534153
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);
41554155 }
4156 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);
4156 return ir_lval_wrap(ag, scope, type_of, lval, result_loc);
41574157 }
41584158 case BuiltinFnIdSetCold:
41594159 {
41604160 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4161 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4162 if (arg0_value == irb->codegen->invalid_inst_src)
4161 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4162 if (arg0_value == ag->codegen->invalid_inst_src)
41634163 return arg0_value;
41644164
4165 IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
4166 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);
4165 IrInstSrc *set_cold = ir_build_set_cold(ag, scope, node, arg0_value);
4166 return ir_lval_wrap(ag, scope, set_cold, lval, result_loc);
41674167 }
41684168 case BuiltinFnIdSetRuntimeSafety:
41694169 {
41704170 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4171 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4172 if (arg0_value == irb->codegen->invalid_inst_src)
4171 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4172 if (arg0_value == ag->codegen->invalid_inst_src)
41734173 return arg0_value;
41744174
4175 IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
4176 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);
4175 IrInstSrc *set_safety = ir_build_set_runtime_safety(ag, scope, node, arg0_value);
4176 return ir_lval_wrap(ag, scope, set_safety, lval, result_loc);
41774177 }
41784178 case BuiltinFnIdSetFloatMode:
41794179 {
41804180 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4181 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4182 if (arg0_value == irb->codegen->invalid_inst_src)
4181 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4182 if (arg0_value == ag->codegen->invalid_inst_src)
41834183 return arg0_value;
41844184
4185 IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
4186 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);
4185 IrInstSrc *set_float_mode = ir_build_set_float_mode(ag, scope, node, arg0_value);
4186 return ir_lval_wrap(ag, scope, set_float_mode, lval, result_loc);
41874187 }
41884188 case BuiltinFnIdSizeof:
41894189 case BuiltinFnIdBitSizeof:
41904190 {
41914191 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4192 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4193 if (arg0_value == irb->codegen->invalid_inst_src)
4192 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4193 if (arg0_value == ag->codegen->invalid_inst_src)
41944194 return arg0_value;
41954195
4196 IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
4197 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);
4196 IrInstSrc *size_of = ir_build_size_of(ag, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
4197 return ir_lval_wrap(ag, scope, size_of, lval, result_loc);
41984198 }
41994199 case BuiltinFnIdImport:
42004200 {
42014201 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4202 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4203 if (arg0_value == irb->codegen->invalid_inst_src)
4202 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4203 if (arg0_value == ag->codegen->invalid_inst_src)
42044204 return arg0_value;
42054205
4206 IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value);
4207 return ir_lval_wrap(irb, scope, import, lval, result_loc);
4206 IrInstSrc *import = ir_build_import(ag, scope, node, arg0_value);
4207 return ir_lval_wrap(ag, scope, import, lval, result_loc);
42084208 }
42094209 case BuiltinFnIdCImport:
42104210 {
4211 IrInstSrc *c_import = ir_build_c_import(irb, scope, node);
4212 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);
4211 IrInstSrc *c_import = ir_build_c_import(ag, scope, node);
4212 return ir_lval_wrap(ag, scope, c_import, lval, result_loc);
42134213 }
42144214 case BuiltinFnIdCInclude:
42154215 {
42164216 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4217 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4218 if (arg0_value == irb->codegen->invalid_inst_src)
4217 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4218 if (arg0_value == ag->codegen->invalid_inst_src)
42194219 return arg0_value;
42204220
4221 if (!exec_c_import_buf(irb->exec)) {
4222 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));
4223 return irb->codegen->invalid_inst_src;
4221 if (!exec_c_import_buf(ag->exec)) {
4222 add_node_error(ag->codegen, node, buf_sprintf("C include valid only inside C import block"));
4223 return ag->codegen->invalid_inst_src;
42244224 }
42254225
4226 IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value);
4227 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);
4226 IrInstSrc *c_include = ir_build_c_include(ag, scope, node, arg0_value);
4227 return ir_lval_wrap(ag, scope, c_include, lval, result_loc);
42284228 }
42294229 case BuiltinFnIdCDefine:
42304230 {
42314231 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4232 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4233 if (arg0_value == irb->codegen->invalid_inst_src)
4232 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4233 if (arg0_value == ag->codegen->invalid_inst_src)
42344234 return arg0_value;
42354235
42364236 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4237 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4238 if (arg1_value == irb->codegen->invalid_inst_src)
4237 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4238 if (arg1_value == ag->codegen->invalid_inst_src)
42394239 return arg1_value;
42404240
4241 if (!exec_c_import_buf(irb->exec)) {
4242 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));
4243 return irb->codegen->invalid_inst_src;
4241 if (!exec_c_import_buf(ag->exec)) {
4242 add_node_error(ag->codegen, node, buf_sprintf("C define valid only inside C import block"));
4243 return ag->codegen->invalid_inst_src;
42444244 }
42454245
4246 IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
4247 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);
4246 IrInstSrc *c_define = ir_build_c_define(ag, scope, node, arg0_value, arg1_value);
4247 return ir_lval_wrap(ag, scope, c_define, lval, result_loc);
42484248 }
42494249 case BuiltinFnIdCUndef:
42504250 {
42514251 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4252 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4253 if (arg0_value == irb->codegen->invalid_inst_src)
4252 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4253 if (arg0_value == ag->codegen->invalid_inst_src)
42544254 return arg0_value;
42554255
4256 if (!exec_c_import_buf(irb->exec)) {
4257 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));
4258 return irb->codegen->invalid_inst_src;
4256 if (!exec_c_import_buf(ag->exec)) {
4257 add_node_error(ag->codegen, node, buf_sprintf("C undef valid only inside C import block"));
4258 return ag->codegen->invalid_inst_src;
42594259 }
42604260
4261 IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
4262 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);
4261 IrInstSrc *c_undef = ir_build_c_undef(ag, scope, node, arg0_value);
4262 return ir_lval_wrap(ag, scope, c_undef, lval, result_loc);
42634263 }
42644264 case BuiltinFnIdCompileErr:
42654265 {
42664266 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4267 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4268 if (arg0_value == irb->codegen->invalid_inst_src)
4267 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4268 if (arg0_value == ag->codegen->invalid_inst_src)
42694269 return arg0_value;
42704270
4271 IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
4272 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);
4271 IrInstSrc *compile_err = ir_build_compile_err(ag, scope, node, arg0_value);
4272 return ir_lval_wrap(ag, scope, compile_err, lval, result_loc);
42734273 }
42744274 case BuiltinFnIdCompileLog:
42754275 {
......@@ -4277,171 +4277,171 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
42774277
42784278 for (size_t i = 0; i < actual_param_count; i += 1) {
42794279 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
4280 args[i] = ir_gen_node(irb, arg_node, scope);
4281 if (args[i] == irb->codegen->invalid_inst_src)
4282 return irb->codegen->invalid_inst_src;
4280 args[i] = ir_gen_node(ag, arg_node, scope);
4281 if (args[i] == ag->codegen->invalid_inst_src)
4282 return ag->codegen->invalid_inst_src;
42834283 }
42844284
4285 IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
4286 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);
4285 IrInstSrc *compile_log = ir_build_compile_log(ag, scope, node, actual_param_count, args);
4286 return ir_lval_wrap(ag, scope, compile_log, lval, result_loc);
42874287 }
42884288 case BuiltinFnIdErrName:
42894289 {
42904290 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4291 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4292 if (arg0_value == irb->codegen->invalid_inst_src)
4291 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4292 if (arg0_value == ag->codegen->invalid_inst_src)
42934293 return arg0_value;
42944294
4295 IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value);
4296 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);
4295 IrInstSrc *err_name = ir_build_err_name(ag, scope, node, arg0_value);
4296 return ir_lval_wrap(ag, scope, err_name, lval, result_loc);
42974297 }
42984298 case BuiltinFnIdEmbedFile:
42994299 {
43004300 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4301 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4302 if (arg0_value == irb->codegen->invalid_inst_src)
4301 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4302 if (arg0_value == ag->codegen->invalid_inst_src)
43034303 return arg0_value;
43044304
4305 IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
4306 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);
4305 IrInstSrc *embed_file = ir_build_embed_file(ag, scope, node, arg0_value);
4306 return ir_lval_wrap(ag, scope, embed_file, lval, result_loc);
43074307 }
43084308 case BuiltinFnIdCmpxchgWeak:
43094309 case BuiltinFnIdCmpxchgStrong:
43104310 {
43114311 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4312 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4313 if (arg0_value == irb->codegen->invalid_inst_src)
4312 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4313 if (arg0_value == ag->codegen->invalid_inst_src)
43144314 return arg0_value;
43154315
43164316 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4317 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4318 if (arg1_value == irb->codegen->invalid_inst_src)
4317 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4318 if (arg1_value == ag->codegen->invalid_inst_src)
43194319 return arg1_value;
43204320
43214321 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4322 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
4323 if (arg2_value == irb->codegen->invalid_inst_src)
4322 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
4323 if (arg2_value == ag->codegen->invalid_inst_src)
43244324 return arg2_value;
43254325
43264326 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
4327 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
4328 if (arg3_value == irb->codegen->invalid_inst_src)
4327 IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope);
4328 if (arg3_value == ag->codegen->invalid_inst_src)
43294329 return arg3_value;
43304330
43314331 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
4332 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
4333 if (arg4_value == irb->codegen->invalid_inst_src)
4332 IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope);
4333 if (arg4_value == ag->codegen->invalid_inst_src)
43344334 return arg4_value;
43354335
43364336 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);
4337 IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope);
4338 if (arg5_value == irb->codegen->invalid_inst_src)
4337 IrInstSrc *arg5_value = ir_gen_node(ag, arg5_node, scope);
4338 if (arg5_value == ag->codegen->invalid_inst_src)
43394339 return arg5_value;
43404340
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,
43424342 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),
43434343 result_loc);
4344 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);
4344 return ir_lval_wrap(ag, scope, cmpxchg, lval, result_loc);
43454345 }
43464346 case BuiltinFnIdFence:
43474347 {
43484348 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4349 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4350 if (arg0_value == irb->codegen->invalid_inst_src)
4349 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4350 if (arg0_value == ag->codegen->invalid_inst_src)
43514351 return arg0_value;
43524352
4353 IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value);
4354 return ir_lval_wrap(irb, scope, fence, lval, result_loc);
4353 IrInstSrc *fence = ir_build_fence(ag, scope, node, arg0_value);
4354 return ir_lval_wrap(ag, scope, fence, lval, result_loc);
43554355 }
43564356 case BuiltinFnIdReduce:
43574357 {
43584358 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4359 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4360 if (arg0_value == irb->codegen->invalid_inst_src)
4359 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4360 if (arg0_value == ag->codegen->invalid_inst_src)
43614361 return arg0_value;
43624362
43634363 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4364 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4365 if (arg1_value == irb->codegen->invalid_inst_src)
4364 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4365 if (arg1_value == ag->codegen->invalid_inst_src)
43664366 return arg1_value;
43674367
4368 IrInstSrc *reduce = ir_build_reduce(irb, scope, node, arg0_value, arg1_value);
4369 return ir_lval_wrap(irb, scope, reduce, lval, result_loc);
4368 IrInstSrc *reduce = ir_build_reduce(ag, scope, node, arg0_value, arg1_value);
4369 return ir_lval_wrap(ag, scope, reduce, lval, result_loc);
43704370 }
43714371 case BuiltinFnIdDivExact:
43724372 {
43734373 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4374 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4375 if (arg0_value == irb->codegen->invalid_inst_src)
4374 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4375 if (arg0_value == ag->codegen->invalid_inst_src)
43764376 return arg0_value;
43774377
43784378 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4379 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4380 if (arg1_value == irb->codegen->invalid_inst_src)
4379 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4380 if (arg1_value == ag->codegen->invalid_inst_src)
43814381 return arg1_value;
43824382
4383 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
4384 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
4383 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
4384 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
43854385 }
43864386 case BuiltinFnIdDivTrunc:
43874387 {
43884388 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4389 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4390 if (arg0_value == irb->codegen->invalid_inst_src)
4389 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4390 if (arg0_value == ag->codegen->invalid_inst_src)
43914391 return arg0_value;
43924392
43934393 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4394 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4395 if (arg1_value == irb->codegen->invalid_inst_src)
4394 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4395 if (arg1_value == ag->codegen->invalid_inst_src)
43964396 return arg1_value;
43974397
4398 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
4399 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
4398 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
4399 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
44004400 }
44014401 case BuiltinFnIdDivFloor:
44024402 {
44034403 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4404 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4405 if (arg0_value == irb->codegen->invalid_inst_src)
4404 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4405 if (arg0_value == ag->codegen->invalid_inst_src)
44064406 return arg0_value;
44074407
44084408 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4409 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4410 if (arg1_value == irb->codegen->invalid_inst_src)
4409 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4410 if (arg1_value == ag->codegen->invalid_inst_src)
44114411 return arg1_value;
44124412
4413 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
4414 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
4413 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
4414 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
44154415 }
44164416 case BuiltinFnIdRem:
44174417 {
44184418 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4419 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4420 if (arg0_value == irb->codegen->invalid_inst_src)
4419 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4420 if (arg0_value == ag->codegen->invalid_inst_src)
44214421 return arg0_value;
44224422
44234423 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4424 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4425 if (arg1_value == irb->codegen->invalid_inst_src)
4424 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4425 if (arg1_value == ag->codegen->invalid_inst_src)
44264426 return arg1_value;
44274427
4428 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
4429 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
4428 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
4429 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
44304430 }
44314431 case BuiltinFnIdMod:
44324432 {
44334433 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4434 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4435 if (arg0_value == irb->codegen->invalid_inst_src)
4434 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4435 if (arg0_value == ag->codegen->invalid_inst_src)
44364436 return arg0_value;
44374437
44384438 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4439 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4440 if (arg1_value == irb->codegen->invalid_inst_src)
4439 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4440 if (arg1_value == ag->codegen->invalid_inst_src)
44414441 return arg1_value;
44424442
4443 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
4444 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
4443 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
4444 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
44454445 }
44464446 case BuiltinFnIdSqrt:
44474447 case BuiltinFnIdSin:
......@@ -4459,537 +4459,537 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
44594459 case BuiltinFnIdRound:
44604460 {
44614461 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4462 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4463 if (arg0_value == irb->codegen->invalid_inst_src)
4462 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4463 if (arg0_value == ag->codegen->invalid_inst_src)
44644464 return arg0_value;
44654465
4466 IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id);
4467 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
4466 IrInstSrc *inst = ir_build_float_op_src(ag, scope, node, arg0_value, builtin_fn->id);
4467 return ir_lval_wrap(ag, scope, inst, lval, result_loc);
44684468 }
44694469 case BuiltinFnIdTruncate:
44704470 {
44714471 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4472 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4473 if (arg0_value == irb->codegen->invalid_inst_src)
4472 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4473 if (arg0_value == ag->codegen->invalid_inst_src)
44744474 return arg0_value;
44754475
44764476 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4477 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4478 if (arg1_value == irb->codegen->invalid_inst_src)
4477 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4478 if (arg1_value == ag->codegen->invalid_inst_src)
44794479 return arg1_value;
44804480
4481 IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
4482 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);
4481 IrInstSrc *truncate = ir_build_truncate(ag, scope, node, arg0_value, arg1_value);
4482 return ir_lval_wrap(ag, scope, truncate, lval, result_loc);
44834483 }
44844484 case BuiltinFnIdIntCast:
44854485 {
44864486 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4487 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4488 if (arg0_value == irb->codegen->invalid_inst_src)
4487 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4488 if (arg0_value == ag->codegen->invalid_inst_src)
44894489 return arg0_value;
44904490
44914491 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4492 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4493 if (arg1_value == irb->codegen->invalid_inst_src)
4492 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4493 if (arg1_value == ag->codegen->invalid_inst_src)
44944494 return arg1_value;
44954495
4496 IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
4497 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4496 IrInstSrc *result = ir_build_int_cast(ag, scope, node, arg0_value, arg1_value);
4497 return ir_lval_wrap(ag, scope, result, lval, result_loc);
44984498 }
44994499 case BuiltinFnIdFloatCast:
45004500 {
45014501 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4502 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4503 if (arg0_value == irb->codegen->invalid_inst_src)
4502 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4503 if (arg0_value == ag->codegen->invalid_inst_src)
45044504 return arg0_value;
45054505
45064506 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4507 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4508 if (arg1_value == irb->codegen->invalid_inst_src)
4507 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4508 if (arg1_value == ag->codegen->invalid_inst_src)
45094509 return arg1_value;
45104510
4511 IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
4512 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4511 IrInstSrc *result = ir_build_float_cast(ag, scope, node, arg0_value, arg1_value);
4512 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45134513 }
45144514 case BuiltinFnIdErrSetCast:
45154515 {
45164516 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4517 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4518 if (arg0_value == irb->codegen->invalid_inst_src)
4517 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4518 if (arg0_value == ag->codegen->invalid_inst_src)
45194519 return arg0_value;
45204520
45214521 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4522 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4523 if (arg1_value == irb->codegen->invalid_inst_src)
4522 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4523 if (arg1_value == ag->codegen->invalid_inst_src)
45244524 return arg1_value;
45254525
4526 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
4527 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4526 IrInstSrc *result = ir_build_err_set_cast(ag, scope, node, arg0_value, arg1_value);
4527 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45284528 }
45294529 case BuiltinFnIdIntToFloat:
45304530 {
45314531 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4532 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4533 if (arg0_value == irb->codegen->invalid_inst_src)
4532 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4533 if (arg0_value == ag->codegen->invalid_inst_src)
45344534 return arg0_value;
45354535
45364536 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4537 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4538 if (arg1_value == irb->codegen->invalid_inst_src)
4537 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4538 if (arg1_value == ag->codegen->invalid_inst_src)
45394539 return arg1_value;
45404540
4541 IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
4542 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4541 IrInstSrc *result = ir_build_int_to_float(ag, scope, node, arg0_value, arg1_value);
4542 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45434543 }
45444544 case BuiltinFnIdFloatToInt:
45454545 {
45464546 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4547 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4548 if (arg0_value == irb->codegen->invalid_inst_src)
4547 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4548 if (arg0_value == ag->codegen->invalid_inst_src)
45494549 return arg0_value;
45504550
45514551 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4552 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4553 if (arg1_value == irb->codegen->invalid_inst_src)
4552 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4553 if (arg1_value == ag->codegen->invalid_inst_src)
45544554 return arg1_value;
45554555
4556 IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
4557 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4556 IrInstSrc *result = ir_build_float_to_int(ag, scope, node, arg0_value, arg1_value);
4557 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45584558 }
45594559 case BuiltinFnIdErrToInt:
45604560 {
45614561 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4562 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4563 if (arg0_value == irb->codegen->invalid_inst_src)
4562 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4563 if (arg0_value == ag->codegen->invalid_inst_src)
45644564 return arg0_value;
45654565
4566 IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value);
4567 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4566 IrInstSrc *result = ir_build_err_to_int_src(ag, scope, node, arg0_value);
4567 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45684568 }
45694569 case BuiltinFnIdIntToErr:
45704570 {
45714571 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4572 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4573 if (arg0_value == irb->codegen->invalid_inst_src)
4572 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4573 if (arg0_value == ag->codegen->invalid_inst_src)
45744574 return arg0_value;
45754575
4576 IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value);
4577 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4576 IrInstSrc *result = ir_build_int_to_err_src(ag, scope, node, arg0_value);
4577 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45784578 }
45794579 case BuiltinFnIdBoolToInt:
45804580 {
45814581 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4582 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4583 if (arg0_value == irb->codegen->invalid_inst_src)
4582 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4583 if (arg0_value == ag->codegen->invalid_inst_src)
45844584 return arg0_value;
45854585
4586 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
4587 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4586 IrInstSrc *result = ir_build_bool_to_int(ag, scope, node, arg0_value);
4587 return ir_lval_wrap(ag, scope, result, lval, result_loc);
45884588 }
45894589 case BuiltinFnIdVectorType:
45904590 {
45914591 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4592 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4593 if (arg0_value == irb->codegen->invalid_inst_src)
4592 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4593 if (arg0_value == ag->codegen->invalid_inst_src)
45944594 return arg0_value;
45954595
45964596 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4597 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4598 if (arg1_value == irb->codegen->invalid_inst_src)
4597 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4598 if (arg1_value == ag->codegen->invalid_inst_src)
45994599 return arg1_value;
46004600
4601 IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
4602 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);
4601 IrInstSrc *vector_type = ir_build_vector_type(ag, scope, node, arg0_value, arg1_value);
4602 return ir_lval_wrap(ag, scope, vector_type, lval, result_loc);
46034603 }
46044604 case BuiltinFnIdShuffle:
46054605 {
46064606 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4607 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4608 if (arg0_value == irb->codegen->invalid_inst_src)
4607 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4608 if (arg0_value == ag->codegen->invalid_inst_src)
46094609 return arg0_value;
46104610
46114611 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4612 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4613 if (arg1_value == irb->codegen->invalid_inst_src)
4612 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4613 if (arg1_value == ag->codegen->invalid_inst_src)
46144614 return arg1_value;
46154615
46164616 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4617 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
4618 if (arg2_value == irb->codegen->invalid_inst_src)
4617 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
4618 if (arg2_value == ag->codegen->invalid_inst_src)
46194619 return arg2_value;
46204620
46214621 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
4622 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
4623 if (arg3_value == irb->codegen->invalid_inst_src)
4622 IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope);
4623 if (arg3_value == ag->codegen->invalid_inst_src)
46244624 return arg3_value;
46254625
4626 IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
4626 IrInstSrc *shuffle_vector = ir_build_shuffle_vector(ag, scope, node,
46274627 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);
46294629 }
46304630 case BuiltinFnIdSplat:
46314631 {
46324632 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4633 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4634 if (arg0_value == irb->codegen->invalid_inst_src)
4633 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4634 if (arg0_value == ag->codegen->invalid_inst_src)
46354635 return arg0_value;
46364636
46374637 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4638 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4639 if (arg1_value == irb->codegen->invalid_inst_src)
4638 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4639 if (arg1_value == ag->codegen->invalid_inst_src)
46404640 return arg1_value;
46414641
4642 IrInstSrc *splat = ir_build_splat_src(irb, scope, node,
4642 IrInstSrc *splat = ir_build_splat_src(ag, scope, node,
46434643 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);
46454645 }
46464646 case BuiltinFnIdMemcpy:
46474647 {
46484648 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4649 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4650 if (arg0_value == irb->codegen->invalid_inst_src)
4649 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4650 if (arg0_value == ag->codegen->invalid_inst_src)
46514651 return arg0_value;
46524652
46534653 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4654 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4655 if (arg1_value == irb->codegen->invalid_inst_src)
4654 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4655 if (arg1_value == ag->codegen->invalid_inst_src)
46564656 return arg1_value;
46574657
46584658 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4659 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
4660 if (arg2_value == irb->codegen->invalid_inst_src)
4659 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
4660 if (arg2_value == ag->codegen->invalid_inst_src)
46614661 return arg2_value;
46624662
4663 IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
4664 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);
4663 IrInstSrc *ir_memcpy = ir_build_memcpy_src(ag, scope, node, arg0_value, arg1_value, arg2_value);
4664 return ir_lval_wrap(ag, scope, ir_memcpy, lval, result_loc);
46654665 }
46664666 case BuiltinFnIdMemset:
46674667 {
46684668 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4669 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4670 if (arg0_value == irb->codegen->invalid_inst_src)
4669 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4670 if (arg0_value == ag->codegen->invalid_inst_src)
46714671 return arg0_value;
46724672
46734673 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4674 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4675 if (arg1_value == irb->codegen->invalid_inst_src)
4674 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4675 if (arg1_value == ag->codegen->invalid_inst_src)
46764676 return arg1_value;
46774677
46784678 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4679 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
4680 if (arg2_value == irb->codegen->invalid_inst_src)
4679 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
4680 if (arg2_value == ag->codegen->invalid_inst_src)
46814681 return arg2_value;
46824682
4683 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
4684 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
4683 IrInstSrc *ir_memset = ir_build_memset_src(ag, scope, node, arg0_value, arg1_value, arg2_value);
4684 return ir_lval_wrap(ag, scope, ir_memset, lval, result_loc);
46854685 }
46864686 case BuiltinFnIdWasmMemorySize:
46874687 {
46884688 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4689 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4690 if (arg0_value == irb->codegen->invalid_inst_src)
4689 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4690 if (arg0_value == ag->codegen->invalid_inst_src)
46914691 return arg0_value;
46924692
4693 IrInstSrc *ir_wasm_memory_size = ir_build_wasm_memory_size_src(irb, scope, node, arg0_value);
4694 return ir_lval_wrap(irb, scope, ir_wasm_memory_size, lval, result_loc);
4693 IrInstSrc *ir_wasm_memory_size = ir_build_wasm_memory_size_src(ag, scope, node, arg0_value);
4694 return ir_lval_wrap(ag, scope, ir_wasm_memory_size, lval, result_loc);
46954695 }
46964696 case BuiltinFnIdWasmMemoryGrow:
46974697 {
46984698 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4699 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4700 if (arg0_value == irb->codegen->invalid_inst_src)
4699 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4700 if (arg0_value == ag->codegen->invalid_inst_src)
47014701 return arg0_value;
47024702
47034703 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4704 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4705 if (arg1_value == irb->codegen->invalid_inst_src)
4704 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4705 if (arg1_value == ag->codegen->invalid_inst_src)
47064706 return arg1_value;
47074707
4708 IrInstSrc *ir_wasm_memory_grow = ir_build_wasm_memory_grow_src(irb, scope, node, arg0_value, arg1_value);
4709 return ir_lval_wrap(irb, scope, ir_wasm_memory_grow, lval, result_loc);
4708 IrInstSrc *ir_wasm_memory_grow = ir_build_wasm_memory_grow_src(ag, scope, node, arg0_value, arg1_value);
4709 return ir_lval_wrap(ag, scope, ir_wasm_memory_grow, lval, result_loc);
47104710 }
47114711 case BuiltinFnIdField:
47124712 {
47134713 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);
4715 if (arg0_value == irb->codegen->invalid_inst_src)
4714 IrInstSrc *arg0_value = ir_gen_node_extra(ag, arg0_node, scope, LValPtr, nullptr);
4715 if (arg0_value == ag->codegen->invalid_inst_src)
47164716 return arg0_value;
47174717
47184718 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4719 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4720 if (arg1_value == irb->codegen->invalid_inst_src)
4719 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4720 if (arg1_value == ag->codegen->invalid_inst_src)
47214721 return arg1_value;
47224722
4723 IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
4723 IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(ag, scope, node,
47244724 arg0_value, arg1_value, false);
47254725
47264726 if (lval == LValPtr || lval == LValAssign)
47274727 return ptr_instruction;
47284728
4729 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
4730 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
4729 IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction);
4730 return ir_expr_wrap(ag, scope, load_ptr, result_loc);
47314731 }
47324732 case BuiltinFnIdHasField:
47334733 {
47344734 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4735 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4736 if (arg0_value == irb->codegen->invalid_inst_src)
4735 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4736 if (arg0_value == ag->codegen->invalid_inst_src)
47374737 return arg0_value;
47384738
47394739 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4740 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4741 if (arg1_value == irb->codegen->invalid_inst_src)
4740 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4741 if (arg1_value == ag->codegen->invalid_inst_src)
47424742 return arg1_value;
47434743
4744 IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
4745 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
4744 IrInstSrc *type_info = ir_build_has_field(ag, scope, node, arg0_value, arg1_value);
4745 return ir_lval_wrap(ag, scope, type_info, lval, result_loc);
47464746 }
47474747 case BuiltinFnIdTypeInfo:
47484748 {
47494749 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4750 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4751 if (arg0_value == irb->codegen->invalid_inst_src)
4750 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4751 if (arg0_value == ag->codegen->invalid_inst_src)
47524752 return arg0_value;
47534753
4754 IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value);
4755 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
4754 IrInstSrc *type_info = ir_build_type_info(ag, scope, node, arg0_value);
4755 return ir_lval_wrap(ag, scope, type_info, lval, result_loc);
47564756 }
47574757 case BuiltinFnIdType:
47584758 {
47594759 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
4760 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
4761 if (arg == irb->codegen->invalid_inst_src)
4760 IrInstSrc *arg = ir_gen_node(ag, arg_node, scope);
4761 if (arg == ag->codegen->invalid_inst_src)
47624762 return arg;
47634763
4764 IrInstSrc *type = ir_build_type(irb, scope, node, arg);
4765 return ir_lval_wrap(irb, scope, type, lval, result_loc);
4764 IrInstSrc *type = ir_build_type(ag, scope, node, arg);
4765 return ir_lval_wrap(ag, scope, type, lval, result_loc);
47664766 }
47674767 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);
47694769 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);
47714771 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);
47734773 case BuiltinFnIdFrameHandle:
4774 if (!irb->exec->fn_entry) {
4775 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));
4776 return irb->codegen->invalid_inst_src;
4774 if (!ag->exec->fn_entry) {
4775 add_node_error(ag->codegen, node, buf_sprintf("@frame() called outside of function definition"));
4776 return ag->codegen->invalid_inst_src;
47774777 }
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);
47794779 case BuiltinFnIdFrameType: {
47804780 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4781 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4782 if (arg0_value == irb->codegen->invalid_inst_src)
4781 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4782 if (arg0_value == ag->codegen->invalid_inst_src)
47834783 return arg0_value;
47844784
4785 IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
4786 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);
4785 IrInstSrc *frame_type = ir_build_frame_type(ag, scope, node, arg0_value);
4786 return ir_lval_wrap(ag, scope, frame_type, lval, result_loc);
47874787 }
47884788 case BuiltinFnIdFrameSize: {
47894789 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4790 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4791 if (arg0_value == irb->codegen->invalid_inst_src)
4790 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4791 if (arg0_value == ag->codegen->invalid_inst_src)
47924792 return arg0_value;
47934793
4794 IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
4795 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);
4794 IrInstSrc *frame_size = ir_build_frame_size_src(ag, scope, node, arg0_value);
4795 return ir_lval_wrap(ag, scope, frame_size, lval, result_loc);
47964796 }
47974797 case BuiltinFnIdAlignOf:
47984798 {
47994799 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4800 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4801 if (arg0_value == irb->codegen->invalid_inst_src)
4800 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4801 if (arg0_value == ag->codegen->invalid_inst_src)
48024802 return arg0_value;
48034803
4804 IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value);
4805 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);
4804 IrInstSrc *align_of = ir_build_align_of(ag, scope, node, arg0_value);
4805 return ir_lval_wrap(ag, scope, align_of, lval, result_loc);
48064806 }
48074807 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);
48094809 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);
48114811 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);
48134813 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);
48154815 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);
48174817 case BuiltinFnIdTypeName:
48184818 {
48194819 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4820 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4821 if (arg0_value == irb->codegen->invalid_inst_src)
4820 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4821 if (arg0_value == ag->codegen->invalid_inst_src)
48224822 return arg0_value;
48234823
4824 IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value);
4825 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);
4824 IrInstSrc *type_name = ir_build_type_name(ag, scope, node, arg0_value);
4825 return ir_lval_wrap(ag, scope, type_name, lval, result_loc);
48264826 }
48274827 case BuiltinFnIdPanic:
48284828 {
48294829 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4830 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4831 if (arg0_value == irb->codegen->invalid_inst_src)
4830 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4831 if (arg0_value == ag->codegen->invalid_inst_src)
48324832 return arg0_value;
48334833
4834 IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value);
4835 return ir_lval_wrap(irb, scope, panic, lval, result_loc);
4834 IrInstSrc *panic = ir_build_panic_src(ag, scope, node, arg0_value);
4835 return ir_lval_wrap(ag, scope, panic, lval, result_loc);
48364836 }
48374837 case BuiltinFnIdPtrCast:
48384838 {
48394839 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4840 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4841 if (arg0_value == irb->codegen->invalid_inst_src)
4840 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4841 if (arg0_value == ag->codegen->invalid_inst_src)
48424842 return arg0_value;
48434843
48444844 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4845 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4846 if (arg1_value == irb->codegen->invalid_inst_src)
4845 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4846 if (arg1_value == ag->codegen->invalid_inst_src)
48474847 return arg1_value;
48484848
4849 IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
4850 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);
4849 IrInstSrc *ptr_cast = ir_build_ptr_cast_src(ag, scope, node, arg0_value, arg1_value, true);
4850 return ir_lval_wrap(ag, scope, ptr_cast, lval, result_loc);
48514851 }
48524852 case BuiltinFnIdBitCast:
48534853 {
48544854 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
4855 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
4856 if (dest_type == irb->codegen->invalid_inst_src)
4855 IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope);
4856 if (dest_type == ag->codegen->invalid_inst_src)
48574857 return dest_type;
48584858
48594859 ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>();
48604860 result_loc_bit_cast->base.id = ResultLocIdBitCast;
48614861 result_loc_bit_cast->base.source_instruction = dest_type;
48624862 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);
48644864 result_loc_bit_cast->parent = result_loc;
48654865
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);
48674867
48684868 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,
48704870 &result_loc_bit_cast->base);
4871 if (arg1_value == irb->codegen->invalid_inst_src)
4871 if (arg1_value == ag->codegen->invalid_inst_src)
48724872 return arg1_value;
48734873
4874 IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
4875 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
4874 IrInstSrc *bitcast = ir_build_bit_cast_src(ag, scope, arg1_node, arg1_value, result_loc_bit_cast);
4875 return ir_lval_wrap(ag, scope, bitcast, lval, result_loc);
48764876 }
48774877 case BuiltinFnIdAs:
48784878 {
48794879 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
4880 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
4881 if (dest_type == irb->codegen->invalid_inst_src)
4880 IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope);
4881 if (dest_type == ag->codegen->invalid_inst_src)
48824882 return dest_type;
48834883
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);
48854885
48864886 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,
48884888 &result_loc_cast->base);
4889 if (arg1_value == irb->codegen->invalid_inst_src)
4889 if (arg1_value == ag->codegen->invalid_inst_src)
48904890 return arg1_value;
48914891
4892 IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
4893 return ir_lval_wrap(irb, scope, result, lval, result_loc);
4892 IrInstSrc *result = ir_build_implicit_cast(ag, scope, node, arg1_value, result_loc_cast);
4893 return ir_lval_wrap(ag, scope, result, lval, result_loc);
48944894 }
48954895 case BuiltinFnIdIntToPtr:
48964896 {
48974897 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4898 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4899 if (arg0_value == irb->codegen->invalid_inst_src)
4898 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4899 if (arg0_value == ag->codegen->invalid_inst_src)
49004900 return arg0_value;
49014901
49024902 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4903 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4904 if (arg1_value == irb->codegen->invalid_inst_src)
4903 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4904 if (arg1_value == ag->codegen->invalid_inst_src)
49054905 return arg1_value;
49064906
4907 IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value);
4908 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);
4907 IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(ag, scope, node, arg0_value, arg1_value);
4908 return ir_lval_wrap(ag, scope, int_to_ptr, lval, result_loc);
49094909 }
49104910 case BuiltinFnIdPtrToInt:
49114911 {
49124912 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4913 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4914 if (arg0_value == irb->codegen->invalid_inst_src)
4913 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4914 if (arg0_value == ag->codegen->invalid_inst_src)
49154915 return arg0_value;
49164916
4917 IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value);
4918 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);
4917 IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(ag, scope, node, arg0_value);
4918 return ir_lval_wrap(ag, scope, ptr_to_int, lval, result_loc);
49194919 }
49204920 case BuiltinFnIdTagName:
49214921 {
49224922 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4923 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4924 if (arg0_value == irb->codegen->invalid_inst_src)
4923 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4924 if (arg0_value == ag->codegen->invalid_inst_src)
49254925 return arg0_value;
49264926
4927 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
4928 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
4927 IrInstSrc *tag_name = ir_build_tag_name_src(ag, scope, node, arg0_value);
4928 return ir_lval_wrap(ag, scope, tag_name, lval, result_loc);
49294929 }
49304930 case BuiltinFnIdFieldParentPtr:
49314931 {
49324932 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4933 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4934 if (arg0_value == irb->codegen->invalid_inst_src)
4933 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4934 if (arg0_value == ag->codegen->invalid_inst_src)
49354935 return arg0_value;
49364936
49374937 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4938 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4939 if (arg1_value == irb->codegen->invalid_inst_src)
4938 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4939 if (arg1_value == ag->codegen->invalid_inst_src)
49404940 return arg1_value;
49414941
49424942 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4943 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
4944 if (arg2_value == irb->codegen->invalid_inst_src)
4943 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
4944 if (arg2_value == ag->codegen->invalid_inst_src)
49454945 return arg2_value;
49464946
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,
49484948 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);
49504950 }
49514951 case BuiltinFnIdByteOffsetOf:
49524952 {
49534953 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4954 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4955 if (arg0_value == irb->codegen->invalid_inst_src)
4954 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4955 if (arg0_value == ag->codegen->invalid_inst_src)
49564956 return arg0_value;
49574957
49584958 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4959 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4960 if (arg1_value == irb->codegen->invalid_inst_src)
4959 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4960 if (arg1_value == ag->codegen->invalid_inst_src)
49614961 return arg1_value;
49624962
4963 IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
4964 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
4963 IrInstSrc *offset_of = ir_build_byte_offset_of(ag, scope, node, arg0_value, arg1_value);
4964 return ir_lval_wrap(ag, scope, offset_of, lval, result_loc);
49654965 }
49664966 case BuiltinFnIdBitOffsetOf:
49674967 {
49684968 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4969 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
4970 if (arg0_value == irb->codegen->invalid_inst_src)
4969 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
4970 if (arg0_value == ag->codegen->invalid_inst_src)
49714971 return arg0_value;
49724972
49734973 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4974 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
4975 if (arg1_value == irb->codegen->invalid_inst_src)
4974 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
4975 if (arg1_value == ag->codegen->invalid_inst_src)
49764976 return arg1_value;
49774977
4978 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
4979 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
4978 IrInstSrc *offset_of = ir_build_bit_offset_of(ag, scope, node, arg0_value, arg1_value);
4979 return ir_lval_wrap(ag, scope, offset_of, lval, result_loc);
49804980 }
49814981 case BuiltinFnIdCall: {
49824982 // Cast the options parameter to the options type
4983 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
4984 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
4985 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
4983 ZigType *options_type = get_builtin_type(ag->codegen, "CallOptions");
4984 IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type);
4985 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc());
49864986
49874987 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,
49894989 LValNone, &result_loc_cast->base);
4990 if (options_inner == irb->codegen->invalid_inst_src)
4990 if (options_inner == ag->codegen->invalid_inst_src)
49914991 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);
49934993
49944994 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
49954995 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
49974997 if (args_node->data.container_init_expr.kind == ContainerInitKindArray ||
49984998 args_node->data.container_init_expr.entries.length == 0)
49994999 {
5000 return ir_gen_fn_call_with_args(irb, scope, node,
5000 return ir_gen_fn_call_with_args(ag, scope, node,
50015001 fn_ref_node, CallModifierNone, options,
50025002 args_node->data.container_init_expr.entries.items,
50035003 args_node->data.container_init_expr.entries.length,
50045004 lval, result_loc);
50055005 } else {
5006 exec_add_error_node(irb->codegen, irb->exec, args_node,
5006 exec_add_error_node(ag->codegen, ag->exec, args_node,
50075007 buf_sprintf("TODO: @call with anon struct literal"));
5008 return irb->codegen->invalid_inst_src;
5008 return ag->codegen->invalid_inst_src;
50095009 }
50105010 } else {
5011 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5012 if (fn_ref == irb->codegen->invalid_inst_src)
5011 IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope);
5012 if (fn_ref == ag->codegen->invalid_inst_src)
50135013 return fn_ref;
50145014
5015 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
5016 if (args == irb->codegen->invalid_inst_src)
5015 IrInstSrc *args = ir_gen_node(ag, args_node, scope);
5016 if (args == ag->codegen->invalid_inst_src)
50175017 return args;
50185018
5019 IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
5020 return ir_lval_wrap(irb, scope, call, lval, result_loc);
5019 IrInstSrc *call = ir_build_call_extra(ag, scope, node, options, fn_ref, args, result_loc);
5020 return ir_lval_wrap(ag, scope, call, lval, result_loc);
50215021 }
50225022 }
50235023 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);
50255025 case BuiltinFnIdShlExact:
50265026 {
50275027 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5028 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5029 if (arg0_value == irb->codegen->invalid_inst_src)
5028 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5029 if (arg0_value == ag->codegen->invalid_inst_src)
50305030 return arg0_value;
50315031
50325032 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5033 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5034 if (arg1_value == irb->codegen->invalid_inst_src)
5033 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5034 if (arg1_value == ag->codegen->invalid_inst_src)
50355035 return arg1_value;
50365036
5037 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
5038 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5037 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
5038 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
50395039 }
50405040 case BuiltinFnIdShrExact:
50415041 {
50425042 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5043 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5044 if (arg0_value == irb->codegen->invalid_inst_src)
5043 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5044 if (arg0_value == ag->codegen->invalid_inst_src)
50455045 return arg0_value;
50465046
50475047 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5048 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5049 if (arg1_value == irb->codegen->invalid_inst_src)
5048 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5049 if (arg1_value == ag->codegen->invalid_inst_src)
50505050 return arg1_value;
50515051
5052 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
5053 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5052 IrInstSrc *bin_op = ir_build_bin_op(ag, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
5053 return ir_lval_wrap(ag, scope, bin_op, lval, result_loc);
50545054 }
50555055 case BuiltinFnIdSetEvalBranchQuota:
50565056 {
50575057 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5058 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5059 if (arg0_value == irb->codegen->invalid_inst_src)
5058 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5059 if (arg0_value == ag->codegen->invalid_inst_src)
50605060 return arg0_value;
50615061
5062 IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
5063 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);
5062 IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(ag, scope, node, arg0_value);
5063 return ir_lval_wrap(ag, scope, set_eval_branch_quota, lval, result_loc);
50645064 }
50655065 case BuiltinFnIdAlignCast:
50665066 {
50675067 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5068 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5069 if (arg0_value == irb->codegen->invalid_inst_src)
5068 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5069 if (arg0_value == ag->codegen->invalid_inst_src)
50705070 return arg0_value;
50715071
50725072 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5073 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5074 if (arg1_value == irb->codegen->invalid_inst_src)
5073 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5074 if (arg1_value == ag->codegen->invalid_inst_src)
50755075 return arg1_value;
50765076
5077 IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value);
5078 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);
5077 IrInstSrc *align_cast = ir_build_align_cast_src(ag, scope, node, arg0_value, arg1_value);
5078 return ir_lval_wrap(ag, scope, align_cast, lval, result_loc);
50795079 }
50805080 case BuiltinFnIdThis:
50815081 {
5082 IrInstSrc *this_inst = ir_gen_this(irb, scope, node);
5083 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);
5082 IrInstSrc *this_inst = ir_gen_this(ag, scope, node);
5083 return ir_lval_wrap(ag, scope, this_inst, lval, result_loc);
50845084 }
50855085 case BuiltinFnIdSetAlignStack:
50865086 {
50875087 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5088 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5089 if (arg0_value == irb->codegen->invalid_inst_src)
5088 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5089 if (arg0_value == ag->codegen->invalid_inst_src)
50905090 return arg0_value;
50915091
5092 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
5093 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
5092 IrInstSrc *set_align_stack = ir_build_set_align_stack(ag, scope, node, arg0_value);
5093 return ir_lval_wrap(ag, scope, set_align_stack, lval, result_loc);
50945094 }
50955095 case BuiltinFnIdExport:
50965096 {
50975097 // Cast the options parameter to the options type
5098 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");
5099 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
5100 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
5098 ZigType *options_type = get_builtin_type(ag->codegen, "ExportOptions");
5099 IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type);
5100 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc());
51015101
51025102 AstNode *target_node = node->data.fn_call_expr.params.at(0);
5103 IrInstSrc *target_value = ir_gen_node(irb, target_node, scope);
5104 if (target_value == irb->codegen->invalid_inst_src)
5103 IrInstSrc *target_value = ir_gen_node(ag, target_node, scope);
5104 if (target_value == ag->codegen->invalid_inst_src)
51055105 return target_value;
51065106
51075107 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,
51095109 scope, LValNone, &result_loc_cast->base);
5110 if (options_value == irb->codegen->invalid_inst_src)
5110 if (options_value == ag->codegen->invalid_inst_src)
51115111 return options_value;
51125112
51135113 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);
51155115
5116 IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
5117 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
5116 IrInstSrc *ir_export = ir_build_export(ag, scope, node, target_value, casted_options_value);
5117 return ir_lval_wrap(ag, scope, ir_export, lval, result_loc);
51185118 }
51195119 case BuiltinFnIdExtern:
51205120 {
51215121 // Cast the options parameter to the options type
5122 ZigType *options_type = get_builtin_type(irb->codegen, "ExternOptions");
5123 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
5124 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
5122 ZigType *options_type = get_builtin_type(ag->codegen, "ExternOptions");
5123 IrInstSrc *options_type_inst = ir_build_const_type(ag, scope, node, options_type);
5124 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc());
51255125
51265126 AstNode *type_node = node->data.fn_call_expr.params.at(0);
5127 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
5128 if (type_value == irb->codegen->invalid_inst_src)
5127 IrInstSrc *type_value = ir_gen_node(ag, type_node, scope);
5128 if (type_value == ag->codegen->invalid_inst_src)
51295129 return type_value;
51305130
51315131 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,
51335133 scope, LValNone, &result_loc_cast->base);
5134 if (options_value == irb->codegen->invalid_inst_src)
5134 if (options_value == ag->codegen->invalid_inst_src)
51355135 return options_value;
51365136
51375137 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);
51395139
5140 IrInstSrc *ir_extern = ir_build_extern(irb, scope, node, type_value, casted_options_value);
5141 return ir_lval_wrap(irb, scope, ir_extern, lval, result_loc);
5140 IrInstSrc *ir_extern = ir_build_extern(ag, scope, node, type_value, casted_options_value);
5141 return ir_lval_wrap(ag, scope, ir_extern, lval, result_loc);
51425142 }
51435143 case BuiltinFnIdErrorReturnTrace:
51445144 {
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,
51465146 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);
51485148 }
51495149 case BuiltinFnIdAtomicRmw:
51505150 {
51515151 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5152 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5153 if (arg0_value == irb->codegen->invalid_inst_src)
5152 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5153 if (arg0_value == ag->codegen->invalid_inst_src)
51545154 return arg0_value;
51555155
51565156 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5157 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5158 if (arg1_value == irb->codegen->invalid_inst_src)
5157 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5158 if (arg1_value == ag->codegen->invalid_inst_src)
51595159 return arg1_value;
51605160
51615161 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5162 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5163 if (arg2_value == irb->codegen->invalid_inst_src)
5162 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
5163 if (arg2_value == ag->codegen->invalid_inst_src)
51645164 return arg2_value;
51655165
51665166 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5167 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5168 if (arg3_value == irb->codegen->invalid_inst_src)
5167 IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope);
5168 if (arg3_value == ag->codegen->invalid_inst_src)
51695169 return arg3_value;
51705170
51715171 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
5172 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
5173 if (arg4_value == irb->codegen->invalid_inst_src)
5172 IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope);
5173 if (arg4_value == ag->codegen->invalid_inst_src)
51745174 return arg4_value;
51755175
5176 IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node,
5176 IrInstSrc *inst = ir_build_atomic_rmw_src(ag, scope, node,
51775177 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);
51795179 }
51805180 case BuiltinFnIdAtomicLoad:
51815181 {
51825182 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5183 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5184 if (arg0_value == irb->codegen->invalid_inst_src)
5183 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5184 if (arg0_value == ag->codegen->invalid_inst_src)
51855185 return arg0_value;
51865186
51875187 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5188 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5189 if (arg1_value == irb->codegen->invalid_inst_src)
5188 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5189 if (arg1_value == ag->codegen->invalid_inst_src)
51905190 return arg1_value;
51915191
51925192 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5193 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5194 if (arg2_value == irb->codegen->invalid_inst_src)
5193 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
5194 if (arg2_value == ag->codegen->invalid_inst_src)
51955195 return arg2_value;
51965196
5197 IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
5198 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
5197 IrInstSrc *inst = ir_build_atomic_load_src(ag, scope, node, arg0_value, arg1_value, arg2_value);
5198 return ir_lval_wrap(ag, scope, inst, lval, result_loc);
51995199 }
52005200 case BuiltinFnIdAtomicStore:
52015201 {
52025202 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5203 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5204 if (arg0_value == irb->codegen->invalid_inst_src)
5203 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5204 if (arg0_value == ag->codegen->invalid_inst_src)
52055205 return arg0_value;
52065206
52075207 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5208 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5209 if (arg1_value == irb->codegen->invalid_inst_src)
5208 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5209 if (arg1_value == ag->codegen->invalid_inst_src)
52105210 return arg1_value;
52115211
52125212 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5213 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5214 if (arg2_value == irb->codegen->invalid_inst_src)
5213 IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope);
5214 if (arg2_value == ag->codegen->invalid_inst_src)
52155215 return arg2_value;
52165216
52175217 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5218 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5219 if (arg3_value == irb->codegen->invalid_inst_src)
5218 IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope);
5219 if (arg3_value == ag->codegen->invalid_inst_src)
52205220 return arg3_value;
52215221
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,
52235223 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);
52255225 }
52265226 case BuiltinFnIdIntToEnum:
52275227 {
52285228 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5229 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5230 if (arg0_value == irb->codegen->invalid_inst_src)
5229 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5230 if (arg0_value == ag->codegen->invalid_inst_src)
52315231 return arg0_value;
52325232
52335233 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5234 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5235 if (arg1_value == irb->codegen->invalid_inst_src)
5234 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5235 if (arg1_value == ag->codegen->invalid_inst_src)
52365236 return arg1_value;
52375237
5238 IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value);
5239 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5238 IrInstSrc *result = ir_build_int_to_enum_src(ag, scope, node, arg0_value, arg1_value);
5239 return ir_lval_wrap(ag, scope, result, lval, result_loc);
52405240 }
52415241 case BuiltinFnIdEnumToInt:
52425242 {
52435243 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5244 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5245 if (arg0_value == irb->codegen->invalid_inst_src)
5244 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5245 if (arg0_value == ag->codegen->invalid_inst_src)
52465246 return arg0_value;
52475247
5248 IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
5249 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5248 IrInstSrc *result = ir_build_enum_to_int(ag, scope, node, arg0_value);
5249 return ir_lval_wrap(ag, scope, result, lval, result_loc);
52505250 }
52515251 case BuiltinFnIdCtz:
52525252 case BuiltinFnIdPopCount:
......@@ -5255,73 +5255,73 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
52555255 case BuiltinFnIdBitReverse:
52565256 {
52575257 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5258 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5259 if (arg0_value == irb->codegen->invalid_inst_src)
5258 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5259 if (arg0_value == ag->codegen->invalid_inst_src)
52605260 return arg0_value;
52615261
52625262 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5263 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5264 if (arg1_value == irb->codegen->invalid_inst_src)
5263 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5264 if (arg1_value == ag->codegen->invalid_inst_src)
52655265 return arg1_value;
52665266
52675267 IrInstSrc *result;
52685268 switch (builtin_fn->id) {
52695269 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);
52715271 break;
52725272 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);
52745274 break;
52755275 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);
52775277 break;
52785278 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);
52805280 break;
52815281 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);
52835283 break;
52845284 default:
52855285 zig_unreachable();
52865286 }
5287 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5287 return ir_lval_wrap(ag, scope, result, lval, result_loc);
52885288 }
52895289 case BuiltinFnIdHasDecl:
52905290 {
52915291 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5292 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5293 if (arg0_value == irb->codegen->invalid_inst_src)
5292 IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope);
5293 if (arg0_value == ag->codegen->invalid_inst_src)
52945294 return arg0_value;
52955295
52965296 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5297 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5298 if (arg1_value == irb->codegen->invalid_inst_src)
5297 IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope);
5298 if (arg1_value == ag->codegen->invalid_inst_src)
52995299 return arg1_value;
53005300
5301 IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
5302 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);
5301 IrInstSrc *has_decl = ir_build_has_decl(ag, scope, node, arg0_value, arg1_value);
5302 return ir_lval_wrap(ag, scope, has_decl, lval, result_loc);
53035303 }
53045304 case BuiltinFnIdUnionInit:
53055305 {
53065306 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);
5308 if (union_type_inst == irb->codegen->invalid_inst_src)
5307 IrInstSrc *union_type_inst = ir_gen_node(ag, union_type_node, scope);
5308 if (union_type_inst == ag->codegen->invalid_inst_src)
53095309 return union_type_inst;
53105310
53115311 AstNode *name_node = node->data.fn_call_expr.params.at(1);
5312 IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope);
5313 if (name_inst == irb->codegen->invalid_inst_src)
5312 IrInstSrc *name_inst = ir_gen_node(ag, name_node, scope);
5313 if (name_inst == ag->codegen->invalid_inst_src)
53145314 return name_inst;
53155315
53165316 AstNode *init_node = node->data.fn_call_expr.params.at(2);
53175317
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,
53195319 lval, result_loc);
53205320 }
53215321 case BuiltinFnIdSrc:
53225322 {
5323 IrInstSrc *src_inst = ir_build_src(irb, scope, node);
5324 return ir_lval_wrap(irb, scope, src_inst, lval, result_loc);
5323 IrInstSrc *src_inst = ir_build_src(ag, scope, node);
5324 return ir_lval_wrap(ag, scope, src_inst, lval, result_loc);
53255325 }
53265326 }
53275327 zig_unreachable();
......@@ -5339,13 +5339,13 @@ static ScopeNoSuspend *get_scope_nosuspend(Scope *scope) {
53395339 return nullptr;
53405340}
53415341
5342static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5342static IrInstSrc *ir_gen_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
53435343 ResultLoc *result_loc)
53445344{
53455345 assert(node->type == NodeTypeFnCallExpr);
53465346
53475347 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);
53495349
53505350 bool is_nosuspend = get_scope_nosuspend(scope) != nullptr;
53515351 CallModifier modifier = node->data.fn_call_expr.modifier;
......@@ -5354,64 +5354,64 @@ static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node,
53545354 }
53555355
53565356 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,
53585358 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);
53595359}
53605360
5361static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5361static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
53625362 ResultLoc *result_loc)
53635363{
53645364 assert(node->type == NodeTypeIfBoolExpr);
53655365
5366 IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
5367 if (condition == irb->codegen->invalid_inst_src)
5368 return irb->codegen->invalid_inst_src;
5366 IrInstSrc *condition = ir_gen_node(ag, node->data.if_bool_expr.condition, scope);
5367 if (condition == ag->codegen->invalid_inst_src)
5368 return ag->codegen->invalid_inst_src;
53695369
53705370 IrInstSrc *is_comptime;
5371 if (ir_should_inline(irb->exec, scope)) {
5372 is_comptime = ir_build_const_bool(irb, scope, node, true);
5371 if (ir_should_inline(ag->exec, scope)) {
5372 is_comptime = ir_build_const_bool(ag, scope, node, true);
53735373 } else {
5374 is_comptime = ir_build_test_comptime(irb, scope, node, condition);
5374 is_comptime = ir_build_test_comptime(ag, scope, node, condition);
53755375 }
53765376
53775377 AstNode *then_node = node->data.if_bool_expr.then_block;
53785378 AstNode *else_node = node->data.if_bool_expr.else_node;
53795379
5380 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then");
5381 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else");
5382 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf");
5380 IrBasicBlockSrc *then_block = ir_create_basic_block(ag, scope, "Then");
5381 IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "Else");
5382 IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "EndIf");
53835383
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,
53855385 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,
53875387 result_loc, is_comptime);
53885388
5389 ir_set_cursor_at_end_and_append_block(irb, then_block);
5389 ir_set_cursor_at_end_and_append_block(ag, then_block);
53905390
5391 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
5392 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
5391 Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime);
5392 IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, subexpr_scope, lval,
53935393 &peer_parent->peers.at(0)->base);
5394 if (then_expr_result == irb->codegen->invalid_inst_src)
5395 return irb->codegen->invalid_inst_src;
5396 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
5394 if (then_expr_result == ag->codegen->invalid_inst_src)
5395 return ag->codegen->invalid_inst_src;
5396 IrBasicBlockSrc *after_then_block = ag->current_basic_block;
53975397 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));
53995399
5400 ir_set_cursor_at_end_and_append_block(irb, else_block);
5400 ir_set_cursor_at_end_and_append_block(ag, else_block);
54015401 IrInstSrc *else_expr_result;
54025402 if (else_node) {
5403 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
5404 if (else_expr_result == irb->codegen->invalid_inst_src)
5405 return irb->codegen->invalid_inst_src;
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 == ag->codegen->invalid_inst_src)
5405 return ag->codegen->invalid_inst_src;
54065406 } else {
5407 else_expr_result = ir_build_const_void(irb, scope, node);
5408 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
5407 else_expr_result = ir_build_const_void(ag, scope, node);
5408 ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
54095409 }
5410 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
5410 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
54115411 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));
54135413
5414 ir_set_cursor_at_end_and_append_block(irb, endif_block);
5414 ir_set_cursor_at_end_and_append_block(ag, endif_block);
54155415 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
54165416 incoming_values[0] = then_expr_result;
54175417 incoming_values[1] = else_expr_result;
......@@ -5419,37 +5419,37 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *
54195419 incoming_blocks[0] = after_then_block;
54205420 incoming_blocks[1] = after_else_block;
54215421
5422 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
5423 return ir_expr_wrap(irb, scope, phi, result_loc);
5422 IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
5423 return ir_expr_wrap(ag, scope, phi, result_loc);
54245424}
54255425
5426static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
5426static IrInstSrc *ir_gen_prefix_op_id_lval(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
54275427 assert(node->type == NodeTypePrefixOpExpr);
54285428 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
54295429
5430 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
5431 if (value == irb->codegen->invalid_inst_src)
5430 IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, lval, nullptr);
5431 if (value == ag->codegen->invalid_inst_src)
54325432 return value;
54335433
5434 return ir_build_un_op(irb, scope, node, op_id, value);
5434 return ir_build_un_op(ag, scope, node, op_id, value);
54355435}
54365436
5437static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
5438 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
5437static IrInstSrc *ir_gen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id) {
5438 return ir_gen_prefix_op_id_lval(ag, scope, node, op_id, LValNone);
54395439}
54405440
5441static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
5442 if (inst == irb->codegen->invalid_inst_src) return inst;
5443 ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc);
5441static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
5442 if (inst == ag->codegen->invalid_inst_src) return inst;
5443 ir_build_end_expr(ag, scope, inst->base.source_node, inst, result_loc);
54445444 return inst;
54455445}
54465446
5447static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval,
5447static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value, LVal lval,
54485448 ResultLoc *result_loc)
54495449{
54505450 // This logic must be kept in sync with
54515451 // [STMT_EXPR_TEST_THING] <--- (search this token)
5452 if (value == irb->codegen->invalid_inst_src ||
5452 if (value == ag->codegen->invalid_inst_src ||
54535453 instr_is_unreachable(value) ||
54545454 value->base.source_node->type == NodeTypeDefer ||
54555455 value->id == IrInstSrcIdDeclVar)
......@@ -5461,9 +5461,9 @@ static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value
54615461 if (lval == LValPtr) {
54625462 // We needed a pointer to a value, but we got a value. So we create
54635463 // 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);
54655465 } 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);
54675467 } else {
54685468 return value;
54695469 }
......@@ -5484,7 +5484,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {
54845484 }
54855485}
54865486
5487static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node,
5487static Error token_number_literal_u32(Stage1AstGen *ag, AstNode *source_node,
54885488 RootStruct *root_struct, uint32_t *result, TokenIndex token)
54895489{
54905490 BigInt bigint;
......@@ -5493,7 +5493,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node,
54935493 if (!bigint_fits_in_bits(&bigint, 32, false)) {
54945494 Buf *val_buf = buf_alloc();
54955495 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,
54975497 buf_sprintf("value %s too large for u32", buf_ptr(val_buf)));
54985498 bigint_deinit(&bigint);
54995499 return ErrorSemanticAnalyzeFail;
......@@ -5504,7 +5504,7 @@ static Error token_number_literal_u32(IrBuilderSrc *irb, AstNode *source_node,
55045504
55055505}
55065506
5507static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5507static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *node) {
55085508 Error err;
55095509 assert(node->type == NodeTypePointerType);
55105510
......@@ -5521,8 +5521,8 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *
55215521
55225522 IrInstSrc *sentinel;
55235523 if (sentinel_expr != nullptr) {
5524 sentinel = ir_gen_node(irb, sentinel_expr, scope);
5525 if (sentinel == irb->codegen->invalid_inst_src)
5524 sentinel = ir_gen_node(ag, sentinel_expr, scope);
5525 if (sentinel == ag->codegen->invalid_inst_src)
55265526 return sentinel;
55275527 } else {
55285528 sentinel = nullptr;
......@@ -5530,75 +5530,75 @@ static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *
55305530
55315531 IrInstSrc *align_value;
55325532 if (align_expr != nullptr) {
5533 align_value = ir_gen_node(irb, align_expr, scope);
5534 if (align_value == irb->codegen->invalid_inst_src)
5533 align_value = ir_gen_node(ag, align_expr, scope);
5534 if (align_value == ag->codegen->invalid_inst_src)
55355535 return align_value;
55365536 } else {
55375537 align_value = nullptr;
55385538 }
55395539
5540 IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope);
5541 if (child_type == irb->codegen->invalid_inst_src)
5540 IrInstSrc *child_type = ir_gen_node(ag, expr_node, scope);
5541 if (child_type == ag->codegen->invalid_inst_src)
55425542 return child_type;
55435543
55445544 uint32_t bit_offset_start = 0;
55455545 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,
55475547 node->data.pointer_type.bit_offset_start)))
55485548 {
5549 return irb->codegen->invalid_inst_src;
5549 return ag->codegen->invalid_inst_src;
55505550 }
55515551 }
55525552
55535553 uint32_t host_int_bytes = 0;
55545554 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,
55565556 node->data.pointer_type.host_int_bytes)))
55575557 {
5558 return irb->codegen->invalid_inst_src;
5558 return ag->codegen->invalid_inst_src;
55595559 }
55605560 }
55615561
55625562 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,
55645564 buf_sprintf("bit offset starts after end of host integer"));
5565 return irb->codegen->invalid_inst_src;
5565 return ag->codegen->invalid_inst_src;
55665566 }
55675567
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,
55695569 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);
55705570}
55715571
5572static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5572static IrInstSrc *ir_gen_catch_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
55735573 AstNode *expr_node, LVal lval, ResultLoc *result_loc)
55745574{
5575 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
5576 if (err_union_ptr == irb->codegen->invalid_inst_src)
5577 return irb->codegen->invalid_inst_src;
5575 IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr);
5576 if (err_union_ptr == ag->codegen->invalid_inst_src)
5577 return ag->codegen->invalid_inst_src;
55785578
5579 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false);
5580 if (payload_ptr == irb->codegen->invalid_inst_src)
5581 return irb->codegen->invalid_inst_src;
5579 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(ag, scope, source_node, err_union_ptr, true, false);
5580 if (payload_ptr == ag->codegen->invalid_inst_src)
5581 return ag->codegen->invalid_inst_src;
55825582
55835583 if (lval == LValPtr)
55845584 return payload_ptr;
55855585
5586 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
5587 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
5586 IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, source_node, payload_ptr);
5587 return ir_expr_wrap(ag, scope, load_ptr, result_loc);
55885588}
55895589
5590static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5590static IrInstSrc *ir_gen_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *node) {
55915591 assert(node->type == NodeTypePrefixOpExpr);
55925592 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
55935593
5594 IrInstSrc *value = ir_gen_node(irb, expr_node, scope);
5595 if (value == irb->codegen->invalid_inst_src)
5596 return irb->codegen->invalid_inst_src;
5594 IrInstSrc *value = ir_gen_node(ag, expr_node, scope);
5595 if (value == ag->codegen->invalid_inst_src)
5596 return ag->codegen->invalid_inst_src;
55975597
5598 return ir_build_bool_not(irb, scope, node, value);
5598 return ir_build_bool_not(ag, scope, node, value);
55995599}
56005600
5601static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5601static IrInstSrc *ir_gen_prefix_op_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
56025602 ResultLoc *result_loc)
56035603{
56045604 assert(node->type == NodeTypePrefixOpExpr);
......@@ -5609,49 +5609,49 @@ static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode
56095609 case PrefixOpInvalid:
56105610 zig_unreachable();
56115611 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);
56135613 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);
56155615 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);
56175617 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);
56195619 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);
56215621 case PrefixOpAddrOf: {
56225622 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);
56245624 }
56255625 }
56265626 zig_unreachable();
56275627}
56285628
5629static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5629static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
56305630 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
56315631 LVal lval, ResultLoc *parent_result_loc)
56325632{
5633 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
5634 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
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(ag, scope, source_node, container_ptr,
56355635 field_name, true);
56365636
56375637 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
56385638 result_loc_inst->base.id = ResultLocIdInstruction;
56395639 result_loc_inst->base.source_instruction = field_ptr;
5640 ir_ref_instruction(field_ptr, irb->current_basic_block);
5641 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
5640 ir_ref_instruction(field_ptr, ag->current_basic_block);
5641 ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base);
56425642
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,
56445644 &result_loc_inst->base);
5645 if (expr_value == irb->codegen->invalid_inst_src)
5645 if (expr_value == ag->codegen->invalid_inst_src)
56465646 return expr_value;
56475647
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,
56495649 field_name, field_ptr, container_ptr);
56505650
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);
56525652}
56535653
5654static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5654static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
56555655 ResultLoc *parent_result_loc)
56565656{
56575657 assert(node->type == NodeTypeContainerInitExpr);
......@@ -5666,33 +5666,33 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
56665666 IrInstSrc *container_type;
56675667 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
56685668 if (kind == ContainerInitKindStruct) {
5669 add_node_error(irb->codegen, container_init_expr->type,
5669 add_node_error(ag->codegen, container_init_expr->type,
56705670 buf_sprintf("initializing array with struct syntax"));
5671 return irb->codegen->invalid_inst_src;
5671 return ag->codegen->invalid_inst_src;
56725672 }
56735673 IrInstSrc *sentinel;
56745674 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);
5676 if (sentinel == irb->codegen->invalid_inst_src)
5675 sentinel = ir_gen_node(ag, container_init_expr->type->data.inferred_array_type.sentinel, scope);
5676 if (sentinel == ag->codegen->invalid_inst_src)
56775677 return sentinel;
56785678 } else {
56795679 sentinel = nullptr;
56805680 }
56815681
5682 IrInstSrc *elem_type = ir_gen_node(irb,
5682 IrInstSrc *elem_type = ir_gen_node(ag,
56835683 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)
56855685 return elem_type;
56865686 size_t item_count = container_init_expr->entries.length;
5687 IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
5688 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);
5687 IrInstSrc *item_count_inst = ir_build_const_usize(ag, scope, node, item_count);
5688 container_type = ir_build_array_type(ag, scope, node, item_count_inst, sentinel, elem_type);
56895689 } else {
5690 container_type = ir_gen_node(irb, container_init_expr->type, scope);
5691 if (container_type == irb->codegen->invalid_inst_src)
5690 container_type = ir_gen_node(ag, container_init_expr->type, scope);
5691 if (container_type == ag->codegen->invalid_inst_src)
56925692 return container_type;
56935693 }
56945694
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);
56965696 child_result_loc = &result_loc_cast->base;
56975697 init_array_type_source_node = container_type->base.source_node;
56985698 } else {
......@@ -5706,7 +5706,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
57065706
57075707 switch (kind) {
57085708 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,
57105710 nullptr);
57115711
57125712 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
57185718 Buf *name = entry_node->data.struct_val_field.name;
57195719 AstNode *expr_node = entry_node->data.struct_val_field.expr;
57205720
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);
57225722 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
57235723 result_loc_inst->base.id = ResultLocIdInstruction;
57245724 result_loc_inst->base.source_instruction = field_ptr;
57255725 result_loc_inst->base.allow_write_through_const = true;
5726 ir_ref_instruction(field_ptr, irb->current_basic_block);
5727 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
5726 ir_ref_instruction(field_ptr, ag->current_basic_block);
5727 ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base);
57285728
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,
57305730 &result_loc_inst->base);
5731 if (expr_value == irb->codegen->invalid_inst_src)
5731 if (expr_value == ag->codegen->invalid_inst_src)
57325732 return expr_value;
57335733
57345734 fields[i].name = name;
57355735 fields[i].source_node = entry_node;
57365736 fields[i].result_loc = field_ptr;
57375737 }
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,
57395739 fields, container_ptr);
57405740
57415741 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);
57435743 }
5744 return ir_lval_wrap(irb, scope, result, lval, parent_result_loc);
5744 return ir_lval_wrap(ag, scope, result, lval, parent_result_loc);
57455745 }
57465746 case ContainerInitKindArray: {
57475747 size_t item_count = container_init_expr->entries.length;
57485748
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,
57505750 nullptr);
57515751
57525752 IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count);
57535753 for (size_t i = 0; i < item_count; i += 1) {
57545754 AstNode *expr_node = container_init_expr->entries.at(i);
57555755
5756 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
5757 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
5756 IrInstSrc *elem_index = ir_build_const_usize(ag, scope, expr_node, i);
5757 IrInstSrc *elem_ptr = ir_build_elem_ptr(ag, scope, expr_node, container_ptr,
57585758 elem_index, false, PtrLenSingle, init_array_type_source_node);
57595759 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
57605760 result_loc_inst->base.id = ResultLocIdInstruction;
57615761 result_loc_inst->base.source_instruction = elem_ptr;
57625762 result_loc_inst->base.allow_write_through_const = true;
5763 ir_ref_instruction(elem_ptr, irb->current_basic_block);
5764 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
5763 ir_ref_instruction(elem_ptr, ag->current_basic_block);
5764 ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base);
57655765
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,
57675767 &result_loc_inst->base);
5768 if (expr_value == irb->codegen->invalid_inst_src)
5768 if (expr_value == ag->codegen->invalid_inst_src)
57695769 return expr_value;
57705770
57715771 result_locs[i] = elem_ptr;
57725772 }
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,
57745774 result_locs, container_ptr, init_array_type_source_node);
57755775 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);
57775777 }
5778 return ir_lval_wrap(irb, scope, result, lval, parent_result_loc);
5778 return ir_lval_wrap(ag, scope, result, lval, parent_result_loc);
57795779 }
57805780 }
57815781 zig_unreachable();
57825782}
57835783
5784static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
5784static ResultLocVar *ir_build_var_result_loc(Stage1AstGen *ag, IrInstSrc *alloca, ZigVar *var) {
57855785 ResultLocVar *result_loc_var = heap::c_allocator.create<ResultLocVar>();
57865786 result_loc_var->base.id = ResultLocIdVar;
57875787 result_loc_var->base.source_instruction = alloca;
57885788 result_loc_var->base.allow_write_through_const = true;
57895789 result_loc_var->var = var;
57905790
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);
57925792
57935793 return result_loc_var;
57945794}
57955795
5796static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
5796static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest_type,
57975797 ResultLoc *parent_result_loc)
57985798{
57995799 ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>();
58005800 result_loc_cast->base.id = ResultLocIdCast;
58015801 result_loc_cast->base.source_instruction = dest_type;
58025802 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);
58045804 result_loc_cast->parent = parent_result_loc;
58055805
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);
58075807
58085808 return result_loc_cast;
58095809}
58105810
5811static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
5811static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node, ZigVar *var,
58125812 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime)
58135813{
5814 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
5815 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);
5816 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
5817 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
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(ag, alloca, var);
5816 ir_build_end_expr(ag, scope, source_node, init, &var_result_loc->base);
5817 ir_build_var_decl_src(ag, scope, source_node, var, nullptr, alloca);
58185818}
58195819
5820static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5820static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) {
58215821 assert(node->type == NodeTypeVariableDeclaration);
58225822
58235823 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;
58245824
58255825 if (buf_eql_str(variable_declaration->symbol, "_")) {
5826 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));
5827 return irb->codegen->invalid_inst_src;
5826 add_node_error(ag->codegen, node, buf_sprintf("`_` is not a declarable symbol"));
5827 return ag->codegen->invalid_inst_src;
58285828 }
58295829
58305830 // 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);
58325832
58335833 IrInstSrc *type_instruction;
58345834 if (variable_declaration->type != nullptr) {
5835 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);
5836 if (type_instruction == irb->codegen->invalid_inst_src)
5835 type_instruction = ir_gen_node(ag, variable_declaration->type, comptime_scope);
5836 if (type_instruction == ag->codegen->invalid_inst_src)
58375837 return type_instruction;
58385838 } else {
58395839 type_instruction = nullptr;
......@@ -5843,43 +5843,43 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node
58435843 bool is_const = variable_declaration->is_const;
58445844 bool is_extern = variable_declaration->is_extern;
58455845
5846 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
5847 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
5848 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
5846 bool is_comptime_scalar = ir_should_inline(ag->exec, scope) || variable_declaration->is_comptime;
5847 IrInstSrc *is_comptime = ir_build_const_bool(ag, scope, node, is_comptime_scalar);
5848 ZigVar *var = ir_create_var(ag, node, scope, variable_declaration->symbol,
58495849 is_const, is_const, is_shadowable, is_comptime);
58505850 // we detect IrInstSrcDeclVar in gen_block to make sure the next node
58515851 // is inside var->child_scope
58525852
58535853 if (!is_extern && !variable_declaration->expr) {
5854 var->var_type = irb->codegen->builtin_types.entry_invalid;
5855 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));
5856 return irb->codegen->invalid_inst_src;
5854 var->var_type = ag->codegen->builtin_types.entry_invalid;
5855 add_node_error(ag->codegen, node, buf_sprintf("variables must be initialized"));
5856 return ag->codegen->invalid_inst_src;
58575857 }
58585858
58595859 IrInstSrc *align_value = nullptr;
58605860 if (variable_declaration->align_expr != nullptr) {
5861 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);
5862 if (align_value == irb->codegen->invalid_inst_src)
5861 align_value = ir_gen_node(ag, variable_declaration->align_expr, comptime_scope);
5862 if (align_value == ag->codegen->invalid_inst_src)
58635863 return align_value;
58645864 }
58655865
58665866 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,
58685868 buf_sprintf("cannot set section of local variable '%s'", buf_ptr(variable_declaration->symbol)));
58695869 }
58705870
58715871 // Parser should ensure that this never happens
58725872 assert(variable_declaration->threadlocal_tok == 0);
58735873
5874 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value,
5874 IrInstSrc *alloca = ir_build_alloca_src(ag, scope, node, align_value,
58755875 buf_ptr(variable_declaration->symbol), is_comptime);
58765876
58775877 // 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);
58795879 ResultLoc *init_result_loc;
58805880 ResultLocCast *result_loc_cast;
58815881 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);
58835883 init_result_loc = &result_loc_cast->base;
58845884 } else {
58855885 result_loc_cast = nullptr;
......@@ -5887,29 +5887,29 @@ static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node
58875887 }
58885888
58895889 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;
58915891
58925892 // Temporarily set the name of the Stage1Zir to the VariableDeclaration
58935893 // so that the struct or enum from the init expression inherits the name.
5894 Buf *old_exec_name = irb->exec->name;
5895 irb->exec->name = variable_declaration->symbol;
5896 IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
5894 Buf *old_exec_name = ag->exec->name;
5895 ag->exec->name = variable_declaration->symbol;
5896 IrInstSrc *init_value = ir_gen_node_extra(ag, variable_declaration->expr, init_scope,
58975897 LValNone, init_result_loc);
5898 irb->exec->name = old_exec_name;
5898 ag->exec->name = old_exec_name;
58995899
5900 if (init_value == irb->codegen->invalid_inst_src)
5901 return irb->codegen->invalid_inst_src;
5900 if (init_value == ag->codegen->invalid_inst_src)
5901 return ag->codegen->invalid_inst_src;
59025902
59035903 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,
59055905 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);
59075907 }
59085908
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);
59105910}
59115911
5912static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5912static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
59135913 ResultLoc *result_loc)
59145914{
59155915 assert(node->type == NodeTypeWhileExpr);
......@@ -5917,73 +5917,73 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
59175917 AstNode *continue_expr_node = node->data.while_expr.continue_expr;
59185918 AstNode *else_node = node->data.while_expr.else_node;
59195919
5920 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
5921 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody");
5920 IrBasicBlockSrc *cond_block = ir_create_basic_block(ag, scope, "WhileCond");
5921 IrBasicBlockSrc *body_block = ir_create_basic_block(ag, scope, "WhileBody");
59225922 IrBasicBlockSrc *continue_block = continue_expr_node ?
5923 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;
5924 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
5923 ir_create_basic_block(ag, scope, "WhileContinue") : cond_block;
5924 IrBasicBlockSrc *end_block = ir_create_basic_block(ag, scope, "WhileEnd");
59255925 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;
59275927
5928 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node,
5929 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
5930 ir_build_br(irb, scope, node, cond_block, is_comptime);
5928 IrInstSrc *is_comptime = ir_build_const_bool(ag, scope, node,
5929 ir_should_inline(ag->exec, scope) || node->data.while_expr.is_inline);
5930 ir_build_br(ag, scope, node, cond_block, is_comptime);
59315931
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);
59335933 Buf *var_symbol = node->data.while_expr.var_symbol;
59345934 Buf *err_symbol = node->data.while_expr.err_symbol;
59355935 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);
59375937
59385938 Scope *payload_scope;
59395939 AstNode *symbol_node = node; // TODO make more accurate
59405940 ZigVar *payload_var;
59415941 if (var_symbol) {
59425942 // 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,
59445944 true, false, false, is_comptime);
59455945 payload_scope = payload_var->child_scope;
59465946 } else {
59475947 payload_scope = subexpr_scope;
59485948 }
5949 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, payload_scope);
5950 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
5949 ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, payload_scope);
5950 IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope,
59515951 LValPtr, nullptr);
5952 if (err_val_ptr == irb->codegen->invalid_inst_src)
5952 if (err_val_ptr == ag->codegen->invalid_inst_src)
59535953 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,
59555955 true, false);
5956 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
5957 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
5956 IrBasicBlockSrc *after_cond_block = ag->current_basic_block;
5957 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node));
59585958 IrInstSrc *cond_br_inst;
59595959 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,
59615961 else_block, body_block, is_comptime);
59625962 cond_br_inst->is_gen = true;
59635963 } else {
59645964 // 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();
59665966 }
59675967
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,
59695969 is_comptime);
59705970
5971 ir_set_cursor_at_end_and_append_block(irb, body_block);
5971 ir_set_cursor_at_end_and_append_block(ag, body_block);
59725972 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,
59745974 err_val_ptr, false, false);
59755975 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);
5977 build_decl_var_and_init(irb, payload_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
5976 payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, symbol_node, payload_ptr);
5977 build_decl_var_and_init(ag, payload_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
59785978 }
59795979
59805980 ZigList<IrInstSrc *> incoming_values = {0};
59815981 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
59825982
5983 if (is_duplicate_label(irb->codegen, payload_scope, node, node->data.while_expr.name))
5984 return irb->codegen->invalid_inst_src;
5983 if (is_duplicate_label(ag->codegen, payload_scope, node, node->data.while_expr.name))
5984 return ag->codegen->invalid_inst_src;
59855985
5986 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);
5986 ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, payload_scope);
59875987 loop_scope->break_block = end_block;
59885988 loop_scope->continue_block = continue_block;
59895989 loop_scope->is_comptime = is_comptime;
......@@ -5996,54 +5996,54 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
59965996 // Note the body block of the loop is not the place that lval and result_loc are used -
59975997 // it's actually in break statements, handled similarly to return statements.
59985998 // 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);
6000 if (body_result == irb->codegen->invalid_inst_src)
5999 IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base);
6000 if (body_result == ag->codegen->invalid_inst_src)
60016001 return body_result;
60026002
60036003 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"));
60056005 }
60066006
60076007 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));
6009 ir_mark_gen(ir_build_br(irb, payload_scope, node, continue_block, is_comptime));
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(ag, payload_scope, node, continue_block, is_comptime));
60106010 }
60116011
60126012 if (continue_expr_node) {
6013 ir_set_cursor_at_end_and_append_block(irb, continue_block);
6014 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
6015 if (expr_result == irb->codegen->invalid_inst_src)
6013 ir_set_cursor_at_end_and_append_block(ag, continue_block);
6014 IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, payload_scope);
6015 if (expr_result == ag->codegen->invalid_inst_src)
60166016 return expr_result;
60176017 if (!instr_is_unreachable(expr_result)) {
6018 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
6019 ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime));
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(ag, payload_scope, node, cond_block, is_comptime));
60206020 }
60216021 }
60226022
6023 ir_set_cursor_at_end_and_append_block(irb, else_block);
6023 ir_set_cursor_at_end_and_append_block(ag, else_block);
60246024 assert(else_node != nullptr);
60256025
60266026 // TODO make it an error to write to error variable
60276027 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,
60296029 true, false, false, is_comptime);
60306030 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);
6032 IrInstSrc *err_value = ir_build_load_ptr(irb, 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);
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(ag, err_scope, err_symbol_node, err_ptr);
6033 build_decl_var_and_init(ag, err_scope, err_symbol_node, err_var, err_value, buf_ptr(err_symbol), is_comptime);
60346034
60356035 if (peer_parent->peers.length != 0) {
60366036 peer_parent->peers.last()->next_bb = else_block;
60376037 }
60386038 ResultLocPeer *peer_result = create_peer_result(peer_parent);
60396039 peer_parent->peers.append(peer_result);
6040 IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
6041 if (else_result == irb->codegen->invalid_inst_src)
6040 IrInstSrc *else_result = ir_gen_node_extra(ag, else_node, err_scope, lval, &peer_result->base);
6041 if (else_result == ag->codegen->invalid_inst_src)
60426042 return else_result;
60436043 if (!instr_is_unreachable(else_result))
6044 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
6045 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6046 ir_set_cursor_at_end_and_append_block(irb, end_block);
6044 ir_mark_gen(ir_build_br(ag, scope, node, end_block, is_comptime));
6045 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
6046 ir_set_cursor_at_end_and_append_block(ag, end_block);
60476047 if (else_result) {
60486048 incoming_blocks.append(after_else_block);
60496049 incoming_values.append(else_result);
......@@ -6055,53 +6055,53 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
60556055 peer_parent->peers.last()->next_bb = end_block;
60566056 }
60576057
6058 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
6058 IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length,
60596059 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);
60616061 } else if (var_symbol != nullptr) {
6062 ir_set_cursor_at_end_and_append_block(irb, cond_block);
6063 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6062 ir_set_cursor_at_end_and_append_block(ag, cond_block);
6063 Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime);
60646064 // TODO make it an error to write to payload variable
60656065 AstNode *symbol_node = node; // TODO make more accurate
60666066
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,
60686068 true, false, false, is_comptime);
60696069 Scope *child_scope = payload_var->child_scope;
6070 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, child_scope);
6071 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
6070 ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, child_scope);
6071 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope,
60726072 LValPtr, nullptr);
6073 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
6073 if (maybe_val_ptr == ag->codegen->invalid_inst_src)
60746074 return maybe_val_ptr;
6075 IrInstSrc *maybe_val = ir_build_load_ptr(irb, 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);
6077 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
6078 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
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(ag, scope, node->data.while_expr.condition, maybe_val);
6077 IrBasicBlockSrc *after_cond_block = ag->current_basic_block;
6078 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node));
60796079 IrInstSrc *cond_br_inst;
60806080 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,
60826082 body_block, else_block, is_comptime);
60836083 cond_br_inst->is_gen = true;
60846084 } else {
60856085 // 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();
60876087 }
60886088
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,
60906090 is_comptime);
60916091
6092 ir_set_cursor_at_end_and_append_block(irb, body_block);
6093 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, &spill_scope->base, symbol_node, maybe_val_ptr, false);
6092 ir_set_cursor_at_end_and_append_block(ag, body_block);
6093 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(ag, &spill_scope->base, symbol_node, maybe_val_ptr, false);
60946094 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);
6096 build_decl_var_and_init(irb, child_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
6095 payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, symbol_node, payload_ptr);
6096 build_decl_var_and_init(ag, child_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
60976097
60986098 ZigList<IrInstSrc *> incoming_values = {0};
60996099 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
61006100
6101 if (is_duplicate_label(irb->codegen, child_scope, node, node->data.while_expr.name))
6102 return irb->codegen->invalid_inst_src;
6101 if (is_duplicate_label(ag->codegen, child_scope, node, node->data.while_expr.name))
6102 return ag->codegen->invalid_inst_src;
61036103
6104 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
6104 ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, child_scope);
61056105 loop_scope->break_block = end_block;
61066106 loop_scope->continue_block = continue_block;
61076107 loop_scope->is_comptime = is_comptime;
......@@ -6114,47 +6114,47 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
61146114 // Note the body block of the loop is not the place that lval and result_loc are used -
61156115 // it's actually in break statements, handled similarly to return statements.
61166116 // 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);
6118 if (body_result == irb->codegen->invalid_inst_src)
6117 IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base);
6118 if (body_result == ag->codegen->invalid_inst_src)
61196119 return body_result;
61206120
61216121 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"));
61236123 }
61246124
61256125 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));
6127 ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime));
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(ag, child_scope, node, continue_block, is_comptime));
61286128 }
61296129
61306130 if (continue_expr_node) {
6131 ir_set_cursor_at_end_and_append_block(irb, continue_block);
6132 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
6133 if (expr_result == irb->codegen->invalid_inst_src)
6131 ir_set_cursor_at_end_and_append_block(ag, continue_block);
6132 IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, child_scope);
6133 if (expr_result == ag->codegen->invalid_inst_src)
61346134 return expr_result;
61356135 if (!instr_is_unreachable(expr_result)) {
6136 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
6137 ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime));
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(ag, child_scope, node, cond_block, is_comptime));
61386138 }
61396139 }
61406140
61416141 IrInstSrc *else_result = nullptr;
61426142 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);
61446144
61456145 if (peer_parent->peers.length != 0) {
61466146 peer_parent->peers.last()->next_bb = else_block;
61476147 }
61486148 ResultLocPeer *peer_result = create_peer_result(peer_parent);
61496149 peer_parent->peers.append(peer_result);
6150 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);
6151 if (else_result == irb->codegen->invalid_inst_src)
6150 else_result = ir_gen_node_extra(ag, else_node, scope, lval, &peer_result->base);
6151 if (else_result == ag->codegen->invalid_inst_src)
61526152 return else_result;
61536153 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));
61556155 }
6156 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6157 ir_set_cursor_at_end_and_append_block(irb, end_block);
6156 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
6157 ir_set_cursor_at_end_and_append_block(ag, end_block);
61586158 if (else_result) {
61596159 incoming_blocks.append(after_else_block);
61606160 incoming_values.append(else_result);
......@@ -6166,39 +6166,39 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
61666166 peer_parent->peers.last()->next_bb = end_block;
61676167 }
61686168
6169 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
6169 IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length,
61706170 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);
61726172 } else {
6173 ir_set_cursor_at_end_and_append_block(irb, cond_block);
6174 IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
6175 if (cond_val == irb->codegen->invalid_inst_src)
6173 ir_set_cursor_at_end_and_append_block(ag, cond_block);
6174 IrInstSrc *cond_val = ir_gen_node(ag, node->data.while_expr.condition, scope);
6175 if (cond_val == ag->codegen->invalid_inst_src)
61766176 return cond_val;
6177 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
6178 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
6177 IrBasicBlockSrc *after_cond_block = ag->current_basic_block;
6178 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(ag, scope, node));
61796179 IrInstSrc *cond_br_inst;
61806180 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,
61826182 body_block, else_block, is_comptime);
61836183 cond_br_inst->is_gen = true;
61846184 } else {
61856185 // 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();
61876187 }
61886188
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,
61906190 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);
61926192
61936193 ZigList<IrInstSrc *> incoming_values = {0};
61946194 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
61956195
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);
61976197
6198 if (is_duplicate_label(irb->codegen, subexpr_scope, node, node->data.while_expr.name))
6199 return irb->codegen->invalid_inst_src;
6198 if (is_duplicate_label(ag->codegen, subexpr_scope, node, node->data.while_expr.name))
6199 return ag->codegen->invalid_inst_src;
62006200
6201 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, subexpr_scope);
6201 ScopeLoop *loop_scope = create_loop_scope(ag->codegen, node, subexpr_scope);
62026202 loop_scope->break_block = end_block;
62036203 loop_scope->continue_block = continue_block;
62046204 loop_scope->is_comptime = is_comptime;
......@@ -6210,33 +6210,33 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
62106210 // Note the body block of the loop is not the place that lval and result_loc are used -
62116211 // it's actually in break statements, handled similarly to return statements.
62126212 // 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);
6214 if (body_result == irb->codegen->invalid_inst_src)
6213 IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base);
6214 if (body_result == ag->codegen->invalid_inst_src)
62156215 return body_result;
62166216
62176217 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"));
62196219 }
62206220
62216221 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));
6223 ir_mark_gen(ir_build_br(irb, scope, node, continue_block, is_comptime));
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(ag, scope, node, continue_block, is_comptime));
62246224 }
62256225
62266226 if (continue_expr_node) {
6227 ir_set_cursor_at_end_and_append_block(irb, continue_block);
6228 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
6229 if (expr_result == irb->codegen->invalid_inst_src)
6227 ir_set_cursor_at_end_and_append_block(ag, continue_block);
6228 IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, subexpr_scope);
6229 if (expr_result == ag->codegen->invalid_inst_src)
62306230 return expr_result;
62316231 if (!instr_is_unreachable(expr_result)) {
6232 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
6233 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
6232 ir_mark_gen(ir_build_check_statement_is_void(ag, scope, continue_expr_node, expr_result));
6233 ir_mark_gen(ir_build_br(ag, scope, node, cond_block, is_comptime));
62346234 }
62356235 }
62366236
62376237 IrInstSrc *else_result = nullptr;
62386238 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);
62406240
62416241 if (peer_parent->peers.length != 0) {
62426242 peer_parent->peers.last()->next_bb = else_block;
......@@ -6244,14 +6244,14 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
62446244 ResultLocPeer *peer_result = create_peer_result(peer_parent);
62456245 peer_parent->peers.append(peer_result);
62466246
6247 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);
6248 if (else_result == irb->codegen->invalid_inst_src)
6247 else_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_result->base);
6248 if (else_result == ag->codegen->invalid_inst_src)
62496249 return else_result;
62506250 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));
62526252 }
6253 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6254 ir_set_cursor_at_end_and_append_block(irb, end_block);
6253 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
6254 ir_set_cursor_at_end_and_append_block(ag, end_block);
62556255 if (else_result) {
62566256 incoming_blocks.append(after_else_block);
62576257 incoming_values.append(else_result);
......@@ -6263,13 +6263,13 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
62636263 peer_parent->peers.last()->next_bb = end_block;
62646264 }
62656265
6266 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
6266 IrInstSrc *phi = ir_build_phi(ag, scope, node, incoming_blocks.length,
62676267 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);
62696269 }
62706270}
62716271
6272static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
6272static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval,
62736273 ResultLoc *result_loc)
62746274{
62756275 assert(node->type == NodeTypeForExpr);
......@@ -6281,19 +6281,19 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
62816281 AstNode *else_node = node->data.for_expr.else_node;
62826282
62836283 if (!elem_node) {
6284 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));
6285 return irb->codegen->invalid_inst_src;
6284 add_node_error(ag->codegen, node, buf_sprintf("for loop expression missing element parameter"));
6285 return ag->codegen->invalid_inst_src;
62866286 }
62876287 assert(elem_node->type == NodeTypeIdentifier);
62886288
6289 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);
6289 ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, parent_scope);
62906290
6291 IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
6292 if (array_val_ptr == irb->codegen->invalid_inst_src)
6291 IrInstSrc *array_val_ptr = ir_gen_node_extra(ag, array_node, &spill_scope->base, LValPtr, nullptr);
6292 if (array_val_ptr == ag->codegen->invalid_inst_src)
62936293 return array_val_ptr;
62946294
6295 IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node,
6296 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
6295 IrInstSrc *is_comptime = ir_build_const_bool(ag, parent_scope, node,
6296 ir_should_inline(ag->exec, parent_scope) || node->data.for_expr.is_inline);
62976297
62986298 AstNode *index_var_source_node;
62996299 ZigVar *index_var;
......@@ -6301,61 +6301,61 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
63016301 if (index_node) {
63026302 index_var_source_node = index_node;
63036303 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);
63056305 index_var_name = buf_ptr(index_var_name_buf);
63066306 } else {
63076307 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);
63096309 index_var_name = "i";
63106310 }
63116311
6312 IrInstSrc *zero = ir_build_const_usize(irb, 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);
6312 IrInstSrc *zero = ir_build_const_usize(ag, parent_scope, node, 0);
6313 build_decl_var_and_init(ag, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
63146314 parent_scope = index_var->child_scope;
63156315
6316 IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1);
6317 IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
6316 IrInstSrc *one = ir_build_const_usize(ag, parent_scope, node, 1);
6317 IrInstSrc *index_ptr = ir_build_var_ptr(ag, parent_scope, node, index_var);
63186318
63196319
6320 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
6321 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
6322 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
6323 IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
6324 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
6320 IrBasicBlockSrc *cond_block = ir_create_basic_block(ag, parent_scope, "ForCond");
6321 IrBasicBlockSrc *body_block = ir_create_basic_block(ag, parent_scope, "ForBody");
6322 IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "ForEnd");
6323 IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(ag, parent_scope, "ForElse") : end_block;
6324 IrBasicBlockSrc *continue_block = ir_create_basic_block(ag, parent_scope, "ForContinue");
63256325
63266326 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);
6328 IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
6329 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
6330
6331 ir_set_cursor_at_end_and_append_block(irb, cond_block);
6332 IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
6333 IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
6334 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
6335 IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
6336 IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
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(ag, &spill_scope->base, node, len_ref);
6329 ir_build_br(ag, parent_scope, node, cond_block, is_comptime);
6330
6331 ir_set_cursor_at_end_and_append_block(ag, cond_block);
6332 IrInstSrc *index_val = ir_build_load_ptr(ag, &spill_scope->base, node, index_ptr);
6333 IrInstSrc *cond = ir_build_bin_op(ag, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
6334 IrBasicBlockSrc *after_cond_block = ag->current_basic_block;
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(ag, parent_scope, node, cond,
63376337 body_block, else_block, is_comptime));
63386338
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);
63406340
6341 ir_set_cursor_at_end_and_append_block(irb, body_block);
6342 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, &spill_scope->base, node, array_val_ptr, index_val,
6341 ir_set_cursor_at_end_and_append_block(ag, body_block);
6342 IrInstSrc *elem_ptr = ir_build_elem_ptr(ag, &spill_scope->base, node, array_val_ptr, index_val,
63436343 false, PtrLenSingle, nullptr);
63446344 // TODO make it an error to write to element variable or i variable.
63456345 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);
63476347 Scope *child_scope = elem_var->child_scope;
63486348
63496349 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);
6351 build_decl_var_and_init(irb, parent_scope, elem_node, elem_var, elem_value, buf_ptr(elem_var_name), is_comptime);
6350 elem_ptr : ir_build_load_ptr(ag, &spill_scope->base, elem_node, elem_ptr);
6351 build_decl_var_and_init(ag, parent_scope, elem_node, elem_var, elem_value, buf_ptr(elem_var_name), is_comptime);
63526352
6353 if (is_duplicate_label(irb->codegen, child_scope, node, node->data.for_expr.name))
6354 return irb->codegen->invalid_inst_src;
6353 if (is_duplicate_label(ag->codegen, child_scope, node, node->data.for_expr.name))
6354 return ag->codegen->invalid_inst_src;
63556355
63566356 ZigList<IrInstSrc *> incoming_values = {0};
63576357 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);
63596359 loop_scope->break_block = end_block;
63606360 loop_scope->continue_block = continue_block;
63616361 loop_scope->is_comptime = is_comptime;
......@@ -6368,41 +6368,41 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
63686368 // Note the body block of the loop is not the place that lval and result_loc are used -
63696369 // it's actually in break statements, handled similarly to return statements.
63706370 // 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);
6372 if (body_result == irb->codegen->invalid_inst_src)
6373 return irb->codegen->invalid_inst_src;
6371 IrInstSrc *body_result = ir_gen_node(ag, body_node, &loop_scope->base);
6372 if (body_result == ag->codegen->invalid_inst_src)
6373 return ag->codegen->invalid_inst_src;
63746374
63756375 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"));
63776377 }
63786378
63796379 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));
6381 ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime));
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(ag, child_scope, node, continue_block, is_comptime));
63826382 }
63836383
6384 ir_set_cursor_at_end_and_append_block(irb, continue_block);
6385 IrInstSrc *new_index_val = ir_build_bin_op(irb, 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;
6387 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
6384 ir_set_cursor_at_end_and_append_block(ag, continue_block);
6385 IrInstSrc *new_index_val = ir_build_bin_op(ag, child_scope, node, IrBinOpAdd, index_val, one, false);
6386 ir_build_store_ptr(ag, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;
6387 ir_build_br(ag, child_scope, node, cond_block, is_comptime);
63886388
63896389 IrInstSrc *else_result = nullptr;
63906390 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);
63926392
63936393 if (peer_parent->peers.length != 0) {
63946394 peer_parent->peers.last()->next_bb = else_block;
63956395 }
63966396 ResultLocPeer *peer_result = create_peer_result(peer_parent);
63976397 peer_parent->peers.append(peer_result);
6398 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);
6399 if (else_result == irb->codegen->invalid_inst_src)
6398 else_result = ir_gen_node_extra(ag, else_node, parent_scope, LValNone, &peer_result->base);
6399 if (else_result == ag->codegen->invalid_inst_src)
64006400 return else_result;
64016401 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));
64036403 }
6404 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6405 ir_set_cursor_at_end_and_append_block(irb, end_block);
6404 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
6405 ir_set_cursor_at_end_and_append_block(ag, end_block);
64066406
64076407 if (else_result) {
64086408 incoming_blocks.append(after_else_block);
......@@ -6415,24 +6415,24 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
64156415 peer_parent->peers.last()->next_bb = end_block;
64166416 }
64176417
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,
64196419 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);
64216421}
64226422
6423static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6423static IrInstSrc *ir_gen_bool_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) {
64246424 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);
64266426}
64276427
6428static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6428static IrInstSrc *ir_gen_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) {
64296429 assert(node->type == NodeTypeEnumLiteral);
64306430 RootStruct *root_struct = node->owner->data.structure.root_struct;
64316431 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);
64336433}
64346434
6435static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6435static IrInstSrc *ir_gen_string_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) {
64366436 Error err;
64376437 assert(node->type == NodeTypeStringLiteral);
64386438
......@@ -6446,7 +6446,7 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode
64466446 size_t byte_offset = root_struct->token_locs[node->main_token].offset;
64476447 size_t bad_index;
64486448 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,
64506450 buf_create_from_str("invalid string literal character"), bad_index);
64516451 }
64526452 src_assert(source[byte_offset] == '"', node);
......@@ -6470,10 +6470,10 @@ static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode
64706470 } else {
64716471 zig_unreachable();
64726472 }
6473 return ir_build_const_str_lit(irb, scope, node, str);
6473 return ir_build_const_str_lit(ag, scope, node, str);
64746474}
64756475
6476static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6476static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *node) {
64776477 assert(node->type == NodeTypeArrayType);
64786478
64796479 AstNode *size_node = node->data.array_type.size;
......@@ -6484,12 +6484,12 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no
64846484 AstNode *sentinel_expr = node->data.array_type.sentinel;
64856485 AstNode *align_expr = node->data.array_type.align_expr;
64866486
6487 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
6487 Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope);
64886488
64896489 IrInstSrc *sentinel;
64906490 if (sentinel_expr != nullptr) {
6491 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);
6492 if (sentinel == irb->codegen->invalid_inst_src)
6491 sentinel = ir_gen_node(ag, sentinel_expr, comptime_scope);
6492 if (sentinel == ag->codegen->invalid_inst_src)
64936493 return sentinel;
64946494 } else {
64956495 sentinel = nullptr;
......@@ -6497,98 +6497,98 @@ static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *no
64976497
64986498 if (size_node) {
64996499 if (is_const) {
6500 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));
6501 return irb->codegen->invalid_inst_src;
6500 add_node_error(ag->codegen, node, buf_create_from_str("const qualifier invalid on array type"));
6501 return ag->codegen->invalid_inst_src;
65026502 }
65036503 if (is_volatile) {
6504 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));
6505 return irb->codegen->invalid_inst_src;
6504 add_node_error(ag->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));
6505 return ag->codegen->invalid_inst_src;
65066506 }
65076507 if (is_allow_zero) {
6508 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));
6509 return irb->codegen->invalid_inst_src;
6508 add_node_error(ag->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));
6509 return ag->codegen->invalid_inst_src;
65106510 }
65116511 if (align_expr != nullptr) {
6512 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));
6513 return irb->codegen->invalid_inst_src;
6512 add_node_error(ag->codegen, node, buf_create_from_str("align qualifier invalid on array type"));
6513 return ag->codegen->invalid_inst_src;
65146514 }
65156515
6516 IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope);
6517 if (size_value == irb->codegen->invalid_inst_src)
6516 IrInstSrc *size_value = ir_gen_node(ag, size_node, comptime_scope);
6517 if (size_value == ag->codegen->invalid_inst_src)
65186518 return size_value;
65196519
6520 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
6521 if (child_type == irb->codegen->invalid_inst_src)
6520 IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope);
6521 if (child_type == ag->codegen->invalid_inst_src)
65226522 return child_type;
65236523
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);
65256525 } else {
65266526 IrInstSrc *align_value;
65276527 if (align_expr != nullptr) {
6528 align_value = ir_gen_node(irb, align_expr, comptime_scope);
6529 if (align_value == irb->codegen->invalid_inst_src)
6528 align_value = ir_gen_node(ag, align_expr, comptime_scope);
6529 if (align_value == ag->codegen->invalid_inst_src)
65306530 return align_value;
65316531 } else {
65326532 align_value = nullptr;
65336533 }
65346534
6535 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
6536 if (child_type == irb->codegen->invalid_inst_src)
6535 IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope);
6536 if (child_type == ag->codegen->invalid_inst_src)
65376537 return child_type;
65386538
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,
65406540 align_value, is_allow_zero);
65416541 }
65426542}
65436543
6544static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6544static IrInstSrc *ir_gen_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *node) {
65456545 assert(node->type == NodeTypeAnyFrameType);
65466546
65476547 AstNode *payload_type_node = node->data.anyframe_type.payload_type;
65486548 IrInstSrc *payload_type_value = nullptr;
65496549
65506550 if (payload_type_node != nullptr) {
6551 payload_type_value = ir_gen_node(irb, payload_type_node, scope);
6552 if (payload_type_value == irb->codegen->invalid_inst_src)
6551 payload_type_value = ir_gen_node(ag, payload_type_node, scope);
6552 if (payload_type_value == ag->codegen->invalid_inst_src)
65536553 return payload_type_value;
65546554
65556555 }
65566556
6557 return ir_build_anyframe_type(irb, scope, node, payload_type_value);
6557 return ir_build_anyframe_type(ag, scope, node, payload_type_value);
65586558}
65596559
6560static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6560static IrInstSrc *ir_gen_undefined_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) {
65616561 assert(node->type == NodeTypeUndefinedLiteral);
6562 return ir_build_const_undefined(irb, scope, node);
6562 return ir_build_const_undefined(ag, scope, node);
65636563}
65646564
6565static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6565static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) {
65666566 assert(node->type == NodeTypeAsmExpr);
65676567 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;
65686568
6569 IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
6570 if (asm_template == irb->codegen->invalid_inst_src)
6571 return irb->codegen->invalid_inst_src;
6569 IrInstSrc *asm_template = ir_gen_node(ag, asm_expr->asm_template, scope);
6570 if (asm_template == ag->codegen->invalid_inst_src)
6571 return ag->codegen->invalid_inst_src;
65726572
65736573 bool is_volatile = asm_expr->volatile_token != 0;
65746574 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);
65756575
65766576 if (!in_fn_scope) {
65776577 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,
65796579 buf_sprintf("volatile is meaningless on global assembly"));
6580 return irb->codegen->invalid_inst_src;
6580 return ag->codegen->invalid_inst_src;
65816581 }
65826582
65836583 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||
65846584 asm_expr->clobber_list.length != 0)
65856585 {
6586 add_node_error(irb->codegen, node,
6586 add_node_error(ag->codegen, node,
65876587 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));
6588 return irb->codegen->invalid_inst_src;
6588 return ag->codegen->invalid_inst_src;
65896589 }
65906590
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,
65926592 nullptr, 0, is_volatile, true);
65936593 }
65946594
......@@ -6597,61 +6597,61 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node
65976597 ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length);
65986598 size_t return_count = 0;
65996599 if (!is_volatile && asm_expr->output_list.length == 0) {
6600 add_node_error(irb->codegen, node,
6600 add_node_error(ag->codegen, node,
66016601 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;
66036603 }
66046604 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
66056605 AsmOutput *asm_output = asm_expr->output_list.at(i);
66066606 if (asm_output->return_type) {
66076607 return_count += 1;
66086608
6609 IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope);
6610 if (return_type == irb->codegen->invalid_inst_src)
6611 return irb->codegen->invalid_inst_src;
6609 IrInstSrc *return_type = ir_gen_node(ag, asm_output->return_type, scope);
6610 if (return_type == ag->codegen->invalid_inst_src)
6611 return ag->codegen->invalid_inst_src;
66126612 if (return_count > 1) {
6613 add_node_error(irb->codegen, node,
6613 add_node_error(ag->codegen, node,
66146614 buf_sprintf("inline assembly allows up to one output value"));
6615 return irb->codegen->invalid_inst_src;
6615 return ag->codegen->invalid_inst_src;
66166616 }
66176617 output_types[i] = return_type;
66186618 } else {
66196619 Buf *variable_name = asm_output->variable_name;
66206620 // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how
66216621 // 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);
66236623 if (var) {
66246624 output_vars[i] = var;
66256625 } else {
6626 add_node_error(irb->codegen, node,
6626 add_node_error(ag->codegen, node,
66276627 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;
66296629 }
66306630 }
66316631
66326632 const char modifier = *buf_ptr(asm_output->constraint);
66336633 if (modifier != '=') {
6634 add_node_error(irb->codegen, node,
6634 add_node_error(ag->codegen, node,
66356635 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."
66366636 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",
66376637 buf_ptr(asm_output->asm_symbolic_name), modifier));
6638 return irb->codegen->invalid_inst_src;
6638 return ag->codegen->invalid_inst_src;
66396639 }
66406640 }
66416641 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
66426642 AsmInput *asm_input = asm_expr->input_list.at(i);
6643 IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope);
6644 if (input_value == irb->codegen->invalid_inst_src)
6645 return irb->codegen->invalid_inst_src;
6643 IrInstSrc *input_value = ir_gen_node(ag, asm_input->expr, scope);
6644 if (input_value == ag->codegen->invalid_inst_src)
6645 return ag->codegen->invalid_inst_src;
66466646
66476647 input_list[i] = input_value;
66486648 }
66496649
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,
66516651 output_vars, return_count, is_volatile, false);
66526652}
66536653
6654static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6654static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
66556655 ResultLoc *result_loc)
66566656{
66576657 assert(node->type == NodeTypeIfOptional);
......@@ -6662,73 +6662,73 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
66626662 AstNode *else_node = node->data.test_expr.else_node;
66636663 bool var_is_ptr = node->data.test_expr.var_is_ptr;
66646664
6665 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, expr_node, scope);
6665 ScopeExpr *spill_scope = create_expr_scope(ag->codegen, expr_node, scope);
66666666 spill_scope->spill_harder = true;
66676667
6668 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, &spill_scope->base, LValPtr, nullptr);
6669 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
6668 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, expr_node, &spill_scope->base, LValPtr, nullptr);
6669 if (maybe_val_ptr == ag->codegen->invalid_inst_src)
66706670 return maybe_val_ptr;
66716671
6672 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
6673 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val);
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(ag, scope, node, maybe_val);
66746674
6675 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
6676 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
6677 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
6675 IrBasicBlockSrc *then_block = ir_create_basic_block(ag, scope, "OptionalThen");
6676 IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "OptionalElse");
6677 IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "OptionalEndIf");
66786678
66796679 IrInstSrc *is_comptime;
6680 if (ir_should_inline(irb->exec, scope)) {
6681 is_comptime = ir_build_const_bool(irb, scope, node, true);
6680 if (ir_should_inline(ag->exec, scope)) {
6681 is_comptime = ir_build_const_bool(ag, scope, node, true);
66826682 } 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);
66846684 }
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,
66866686 then_block, else_block, is_comptime);
66876687
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,
66896689 result_loc, is_comptime);
66906690
6691 ir_set_cursor_at_end_and_append_block(irb, then_block);
6691 ir_set_cursor_at_end_and_append_block(ag, then_block);
66926692
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);
66946694 Scope *var_scope;
66956695 if (var_symbol) {
66966696 bool is_shadowable = false;
66976697 bool is_const = true;
6698 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
6698 ZigVar *var = ir_create_var(ag, node, subexpr_scope,
66996699 var_symbol, is_const, is_const, is_shadowable, is_comptime);
67006700
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);
67026702 IrInstSrc *var_value = var_is_ptr ?
6703 payload_ptr : ir_build_load_ptr(irb, &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);
6703 payload_ptr : ir_build_load_ptr(ag, &spill_scope->base, node, payload_ptr);
6704 build_decl_var_and_init(ag, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), is_comptime);
67056705 var_scope = var->child_scope;
67066706 } else {
67076707 var_scope = subexpr_scope;
67086708 }
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,
67106710 &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)
67126712 return then_expr_result;
6713 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
6713 IrBasicBlockSrc *after_then_block = ag->current_basic_block;
67146714 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));
67166716
6717 ir_set_cursor_at_end_and_append_block(irb, else_block);
6717 ir_set_cursor_at_end_and_append_block(ag, else_block);
67186718 IrInstSrc *else_expr_result;
67196719 if (else_node) {
6720 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
6721 if (else_expr_result == irb->codegen->invalid_inst_src)
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 == ag->codegen->invalid_inst_src)
67226722 return else_expr_result;
67236723 } else {
6724 else_expr_result = ir_build_const_void(irb, scope, node);
6725 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
6724 else_expr_result = ir_build_const_void(ag, scope, node);
6725 ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
67266726 }
6727 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6727 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
67286728 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));
67306730
6731 ir_set_cursor_at_end_and_append_block(irb, endif_block);
6731 ir_set_cursor_at_end_and_append_block(ag, endif_block);
67326732 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
67336733 incoming_values[0] = then_expr_result;
67346734 incoming_values[1] = else_expr_result;
......@@ -6736,11 +6736,11 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
67366736 incoming_blocks[0] = after_then_block;
67376737 incoming_blocks[1] = after_else_block;
67386738
6739 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
6740 return ir_expr_wrap(irb, scope, phi, result_loc);
6739 IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
6740 return ir_expr_wrap(ag, scope, phi, result_loc);
67416741}
67426742
6743static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6743static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
67446744 ResultLoc *result_loc)
67456745{
67466746 assert(node->type == NodeTypeIfErrorExpr);
......@@ -6753,51 +6753,51 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
67536753 Buf *var_symbol = node->data.if_err_expr.var_symbol;
67546754 Buf *err_symbol = node->data.if_err_expr.err_symbol;
67556755
6756 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
6757 if (err_val_ptr == irb->codegen->invalid_inst_src)
6756 IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr);
6757 if (err_val_ptr == ag->codegen->invalid_inst_src)
67586758 return err_val_ptr;
67596759
6760 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
6761 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
6760 IrInstSrc *err_val = ir_build_load_ptr(ag, scope, node, err_val_ptr);
6761 IrInstSrc *is_err = ir_build_test_err_src(ag, scope, node, err_val_ptr, true, false);
67626762
6763 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk");
6764 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse");
6765 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
6763 IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, scope, "TryOk");
6764 IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "TryElse");
6765 IrBasicBlockSrc *endif_block = ir_create_basic_block(ag, scope, "TryEnd");
67666766
6767 bool force_comptime = ir_should_inline(irb->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);
6769 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
6767 bool force_comptime = ir_should_inline(ag->exec, scope);
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(ag, scope, node, is_err, else_block, ok_block, is_comptime);
67706770
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,
67726772 result_loc, is_comptime);
67736773
6774 ir_set_cursor_at_end_and_append_block(irb, ok_block);
6774 ir_set_cursor_at_end_and_append_block(ag, ok_block);
67756775
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);
67776777 Scope *var_scope;
67786778 if (var_symbol) {
67796779 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);
6781 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
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(ag, node, subexpr_scope,
67826782 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
67836783
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);
67856785 IrInstSrc *var_value = var_is_ptr ?
6786 payload_ptr : ir_build_load_ptr(irb, 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);
6786 payload_ptr : ir_build_load_ptr(ag, subexpr_scope, node, payload_ptr);
6787 build_decl_var_and_init(ag, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), var_is_comptime);
67886788 var_scope = var->child_scope;
67896789 } else {
67906790 var_scope = subexpr_scope;
67916791 }
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,
67936793 &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)
67956795 return then_expr_result;
6796 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
6796 IrBasicBlockSrc *after_then_block = ag->current_basic_block;
67976797 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));
67996799
6800 ir_set_cursor_at_end_and_append_block(irb, else_block);
6800 ir_set_cursor_at_end_and_append_block(ag, else_block);
68016801
68026802 IrInstSrc *else_expr_result;
68036803 if (else_node) {
......@@ -6805,28 +6805,28 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
68056805 if (err_symbol) {
68066806 bool is_shadowable = false;
68076807 bool is_const = true;
6808 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
6808 ZigVar *var = ir_create_var(ag, node, subexpr_scope,
68096809 err_symbol, is_const, is_const, is_shadowable, is_comptime);
68106810
6811 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr);
6812 IrInstSrc *err_value = ir_build_load_ptr(irb, subexpr_scope, node, err_ptr);
6813 build_decl_var_and_init(irb, subexpr_scope, node, var, err_value, buf_ptr(err_symbol), is_comptime);
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(ag, subexpr_scope, node, err_ptr);
6813 build_decl_var_and_init(ag, subexpr_scope, node, var, err_value, buf_ptr(err_symbol), is_comptime);
68146814 err_var_scope = var->child_scope;
68156815 } else {
68166816 err_var_scope = subexpr_scope;
68176817 }
6818 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);
6819 if (else_expr_result == irb->codegen->invalid_inst_src)
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 == ag->codegen->invalid_inst_src)
68206820 return else_expr_result;
68216821 } else {
6822 else_expr_result = ir_build_const_void(irb, scope, node);
6823 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
6822 else_expr_result = ir_build_const_void(ag, scope, node);
6823 ir_build_end_expr(ag, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
68246824 }
6825 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6825 IrBasicBlockSrc *after_else_block = ag->current_basic_block;
68266826 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));
68286828
6829 ir_set_cursor_at_end_and_append_block(irb, endif_block);
6829 ir_set_cursor_at_end_and_append_block(ag, endif_block);
68306830 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
68316831 incoming_values[0] = then_expr_result;
68326832 incoming_values[1] = else_expr_result;
......@@ -6834,11 +6834,11 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
68346834 incoming_blocks[0] = after_then_block;
68356835 incoming_blocks[1] = after_else_block;
68366836
6837 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
6838 return ir_expr_wrap(irb, scope, phi, result_loc);
6837 IrInstSrc *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
6838 return ir_expr_wrap(ag, scope, phi, result_loc);
68396839}
68406840
6841static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
6841static bool ir_gen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *switch_node, AstNode *prong_node,
68426842 IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime,
68436843 IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len,
68446844 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
68576857
68586858 bool is_shadowable = false;
68596859 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,
68616861 var_name, is_const, is_const, is_shadowable, var_is_comptime);
68626862 child_scope = var->child_scope;
68636863 IrInstSrc *var_value;
68646864 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,
68666866 target_value_ptr);
68676867 *out_switch_else_var = switch_else_var;
68686868 IrInstSrc *payload_ptr = &switch_else_var->base;
68696869 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);
68716871 } 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,
68736873 prong_values, prong_values_len);
68746874 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);
68766876 } else {
68776877 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);
68796879 }
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);
68816881 } else {
68826882 child_scope = scope;
68836883 }
68846884
6885 IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
6886 if (expr_result == irb->codegen->invalid_inst_src)
6885 IrInstSrc *expr_result = ir_gen_node_extra(ag, expr_node, child_scope, lval, result_loc);
6886 if (expr_result == ag->codegen->invalid_inst_src)
68876887 return false;
68886888 if (!instr_is_unreachable(expr_result))
6889 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));
6890 incoming_blocks->append(irb->current_basic_block);
6889 ir_mark_gen(ir_build_br(ag, scope, switch_node, end_block, is_comptime));
6890 incoming_blocks->append(ag->current_basic_block);
68916891 incoming_values->append(expr_result);
68926892 return true;
68936893}
68946894
6895static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6895static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
68966896 ResultLoc *result_loc)
68976897{
68986898 assert(node->type == NodeTypeSwitchExpr);
68996899
69006900 AstNode *target_node = node->data.switch_expr.expr;
6901 IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
6902 if (target_value_ptr == irb->codegen->invalid_inst_src)
6901 IrInstSrc *target_value_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr);
6902 if (target_value_ptr == ag->codegen->invalid_inst_src)
69036903 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);
69056905
6906 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
6907 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
6906 IrBasicBlockSrc *else_block = ir_create_basic_block(ag, scope, "SwitchElse");
6907 IrBasicBlockSrc *end_block = ir_create_basic_block(ag, scope, "SwitchEnd");
69086908
69096909 size_t prong_count = node->data.switch_expr.prongs.length;
69106910 ZigList<IrInstSrcSwitchBrCase> cases = {0};
69116911
69126912 IrInstSrc *is_comptime;
69136913 IrInstSrc *var_is_comptime;
6914 if (ir_should_inline(irb->exec, scope)) {
6915 is_comptime = ir_build_const_bool(irb, scope, node, true);
6914 if (ir_should_inline(ag->exec, scope)) {
6915 is_comptime = ir_build_const_bool(ag, scope, node, true);
69166916 var_is_comptime = is_comptime;
69176917 } else {
6918 is_comptime = ir_build_test_comptime(irb, scope, node, target_value);
6919 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);
6918 is_comptime = ir_build_test_comptime(ag, scope, node, target_value);
6919 var_is_comptime = ir_build_test_comptime(ag, scope, node, target_value_ptr);
69206920 }
69216921
69226922 ZigList<IrInstSrc *> incoming_values = {0};
......@@ -6932,11 +6932,11 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
69326932 peer_parent->is_comptime = is_comptime;
69336933 peer_parent->parent = result_loc;
69346934
6935 ir_build_reset_result(irb, scope, node, &peer_parent->base);
6935 ir_build_reset_result(ag, scope, node, &peer_parent->base);
69366936
69376937 // First do the else and the ranges
6938 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6939 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
6938 Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime);
6939 Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope);
69406940 AstNode *else_prong = nullptr;
69416941 AstNode *underscore_prong = nullptr;
69426942 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
69546954 AstNode *start_node = item_node->data.switch_range.start;
69556955 AstNode *end_node = item_node->data.switch_range.end;
69566956
6957 IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope);
6958 if (start_value == irb->codegen->invalid_inst_src)
6959 return irb->codegen->invalid_inst_src;
6957 IrInstSrc *start_value = ir_gen_node(ag, start_node, comptime_scope);
6958 if (start_value == ag->codegen->invalid_inst_src)
6959 return ag->codegen->invalid_inst_src;
69606960
6961 IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope);
6962 if (end_value == irb->codegen->invalid_inst_src)
6963 return irb->codegen->invalid_inst_src;
6961 IrInstSrc *end_value = ir_gen_node(ag, end_node, comptime_scope);
6962 if (end_value == ag->codegen->invalid_inst_src)
6963 return ag->codegen->invalid_inst_src;
69646964
69656965 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
69666966 check_range->start = start_value;
69676967 check_range->end = end_value;
69686968
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,
69706970 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,
69726972 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,
69746974 lower_range_ok, upper_range_ok, false);
69756975 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);
69776977 } else {
69786978 ok_bit = both_ok;
69796979 }
69806980 } else {
6981 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
6982 if (item_value == irb->codegen->invalid_inst_src)
6983 return irb->codegen->invalid_inst_src;
6981 IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope);
6982 if (item_value == ag->codegen->invalid_inst_src)
6983 return ag->codegen->invalid_inst_src;
69846984
69856985 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
69866986 check_range->start = item_value;
69876987 check_range->end = item_value;
69886988
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,
69906990 item_value, target_value, false);
69916991 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);
69936993 } else {
69946994 ok_bit = cmp_ok;
69956995 }
69966996 }
69976997 }
69986998
6999 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
7000 IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
6999 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(ag, scope, "SwitchRangeYes");
7000 IrBasicBlockSrc *range_block_no = ir_create_basic_block(ag, scope, "SwitchRangeNo");
70017001
70027002 assert(ok_bit);
70037003 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,
70057005 range_block_yes, range_block_no, is_comptime));
70067006 if (peer_parent->base.source_instruction == nullptr) {
70077007 peer_parent->base.source_instruction = br_inst;
......@@ -7011,65 +7011,65 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
70117011 peer_parent->peers.last()->next_bb = range_block_yes;
70127012 }
70137013 peer_parent->peers.append(this_peer_result_loc);
7014 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);
7015 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7014 ir_set_cursor_at_end_and_append_block(ag, range_block_yes);
7015 if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block,
70167016 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
70177017 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
70187018 {
7019 return irb->codegen->invalid_inst_src;
7019 return ag->codegen->invalid_inst_src;
70207020 }
70217021
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);
70237023 } else {
70247024 if (prong_item_count == 0) {
70257025 if (else_prong) {
7026 ErrorMsg *msg = add_node_error(irb->codegen, prong_node,
7026 ErrorMsg *msg = add_node_error(ag->codegen, prong_node,
70277027 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,
70297029 buf_sprintf("previous else prong is here"));
7030 return irb->codegen->invalid_inst_src;
7030 return ag->codegen->invalid_inst_src;
70317031 }
70327032 else_prong = prong_node;
70337033 } else if (prong_item_count == 1 &&
70347034 prong_node->data.switch_prong.items.at(0)->type == NodeTypeIdentifier &&
70357035 buf_eql_str(node_identifier_buf(prong_node->data.switch_prong.items.at(0)), "_")) {
70367036 if (underscore_prong) {
7037 ErrorMsg *msg = add_node_error(irb->codegen, prong_node,
7037 ErrorMsg *msg = add_node_error(ag->codegen, prong_node,
70387038 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,
70407040 buf_sprintf("previous '_' prong is here"));
7041 return irb->codegen->invalid_inst_src;
7041 return ag->codegen->invalid_inst_src;
70427042 }
70437043 underscore_prong = prong_node;
70447044 } else {
70457045 continue;
70467046 }
70477047 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,
70497049 buf_sprintf("else and '_' prong in switch expression"));
70507050 if (underscore_prong == prong_node)
7051 add_error_note(irb->codegen, msg, else_prong,
7051 add_error_note(ag->codegen, msg, else_prong,
70527052 buf_sprintf("else prong is here"));
70537053 else
7054 add_error_note(irb->codegen, msg, underscore_prong,
7054 add_error_note(ag->codegen, msg, underscore_prong,
70557055 buf_sprintf("'_' prong is here"));
7056 return irb->codegen->invalid_inst_src;
7056 return ag->codegen->invalid_inst_src;
70577057 }
70587058 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
70597059
7060 IrBasicBlockSrc *prev_block = irb->current_basic_block;
7060 IrBasicBlockSrc *prev_block = ag->current_basic_block;
70617061 if (peer_parent->peers.length > 0) {
70627062 peer_parent->peers.last()->next_bb = else_block;
70637063 }
70647064 peer_parent->peers.append(this_peer_result_loc);
7065 ir_set_cursor_at_end_and_append_block(irb, else_block);
7066 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7065 ir_set_cursor_at_end_and_append_block(ag, else_block);
7066 if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block,
70677067 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
70687068 &switch_else_var, LValNone, &this_peer_result_loc->base))
70697069 {
7070 return irb->codegen->invalid_inst_src;
7070 return ag->codegen->invalid_inst_src;
70717071 }
7072 ir_set_cursor_at_end(irb, prev_block);
7072 ir_set_cursor_at_end(ag, prev_block);
70737073 }
70747074 }
70757075
......@@ -7086,16 +7086,16 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
70867086
70877087 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
70887088
7089 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
7089 IrBasicBlockSrc *prong_block = ir_create_basic_block(ag, scope, "SwitchProng");
70907090 IrInstSrc **items = heap::c_allocator.allocate<IrInstSrc *>(prong_item_count);
70917091
70927092 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
70937093 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
70947094 assert(item_node->type != NodeTypeSwitchRange);
70957095
7096 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
7097 if (item_value == irb->codegen->invalid_inst_src)
7098 return irb->codegen->invalid_inst_src;
7096 IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope);
7097 if (item_value == ag->codegen->invalid_inst_src)
7098 return ag->codegen->invalid_inst_src;
70997099
71007100 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
71017101 check_range->start = item_value;
......@@ -7108,31 +7108,31 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
71087108 items[item_i] = item_value;
71097109 }
71107110
7111 IrBasicBlockSrc *prev_block = irb->current_basic_block;
7111 IrBasicBlockSrc *prev_block = ag->current_basic_block;
71127112 if (peer_parent->peers.length > 0) {
71137113 peer_parent->peers.last()->next_bb = prong_block;
71147114 }
71157115 peer_parent->peers.append(this_peer_result_loc);
7116 ir_set_cursor_at_end_and_append_block(irb, prong_block);
7117 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
7116 ir_set_cursor_at_end_and_append_block(ag, prong_block);
7117 if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block,
71187118 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
71197119 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
71207120 {
7121 return irb->codegen->invalid_inst_src;
7121 return ag->codegen->invalid_inst_src;
71227122 }
71237123
7124 ir_set_cursor_at_end(irb, prev_block);
7124 ir_set_cursor_at_end(ag, prev_block);
71257125
71267126 }
71277127
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,
71297129 check_ranges.items, check_ranges.length, else_prong, underscore_prong != nullptr);
71307130
71317131 IrInstSrc *br_instruction;
71327132 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);
71347134 } 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,
71367136 cases.length, cases.items, is_comptime, switch_prongs_void);
71377137 if (switch_else_var != nullptr) {
71387138 switch_else_var->switch_br = switch_br;
......@@ -7150,46 +7150,46 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
71507150 if (peer_parent->peers.length != 0) {
71517151 peer_parent->peers.last()->next_bb = else_block;
71527152 }
7153 ir_set_cursor_at_end_and_append_block(irb, else_block);
7154 ir_build_unreachable(irb, scope, node);
7153 ir_set_cursor_at_end_and_append_block(ag, else_block);
7154 ir_build_unreachable(ag, scope, node);
71557155 } else {
71567156 if (peer_parent->peers.length != 0) {
71577157 peer_parent->peers.last()->next_bb = end_block;
71587158 }
71597159 }
71607160
7161 ir_set_cursor_at_end_and_append_block(irb, end_block);
7161 ir_set_cursor_at_end_and_append_block(ag, end_block);
71627162 assert(incoming_blocks.length == incoming_values.length);
71637163 IrInstSrc *result_instruction;
71647164 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);
71667166 } 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,
71687168 incoming_blocks.items, incoming_values.items, peer_parent);
71697169 }
7170 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
7170 return ir_lval_wrap(ag, scope, result_instruction, lval, result_loc);
71717171}
71727172
7173static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) {
7173static IrInstSrc *ir_gen_comptime(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) {
71747174 assert(node->type == NodeTypeCompTime);
71757175
7176 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);
7176 Scope *child_scope = create_comptime_scope(ag->codegen, node, parent_scope);
71777177 // 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);
71797179}
71807180
7181static IrInstSrc *ir_gen_nosuspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) {
7181static IrInstSrc *ir_gen_nosuspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) {
71827182 assert(node->type == NodeTypeNoSuspend);
71837183
7184 Scope *child_scope = create_nosuspend_scope(irb->codegen, node, parent_scope);
7184 Scope *child_scope = create_nosuspend_scope(ag->codegen, node, parent_scope);
71857185 // 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);
71877187}
71887188
7189static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
7189static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
71907190 IrInstSrc *is_comptime;
7191 if (ir_should_inline(irb->exec, break_scope)) {
7192 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
7191 if (ir_should_inline(ag->exec, break_scope)) {
7192 is_comptime = ir_build_const_bool(ag, break_scope, node, true);
71937193 } else {
71947194 is_comptime = block_scope->is_comptime;
71957195 }
......@@ -7199,24 +7199,24 @@ static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope
71997199 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);
72007200 block_scope->peer_parent->peers.append(peer_result);
72017201
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,
72037203 &peer_result->base);
7204 if (result_value == irb->codegen->invalid_inst_src)
7205 return irb->codegen->invalid_inst_src;
7204 if (result_value == ag->codegen->invalid_inst_src)
7205 return ag->codegen->invalid_inst_src;
72067206 } else {
7207 result_value = ir_build_const_void(irb, break_scope, node);
7207 result_value = ir_build_const_void(ag, break_scope, node);
72087208 }
72097209
72107210 IrBasicBlockSrc *dest_block = block_scope->end_block;
7211 if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr))
7212 return irb->codegen->invalid_inst_src;
7211 if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr))
7212 return ag->codegen->invalid_inst_src;
72137213
7214 block_scope->incoming_blocks->append(irb->current_basic_block);
7214 block_scope->incoming_blocks->append(ag->current_basic_block);
72157215 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);
72177217}
72187218
7219static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) {
7219static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *node) {
72207220 assert(node->type == NodeTypeBreak);
72217221
72227222 // 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
72307230 for (;;) {
72317231 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
72327232 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)));
7234 return irb->codegen->invalid_inst_src;
7233 add_node_error(ag->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
7234 return ag->codegen->invalid_inst_src;
72357235 } else {
7236 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));
7237 return irb->codegen->invalid_inst_src;
7236 add_node_error(ag->codegen, node, buf_sprintf("break expression outside loop"));
7237 return ag->codegen->invalid_inst_src;
72387238 }
72397239 } else if (search_scope->id == ScopeIdDeferExpr) {
7240 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));
7241 return irb->codegen->invalid_inst_src;
7240 add_node_error(ag->codegen, node, buf_sprintf("cannot break out of defer expression"));
7241 return ag->codegen->invalid_inst_src;
72427242 } else if (search_scope->id == ScopeIdLoop) {
72437243 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
72447244 if (node->data.break_expr.name == nullptr ||
......@@ -7255,18 +7255,18 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n
72557255 {
72567256 assert(this_block_scope->end_block != nullptr);
72577257 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);
72597259 }
72607260 } else if (search_scope->id == ScopeIdSuspend) {
7261 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));
7262 return irb->codegen->invalid_inst_src;
7261 add_node_error(ag->codegen, node, buf_sprintf("cannot break out of suspend block"));
7262 return ag->codegen->invalid_inst_src;
72637263 }
72647264 search_scope = search_scope->parent;
72657265 }
72667266
72677267 IrInstSrc *is_comptime;
7268 if (ir_should_inline(irb->exec, break_scope)) {
7269 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
7268 if (ir_should_inline(ag->exec, break_scope)) {
7269 is_comptime = ir_build_const_bool(ag, break_scope, node, true);
72707270 } else {
72717271 is_comptime = loop_scope->is_comptime;
72727272 }
......@@ -7276,24 +7276,24 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n
72767276 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);
72777277 loop_scope->peer_parent->peers.append(peer_result);
72787278
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,
72807280 loop_scope->lval, &peer_result->base);
7281 if (result_value == irb->codegen->invalid_inst_src)
7282 return irb->codegen->invalid_inst_src;
7281 if (result_value == ag->codegen->invalid_inst_src)
7282 return ag->codegen->invalid_inst_src;
72837283 } else {
7284 result_value = ir_build_const_void(irb, break_scope, node);
7284 result_value = ir_build_const_void(ag, break_scope, node);
72857285 }
72867286
72877287 IrBasicBlockSrc *dest_block = loop_scope->break_block;
7288 if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr))
7289 return irb->codegen->invalid_inst_src;
7288 if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr))
7289 return ag->codegen->invalid_inst_src;
72907290
7291 loop_scope->incoming_blocks->append(irb->current_basic_block);
7291 loop_scope->incoming_blocks->append(ag->current_basic_block);
72927292 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);
72947294}
72957295
7296static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) {
7296static IrInstSrc *ir_gen_continue(Stage1AstGen *ag, Scope *continue_scope, AstNode *node) {
72977297 assert(node->type == NodeTypeContinue);
72987298
72997299 // 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
73087308 for (;;) {
73097309 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
73107310 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)));
7312 return irb->codegen->invalid_inst_src;
7311 add_node_error(ag->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
7312 return ag->codegen->invalid_inst_src;
73137313 } else {
7314 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));
7315 return irb->codegen->invalid_inst_src;
7314 add_node_error(ag->codegen, node, buf_sprintf("continue expression outside loop"));
7315 return ag->codegen->invalid_inst_src;
73167316 }
73177317 } else if (search_scope->id == ScopeIdDeferExpr) {
7318 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));
7319 return irb->codegen->invalid_inst_src;
7318 add_node_error(ag->codegen, node, buf_sprintf("cannot continue out of defer expression"));
7319 return ag->codegen->invalid_inst_src;
73207320 } else if (search_scope->id == ScopeIdLoop) {
73217321 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
73227322 if (node->data.continue_expr.name == nullptr ||
......@@ -7334,42 +7334,42 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN
73347334 }
73357335
73367336 IrInstSrc *is_comptime;
7337 if (ir_should_inline(irb->exec, continue_scope)) {
7338 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);
7337 if (ir_should_inline(ag->exec, continue_scope)) {
7338 is_comptime = ir_build_const_bool(ag, continue_scope, node, true);
73397339 } else {
73407340 is_comptime = loop_scope->is_comptime;
73417341 }
73427342
73437343 for (size_t i = 0; i < runtime_scopes.length; i += 1) {
73447344 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));
73467346 }
73477347 runtime_scopes.deinit();
73487348
73497349 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
7350 if (!ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, nullptr, nullptr))
7351 return irb->codegen->invalid_inst_src;
7352 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
7350 if (!ir_gen_defers_for_block(ag, continue_scope, dest_block->scope, nullptr, nullptr))
7351 return ag->codegen->invalid_inst_src;
7352 return ir_mark_gen(ir_build_br(ag, continue_scope, node, dest_block, is_comptime));
73537353}
73547354
7355static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7355static IrInstSrc *ir_gen_error_type(Stage1AstGen *ag, Scope *scope, AstNode *node) {
73567356 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);
73587358}
73597359
7360static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
7360static IrInstSrc *ir_gen_defer(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
73617361 assert(node->type == NodeTypeDefer);
73627362
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);
73647364 node->data.defer.child_scope = &defer_child_scope->base;
73657365
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);
73677367 node->data.defer.expr_scope = &defer_expr_scope->base;
73687368
7369 return ir_build_const_void(irb, parent_scope, node);
7369 return ir_build_const_void(ag, parent_scope, node);
73707370}
73717371
7372static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
7372static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
73737373 assert(node->type == NodeTypeSliceExpr);
73747374
73757375 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;
......@@ -7378,38 +7378,38 @@ static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, L
73787378 AstNode *end_node = slice_expr->end;
73797379 AstNode *sentinel_node = slice_expr->sentinel;
73807380
7381 IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
7382 if (ptr_value == irb->codegen->invalid_inst_src)
7383 return irb->codegen->invalid_inst_src;
7381 IrInstSrc *ptr_value = ir_gen_node_extra(ag, array_node, scope, LValPtr, nullptr);
7382 if (ptr_value == ag->codegen->invalid_inst_src)
7383 return ag->codegen->invalid_inst_src;
73847384
7385 IrInstSrc *start_value = ir_gen_node(irb, start_node, scope);
7386 if (start_value == irb->codegen->invalid_inst_src)
7387 return irb->codegen->invalid_inst_src;
7385 IrInstSrc *start_value = ir_gen_node(ag, start_node, scope);
7386 if (start_value == ag->codegen->invalid_inst_src)
7387 return ag->codegen->invalid_inst_src;
73887388
73897389 IrInstSrc *end_value;
73907390 if (end_node) {
7391 end_value = ir_gen_node(irb, end_node, scope);
7392 if (end_value == irb->codegen->invalid_inst_src)
7393 return irb->codegen->invalid_inst_src;
7391 end_value = ir_gen_node(ag, end_node, scope);
7392 if (end_value == ag->codegen->invalid_inst_src)
7393 return ag->codegen->invalid_inst_src;
73947394 } else {
73957395 end_value = nullptr;
73967396 }
73977397
73987398 IrInstSrc *sentinel_value;
73997399 if (sentinel_node) {
7400 sentinel_value = ir_gen_node(irb, sentinel_node, scope);
7401 if (sentinel_value == irb->codegen->invalid_inst_src)
7402 return irb->codegen->invalid_inst_src;
7400 sentinel_value = ir_gen_node(ag, sentinel_node, scope);
7401 if (sentinel_value == ag->codegen->invalid_inst_src)
7402 return ag->codegen->invalid_inst_src;
74037403 } else {
74047404 sentinel_value = nullptr;
74057405 }
74067406
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,
74087408 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);
74107410}
74117411
7412static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
7412static IrInstSrc *ir_gen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval,
74137413 ResultLoc *result_loc)
74147414{
74157415 assert(node->type == NodeTypeCatchExpr);
......@@ -7422,77 +7422,77 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
74227422 if (var_node != nullptr) {
74237423 assert(var_node->type == NodeTypeIdentifier);
74247424 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)));
7426 return irb->codegen->invalid_inst_src;
7425 add_node_error(ag->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
7426 return ag->codegen->invalid_inst_src;
74277427 }
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);
74297429 }
74307430
74317431
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);
74337433 spill_scope->spill_harder = true;
74347434
7435 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, &spill_scope->base, LValPtr, nullptr);
7436 if (err_union_ptr == irb->codegen->invalid_inst_src)
7437 return irb->codegen->invalid_inst_src;
7435 IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, op1_node, &spill_scope->base, LValPtr, nullptr);
7436 if (err_union_ptr == ag->codegen->invalid_inst_src)
7437 return ag->codegen->invalid_inst_src;
74387438
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);
74407440
74417441 IrInstSrc *is_comptime;
7442 if (ir_should_inline(irb->exec, parent_scope)) {
7443 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
7442 if (ir_should_inline(ag->exec, parent_scope)) {
7443 is_comptime = ir_build_const_bool(ag, parent_scope, node, true);
74447444 } 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);
74467446 }
74477447
7448 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
7449 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
7450 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
7451 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
7448 IrBasicBlockSrc *ok_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrOk");
7449 IrBasicBlockSrc *err_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrError");
7450 IrBasicBlockSrc *end_block = ir_create_basic_block(ag, parent_scope, "UnwrapErrEnd");
7451 IrInstSrc *cond_br_inst = ir_build_cond_br(ag, parent_scope, node, is_err, err_block, ok_block, is_comptime);
74527452
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,
74547454 is_comptime);
74557455
7456 ir_set_cursor_at_end_and_append_block(irb, err_block);
7457 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, &spill_scope->base, is_comptime);
7456 ir_set_cursor_at_end_and_append_block(ag, err_block);
7457 Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, &spill_scope->base, is_comptime);
74587458 Scope *err_scope;
74597459 if (var_node) {
74607460 assert(var_node->type == NodeTypeIdentifier);
74617461 Buf *var_name = node_identifier_buf(var_node);
74627462 bool is_const = true;
74637463 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,
74657465 is_const, is_const, is_shadowable, is_comptime);
74667466 err_scope = var->child_scope;
7467 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr);
7468 IrInstSrc *err_value = ir_build_load_ptr(irb, 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);
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(ag, err_scope, var_node, err_ptr);
7469 build_decl_var_and_init(ag, err_scope, var_node, var, err_value, buf_ptr(var_name), is_comptime);
74707470 } else {
74717471 err_scope = subexpr_scope;
74727472 }
7473 IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
7474 if (err_result == irb->codegen->invalid_inst_src)
7475 return irb->codegen->invalid_inst_src;
7476 IrBasicBlockSrc *after_err_block = irb->current_basic_block;
7473 IrInstSrc *err_result = ir_gen_node_extra(ag, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
7474 if (err_result == ag->codegen->invalid_inst_src)
7475 return ag->codegen->invalid_inst_src;
7476 IrBasicBlockSrc *after_err_block = ag->current_basic_block;
74777477 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));
74797479
7480 ir_set_cursor_at_end_and_append_block(irb, ok_block);
7481 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false);
7482 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
7483 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
7484 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
7485 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
7480 ir_set_cursor_at_end_and_append_block(ag, ok_block);
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(ag, parent_scope, node, unwrapped_ptr);
7483 ir_build_end_expr(ag, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
7484 IrBasicBlockSrc *after_ok_block = ag->current_basic_block;
7485 ir_build_br(ag, parent_scope, node, end_block, is_comptime);
74867486
7487 ir_set_cursor_at_end_and_append_block(irb, end_block);
7487 ir_set_cursor_at_end_and_append_block(ag, end_block);
74887488 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
74897489 incoming_values[0] = err_result;
74907490 incoming_values[1] = unwrapped_payload;
74917491 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
74927492 incoming_blocks[0] = after_err_block;
74937493 incoming_blocks[1] = after_ok_block;
7494 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7495 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
7494 IrInstSrc *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7495 return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc);
74967496}
74977497
74987498static 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
75407540 }
75417541}
75427542
7543static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
7543static IrInstSrc *ir_gen_container_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
75447544 assert(node->type == NodeTypeContainerDecl);
75457545
75467546 ContainerKind kind = node->data.container_decl.kind;
75477547 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);
75497549
75507550 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,
75527552 kind, node, buf_ptr(name), bare_name, layout);
75537553 ScopeDecls *child_scope = get_container_scope(container_type);
75547554
75557555 for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) {
75567556 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);
75587558 }
75597559
75607560 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
75617561 init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);
75627562 tld_container->type_entry = container_type;
75637563 tld_container->decls_scope = child_scope;
7564 irb->codegen->resolve_queue.append(&tld_container->base);
7564 ag->codegen->resolve_queue.append(&tld_container->base);
75657565
75667566 // 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);
75687568
7569 return ir_build_const_type(irb, parent_scope, node, container_type);
7569 return ir_build_const_type(ag, parent_scope, node, container_type);
75707570}
75717571
7572static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
7572static IrInstSrc *ir_gen_err_set_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
75737573 assert(node->type == NodeTypeErrorSetDecl);
75747574
75757575 uint32_t err_count = node->data.err_set_decl.decls.length;
75767576
75777577 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);
75797579 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
75807580 buf_init_from_buf(&err_set_type->name, type_name);
75817581 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;
7583 err_set_type->abi_align = irb->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;
7582 err_set_type->size_in_bits = ag->codegen->builtin_types.entry_global_error_set->size_in_bits;
7583 err_set_type->abi_align = ag->codegen->builtin_types.entry_global_error_set->abi_align;
7584 err_set_type->abi_size = ag->codegen->builtin_types.entry_global_error_set->abi_size;
75857585 err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(err_count);
75867586
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;
75887588 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
75897589
75907590 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
75957595 err->decl_node = field_node;
75967596 buf_init_from_buf(&err->name, err_name);
75977597
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);
75997599 if (existing_entry) {
76007600 err->value = existing_entry->value->value;
76017601 } else {
7602 size_t error_value_count = irb->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));
7602 size_t error_value_count = ag->codegen->errors_by_index.length;
7603 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ag->codegen->err_tag_type->data.integral.bit_count));
76047604 err->value = error_value_count;
7605 irb->codegen->errors_by_index.append(err);
7605 ag->codegen->errors_by_index.append(err);
76067606 }
76077607 err_set_type->data.error_set.errors[i] = err;
76087608
76097609 ErrorTableEntry *prev_err = errors[err->value];
76107610 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),
76127612 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),
76147614 buf_sprintf("other error here"));
7615 return irb->codegen->invalid_inst_src;
7615 return ag->codegen->invalid_inst_src;
76167616 }
76177617 errors[err->value] = err;
76187618 }
76197619 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);
76217621}
76227622
7623static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
7623static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
76247624 assert(node->type == NodeTypeFnProto);
76257625
76267626 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
76357635 }
76367636 if (param_node->data.param_decl.anytype_token == 0) {
76377637 AstNode *type_node = param_node->data.param_decl.type;
7638 IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope);
7639 if (type_value == irb->codegen->invalid_inst_src)
7640 return irb->codegen->invalid_inst_src;
7638 IrInstSrc *type_value = ir_gen_node(ag, type_node, parent_scope);
7639 if (type_value == ag->codegen->invalid_inst_src)
7640 return ag->codegen->invalid_inst_src;
76417641 param_types[i] = type_value;
76427642 } else {
76437643 param_types[i] = nullptr;
......@@ -7646,41 +7646,41 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod
76467646
76477647 IrInstSrc *align_value = nullptr;
76487648 if (node->data.fn_proto.align_expr != nullptr) {
7649 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);
7650 if (align_value == irb->codegen->invalid_inst_src)
7651 return irb->codegen->invalid_inst_src;
7649 align_value = ir_gen_node(ag, node->data.fn_proto.align_expr, parent_scope);
7650 if (align_value == ag->codegen->invalid_inst_src)
7651 return ag->codegen->invalid_inst_src;
76527652 }
76537653
76547654 IrInstSrc *callconv_value = nullptr;
76557655 if (node->data.fn_proto.callconv_expr != nullptr) {
7656 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
7657 if (callconv_value == irb->codegen->invalid_inst_src)
7658 return irb->codegen->invalid_inst_src;
7656 callconv_value = ir_gen_node(ag, node->data.fn_proto.callconv_expr, parent_scope);
7657 if (callconv_value == ag->codegen->invalid_inst_src)
7658 return ag->codegen->invalid_inst_src;
76597659 }
76607660
76617661 IrInstSrc *return_type;
76627662 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);
76647664 } else {
7665 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
7666 if (return_type == irb->codegen->invalid_inst_src)
7667 return irb->codegen->invalid_inst_src;
7665 return_type = ir_gen_node(ag, node->data.fn_proto.return_type, parent_scope);
7666 if (return_type == ag->codegen->invalid_inst_src)
7667 return ag->codegen->invalid_inst_src;
76687668 }
76697669
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);
76717671}
76727672
7673static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7673static IrInstSrc *ir_gen_resume(Stage1AstGen *ag, Scope *scope, AstNode *node) {
76747674 assert(node->type == NodeTypeResume);
76757675
7676 IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
7677 if (target_inst == irb->codegen->invalid_inst_src)
7678 return irb->codegen->invalid_inst_src;
7676 IrInstSrc *target_inst = ir_gen_node_extra(ag, node->data.resume_expr.expr, scope, LValPtr, nullptr);
7677 if (target_inst == ag->codegen->invalid_inst_src)
7678 return ag->codegen->invalid_inst_src;
76797679
7680 return ir_build_resume_src(irb, scope, node, target_inst);
7680 return ir_build_resume_src(ag, scope, node, target_inst);
76817681}
76827682
7683static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
7683static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval,
76847684 ResultLoc *result_loc)
76857685{
76867686 assert(node->type == NodeTypeAwaitExpr);
......@@ -7691,73 +7691,73 @@ static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
76917691 if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.modifier == CallModifierBuiltin) {
76927692 AstNode *fn_ref_expr = expr_node->data.fn_call_expr.fn_ref_expr;
76937693 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);
76957695 if (entry != nullptr) {
76967696 BuiltinFnEntry *builtin_fn = entry->value;
76977697 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);
76997699 }
77007700 }
77017701 }
77027702
7703 ZigFn *fn_entry = exec_fn_entry(irb->exec);
7703 ZigFn *fn_entry = exec_fn_entry(ag->exec);
77047704 if (!fn_entry) {
7705 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
7706 return irb->codegen->invalid_inst_src;
7705 add_node_error(ag->codegen, node, buf_sprintf("await outside function definition"));
7706 return ag->codegen->invalid_inst_src;
77077707 }
77087708 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);
77097709 if (existing_suspend_scope) {
77107710 if (!existing_suspend_scope->reported_err) {
7711 ErrorMsg *msg = add_node_error(irb->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"));
7711 ErrorMsg *msg = add_node_error(ag->codegen, node, buf_sprintf("cannot await inside suspend block"));
7712 add_error_note(ag->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));
77137713 existing_suspend_scope->reported_err = true;
77147714 }
7715 return irb->codegen->invalid_inst_src;
7715 return ag->codegen->invalid_inst_src;
77167716 }
77177717
7718 IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7719 if (target_inst == irb->codegen->invalid_inst_src)
7720 return irb->codegen->invalid_inst_src;
7718 IrInstSrc *target_inst = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr);
7719 if (target_inst == ag->codegen->invalid_inst_src)
7720 return ag->codegen->invalid_inst_src;
77217721
7722 IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc, is_nosuspend);
7723 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
7722 IrInstSrc *await_inst = ir_build_await_src(ag, scope, node, target_inst, result_loc, is_nosuspend);
7723 return ir_lval_wrap(ag, scope, await_inst, lval, result_loc);
77247724}
77257725
7726static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
7726static IrInstSrc *ir_gen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) {
77277727 assert(node->type == NodeTypeSuspend);
77287728
7729 ZigFn *fn_entry = exec_fn_entry(irb->exec);
7729 ZigFn *fn_entry = exec_fn_entry(ag->exec);
77307730 if (!fn_entry) {
7731 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
7732 return irb->codegen->invalid_inst_src;
7731 add_node_error(ag->codegen, node, buf_sprintf("suspend outside function definition"));
7732 return ag->codegen->invalid_inst_src;
77337733 }
77347734 if (get_scope_nosuspend(parent_scope) != nullptr) {
7735 add_node_error(irb->codegen, node, buf_sprintf("suspend in nosuspend scope"));
7736 return irb->codegen->invalid_inst_src;
7735 add_node_error(ag->codegen, node, buf_sprintf("suspend in nosuspend scope"));
7736 return ag->codegen->invalid_inst_src;
77377737 }
77387738
77397739 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
77407740 if (existing_suspend_scope) {
77417741 if (!existing_suspend_scope->reported_err) {
7742 ErrorMsg *msg = add_node_error(irb->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"));
7742 ErrorMsg *msg = add_node_error(ag->codegen, node, buf_sprintf("cannot suspend inside suspend block"));
7743 add_error_note(ag->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
77447744 existing_suspend_scope->reported_err = true;
77457745 }
7746 return irb->codegen->invalid_inst_src;
7746 return ag->codegen->invalid_inst_src;
77477747 }
77487748
7749 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node);
7750 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
7749 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(ag, parent_scope, node);
7750 ScopeSuspend *suspend_scope = create_suspend_scope(ag->codegen, node, parent_scope);
77517751 Scope *child_scope = &suspend_scope->base;
7752 IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
7753 if (susp_res == irb->codegen->invalid_inst_src)
7754 return irb->codegen->invalid_inst_src;
7755 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
7752 IrInstSrc *susp_res = ir_gen_node(ag, node->data.suspend.block, child_scope);
7753 if (susp_res == ag->codegen->invalid_inst_src)
7754 return ag->codegen->invalid_inst_src;
7755 ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, node->data.suspend.block, susp_res));
77567756
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));
77587758}
77597759
7760static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope,
7760static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope,
77617761 LVal lval, ResultLoc *result_loc)
77627762{
77637763 assert(scope);
......@@ -7773,47 +7773,47 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope
77737773 case NodeTypeTestDecl:
77747774 zig_unreachable();
77757775 case NodeTypeBlock:
7776 return ir_gen_block(irb, scope, node, lval, result_loc);
7776 return ir_gen_block(ag, scope, node, lval, result_loc);
77777777 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);
77797779 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);
77817781 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);
77837783 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);
77857785 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);
77877787 case NodeTypeIdentifier:
7788 return ir_gen_symbol(irb, scope, node, lval, result_loc);
7788 return ir_gen_symbol(ag, scope, node, lval, result_loc);
77897789 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);
77917791 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);
77937793 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);
77957795 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);
77977797 case NodeTypeVariableDeclaration:
7798 return ir_gen_var_decl(irb, scope, node);
7798 return ir_gen_var_decl(ag, scope, node);
77997799 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);
78017801 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);
78037803 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);
78057805 case NodeTypeReturnExpr:
7806 return ir_gen_return(irb, scope, node, lval, result_loc);
7806 return ir_gen_return(ag, scope, node, lval, result_loc);
78077807 case NodeTypeFieldAccessExpr:
78087808 {
7809 IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node);
7810 if (ptr_instruction == irb->codegen->invalid_inst_src)
7809 IrInstSrc *ptr_instruction = ir_gen_field_access(ag, scope, node);
7810 if (ptr_instruction == ag->codegen->invalid_inst_src)
78117811 return ptr_instruction;
78127812 if (lval == LValPtr || lval == LValAssign)
78137813 return ptr_instruction;
78147814
7815 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
7816 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
7815 IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, ptr_instruction);
7816 return ir_expr_wrap(ag, scope, load_ptr, result_loc);
78177817 }
78187818 case NodeTypePtrDeref: {
78197819 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
78227822 if (child_lval == LValAssign)
78237823 child_lval = LValPtr;
78247824
7825 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, child_lval, nullptr);
7826 if (value == irb->codegen->invalid_inst_src)
7825 IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, child_lval, nullptr);
7826 if (value == ag->codegen->invalid_inst_src)
78277827 return value;
78287828
78297829 // We essentially just converted any lvalue from &(x.*) to (&x).*;
78307830 // this inhibits checking that x is a pointer later, so we directly
78317831 // record whether the pointer check is needed
7832 IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
7833 return ir_expr_wrap(irb, scope, un_op, result_loc);
7832 IrInstSrc *un_op = ir_build_un_op_lval(ag, scope, node, IrUnOpDereference, value, lval, result_loc);
7833 return ir_expr_wrap(ag, scope, un_op, result_loc);
78347834 }
78357835 case NodeTypeUnwrapOptional: {
78367836 AstNode *expr_node = node->data.unwrap_optional.expr;
78377837
7838 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7839 if (maybe_ptr == irb->codegen->invalid_inst_src)
7840 return irb->codegen->invalid_inst_src;
7838 IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr);
7839 if (maybe_ptr == ag->codegen->invalid_inst_src)
7840 return ag->codegen->invalid_inst_src;
78417841
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 );
78437843 if (lval == LValPtr || lval == LValAssign)
78447844 return unwrapped_ptr;
78457845
7846 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
7847 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
7846 IrInstSrc *load_ptr = ir_build_load_ptr(ag, scope, node, unwrapped_ptr);
7847 return ir_expr_wrap(ag, scope, load_ptr, result_loc);
78487848 }
78497849 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);
78517851 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);
78537853 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);
78557855 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);
78577857 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);
78597859 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);
78617861 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);
78637863 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);
78657865 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);
78677867 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);
78697869 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);
78717871 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);
78737873 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);
78757875 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);
78777877 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);
78797879 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);
78817881 case NodeTypeUnreachable:
7882 return ir_build_unreachable(irb, scope, node);
7882 return ir_build_unreachable(ag, scope, node);
78837883 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);
78857885 case NodeTypeSliceExpr:
7886 return ir_gen_slice(irb, scope, node, lval, result_loc);
7886 return ir_gen_slice(ag, scope, node, lval, result_loc);
78877887 case NodeTypeCatchExpr:
7888 return ir_gen_catch(irb, scope, node, lval, result_loc);
7888 return ir_gen_catch(ag, scope, node, lval, result_loc);
78897889 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);
78917891 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);
78937893 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);
78957895 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);
78977897 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);
78997899 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);
79017901 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);
79037903 case NodeTypeInferredArrayType:
7904 add_node_error(irb->codegen, node,
7904 add_node_error(ag->codegen, node,
79057905 buf_sprintf("inferred array size invalid here"));
7906 return irb->codegen->invalid_inst_src;
7906 return ag->codegen->invalid_inst_src;
79077907 case NodeTypeAnyTypeField:
7908 return ir_lval_wrap(irb, scope,
7909 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_anytype), lval, result_loc);
7908 return ir_lval_wrap(ag, scope,
7909 ir_build_const_type(ag, scope, node, ag->codegen->builtin_types.entry_anytype), lval, result_loc);
79107910 }
79117911 zig_unreachable();
79127912}
......@@ -7917,7 +7917,7 @@ ResultLoc *no_result_loc(void) {
79177917 return &result_loc_none->base;
79187918}
79197919
7920static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
7920static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval,
79217921 ResultLoc *result_loc)
79227922{
79237923 if (lval == LValAssign) {
......@@ -7976,30 +7976,30 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco
79767976 case NodeTypeInferredArrayType:
79777977 case NodeTypeAnyTypeField:
79787978 case NodeTypePrefixOpExpr:
7979 add_node_error(irb->codegen, node,
7979 add_node_error(ag->codegen, node,
79807980 buf_sprintf("invalid left-hand side to assignment"));
7981 return irb->codegen->invalid_inst_src;
7981 return ag->codegen->invalid_inst_src;
79827982
79837983 // @field can be assigned to
79847984 case NodeTypeFnCallExpr:
79857985 if (node->data.fn_call_expr.modifier == CallModifierBuiltin) {
79867986 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;
79877987 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);
79897989
79907990 if (!entry) {
7991 add_node_error(irb->codegen, node,
7991 add_node_error(ag->codegen, node,
79927992 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
7993 return irb->codegen->invalid_inst_src;
7993 return ag->codegen->invalid_inst_src;
79947994 }
79957995
79967996 if (entry->value->id == BuiltinFnIdField) {
79977997 break;
79987998 }
79997999 }
8000 add_node_error(irb->codegen, node,
8000 add_node_error(ag->codegen, node,
80018001 buf_sprintf("invalid left-hand side to assignment"));
8002 return irb->codegen->invalid_inst_src;
8002 return ag->codegen->invalid_inst_src;
80038003
80048004
80058005 // can be assigned to
......@@ -8015,62 +8015,62 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco
80158015 // Create a result location indicating there is none - but if one gets created
80168016 // it will be properly distributed.
80178017 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);
80198019 }
80208020 Scope *child_scope;
8021 if (irb->exec->is_inline ||
8022 (irb->exec->fn_entry != nullptr && irb->exec->fn_entry->child_scope == scope))
8021 if (ag->exec->is_inline ||
8022 (ag->exec->fn_entry != nullptr && ag->exec->fn_entry->child_scope == scope))
80238023 {
80248024 child_scope = scope;
80258025 } else {
8026 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
8026 child_scope = &create_expr_scope(ag->codegen, node, scope)->base;
80278027 }
8028 IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
8029 if (result == irb->codegen->invalid_inst_src) {
8030 if (irb->exec->first_err_trace_msg == nullptr) {
8031 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
8028 IrInstSrc *result = ir_gen_node_raw(ag, node, child_scope, lval, result_loc);
8029 if (result == ag->codegen->invalid_inst_src) {
8030 if (ag->exec->first_err_trace_msg == nullptr) {
8031 ag->exec->first_err_trace_msg = ag->codegen->trace_err;
80328032 }
80338033 }
80348034 return result;
80358035}
80368036
8037static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) {
8038 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
8037static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {
8038 return ir_gen_node_extra(ag, node, scope, LValNone, nullptr);
80398039}
80408040
80418041bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable) {
80428042 assert(node->owner);
80438043
8044 IrBuilderSrc ir_builder = {0};
8045 IrBuilderSrc *irb = &ir_builder;
8044 Stage1AstGen ir_builder = {0};
8045 Stage1AstGen *ag = &ir_builder;
80468046
8047 irb->codegen = codegen;
8048 irb->exec = ir_executable;
8049 irb->main_block_node = node;
8047 ag->codegen = codegen;
8048 ag->exec = ir_executable;
8049 ag->main_block_node = node;
80508050
8051 IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry");
8052 ir_set_cursor_at_end_and_append_block(irb, entry_block);
8051 IrBasicBlockSrc *entry_block = ir_create_basic_block(ag, scope, "Entry");
8052 ir_set_cursor_at_end_and_append_block(ag, entry_block);
80538053 // 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);
80558055
8056 IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
8056 IrInstSrc *result = ir_gen_node_extra(ag, node, scope, LValNone, nullptr);
80578057
8058 if (result == irb->codegen->invalid_inst_src)
8058 if (result == ag->codegen->invalid_inst_src)
80598059 return false;
80608060
8061 if (irb->exec->first_err_trace_msg != nullptr) {
8062 codegen->trace_err = irb->exec->first_err_trace_msg;
8061 if (ag->exec->first_err_trace_msg != nullptr) {
8062 codegen->trace_err = ag->exec->first_err_trace_msg;
80638063 return false;
80648064 }
80658065
80668066 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));
80688068 // no need for save_err_ret_addr because this cannot return error
80698069 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
80708070 result_loc_ret->base.id = ResultLocIdReturn;
8071 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
8072 ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base));
8073 ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result));
8071 ir_build_reset_result(ag, scope, node, &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(ag, scope, result->base.source_node, result));
80748074 }
80758075
80768076 return true;