authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 18:35:57-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 18:35:57-04:00
log1f5c7ff4d7360f83f83f422adf167df5d756e3b4
tree9668b510847e1fe9bb8fba9a38acdd7b7048a8e9
parent3500d32db52eaf485b5cff2a26d382b37cfb85a3
signaturelock-open Commit is signed but in an unrecognized format.

stage1: rename VariableTableEntry to ZigVar


5 files changed, 76 insertions(+), 76 deletions(-)

src/all_types.hpp+10-10
...@@ -25,7 +25,7 @@ struct Scope;...@@ -25,7 +25,7 @@ struct Scope;
25struct ScopeBlock;25struct ScopeBlock;
26struct ScopeFnDef;26struct ScopeFnDef;
27struct ZigType;27struct ZigType;
28struct VariableTableEntry;28struct ZigVar;
29struct ErrorTableEntry;29struct ErrorTableEntry;
30struct BuiltinFnEntry;30struct BuiltinFnEntry;
31struct TypeStructField;31struct TypeStructField;
...@@ -69,7 +69,7 @@ struct IrExecutable {...@@ -69,7 +69,7 @@ struct IrExecutable {
69 IrBasicBlock *coro_normal_final;69 IrBasicBlock *coro_normal_final;
70 IrBasicBlock *coro_suspend_block;70 IrBasicBlock *coro_suspend_block;
71 IrBasicBlock *coro_final_cleanup_block;71 IrBasicBlock *coro_final_cleanup_block;
72 VariableTableEntry *coro_allocator_var;72 ZigVar *coro_allocator_var;
73};73};
7474
75enum OutType {75enum OutType {
...@@ -337,7 +337,7 @@ struct Tld {...@@ -337,7 +337,7 @@ struct Tld {
337struct TldVar {337struct TldVar {
338 Tld base;338 Tld base;
339339
340 VariableTableEntry *var;340 ZigVar *var;
341 Buf *extern_lib_name;341 Buf *extern_lib_name;
342 Buf *section_name;342 Buf *section_name;
343};343};
...@@ -1310,7 +1310,7 @@ struct ZigFn {...@@ -1310,7 +1310,7 @@ struct ZigFn {
1310 AstNode *fn_static_eval_set_node;1310 AstNode *fn_static_eval_set_node;
13111311
1312 ZigList<IrInstruction *> alloca_list;1312 ZigList<IrInstruction *> alloca_list;
1313 ZigList<VariableTableEntry *> variable_list;1313 ZigList<ZigVar *> variable_list;
13141314
1315 Buf *section_name;1315 Buf *section_name;
1316 AstNode *set_alignstack_node;1316 AstNode *set_alignstack_node;
...@@ -1786,7 +1786,7 @@ enum VarLinkage {...@@ -1786,7 +1786,7 @@ enum VarLinkage {
1786 VarLinkageExternal,1786 VarLinkageExternal,
1787};1787};
17881788
1789struct VariableTableEntry {1789struct ZigVar {
1790 Buf name;1790 Buf name;
1791 ConstExprValue *value;1791 ConstExprValue *value;
1792 LLVMValueRef value_ref;1792 LLVMValueRef value_ref;
...@@ -1811,7 +1811,7 @@ struct VariableTableEntry {...@@ -1811,7 +1811,7 @@ struct VariableTableEntry {
1811 // In an inline loop, multiple variables may be created,1811 // In an inline loop, multiple variables may be created,
1812 // In this case, a reference to a variable should follow1812 // In this case, a reference to a variable should follow
1813 // this pointer to the redefined variable.1813 // this pointer to the redefined variable.
1814 VariableTableEntry *next_var;1814 ZigVar *next_var;
1815};1815};
18161816
1817struct ErrorTableEntry {1817struct ErrorTableEntry {
...@@ -1904,7 +1904,7 @@ struct ScopeVarDecl {...@@ -1904,7 +1904,7 @@ struct ScopeVarDecl {
1904 Scope base;1904 Scope base;
19051905
1906 // The variable that creates this scope1906 // The variable that creates this scope
1907 VariableTableEntry *var;1907 ZigVar *var;
1908};1908};
19091909
1910// This scope is created for a @cImport1910// This scope is created for a @cImport
...@@ -2292,7 +2292,7 @@ struct IrInstructionBinOp {...@@ -2292,7 +2292,7 @@ struct IrInstructionBinOp {
2292struct IrInstructionDeclVar {2292struct IrInstructionDeclVar {
2293 IrInstruction base;2293 IrInstruction base;
22942294
2295 VariableTableEntry *var;2295 ZigVar *var;
2296 IrInstruction *var_type;2296 IrInstruction *var_type;
2297 IrInstruction *align_value;2297 IrInstruction *align_value;
2298 IrInstruction *init_value;2298 IrInstruction *init_value;
...@@ -2349,7 +2349,7 @@ struct IrInstructionElemPtr {...@@ -2349,7 +2349,7 @@ struct IrInstructionElemPtr {
2349struct IrInstructionVarPtr {2349struct IrInstructionVarPtr {
2350 IrInstruction base;2350 IrInstruction base;
23512351
2352 VariableTableEntry *var;2352 ZigVar *var;
2353};2353};
23542354
2355struct IrInstructionCall {2355struct IrInstructionCall {
...@@ -2519,7 +2519,7 @@ struct IrInstructionAsm {...@@ -2519,7 +2519,7 @@ struct IrInstructionAsm {
2519 // Most information on inline assembly comes from the source node.2519 // Most information on inline assembly comes from the source node.
2520 IrInstruction **input_list;2520 IrInstruction **input_list;
2521 IrInstruction **output_types;2521 IrInstruction **output_types;
2522 VariableTableEntry **output_vars;2522 ZigVar **output_vars;
2523 size_t return_count;2523 size_t return_count;
2524 bool has_side_effects;2524 bool has_side_effects;
2525};2525};
src/analyze.cpp+7-7
...@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {...@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {
129 return scope;129 return scope;
130}130}
131131
132Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var) {132Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var) {
133 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);133 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
134 init_scope(&scope->base, ScopeIdVarDecl, node, parent);134 init_scope(&scope->base, ScopeIdVarDecl, node, parent);
135 scope->var = var;135 scope->var = var;
...@@ -3501,12 +3501,12 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry...@@ -3501,12 +3501,12 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
35013501
3502// Set name to nullptr to make the variable anonymous (not visible to programmer).3502// Set name to nullptr to make the variable anonymous (not visible to programmer).
3503// TODO merge with definition of add_local_var in ir.cpp3503// TODO merge with definition of add_local_var in ir.cpp
3504VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,3504ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
3505 bool is_const, ConstExprValue *value, Tld *src_tld)3505 bool is_const, ConstExprValue *value, Tld *src_tld)
3506{3506{
3507 assert(value);3507 assert(value);
35083508
3509 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);3509 ZigVar *variable_entry = allocate<ZigVar>(1);
3510 variable_entry->value = value;3510 variable_entry->value = value;
3511 variable_entry->parent_scope = parent_scope;3511 variable_entry->parent_scope = parent_scope;
3512 variable_entry->shadowable = false;3512 variable_entry->shadowable = false;
...@@ -3519,7 +3519,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent...@@ -3519,7 +3519,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
3519 if (!type_is_invalid(value->type)) {3519 if (!type_is_invalid(value->type)) {
3520 variable_entry->align_bytes = get_abi_alignment(g, value->type);3520 variable_entry->align_bytes = get_abi_alignment(g, value->type);
35213521
3522 VariableTableEntry *existing_var = find_variable(g, parent_scope, name);3522 ZigVar *existing_var = find_variable(g, parent_scope, name);
3523 if (existing_var && !existing_var->shadowable) {3523 if (existing_var && !existing_var->shadowable) {
3524 ErrorMsg *msg = add_node_error(g, source_node,3524 ErrorMsg *msg = add_node_error(g, source_node,
3525 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));3525 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
...@@ -3726,7 +3726,7 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {...@@ -3726,7 +3726,7 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
3726 return nullptr;3726 return nullptr;
3727}3727}
37283728
3729VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {3729ZigVar *find_variable(CodeGen *g, Scope *scope, Buf *name) {
3730 while (scope) {3730 while (scope) {
3731 if (scope->id == ScopeIdVarDecl) {3731 if (scope->id == ScopeIdVarDecl) {
3732 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;3732 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
...@@ -4015,7 +4015,7 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4015,7 +4015,7 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4015 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));4015 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
4016 }4016 }
40174017
4018 VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,4018 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
4019 param_name, true, create_const_runtime(param_type), nullptr);4019 param_name, true, create_const_runtime(param_type), nullptr);
4020 var->src_arg_index = i;4020 var->src_arg_index = i;
4021 fn_table_entry->child_scope = var->child_scope;4021 fn_table_entry->child_scope = var->child_scope;
...@@ -5429,7 +5429,7 @@ Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {...@@ -5429,7 +5429,7 @@ Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {
5429 return ErrorNone;5429 return ErrorNone;
5430}5430}
54315431
5432bool ir_get_var_is_comptime(VariableTableEntry *var) {5432bool ir_get_var_is_comptime(ZigVar *var) {
5433 if (!var->is_comptime)5433 if (!var->is_comptime)
5434 return false;5434 return false;
5435 if (var->is_comptime->other)5435 if (var->is_comptime->other)
src/analyze.hpp+4-4
...@@ -48,7 +48,7 @@ bool type_has_bits(ZigType *type_entry);...@@ -48,7 +48,7 @@ bool type_has_bits(ZigType *type_entry);
48ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);48ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
4949
5050
51VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);51ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
52Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);52Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
54bool type_is_codegen_pointer(ZigType *type);54bool type_is_codegen_pointer(ZigType *type);
...@@ -80,7 +80,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node);...@@ -80,7 +80,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node);
80ZigFn *scope_fn_entry(Scope *scope);80ZigFn *scope_fn_entry(Scope *scope);
81ImportTableEntry *get_scope_import(Scope *scope);81ImportTableEntry *get_scope_import(Scope *scope);
82void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);82void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
83VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,83ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
84 bool is_const, ConstExprValue *init_value, Tld *src_tld);84 bool is_const, ConstExprValue *init_value, Tld *src_tld);
85ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);85ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
86ZigFn *create_fn(AstNode *proto_node);86ZigFn *create_fn(AstNode *proto_node);
...@@ -92,7 +92,7 @@ bool type_requires_comptime(ZigType *type_entry);...@@ -92,7 +92,7 @@ bool type_requires_comptime(ZigType *type_entry);
92Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);92Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
93Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);93Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
94void complete_enum(CodeGen *g, ZigType *enum_type);94void complete_enum(CodeGen *g, ZigType *enum_type);
95bool ir_get_var_is_comptime(VariableTableEntry *var);95bool ir_get_var_is_comptime(ZigVar *var);
96bool const_values_equal(ConstExprValue *a, ConstExprValue *b);96bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
97void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);97void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);
98void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);98void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
...@@ -103,7 +103,7 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node)...@@ -103,7 +103,7 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node)
103ScopeBlock *create_block_scope(AstNode *node, Scope *parent);103ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
104ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);104ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);
105ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);105ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);
106Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var);106Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var);
107ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);107ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
108ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);108ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);
109ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);109ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);
src/codegen.cpp+8-8
...@@ -1857,7 +1857,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty...@@ -1857,7 +1857,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty
1857 return nullptr;1857 return nullptr;
1858}1858}
18591859
1860static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {1860static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
1861 AstNode *source_node = var->decl_node;1861 AstNode *source_node = var->decl_node;
1862 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,1862 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
1863 (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));1863 (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));
...@@ -2862,7 +2862,7 @@ static LLVMValueRef get_memset_fn_val(CodeGen *g) {...@@ -2862,7 +2862,7 @@ static LLVMValueRef get_memset_fn_val(CodeGen *g) {
2862static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,2862static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
2863 IrInstructionDeclVar *decl_var_instruction)2863 IrInstructionDeclVar *decl_var_instruction)
2864{2864{
2865 VariableTableEntry *var = decl_var_instruction->var;2865 ZigVar *var = decl_var_instruction->var;
28662866
2867 if (!type_has_bits(var->value->type))2867 if (!type_has_bits(var->value->type))
2868 return nullptr;2868 return nullptr;
...@@ -2955,7 +2955,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -2955,7 +2955,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
2955}2955}
29562956
2957static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {2957static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
2958 VariableTableEntry *var = instruction->var;2958 ZigVar *var = instruction->var;
2959 if (type_has_bits(var->value->type)) {2959 if (type_has_bits(var->value->type)) {
2960 assert(var->value_ref);2960 assert(var->value_ref);
2961 return var->value_ref;2961 return var->value_ref;
...@@ -3370,7 +3370,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3370,7 +3370,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3370 }3370 }
33713371
3372 if (!is_return) {3372 if (!is_return) {
3373 VariableTableEntry *variable = instruction->output_vars[i];3373 ZigVar *variable = instruction->output_vars[i];
3374 assert(variable);3374 assert(variable);
3375 param_types[param_index] = LLVMTypeOf(variable->value_ref);3375 param_types[param_index] = LLVMTypeOf(variable->value_ref);
3376 param_values[param_index] = variable->value_ref;3376 param_values[param_index] = variable->value_ref;
...@@ -5699,7 +5699,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {...@@ -5699,7 +5699,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
5699 LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);5699 LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);
5700}5700}
57015701
5702static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,5702static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
5703 ZigType *type_entry)5703 ZigType *type_entry)
5704{5704{
5705 if (g->strip_debug_symbols) {5705 if (g->strip_debug_symbols) {
...@@ -5788,7 +5788,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5788,7 +5788,7 @@ static void do_code_gen(CodeGen *g) {
5788 // Generate module level variables5788 // Generate module level variables
5789 for (size_t i = 0; i < g->global_vars.length; i += 1) {5789 for (size_t i = 0; i < g->global_vars.length; i += 1) {
5790 TldVar *tld_var = g->global_vars.at(i);5790 TldVar *tld_var = g->global_vars.at(i);
5791 VariableTableEntry *var = tld_var->var;5791 ZigVar *var = tld_var->var;
57925792
5793 if (var->value->type->id == TypeTableEntryIdComptimeFloat) {5793 if (var->value->type->id == TypeTableEntryIdComptimeFloat) {
5794 // Generate debug info for it but that's it.5794 // Generate debug info for it but that's it.
...@@ -5949,7 +5949,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5949,7 +5949,7 @@ static void do_code_gen(CodeGen *g) {
59495949
5950 // create debug variable declarations for variables and allocate all local variables5950 // create debug variable declarations for variables and allocate all local variables
5951 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {5951 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
5952 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);5952 ZigVar *var = fn_table_entry->variable_list.at(var_i);
59535953
5954 if (!type_has_bits(var->value->type)) {5954 if (!type_has_bits(var->value->type)) {
5955 continue;5955 continue;
...@@ -6027,7 +6027,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6027,7 +6027,7 @@ static void do_code_gen(CodeGen *g) {
6027 if (info->gen_index == SIZE_MAX)6027 if (info->gen_index == SIZE_MAX)
6028 continue;6028 continue;
60296029
6030 VariableTableEntry *variable = fn_table_entry->variable_list.at(next_var_i);6030 ZigVar *variable = fn_table_entry->variable_list.at(next_var_i);
6031 assert(variable->src_arg_index != SIZE_MAX);6031 assert(variable->src_arg_index != SIZE_MAX);
6032 next_var_i += 1;6032 next_var_i += 1;
60336033
src/ir.cpp+47-47
...@@ -145,7 +145,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -145,7 +145,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
145static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);145static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
146static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,146static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
147 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);147 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
149static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);149static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
150static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);150static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
151static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);151static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
...@@ -277,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb)...@@ -277,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb)
277 ir_ref_bb(instruction->owner_bb);277 ir_ref_bb(instruction->owner_bb);
278}278}
279279
280static void ir_ref_var(VariableTableEntry *var) {280static void ir_ref_var(ZigVar *var) {
281 var->ref_count += 1;281 var->ref_count += 1;
282}282}
283283
...@@ -1114,7 +1114,7 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in...@@ -1114,7 +1114,7 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1114 return new_instruction;1114 return new_instruction;
1115}1115}
11161116
1117static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {1117static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
1118 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);1118 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
1119 instruction->var = var;1119 instruction->var = var;
11201120
...@@ -1459,7 +1459,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old...@@ -1459,7 +1459,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old
1459}1459}
14601460
1461static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,1461static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,
1462 VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)1462 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
1463{1463{
1464 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);1464 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);
1465 decl_var_instruction->base.value.special = ConstValSpecialStatic;1465 decl_var_instruction->base.value.special = ConstValSpecialStatic;
...@@ -1477,7 +1477,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1477,7 +1477,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
1477}1477}
14781478
1479static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction,1479static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction,
1480 VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)1480 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
1481{1481{
1482 IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,1482 IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,
1483 old_instruction->source_node, var, var_type, align_value, init_value);1483 old_instruction->source_node, var, var_type, align_value, init_value);
...@@ -1622,7 +1622,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode...@@ -1622,7 +1622,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
1622}1622}
16231623
1624static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list,1624static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list,
1625 IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)1625 IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
1626{1626{
1627 IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);1627 IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);
1628 instruction->input_list = input_list;1628 instruction->input_list = input_list;
...@@ -1646,7 +1646,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source...@@ -1646,7 +1646,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source
1646}1646}
16471647
1648static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list,1648static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list,
1649 IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)1649 IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
1650{1650{
1651 IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,1651 IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,
1652 old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects);1652 old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects);
...@@ -3320,11 +3320,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3320,11 +3320,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3320 zig_unreachable();3320 zig_unreachable();
3321}3321}
33223322
3323static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,3323static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
3324 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,3324 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
3325 bool skip_name_check)3325 bool skip_name_check)
3326{3326{
3327 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);3327 ZigVar *variable_entry = allocate<ZigVar>(1);
3328 variable_entry->parent_scope = parent_scope;3328 variable_entry->parent_scope = parent_scope;
3329 variable_entry->shadowable = is_shadowable;3329 variable_entry->shadowable = is_shadowable;
3330 variable_entry->mem_slot_index = SIZE_MAX;3330 variable_entry->mem_slot_index = SIZE_MAX;
...@@ -3336,7 +3336,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3336,7 +3336,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
3336 buf_init_from_buf(&variable_entry->name, name);3336 buf_init_from_buf(&variable_entry->name, name);
33373337
3338 if (!skip_name_check) {3338 if (!skip_name_check) {
3339 VariableTableEntry *existing_var = find_variable(codegen, parent_scope, name);3339 ZigVar *existing_var = find_variable(codegen, parent_scope, name);
3340 if (existing_var && !existing_var->shadowable) {3340 if (existing_var && !existing_var->shadowable) {
3341 ErrorMsg *msg = add_node_error(codegen, node,3341 ErrorMsg *msg = add_node_error(codegen, node,
3342 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));3342 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
...@@ -3377,11 +3377,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3377,11 +3377,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
33773377
3378// Set name to nullptr to make the variable anonymous (not visible to programmer).3378// Set name to nullptr to make the variable anonymous (not visible to programmer).
3379// After you call this function var->child_scope has the variable in scope3379// After you call this function var->child_scope has the variable in scope
3380static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,3380static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
3381 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)3381 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
3382{3382{
3383 bool is_underscored = name ? buf_eql_str(name, "_") : false;3383 bool is_underscored = name ? buf_eql_str(name, "_") : false;
3384 VariableTableEntry *var = create_local_var(irb->codegen, node, scope,3384 ZigVar *var = create_local_var(irb->codegen, node, scope,
3385 (is_underscored ? nullptr : name), src_is_const, gen_is_const,3385 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
3386 (is_underscored ? true : is_shadowable), is_comptime, false);3386 (is_underscored ? true : is_shadowable), is_comptime, false);
3387 if (is_comptime != nullptr || gen_is_const) {3387 if (is_comptime != nullptr || gen_is_const) {
...@@ -3799,7 +3799,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3799,7 +3799,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3799 }3799 }
3800 }3800 }
38013801
3802 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);3802 ZigVar *var = find_variable(irb->codegen, scope, variable_name);
3803 if (var) {3803 if (var) {
3804 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);3804 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3805 if (lval == LValPtr)3805 if (lval == LValPtr)
...@@ -5258,7 +5258,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5258,7 +5258,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
52585258
5259 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,5259 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
5260 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);5260 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);
5261 VariableTableEntry *var = ir_create_var(irb, node, scope, variable_declaration->symbol,5261 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
5262 is_const, is_const, is_shadowable, is_comptime);5262 is_const, is_const, is_shadowable, is_comptime);
5263 // we detect IrInstructionIdDeclVar in gen_block to make sure the next node5263 // we detect IrInstructionIdDeclVar in gen_block to make sure the next node
5264 // is inside var->child_scope5264 // is inside var->child_scope
...@@ -5320,7 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5320,7 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
53205320
5321 Scope *payload_scope;5321 Scope *payload_scope;
5322 AstNode *symbol_node = node; // TODO make more accurate5322 AstNode *symbol_node = node; // TODO make more accurate
5323 VariableTableEntry *payload_var;5323 ZigVar *payload_var;
5324 if (var_symbol) {5324 if (var_symbol) {
5325 // TODO make it an error to write to payload variable5325 // TODO make it an error to write to payload variable
5326 payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,5326 payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
...@@ -5384,7 +5384,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5384,7 +5384,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
53845384
5385 // TODO make it an error to write to error variable5385 // TODO make it an error to write to error variable
5386 AstNode *err_symbol_node = else_node; // TODO make more accurate5386 AstNode *err_symbol_node = else_node; // TODO make more accurate
5387 VariableTableEntry *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,5387 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
5388 true, false, false, is_comptime);5388 true, false, false, is_comptime);
5389 Scope *err_scope = err_var->child_scope;5389 Scope *err_scope = err_var->child_scope;
5390 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);5390 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
...@@ -5413,7 +5413,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5413,7 +5413,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5413 // TODO make it an error to write to payload variable5413 // TODO make it an error to write to payload variable
5414 AstNode *symbol_node = node; // TODO make more accurate5414 AstNode *symbol_node = node; // TODO make more accurate
54155415
5416 VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,5416 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
5417 true, false, false, is_comptime);5417 true, false, false, is_comptime);
5418 Scope *child_scope = payload_var->child_scope;5418 Scope *child_scope = payload_var->child_scope;
5419 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);5419 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);
...@@ -5585,7 +5585,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5585,7 +5585,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
55855585
5586 // TODO make it an error to write to element variable or i variable.5586 // TODO make it an error to write to element variable or i variable.
5587 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;5587 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
5588 VariableTableEntry *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);5588 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
5589 Scope *child_scope = elem_var->child_scope;5589 Scope *child_scope = elem_var->child_scope;
55905590
5591 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);5591 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
...@@ -5593,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5593,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5593 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);5593 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
55945594
5595 AstNode *index_var_source_node;5595 AstNode *index_var_source_node;
5596 VariableTableEntry *index_var;5596 ZigVar *index_var;
5597 if (index_node) {5597 if (index_node) {
5598 index_var_source_node = index_node;5598 index_var_source_node = index_node;
5599 Buf *index_var_name = index_node->data.symbol_expr.symbol;5599 Buf *index_var_name = index_node->data.symbol_expr.symbol;
...@@ -5798,7 +5798,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5798,7 +5798,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
57985798
5799 IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);5799 IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);
5800 IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length);5800 IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length);
5801 VariableTableEntry **output_vars = allocate<VariableTableEntry *>(node->data.asm_expr.output_list.length);5801 ZigVar **output_vars = allocate<ZigVar *>(node->data.asm_expr.output_list.length);
5802 size_t return_count = 0;5802 size_t return_count = 0;
5803 bool is_volatile = node->data.asm_expr.is_volatile;5803 bool is_volatile = node->data.asm_expr.is_volatile;
5804 if (!is_volatile && node->data.asm_expr.output_list.length == 0) {5804 if (!is_volatile && node->data.asm_expr.output_list.length == 0) {
...@@ -5822,7 +5822,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5822,7 +5822,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
5822 output_types[i] = return_type;5822 output_types[i] = return_type;
5823 } else {5823 } else {
5824 Buf *variable_name = asm_output->variable_name;5824 Buf *variable_name = asm_output->variable_name;
5825 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);5825 ZigVar *var = find_variable(irb->codegen, scope, variable_name);
5826 if (var) {5826 if (var) {
5827 output_vars[i] = var;5827 output_vars[i] = var;
5828 } else {5828 } else {
...@@ -5880,7 +5880,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no...@@ -5880,7 +5880,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
5880 IrInstruction *var_type = nullptr;5880 IrInstruction *var_type = nullptr;
5881 bool is_shadowable = false;5881 bool is_shadowable = false;
5882 bool is_const = true;5882 bool is_const = true;
5883 VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope,5883 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5884 var_symbol, is_const, is_const, is_shadowable, is_comptime);5884 var_symbol, is_const, is_const, is_shadowable, is_comptime);
58855885
5886 IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false);5886 IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false);
...@@ -5955,7 +5955,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5955,7 +5955,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
5955 IrInstruction *var_type = nullptr;5955 IrInstruction *var_type = nullptr;
5956 bool is_shadowable = false;5956 bool is_shadowable = false;
5957 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);5957 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
5958 VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope,5958 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5959 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);5959 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
59605960
5961 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);5961 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);
...@@ -5981,7 +5981,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5981,7 +5981,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
5981 IrInstruction *var_type = nullptr;5981 IrInstruction *var_type = nullptr;
5982 bool is_shadowable = false;5982 bool is_shadowable = false;
5983 bool is_const = true;5983 bool is_const = true;
5984 VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope,5984 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5985 err_symbol, is_const, is_const, is_shadowable, is_comptime);5985 err_symbol, is_const, is_const, is_shadowable, is_comptime);
59865986
5987 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);5987 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
...@@ -6029,7 +6029,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit...@@ -6029,7 +6029,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
60296029
6030 bool is_shadowable = false;6030 bool is_shadowable = false;
6031 bool is_const = true;6031 bool is_const = true;
6032 VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope,6032 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
6033 var_name, is_const, is_const, is_shadowable, var_is_comptime);6033 var_name, is_const, is_const, is_shadowable, var_is_comptime);
6034 child_scope = var->child_scope;6034 child_scope = var->child_scope;
6035 IrInstruction *var_value;6035 IrInstruction *var_value;
...@@ -6494,7 +6494,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN...@@ -6494,7 +6494,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
6494 Buf *var_name = var_node->data.symbol_expr.symbol;6494 Buf *var_name = var_node->data.symbol_expr.symbol;
6495 bool is_const = true;6495 bool is_const = true;
6496 bool is_shadowable = false;6496 bool is_shadowable = false;
6497 VariableTableEntry *var = ir_create_var(irb, node, parent_scope, var_name,6497 ZigVar *var = ir_create_var(irb, node, parent_scope, var_name,
6498 is_const, is_const, is_shadowable, is_comptime);6498 is_const, is_const, is_shadowable, is_comptime);
6499 err_scope = var->child_scope;6499 err_scope = var->child_scope;
6500 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);6500 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
...@@ -6976,7 +6976,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -6976,7 +6976,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
6976 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b0016976 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
6977 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b0106977 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
69786978
6979 VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr,6979 ZigVar *result_var = ir_create_var(irb, node, scope, nullptr,
6980 false, false, true, const_bool_false);6980 false, false, true, const_bool_false);
6981 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);6981 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
6982 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);6982 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
...@@ -7388,12 +7388,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7388,12 +7388,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7388 IrInstruction *err_ret_trace_ptr;7388 IrInstruction *err_ret_trace_ptr;
7389 ZigType *return_type;7389 ZigType *return_type;
7390 Buf *result_ptr_field_name;7390 Buf *result_ptr_field_name;
7391 VariableTableEntry *coro_size_var;7391 ZigVar *coro_size_var;
7392 if (is_async) {7392 if (is_async) {
7393 // create the coro promise7393 // create the coro promise
7394 Scope *coro_scope = create_coro_prelude_scope(node, scope);7394 Scope *coro_scope = create_coro_prelude_scope(node, scope);
7395 const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);7395 const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);
7396 VariableTableEntry *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7396 ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
73977397
7398 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;7398 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
7399 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);7399 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);
...@@ -7403,7 +7403,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7403,7 +7403,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7403 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);7403 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
7404 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);7404 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
74057405
7406 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7406 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7407 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);7407 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
7408 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,7408 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
7409 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));7409 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
...@@ -12518,7 +12518,7 @@ static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp...@@ -12518,7 +12518,7 @@ static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp
1251812518
12519static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {12519static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {
12520 Error err;12520 Error err;
12521 VariableTableEntry *var = decl_var_instruction->var;12521 ZigVar *var = decl_var_instruction->var;
1252212522
12523 IrInstruction *init_value = decl_var_instruction->init_value->other;12523 IrInstruction *init_value = decl_var_instruction->init_value->other;
12524 if (type_is_invalid(init_value->value.type)) {12524 if (type_is_invalid(init_value->value.type)) {
...@@ -12591,7 +12591,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec...@@ -12591,7 +12591,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec
12591 // This means that this is actually a different variable due to, e.g. an inline while loop.12591 // This means that this is actually a different variable due to, e.g. an inline while loop.
12592 // We make a new variable so that it can hold a different type, and so the debug info can12592 // We make a new variable so that it can hold a different type, and so the debug info can
12593 // be distinct.12593 // be distinct.
12594 VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,12594 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
12595 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);12595 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);
12596 new_var->owner_exec = var->owner_exec;12596 new_var->owner_exec = var->owner_exec;
12597 new_var->align_bytes = var->align_bytes;12597 new_var->align_bytes = var->align_bytes;
...@@ -12902,7 +12902,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i...@@ -12902,7 +12902,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
12902 }12902 }
12903 case ImplicitAllocatorIdLocalVar:12903 case ImplicitAllocatorIdLocalVar:
12904 {12904 {
12905 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;12905 ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
12906 assert(coro_allocator_var != nullptr);12906 assert(coro_allocator_var != nullptr);
12907 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);12907 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
12908 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);12908 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
...@@ -12977,7 +12977,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -12977,7 +12977,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
12977 return false;12977 return false;
1297812978
12979 Buf *param_name = param_decl_node->data.param_decl.name;12979 Buf *param_name = param_decl_node->data.param_decl.name;
12980 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,12980 ZigVar *var = add_variable(ira->codegen, param_decl_node,
12981 *exec_scope, param_name, true, arg_val, nullptr);12981 *exec_scope, param_name, true, arg_val, nullptr);
12982 *exec_scope = var->child_scope;12982 *exec_scope = var->child_scope;
12983 *next_proto_i += 1;12983 *next_proto_i += 1;
...@@ -13035,7 +13035,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -13035,7 +13035,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
13035 Buf *param_name = param_decl_node->data.param_decl.name;13035 Buf *param_name = param_decl_node->data.param_decl.name;
13036 if (!param_name) return false;13036 if (!param_name) return false;
13037 if (!is_var_args) {13037 if (!is_var_args) {
13038 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,13038 ZigVar *var = add_variable(ira->codegen, param_decl_node,
13039 *child_scope, param_name, true, arg_val, nullptr);13039 *child_scope, param_name, true, arg_val, nullptr);
13040 *child_scope = var->child_scope;13040 *child_scope = var->child_scope;
13041 var->shadowable = !comptime_arg;13041 var->shadowable = !comptime_arg;
...@@ -13067,7 +13067,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -13067,7 +13067,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
13067 return true;13067 return true;
13068}13068}
1306913069
13070static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {13070static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {
13071 size_t next_var_i = 0;13071 size_t next_var_i = 0;
13072 FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;13072 FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;
13073 assert(gen_param_info != nullptr);13073 assert(gen_param_info != nullptr);
...@@ -13086,7 +13086,7 @@ static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {...@@ -13086,7 +13086,7 @@ static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {
13086}13086}
1308713087
13088static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,13088static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13089 VariableTableEntry *var)13089 ZigVar *var)
13090{13090{
13091 Error err;13091 Error err;
13092 while (var->next_var != nullptr) {13092 while (var->next_var != nullptr) {
...@@ -13449,7 +13449,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13449,7 +13449,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13449 found_first_var_arg = true;13449 found_first_var_arg = true;
13450 }13450 }
1345113451
13452 VariableTableEntry *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);13452 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
13453 if (arg_var == nullptr) {13453 if (arg_var == nullptr) {
13454 ir_add_error(ira, arg,13454 ir_add_error(ira, arg,
13455 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));13455 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
...@@ -13496,7 +13496,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13496,7 +13496,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
1349613496
13497 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,13497 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,
13498 first_var_arg, inst_fn_type_id.param_count);13498 first_var_arg, inst_fn_type_id.param_count);
13499 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,13499 ZigVar *var = add_variable(ira->codegen, param_decl_node,
13500 impl_fn->child_scope, param_name, true, var_args_val, nullptr);13500 impl_fn->child_scope, param_name, true, var_args_val, nullptr);
13501 impl_fn->child_scope = var->child_scope;13501 impl_fn->child_scope = var->child_scope;
13502 }13502 }
...@@ -14158,7 +14158,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi...@@ -14158,7 +14158,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi
14158}14158}
1415914159
14160static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,14160static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
14161 VariableTableEntry *var)14161 ZigVar *var)
14162{14162{
14163 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);14163 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
14164 ir_link_new_instruction(result, instruction);14164 ir_link_new_instruction(result, instruction);
...@@ -14166,7 +14166,7 @@ static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -14166,7 +14166,7 @@ static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
14166}14166}
1416714167
14168static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {14168static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
14169 VariableTableEntry *var = var_ptr_instruction->var;14169 ZigVar *var = var_ptr_instruction->var;
14170 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);14170 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
14171}14171}
1417214172
...@@ -14291,7 +14291,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14291,7 +14291,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14291 size_t abs_index = start + index;14291 size_t abs_index = start + index;
14292 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);14292 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
14293 assert(fn_entry);14293 assert(fn_entry);
14294 VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index);14294 ZigVar *var = get_fn_var_by_index(fn_entry, abs_index);
14295 bool is_const = true;14295 bool is_const = true;
14296 bool is_volatile = false;14296 bool is_volatile = false;
14297 if (var) {14297 if (var) {
...@@ -14693,7 +14693,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru...@@ -14693,7 +14693,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru
14693 case TldIdVar:14693 case TldIdVar:
14694 {14694 {
14695 TldVar *tld_var = (TldVar *)tld;14695 TldVar *tld_var = (TldVar *)tld;
14696 VariableTableEntry *var = tld_var->var;14696 ZigVar *var = tld_var->var;
14697 if (tld_var->extern_lib_name != nullptr) {14697 if (tld_var->extern_lib_name != nullptr) {
14698 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);14698 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
14699 }14699 }
...@@ -16976,7 +16976,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -16976,7 +16976,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
16976 TldVar *tld = (TldVar *)entry;16976 TldVar *tld = (TldVar *)entry;
16977 assert(tld->base.id == TldIdVar);16977 assert(tld->base.id == TldIdVar);
1697816978
16979 VariableTableEntry *var = tld->var;16979 ZigVar *var = tld->var;
1698016980
16981 if ((err = ensure_complete_type(ira->codegen, var->value->type)))16981 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
16982 return ira->codegen->builtin_types.entry_invalid;16982 return ira->codegen->builtin_types.entry_invalid;
...@@ -17074,7 +17074,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -17074,7 +17074,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
17074 switch (curr_entry->value->id) {17074 switch (curr_entry->value->id) {
17075 case TldIdVar:17075 case TldIdVar:
17076 {17076 {
17077 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;17077 ZigVar *var = ((TldVar *)curr_entry->value)->var;
17078 if ((err = ensure_complete_type(ira->codegen, var->value->type)))17078 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
17079 return ErrorSemanticAnalyzeFail;17079 return ErrorSemanticAnalyzeFail;
1708017080
...@@ -17191,7 +17191,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -17191,7 +17191,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1719117191
17192 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)17192 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)
17193 {17193 {
17194 VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index);17194 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
17195 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];17195 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];
17196 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);17196 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);
17197 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);17197 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);
...@@ -20317,7 +20317,7 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -20317,7 +20317,7 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20317 case TldIdVar:20317 case TldIdVar:
20318 {20318 {
20319 TldVar *tld_var = (TldVar *)tld;20319 TldVar *tld_var = (TldVar *)tld;
20320 VariableTableEntry *var = tld_var->var;20320 ZigVar *var = tld_var->var;
2032120321
20322 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);20322 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
20323 if (type_is_invalid(var_ptr->value.type))20323 if (type_is_invalid(var_ptr->value.type))