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) {
44184418
44194419 if (g->verbose_ir) {
44204420 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);
44224422 fprintf(stderr, "}\n");
44234423 }
44244424 fn->anal_state = FnAnalStateComplete;
......@@ -4451,8 +4451,8 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
44514451 if (g->verbose_ir) {
44524452 fprintf(stderr, "\n");
44534453 ast_render(stderr, fn_table_entry->body_node, 4);
4454 fprintf(stderr, "\n{ // (IR)\n");
4455 ir_print(g, stderr, &fn_table_entry->ir_executable, 4, 1);
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, IrPassSrc);
44564456 fprintf(stderr, "}\n");
44574457 }
44584458
src/ir.cpp+2-2
......@@ -10892,7 +10892,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1089210892 fprintf(stderr, "\nSource: ");
1089310893 ast_render(stderr, node, 4);
1089410894 fprintf(stderr, "\n{ // (IR)\n");
10895 ir_print(codegen, stderr, ir_executable, 2, 1);
10895 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);
1089610896 fprintf(stderr, "}\n");
1089710897 }
1089810898 IrExecutable *analyzed_executable = allocate<IrExecutable>(1);
......@@ -10913,7 +10913,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1091310913
1091410914 if (codegen->verbose_ir) {
1091510915 fprintf(stderr, "{ // (analyzed)\n");
10916 ir_print(codegen, stderr, analyzed_executable, 2, 2);
10916 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);
1091710917 fprintf(stderr, "}\n");
1091810918 }
1091910919
src/ir.hpp+5
......@@ -10,6 +10,11 @@
1010
1111#include "all_types.hpp"
1212
13enum IrPass {
14 IrPassSrc,
15 IrPassGen,
16};
17
1318bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
1419bool 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
2222using InstructionList = ZigList<IrInstruction*>;
2323
2424struct IrPrint {
25 size_t pass_num;
25 IrPass pass;
2626 CodeGen *codegen;
2727 FILE *f;
2828 int indent;
......@@ -391,7 +391,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
391391
392392static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
393393 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) {
395395 irp->printed.put(instruction, 0);
396396 irp->pending.append(instruction);
397397 }
......@@ -2399,10 +2399,10 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
23992399 fprintf(irp->f, "\n");
24002400}
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) {
24032403 IrPrint ir_print = {};
24042404 IrPrint *irp = &ir_print;
2405 irp->pass_num = pass_num;
2405 irp->pass = pass;
24062406 irp->codegen = codegen;
24072407 irp->f = f;
24082408 irp->indent = indent_size;
......@@ -2416,7 +2416,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
24162416 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
24172417 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
24182418 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2419 if (irp->pass_num == 2) {
2419 if (irp->pass != IrPassSrc) {
24202420 irp->printed.put(instruction, 0);
24212421 irp->pending.clear();
24222422 }
......@@ -2430,10 +2430,10 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
24302430 irp->printed.deinit();
24312431}
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) {
24342434 IrPrint ir_print = {};
24352435 IrPrint *irp = &ir_print;
2436 irp->pass_num = pass_num;
2436 irp->pass = pass;
24372437 irp->codegen = codegen;
24382438 irp->f = f;
24392439 irp->indent = indent_size;
src/ir_print.hpp+2-2
......@@ -12,7 +12,7 @@
1212
1313#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, 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, IrPass pass);
1717
1818#endif