authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-27 21:23:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 12:58:40-07:00
log548ef780707eb2b438015c28d594a59a3f37ba3e
tree4d08a2a50ababf29bbbc38dbb8c3712b3dcf28b7
parent554dd52c36711e9b07f35e20c3427027ad2fa60f

stage1: remove source_node field from Stage1Zir

This field is unneeded because we always have the source node available in the context that we have a Stage1Zir object.

5 files changed, 19 insertions(+), 32 deletions(-)

src/stage1/all_types.hpp+1-6
...@@ -114,17 +114,12 @@ struct Stage1Zir {...@@ -114,17 +114,12 @@ struct Stage1Zir {
114 ZigList<IrBasicBlockSrc *> basic_block_list;114 ZigList<IrBasicBlockSrc *> basic_block_list;
115 Buf *name;115 Buf *name;
116 ZigFn *name_fn;116 ZigFn *name_fn;
117 AstNode *source_node;
118 Scope *begin_scope;117 Scope *begin_scope;
119 ErrorMsg *first_err_trace_msg;118 ErrorMsg *first_err_trace_msg;
120 ZigList<Tld *> tld_list;119 ZigList<Tld *> tld_list;
121120
122 bool is_inline;121 bool is_inline;
123 bool need_err_code_spill;122 bool need_err_code_spill;
124
125 // This is a function for use in the debugger to print
126 // the source location.
127 void src();
128};123};
129124
130struct Stage1Air {125struct Stage1Air {
...@@ -1638,7 +1633,7 @@ struct ZigFn {...@@ -1638,7 +1633,7 @@ struct ZigFn {
1638 // in the case of async functions this is the implicit return type according to the1633 // in the case of async functions this is the implicit return type according to the
1639 // zig source code, not according to zig ir1634 // zig source code, not according to zig ir
1640 ZigType *src_implicit_return_type;1635 ZigType *src_implicit_return_type;
1641 Stage1Zir *ir_executable;1636 Stage1Zir *stage1_zir;
1642 Stage1Air analyzed_executable;1637 Stage1Air analyzed_executable;
1643 size_t branch_quota;1638 size_t branch_quota;
1644 AstNode **param_source_nodes;1639 AstNode **param_source_nodes;
src/stage1/analyze.cpp+4-10
...@@ -3653,7 +3653,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i...@@ -3653,7 +3653,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
36533653
3654static ZigFn *create_fn_raw(CodeGen *g, bool is_noinline) {3654static ZigFn *create_fn_raw(CodeGen *g, bool is_noinline) {
3655 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();3655 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();
3656 fn_entry->ir_executable = heap::c_allocator.create<Stage1Zir>();3656 fn_entry->stage1_zir = heap::c_allocator.create<Stage1Zir>();
3657 fn_entry->is_noinline = is_noinline;3657 fn_entry->is_noinline = is_noinline;
36583658
3659 return fn_entry;3659 return fn_entry;
...@@ -5129,7 +5129,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -5129,7 +5129,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
5129 }5129 }
5130 size_t backward_branch_count = 0;5130 size_t backward_branch_count = 0;
5131 size_t backward_branch_quota = max(fn->branch_quota, default_backward_branch_quota);5131 size_t backward_branch_quota = max(fn->branch_quota, default_backward_branch_quota);
5132 ZigType *block_return_type = ir_analyze(g, fn->ir_executable, &fn->analyzed_executable,5132 ZigType *block_return_type = ir_analyze(g, fn->stage1_zir, &fn->analyzed_executable,
5133 &backward_branch_count, &backward_branch_quota,5133 &backward_branch_count, &backward_branch_quota,
5134 fn_type_id->return_type, return_type_node, nullptr, fn);5134 fn_type_id->return_type, return_type_node, nullptr, fn);
5135 fn->src_implicit_return_type = block_return_type;5135 fn->src_implicit_return_type = block_return_type;
...@@ -5233,14 +5233,14 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {...@@ -5233,14 +5233,14 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
5233 return;5233 return;
5234 }5234 }
52355235
5236 if (fn_table_entry->ir_executable->first_err_trace_msg != nullptr) {5236 if (fn_table_entry->stage1_zir->first_err_trace_msg != nullptr) {
5237 fn_table_entry->anal_state = FnAnalStateInvalid;5237 fn_table_entry->anal_state = FnAnalStateInvalid;
5238 return;5238 return;
5239 }5239 }
52405240
5241 if (g->verbose_ir) {5241 if (g->verbose_ir) {
5242 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));5242 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
5243 ir_print_src(g, stderr, fn_table_entry->ir_executable, 4);5243 ir_print_src(g, stderr, fn_table_entry->stage1_zir, 4);
5244 fprintf(stderr, "}\n");5244 fprintf(stderr, "}\n");
5245 }5245 }
52465246
...@@ -9858,12 +9858,6 @@ void AstNode::src() {...@@ -9858,12 +9858,6 @@ void AstNode::src() {
9858 line, column);9858 line, column);
9859}9859}
98609860
9861void Stage1Zir::src() {
9862 if (this->source_node != nullptr) {
9863 this->source_node->src();
9864 }
9865}
9866
9867void Stage1Air::src() {9861void Stage1Air::src() {
9868 Stage1Air *it;9862 Stage1Air *it;
9869 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {9863 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
src/stage1/astgen.cpp+3-3
...@@ -8031,7 +8031,7 @@ static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {...@@ -8031,7 +8031,7 @@ static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {
8031 return ir_gen_node_extra(ag, node, scope, LValNone, nullptr);8031 return ir_gen_node_extra(ag, node, scope, LValNone, nullptr);
8032}8032}
80338033
8034bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable,8034bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *stage1_zir,
8035 ZigFn *fn, bool in_c_import_scope)8035 ZigFn *fn, bool in_c_import_scope)
8036{8036{
8037 assert(node->owner);8037 assert(node->owner);
...@@ -8042,7 +8042,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_...@@ -8042,7 +8042,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
8042 ag->codegen = codegen;8042 ag->codegen = codegen;
8043 ag->fn = fn;8043 ag->fn = fn;
8044 ag->in_c_import_scope = in_c_import_scope;8044 ag->in_c_import_scope = in_c_import_scope;
8045 ag->exec = ir_executable;8045 ag->exec = stage1_zir;
8046 ag->main_block_node = node;8046 ag->main_block_node = node;
80478047
8048 IrBasicBlockSrc *entry_block = ir_create_basic_block(ag, scope, "Entry");8048 IrBasicBlockSrc *entry_block = ir_create_basic_block(ag, scope, "Entry");
...@@ -8076,7 +8076,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_...@@ -8076,7 +8076,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
8076bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {8076bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {
8077 assert(fn != nullptr);8077 assert(fn != nullptr);
8078 assert(fn->child_scope != nullptr);8078 assert(fn->child_scope != nullptr);
8079 return stage1_astgen(codegen, fn->body_node, fn->child_scope, fn->ir_executable, fn, false);8079 return stage1_astgen(codegen, fn->body_node, fn->child_scope, fn->stage1_zir, fn, false);
8080}8080}
80818081
8082void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {8082void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {
src/stage1/astgen.hpp+1-1
...@@ -10,7 +10,7 @@...@@ -10,7 +10,7 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13bool stage1_astgen(CodeGen *g, AstNode *node, Scope *scope, Stage1Zir *ir_executable,13bool stage1_astgen(CodeGen *g, AstNode *node, Scope *scope, Stage1Zir *stage1_zir,
14 ZigFn *fn, bool in_c_import_scope);14 ZigFn *fn, bool in_c_import_scope);
15bool stage1_astgen_fn(CodeGen *g, ZigFn *fn_entry);15bool stage1_astgen_fn(CodeGen *g, ZigFn *fn_entry);
1616
src/stage1/ir.cpp+10-12
...@@ -5592,36 +5592,35 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -5592,36 +5592,35 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
5592 if (type_is_invalid(return_ptr->type))5592 if (type_is_invalid(return_ptr->type))
5593 return ErrorSemanticAnalyzeFail;5593 return ErrorSemanticAnalyzeFail;
55945594
5595 Stage1Zir *ir_executable = heap::c_allocator.create<Stage1Zir>();5595 Stage1Zir *stage1_zir = heap::c_allocator.create<Stage1Zir>();
5596 ir_executable->source_node = source_node;5596 stage1_zir->name = exec_name;
5597 ir_executable->name = exec_name;5597 stage1_zir->is_inline = true;
5598 ir_executable->is_inline = true;5598 stage1_zir->begin_scope = scope;
5599 ir_executable->begin_scope = scope;
56005599
5601 bool in_c_import_scope = c_import_buf != nullptr;5600 bool in_c_import_scope = c_import_buf != nullptr;
56025601
5603 if (!stage1_astgen(codegen, node, scope, ir_executable, fn_entry, in_c_import_scope))5602 if (!stage1_astgen(codegen, node, scope, stage1_zir, fn_entry, in_c_import_scope))
5604 return ErrorSemanticAnalyzeFail;5603 return ErrorSemanticAnalyzeFail;
56055604
5606 if (ir_executable->first_err_trace_msg != nullptr) {5605 if (stage1_zir->first_err_trace_msg != nullptr) {
5607 codegen->trace_err = ir_executable->first_err_trace_msg;5606 codegen->trace_err = stage1_zir->first_err_trace_msg;
5608 return ErrorSemanticAnalyzeFail;5607 return ErrorSemanticAnalyzeFail;
5609 }5608 }
56105609
5611 if (codegen->verbose_ir) {5610 if (codegen->verbose_ir) {
5612 fprintf(stderr, "\n{ // (IR)\n");5611 fprintf(stderr, "\n{ // (IR)\n");
5613 ir_print_src(codegen, stderr, ir_executable, 2);5612 ir_print_src(codegen, stderr, stage1_zir, 2);
5614 fprintf(stderr, "}\n");5613 fprintf(stderr, "}\n");
5615 }5614 }
5616 Stage1Air *analyzed_executable = heap::c_allocator.create<Stage1Air>();5615 Stage1Air *analyzed_executable = heap::c_allocator.create<Stage1Air>();
5617 analyzed_executable->source_node = source_node;5616 analyzed_executable->source_node = source_node;
5618 analyzed_executable->parent_exec = parent_exec;5617 analyzed_executable->parent_exec = parent_exec;
5619 analyzed_executable->source_exec = ir_executable;5618 analyzed_executable->source_exec = stage1_zir;
5620 analyzed_executable->name = exec_name;5619 analyzed_executable->name = exec_name;
5621 analyzed_executable->is_inline = true;5620 analyzed_executable->is_inline = true;
5622 analyzed_executable->c_import_buf = c_import_buf;5621 analyzed_executable->c_import_buf = c_import_buf;
5623 analyzed_executable->begin_scope = scope;5622 analyzed_executable->begin_scope = scope;
5624 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable,5623 ZigType *result_type = ir_analyze(codegen, stage1_zir, analyzed_executable,
5625 backward_branch_count, backward_branch_quota,5624 backward_branch_count, backward_branch_quota,
5626 return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr,5625 return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr,
5627 fn_entry);5626 fn_entry);
...@@ -12935,7 +12934,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12935,7 +12934,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12935 if (type_is_invalid(impl_fn->type_entry))12934 if (type_is_invalid(impl_fn->type_entry))
12936 return ira->codegen->invalid_inst_gen;12935 return ira->codegen->invalid_inst_gen;
1293712936
12938 impl_fn->ir_executable->source_node = source_instr->source_node;
12939 impl_fn->analyzed_executable.source_node = source_instr->source_node;12937 impl_fn->analyzed_executable.source_node = source_instr->source_node;
12940 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;12938 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
12941 impl_fn->branch_quota = *ira->backward_branch_quota;12939 impl_fn->branch_quota = *ira->backward_branch_quota;