| ... | @@ -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 | }; |
| 22 | | 23 | |
| 23 | static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope); | 24 | static 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 | } |
| 371 | | 372 | |
| 372 | static Buf *exec_c_import_buf(Stage1Zir *exec) { | | |
| 373 | return exec->c_import_buf; | | |
| 374 | } | | |
| 375 | | | |
| 376 | static void ir_ref_bb(IrBasicBlockSrc *bb) { | 373 | static 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; |
| 4217 | | 4214 | |
| 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; |
| 4237 | | 4234 | |
| 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; |
| 4252 | | 4249 | |
| 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 | } |
| 8036 | | 8033 | |
| 8037 | bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *ir_executable, | 8034 | bool 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); |
| 8041 | | 8038 | |
| ... | @@ -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_ |
| 8044 | | 8041 | |
| 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; |
| 8049 | | 8047 | |
| ... | @@ -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_ |
| 8078 | bool stage1_astgen_fn(CodeGen *codegen, ZigFn *fn) { | 8076 | bool 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 | } |
| 8083 | | 8081 | |
| 8084 | void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) { | 8082 | void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg) { |