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 {
114114 ZigList<IrBasicBlockSrc *> basic_block_list;
115115 Buf *name;
116116 ZigFn *name_fn;
117 Buf *c_import_buf;
118117 AstNode *source_node;
119118 Scope *begin_scope;
120119 ErrorMsg *first_err_trace_msg;
src/stage1/astgen.cpp+7-9
......@@ -18,6 +18,7 @@ struct Stage1AstGen {
1818 AstNode *main_block_node;
1919 size_t next_debug_id;
2020 ZigFn *fn;
21 bool in_c_import_scope;
2122};
2223
2324static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope);
......@@ -369,10 +370,6 @@ static size_t irb_next_debug_id(Stage1AstGen *ag) {
369370 return result;
370371}
371372
372static Buf *exec_c_import_buf(Stage1Zir *exec) {
373 return exec->c_import_buf;
374}
375
376373static void ir_ref_bb(IrBasicBlockSrc *bb) {
377374 bb->ref_count += 1;
378375}
......@@ -4215,7 +4212,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
42154212 if (arg0_value == ag->codegen->invalid_inst_src)
42164213 return arg0_value;
42174214
4218 if (!exec_c_import_buf(ag->exec)) {
4215 if (!ag->in_c_import_scope) {
42194216 add_node_error(ag->codegen, node, buf_sprintf("C include valid only inside C import block"));
42204217 return ag->codegen->invalid_inst_src;
42214218 }
......@@ -4235,7 +4232,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
42354232 if (arg1_value == ag->codegen->invalid_inst_src)
42364233 return arg1_value;
42374234
4238 if (!exec_c_import_buf(ag->exec)) {
4235 if (!ag->in_c_import_scope) {
42394236 add_node_error(ag->codegen, node, buf_sprintf("C define valid only inside C import block"));
42404237 return ag->codegen->invalid_inst_src;
42414238 }
......@@ -4250,7 +4247,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
42504247 if (arg0_value == ag->codegen->invalid_inst_src)
42514248 return arg0_value;
42524249
4253 if (!exec_c_import_buf(ag->exec)) {
4250 if (!ag->in_c_import_scope) {
42544251 add_node_error(ag->codegen, node, buf_sprintf("C undef valid only inside C import block"));
42554252 return ag->codegen->invalid_inst_src;
42564253 }
......@@ -8035,7 +8032,7 @@ static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) {
80358032}
80368033
80378034bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable,
8038 ZigFn *fn)
8035 ZigFn *fn, bool in_c_import_scope)
80398036{
80408037 assert(node->owner);
80418038
......@@ -8044,6 +8041,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
80448041
80458042 ag->codegen = codegen;
80468043 ag->fn = fn;
8044 ag->in_c_import_scope = in_c_import_scope;
80478045 ag->exec = ir_executable;
80488046 ag->main_block_node = node;
80498047
......@@ -8078,7 +8076,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_
80788076bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) {
80798077 assert(fn != nullptr);
80808078 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);
80828080}
80838081
80848082void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) {
src/stage1/astgen.hpp+2-1
......@@ -10,7 +10,8 @@
1010
1111#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);
1415bool stage1_astgen_fn(CodeGen *g, ZigFn *fn_entry);
1516
1617bool 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,
55965596 ir_executable->source_node = source_node;
55975597 ir_executable->name = exec_name;
55985598 ir_executable->is_inline = true;
5599 ir_executable->c_import_buf = c_import_buf;
56005599 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))
56035604 return ErrorSemanticAnalyzeFail;
56045605
56055606 if (ir_executable->first_err_trace_msg != nullptr) {