| author | |
| committer | |
| log | d4f2394dcf8e5fc9e5be26c3022f8ce435b722a8 |
| tree | 3e81d18b3b8394cd7539dd0a91a8af10dfc07950 |
| parent | a5c9da0de2d0e2bace3127ba47bd43f5333724c4 |
4 files changed, 36 insertions(+), 27 deletions(-)
src/analyze.cpp+7-3| ... | @@ -847,7 +847,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo | ... | @@ -847,7 +847,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo |
| 847 | return g->invalid_instruction; | 847 | return g->invalid_instruction; |
| 848 | 848 | ||
| 849 | if (g->verbose) { | 849 | if (g->verbose) { |
| 850 | fprintf(stderr, "{\n"); | 850 | fprintf(stderr, "\nSource: "); |
| 851 | ast_render(stderr, node, 4); | ||
| 852 | fprintf(stderr, "\n{ // (IR)\n"); | ||
| 851 | ir_print(stderr, &ir_executable, 4); | 853 | ir_print(stderr, &ir_executable, 4); |
| 852 | fprintf(stderr, "}\n"); | 854 | fprintf(stderr, "}\n"); |
| 853 | } | 855 | } |
| ... | @@ -2573,7 +2575,9 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { | ... | @@ -2573,7 +2575,9 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 2573 | return; | 2575 | return; |
| 2574 | } | 2576 | } |
| 2575 | if (g->verbose) { | 2577 | if (g->verbose) { |
| 2576 | fprintf(stderr, "fn %s {\n", buf_ptr(&fn_table_entry->symbol_name)); | 2578 | fprintf(stderr, "\n"); |
| 2579 | ast_render(stderr, fn_table_entry->fn_def_node, 4); | ||
| 2580 | fprintf(stderr, "\n{ // (IR)\n"); | ||
| 2577 | ir_print(stderr, &fn_table_entry->ir_executable, 4); | 2581 | ir_print(stderr, &fn_table_entry->ir_executable, 4); |
| 2578 | fprintf(stderr, "}\n"); | 2582 | fprintf(stderr, "}\n"); |
| 2579 | } | 2583 | } |
| ... | @@ -2583,7 +2587,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { | ... | @@ -2583,7 +2587,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 2583 | node->data.fn_def.implicit_return_type = block_return_type; | 2587 | node->data.fn_def.implicit_return_type = block_return_type; |
| 2584 | 2588 | ||
| 2585 | if (block_return_type->id != TypeTableEntryIdInvalid && g->verbose) { | 2589 | if (block_return_type->id != TypeTableEntryIdInvalid && g->verbose) { |
| 2586 | fprintf(stderr, "fn %s { // (analyzed)\n", buf_ptr(&fn_table_entry->symbol_name)); | 2590 | fprintf(stderr, "{ // (analyzed)\n"); |
| 2587 | ir_print(stderr, &fn_table_entry->analyzed_executable, 4); | 2591 | ir_print(stderr, &fn_table_entry->analyzed_executable, 4); |
| 2588 | fprintf(stderr, "}\n"); | 2592 | fprintf(stderr, "}\n"); |
| 2589 | } | 2593 | } |
src/ast_render.cpp-2| ... | @@ -655,7 +655,5 @@ void ast_render(FILE *f, AstNode *node, int indent_size) { | ... | @@ -655,7 +655,5 @@ void ast_render(FILE *f, AstNode *node, int indent_size) { |
| 655 | ar.indent_size = indent_size; | 655 | ar.indent_size = indent_size; |
| 656 | ar.indent = 0; | 656 | ar.indent = 0; |
| 657 | 657 | ||
| 658 | assert(node->type == NodeTypeRoot); | ||
| 659 | |||
| 660 | render_node(&ar, node); | 658 | render_node(&ar, node); |
| 661 | } | 659 | } |
src/codegen.cpp+4-3| ... | @@ -2212,7 +2212,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2212,7 +2212,7 @@ static void do_code_gen(CodeGen *g) { |
| 2212 | if (!type_has_bits(var->type)) { | 2212 | if (!type_has_bits(var->type)) { |
| 2213 | continue; | 2213 | continue; |
| 2214 | } | 2214 | } |
| 2215 | if (var->ref_count == 0) | 2215 | if (var->is_inline) |
| 2216 | continue; | 2216 | continue; |
| 2217 | 2217 | ||
| 2218 | if (var->block_context->node->type == NodeTypeFnDef) { | 2218 | if (var->block_context->node->type == NodeTypeFnDef) { |
| ... | @@ -2257,6 +2257,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2257,6 +2257,7 @@ static void do_code_gen(CodeGen *g) { |
| 2257 | 2257 | ||
| 2258 | VariableTableEntry *variable = param_decl->data.param_decl.variable; | 2258 | VariableTableEntry *variable = param_decl->data.param_decl.variable; |
| 2259 | assert(variable); | 2259 | assert(variable); |
| 2260 | assert(variable->value_ref); | ||
| 2260 | 2261 | ||
| 2261 | if (!handle_is_ptr(variable->type)) { | 2262 | if (!handle_is_ptr(variable->type)) { |
| 2262 | clear_debug_source_node(g); | 2263 | clear_debug_source_node(g); |
| ... | @@ -3015,8 +3016,8 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou | ... | @@ -3015,8 +3016,8 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou |
| 3015 | } | 3016 | } |
| 3016 | 3017 | ||
| 3017 | if (g->verbose) { | 3018 | if (g->verbose) { |
| 3018 | fprintf(stderr, "\nSemantic Analysis:\n"); | 3019 | fprintf(stderr, "\nIR Generation and Semantic Analysis:\n"); |
| 3019 | fprintf(stderr, "--------------------\n"); | 3020 | fprintf(stderr, "--------------------------------------\n"); |
| 3020 | } | 3021 | } |
| 3021 | if (!g->error_during_imports) { | 3022 | if (!g->error_during_imports) { |
| 3022 | semantic_analyze(g); | 3023 | semantic_analyze(g); |
src/ir.cpp+25-19| ... | @@ -3389,27 +3389,33 @@ static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -3389,27 +3389,33 @@ static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstruct |
| 3389 | if (var->type->id == TypeTableEntryIdInvalid) | 3389 | if (var->type->id == TypeTableEntryIdInvalid) |
| 3390 | return var->type; | 3390 | return var->type; |
| 3391 | 3391 | ||
| 3392 | zig_panic("TODO if var is a global, this code is wrong"); | ||
| 3393 | |||
| 3394 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, var->type, false); | 3392 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, var->type, false); |
| 3395 | // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing. | ||
| 3396 | if (var->mem_slot_index != SIZE_MAX) { | ||
| 3397 | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; | ||
| 3398 | if (mem_slot->ok) { | ||
| 3399 | zig_panic("TODO do we really want to set up this fake pointer to do constant evaluation?"); | ||
| 3400 | ConstExprValue *out_val = ir_build_const_from(ira, &var_ptr_instruction->base, | ||
| 3401 | mem_slot->depends_on_compile_var); | ||
| 3402 | |||
| 3403 | out_val->data.x_ptr.len = 1; | ||
| 3404 | out_val->data.x_ptr.is_c_str = false; | ||
| 3405 | out_val->data.x_ptr.ptr = allocate<ConstExprValue *>(1); | ||
| 3406 | out_val->data.x_ptr.ptr[0] = mem_slot; | ||
| 3407 | return ptr_type; | ||
| 3408 | } | ||
| 3409 | } | ||
| 3410 | 3393 | ||
| 3411 | ir_build_var_ptr_from(&ira->new_irb, &var_ptr_instruction->base, var); | 3394 | ConstExprValue *mem_slot = nullptr; |
| 3412 | return ptr_type; | 3395 | if (var->block_context->fn_entry) { |
| 3396 | // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing. | ||
| 3397 | if (var->mem_slot_index != SIZE_MAX) | ||
| 3398 | mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; | ||
| 3399 | } else if (var->src_is_const) { | ||
| 3400 | AstNode *var_decl_node = var->decl_node; | ||
| 3401 | assert(var_decl_node->type == NodeTypeVariableDeclaration); | ||
| 3402 | mem_slot = &get_resolved_expr(var_decl_node->data.variable_declaration.expr)->const_val; | ||
| 3403 | assert(mem_slot->ok); | ||
| 3404 | } | ||
| 3405 | |||
| 3406 | if (mem_slot && mem_slot->ok) { | ||
| 3407 | ConstExprValue *out_val = ir_build_const_from(ira, &var_ptr_instruction->base, | ||
| 3408 | mem_slot->depends_on_compile_var); | ||
| 3409 | |||
| 3410 | out_val->data.x_ptr.len = 1; | ||
| 3411 | out_val->data.x_ptr.is_c_str = false; | ||
| 3412 | out_val->data.x_ptr.ptr = allocate<ConstExprValue *>(1); | ||
| 3413 | out_val->data.x_ptr.ptr[0] = mem_slot; | ||
| 3414 | return ptr_type; | ||
| 3415 | } else { | ||
| 3416 | ir_build_var_ptr_from(&ira->new_irb, &var_ptr_instruction->base, var); | ||
| 3417 | return ptr_type; | ||
| 3418 | } | ||
| 3413 | } | 3419 | } |
| 3414 | 3420 | ||
| 3415 | static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { | 3421 | static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |