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 {
114114 ZigList<IrBasicBlockSrc *> basic_block_list;
115115 Buf *name;
116116 ZigFn *name_fn;
117 AstNode *source_node;
118117 Scope *begin_scope;
119118 ErrorMsg *first_err_trace_msg;
120119 ZigList<Tld *> tld_list;
121120
122121 bool is_inline;
123122 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();
128123};
129124
130125struct Stage1Air {
......@@ -1638,7 +1633,7 @@ struct ZigFn {
16381633 // in the case of async functions this is the implicit return type according to the
16391634 // zig source code, not according to zig ir
16401635 ZigType *src_implicit_return_type;
1641 Stage1Zir *ir_executable;
1636 Stage1Zir *stage1_zir;
16421637 Stage1Air analyzed_executable;
16431638 size_t branch_quota;
16441639 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
36533653
36543654static ZigFn *create_fn_raw(CodeGen *g, bool is_noinline) {
36553655 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>();
36573657 fn_entry->is_noinline = is_noinline;
36583658
36593659 return fn_entry;
......@@ -5129,7 +5129,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
51295129 }
51305130 size_t backward_branch_count = 0;
51315131 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,
51335133 &backward_branch_count, &backward_branch_quota,
51345134 fn_type_id->return_type, return_type_node, nullptr, fn);
51355135 fn->src_implicit_return_type = block_return_type;
......@@ -5233,14 +5233,14 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
52335233 return;
52345234 }
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) {
52375237 fn_table_entry->anal_state = FnAnalStateInvalid;
52385238 return;
52395239 }
52405240
52415241 if (g->verbose_ir) {
52425242 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);
52445244 fprintf(stderr, "}\n");
52455245 }
52465246
......@@ -9858,12 +9858,6 @@ void AstNode::src() {
98589858 line, column);
98599859}
98609860
9861void Stage1Zir::src() {
9862 if (this->source_node != nullptr) {
9863 this->source_node->src();
9864 }
9865}
9866
98679861void Stage1Air::src() {
98689862 Stage1Air *it;
98699863 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) {
80318031 return ir_gen_node_extra(ag, node, scope, LValNone, nullptr);
80328032}
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,
80358035 ZigFn *fn, bool in_c_import_scope)
80368036{
80378037 assert(node->owner);
......@@ -8042,7 +8042,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
80428042 ag->codegen = codegen;
80438043 ag->fn = fn;
80448044 ag->in_c_import_scope = in_c_import_scope;
8045 ag->exec = ir_executable;
8045 ag->exec = stage1_zir;
80468046 ag->main_block_node = node;
80478047
80488048 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_
80768076bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {
80778077 assert(fn != nullptr);
80788078 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);
80808080}
80818081
80828082void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {
src/stage1/astgen.hpp+1-1
......@@ -10,7 +10,7 @@
1010
1111#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,
1414 ZigFn *fn, bool in_c_import_scope);
1515bool 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,
55925592 if (type_is_invalid(return_ptr->type))
55935593 return ErrorSemanticAnalyzeFail;
55945594
5595 Stage1Zir *ir_executable = heap::c_allocator.create<Stage1Zir>();
5596 ir_executable->source_node = source_node;
5597 ir_executable->name = exec_name;
5598 ir_executable->is_inline = true;
5599 ir_executable->begin_scope = scope;
5595 Stage1Zir *stage1_zir = heap::c_allocator.create<Stage1Zir>();
5596 stage1_zir->name = exec_name;
5597 stage1_zir->is_inline = true;
5598 stage1_zir->begin_scope = scope;
56005599
56015600 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))
56045603 return ErrorSemanticAnalyzeFail;
56055604
5606 if (ir_executable->first_err_trace_msg != nullptr) {
5607 codegen->trace_err = ir_executable->first_err_trace_msg;
5605 if (stage1_zir->first_err_trace_msg != nullptr) {
5606 codegen->trace_err = stage1_zir->first_err_trace_msg;
56085607 return ErrorSemanticAnalyzeFail;
56095608 }
56105609
56115610 if (codegen->verbose_ir) {
56125611 fprintf(stderr, "\n{ // (IR)\n");
5613 ir_print_src(codegen, stderr, ir_executable, 2);
5612 ir_print_src(codegen, stderr, stage1_zir, 2);
56145613 fprintf(stderr, "}\n");
56155614 }
56165615 Stage1Air *analyzed_executable = heap::c_allocator.create<Stage1Air>();
56175616 analyzed_executable->source_node = source_node;
56185617 analyzed_executable->parent_exec = parent_exec;
5619 analyzed_executable->source_exec = ir_executable;
5618 analyzed_executable->source_exec = stage1_zir;
56205619 analyzed_executable->name = exec_name;
56215620 analyzed_executable->is_inline = true;
56225621 analyzed_executable->c_import_buf = c_import_buf;
56235622 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,
56255624 backward_branch_count, backward_branch_quota,
56265625 return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr,
56275626 fn_entry);
......@@ -12935,7 +12934,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1293512934 if (type_is_invalid(impl_fn->type_entry))
1293612935 return ira->codegen->invalid_inst_gen;
1293712936
12938 impl_fn->ir_executable->source_node = source_instr->source_node;
1293912937 impl_fn->analyzed_executable.source_node = source_instr->source_node;
1294012938 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
1294112939 impl_fn->branch_quota = *ira->backward_branch_quota;