authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-27 21:07:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 12:58:40-07:00
log554dd52c36711e9b07f35e20c3427027ad2fa60f
tree23e81f39de48c91eef233aa594aa6bae82cc018f
parent4ea421f8cb3afc01f6822227b48123dd4844ec07

stage1: remove c_import_buf from Stage1Zir

All we need is a boolean in Stage1AstGen. This is part of an effort to make Stage1Zir immutable.

4 files changed, 12 insertions(+), 13 deletions(-)

src/stage1/all_types.hpp-1
...@@ -114,7 +114,6 @@ struct Stage1Zir {...@@ -114,7 +114,6 @@ 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 Buf *c_import_buf;
118 AstNode *source_node;117 AstNode *source_node;
119 Scope *begin_scope;118 Scope *begin_scope;
120 ErrorMsg *first_err_trace_msg;119 ErrorMsg *first_err_trace_msg;
src/stage1/astgen.cpp+7-9
...@@ -18,6 +18,7 @@ struct Stage1AstGen {...@@ -18,6 +18,7 @@ struct Stage1AstGen {
18 AstNode *main_block_node;18 AstNode *main_block_node;
19 size_t next_debug_id;19 size_t next_debug_id;
20 ZigFn *fn;20 ZigFn *fn;
21 bool in_c_import_scope;
21};22};
2223
23static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope);24static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope);
...@@ -369,10 +370,6 @@ static size_t irb_next_debug_id(Stage1AstGen *ag) {...@@ -369,10 +370,6 @@ static size_t irb_next_debug_id(Stage1AstGen *ag) {
369 return result;370 return result;
370}371}
371372
372static Buf *exec_c_import_buf(Stage1Zir *exec) {
373 return exec->c_import_buf;
374}
375
376static void ir_ref_bb(IrBasicBlockSrc *bb) {373static void ir_ref_bb(IrBasicBlockSrc *bb) {
377 bb->ref_count += 1;374 bb->ref_count += 1;
378}375}
...@@ -4215,7 +4212,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode...@@ -4215,7 +4212,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
4215 if (arg0_value == ag->codegen->invalid_inst_src)4212 if (arg0_value == ag->codegen->invalid_inst_src)
4216 return arg0_value;4213 return arg0_value;
42174214
4218 if (!exec_c_import_buf(ag->exec)) {4215 if (!ag->in_c_import_scope) {
4219 add_node_error(ag->codegen, node, buf_sprintf("C include valid only inside C import block"));4216 add_node_error(ag->codegen, node, buf_sprintf("C include valid only inside C import block"));
4220 return ag->codegen->invalid_inst_src;4217 return ag->codegen->invalid_inst_src;
4221 }4218 }
...@@ -4235,7 +4232,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode...@@ -4235,7 +4232,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
4235 if (arg1_value == ag->codegen->invalid_inst_src)4232 if (arg1_value == ag->codegen->invalid_inst_src)
4236 return arg1_value;4233 return arg1_value;
42374234
4238 if (!exec_c_import_buf(ag->exec)) {4235 if (!ag->in_c_import_scope) {
4239 add_node_error(ag->codegen, node, buf_sprintf("C define valid only inside C import block"));4236 add_node_error(ag->codegen, node, buf_sprintf("C define valid only inside C import block"));
4240 return ag->codegen->invalid_inst_src;4237 return ag->codegen->invalid_inst_src;
4241 }4238 }
...@@ -4250,7 +4247,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode...@@ -4250,7 +4247,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
4250 if (arg0_value == ag->codegen->invalid_inst_src)4247 if (arg0_value == ag->codegen->invalid_inst_src)
4251 return arg0_value;4248 return arg0_value;
42524249
4253 if (!exec_c_import_buf(ag->exec)) {4250 if (!ag->in_c_import_scope) {
4254 add_node_error(ag->codegen, node, buf_sprintf("C undef valid only inside C import block"));4251 add_node_error(ag->codegen, node, buf_sprintf("C undef valid only inside C import block"));
4255 return ag->codegen->invalid_inst_src;4252 return ag->codegen->invalid_inst_src;
4256 }4253 }
...@@ -8035,7 +8032,7 @@ static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {...@@ -8035,7 +8032,7 @@ static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {
8035}8032}
80368033
8037bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable,8034bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable,
8038 ZigFn *fn)8035 ZigFn *fn, bool in_c_import_scope)
8039{8036{
8040 assert(node->owner);8037 assert(node->owner);
80418038
...@@ -8044,6 +8041,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_...@@ -8044,6 +8041,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
80448041
8045 ag->codegen = codegen;8042 ag->codegen = codegen;
8046 ag->fn = fn;8043 ag->fn = fn;
8044 ag->in_c_import_scope = in_c_import_scope;
8047 ag->exec = ir_executable;8045 ag->exec = ir_executable;
8048 ag->main_block_node = node;8046 ag->main_block_node = node;
80498047
...@@ -8078,7 +8076,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_...@@ -8078,7 +8076,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
8078bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {8076bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {
8079 assert(fn != nullptr);8077 assert(fn != nullptr);
8080 assert(fn->child_scope != nullptr);8078 assert(fn->child_scope != nullptr);
8081 return stage1_astgen(codegen, fn->body_node, fn->child_scope, fn->ir_executable, fn);8079 return stage1_astgen(codegen, fn->body_node, fn->child_scope, fn->ir_executable, fn, false);
8082}8080}
80838081
8084void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {8082void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {
src/stage1/astgen.hpp+2-1
...@@ -10,7 +10,8 @@...@@ -10,7 +10,8 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13bool stage1_astgen(CodeGen *g, AstNode *node, Scope *scope, Stage1Zir *ir_executable, ZigFn *fn);13bool stage1_astgen(CodeGen *g, AstNode *node, Scope *scope, Stage1Zir *ir_executable,
14 ZigFn *fn, bool in_c_import_scope);
14bool stage1_astgen_fn(CodeGen *g, ZigFn *fn_entry);15bool stage1_astgen_fn(CodeGen *g, ZigFn *fn_entry);
1516
16bool ir_inst_src_has_side_effects(IrInstSrc *inst);17bool ir_inst_src_has_side_effects(IrInstSrc *inst);
src/stage1/ir.cpp+3-2
...@@ -5596,10 +5596,11 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -5596,10 +5596,11 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
5596 ir_executable->source_node = source_node;5596 ir_executable->source_node = source_node;
5597 ir_executable->name = exec_name;5597 ir_executable->name = exec_name;
5598 ir_executable->is_inline = true;5598 ir_executable->is_inline = true;
5599 ir_executable->c_import_buf = c_import_buf;
5600 ir_executable->begin_scope = scope;5599 ir_executable->begin_scope = scope;
56015600
5602 if (!stage1_astgen(codegen, node, scope, ir_executable, fn_entry))5601 bool in_c_import_scope = c_import_buf != nullptr;
5602
5603 if (!stage1_astgen(codegen, node, scope, ir_executable, fn_entry, in_c_import_scope))
5603 return ErrorSemanticAnalyzeFail;5604 return ErrorSemanticAnalyzeFail;
56045605
5605 if (ir_executable->first_err_trace_msg != nullptr) {5606 if (ir_executable->first_err_trace_msg != nullptr) {