| author | |
| committer | |
| log | fe153ad2a435e26f9904f05858232305bdffd3ac |
| tree | aee8502f0627b5fd5027a180491487bf1fb56b5b |
| parent | fabf45f5fc0a1827913be5675130db5db514c136 |
- print fn name in pass1
- replace scalar with enum IrPass for clarity5 files changed, 19 insertions(+), 14 deletions(-)
src/analyze.cpp+3-3| ... | @@ -4418,7 +4418,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) { | ... | @@ -4418,7 +4418,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) { |
| 4418 | 4418 | ||
| 4419 | if (g->verbose_ir) { | 4419 | if (g->verbose_ir) { |
| 4420 | fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name)); | 4420 | fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name)); |
| 4421 | ir_print(g, stderr, &fn->analyzed_executable, 4, 2); | 4421 | ir_print(g, stderr, &fn->analyzed_executable, 4, IrPassGen); |
| 4422 | fprintf(stderr, "}\n"); | 4422 | fprintf(stderr, "}\n"); |
| 4423 | } | 4423 | } |
| 4424 | fn->anal_state = FnAnalStateComplete; | 4424 | fn->anal_state = FnAnalStateComplete; |
| ... | @@ -4451,8 +4451,8 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -4451,8 +4451,8 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 4451 | if (g->verbose_ir) { | 4451 | if (g->verbose_ir) { |
| 4452 | fprintf(stderr, "\n"); | 4452 | fprintf(stderr, "\n"); |
| 4453 | ast_render(stderr, fn_table_entry->body_node, 4); | 4453 | ast_render(stderr, fn_table_entry->body_node, 4); |
| 4454 | fprintf(stderr, "\n{ // (IR)\n"); | 4454 | fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name)); |
| 4455 | ir_print(g, stderr, &fn_table_entry->ir_executable, 4, 1); | 4455 | ir_print(g, stderr, &fn_table_entry->ir_executable, 4, IrPassSrc); |
| 4456 | fprintf(stderr, "}\n"); | 4456 | fprintf(stderr, "}\n"); |
| 4457 | } | 4457 | } |
| 4458 | 4458 |
src/ir.cpp+2-2| ... | @@ -10892,7 +10892,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod | ... | @@ -10892,7 +10892,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 10892 | fprintf(stderr, "\nSource: "); | 10892 | fprintf(stderr, "\nSource: "); |
| 10893 | ast_render(stderr, node, 4); | 10893 | ast_render(stderr, node, 4); |
| 10894 | fprintf(stderr, "\n{ // (IR)\n"); | 10894 | fprintf(stderr, "\n{ // (IR)\n"); |
| 10895 | ir_print(codegen, stderr, ir_executable, 2, 1); | 10895 | ir_print(codegen, stderr, ir_executable, 2, IrPassSrc); |
| 10896 | fprintf(stderr, "}\n"); | 10896 | fprintf(stderr, "}\n"); |
| 10897 | } | 10897 | } |
| 10898 | IrExecutable *analyzed_executable = allocate<IrExecutable>(1); | 10898 | IrExecutable *analyzed_executable = allocate<IrExecutable>(1); |
| ... | @@ -10913,7 +10913,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod | ... | @@ -10913,7 +10913,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 10913 | 10913 | ||
| 10914 | if (codegen->verbose_ir) { | 10914 | if (codegen->verbose_ir) { |
| 10915 | fprintf(stderr, "{ // (analyzed)\n"); | 10915 | fprintf(stderr, "{ // (analyzed)\n"); |
| 10916 | ir_print(codegen, stderr, analyzed_executable, 2, 2); | 10916 | ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen); |
| 10917 | fprintf(stderr, "}\n"); | 10917 | fprintf(stderr, "}\n"); |
| 10918 | } | 10918 | } |
| 10919 | 10919 |
src/ir.hpp+5| ... | @@ -10,6 +10,11 @@ | ... | @@ -10,6 +10,11 @@ |
| 10 | 10 | ||
| 11 | #include "all_types.hpp" | 11 | #include "all_types.hpp" |
| 12 | 12 | ||
| 13 | enum IrPass { | ||
| 14 | IrPassSrc, | ||
| 15 | IrPassGen, | ||
| 16 | }; | ||
| 17 | |||
| 13 | bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable); | 18 | bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable); |
| 14 | bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry); | 19 | bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry); |
| 15 | 20 |
src/ir_print.cpp+7-7| ... | @@ -22,7 +22,7 @@ using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, in | ... | @@ -22,7 +22,7 @@ using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, in |
| 22 | using InstructionList = ZigList<IrInstruction*>; | 22 | using InstructionList = ZigList<IrInstruction*>; |
| 23 | 23 | ||
| 24 | struct IrPrint { | 24 | struct IrPrint { |
| 25 | size_t pass_num; | 25 | IrPass pass; |
| 26 | CodeGen *codegen; | 26 | CodeGen *codegen; |
| 27 | FILE *f; | 27 | FILE *f; |
| 28 | int indent; | 28 | int indent; |
| ... | @@ -391,7 +391,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { | ... | @@ -391,7 +391,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { |
| 391 | 391 | ||
| 392 | static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) { | 392 | static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 393 | fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id); | 393 | fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id); |
| 394 | if (irp->pass_num == 2 && irp->printed.maybe_get(instruction) == nullptr) { | 394 | if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) { |
| 395 | irp->printed.put(instruction, 0); | 395 | irp->printed.put(instruction, 0); |
| 396 | irp->pending.append(instruction); | 396 | irp->pending.append(instruction); |
| 397 | } | 397 | } |
| ... | @@ -2399,10 +2399,10 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool | ... | @@ -2399,10 +2399,10 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool |
| 2399 | fprintf(irp->f, "\n"); | 2399 | fprintf(irp->f, "\n"); |
| 2400 | } | 2400 | } |
| 2401 | 2401 | ||
| 2402 | void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num) { | 2402 | void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) { |
| 2403 | IrPrint ir_print = {}; | 2403 | IrPrint ir_print = {}; |
| 2404 | IrPrint *irp = &ir_print; | 2404 | IrPrint *irp = &ir_print; |
| 2405 | irp->pass_num = pass_num; | 2405 | irp->pass = pass; |
| 2406 | irp->codegen = codegen; | 2406 | irp->codegen = codegen; |
| 2407 | irp->f = f; | 2407 | irp->f = f; |
| 2408 | irp->indent = indent_size; | 2408 | irp->indent = indent_size; |
| ... | @@ -2416,7 +2416,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si | ... | @@ -2416,7 +2416,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si |
| 2416 | fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id); | 2416 | fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id); |
| 2417 | for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) { | 2417 | for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) { |
| 2418 | IrInstruction *instruction = current_block->instruction_list.at(instr_i); | 2418 | IrInstruction *instruction = current_block->instruction_list.at(instr_i); |
| 2419 | if (irp->pass_num == 2) { | 2419 | if (irp->pass != IrPassSrc) { |
| 2420 | irp->printed.put(instruction, 0); | 2420 | irp->printed.put(instruction, 0); |
| 2421 | irp->pending.clear(); | 2421 | irp->pending.clear(); |
| 2422 | } | 2422 | } |
| ... | @@ -2430,10 +2430,10 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si | ... | @@ -2430,10 +2430,10 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si |
| 2430 | irp->printed.deinit(); | 2430 | irp->printed.deinit(); |
| 2431 | } | 2431 | } |
| 2432 | 2432 | ||
| 2433 | void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num) { | 2433 | void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) { |
| 2434 | IrPrint ir_print = {}; | 2434 | IrPrint ir_print = {}; |
| 2435 | IrPrint *irp = &ir_print; | 2435 | IrPrint *irp = &ir_print; |
| 2436 | irp->pass_num = pass_num; | 2436 | irp->pass = pass; |
| 2437 | irp->codegen = codegen; | 2437 | irp->codegen = codegen; |
| 2438 | irp->f = f; | 2438 | irp->f = f; |
| 2439 | irp->indent = indent_size; | 2439 | irp->indent = indent_size; |
src/ir_print.hpp+2-2| ... | @@ -12,7 +12,7 @@ | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | ||
| 13 | #include <stdio.h> | 13 | #include <stdio.h> |
| 14 | 14 | ||
| 15 | void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num); | 15 | void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass); |
| 16 | void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num); | 16 | void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass); |
| 17 | 17 | ||
| 18 | #endif | 18 | #endif |