authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-09-04 16:04:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-05 13:06:10-04:00
logfe153ad2a435e26f9904f05858232305bdffd3ac
treeaee8502f0627b5fd5027a180491487bf1fb56b5b
parentfabf45f5fc0a1827913be5675130db5db514c136

stage1 enhance IR print

- print fn name in pass1 - replace scalar with enum IrPass for clarity

5 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) {
44184418
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 }
44584458
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
1091310913
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 }
1091910919
src/ir.hpp+5
...@@ -10,6 +10,11 @@...@@ -10,6 +10,11 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13enum IrPass {
14 IrPassSrc,
15 IrPassGen,
16};
17
13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
14bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
1520
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
22using InstructionList = ZigList<IrInstruction*>;22using InstructionList = ZigList<IrInstruction*>;
2323
24struct IrPrint {24struct 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) {
391391
392static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {392static 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}
24012401
2402void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num) {2402void 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}
24322432
2433void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num) {2433void 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 @@
1212
13#include <stdio.h>13#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num);15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num);16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
1717
18#endif18#endif