Skip to content

Commit

Permalink
Fix dump IR
Browse files Browse the repository at this point in the history
  * Unsigned conditional `JMP` may cause segmentation fault
  * Eliminte showing constant register
  • Loading branch information
tyfkda committed Aug 30, 2023
1 parent dac77f6 commit a1d15f7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/_debug/dump_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void dump_vreg(FILE *fp, VReg *vreg) {
}

static void dump_ir(FILE *fp, IR *ir) {
static char *kCond[] = {NULL, "MP", "EQ", "NE", "LT", "LE", "GE", "GT", NULL, NULL, NULL, NULL, "ULT", "ULE", "UGE", "UGT"};
static char *kCond[] = {NULL, "MP", "EQ", "NE", "LT", "LE", "GE", "GT", NULL, "MP", "EQ", "NE", "ULT", "ULE", "UGE", "UGT"};

switch (ir->kind) {
case IR_BOFS: fprintf(fp, "\tBOFS\t"); dump_vreg(fp, ir->dst); fprintf(fp, " = &[rbp %c %d]\n", ir->bofs.frameinfo->offset >= 0 ? '+' : '-', ir->bofs.frameinfo->offset > 0 ? ir->bofs.frameinfo->offset : -ir->bofs.frameinfo->offset); break;
Expand All @@ -52,7 +52,7 @@ static void dump_ir(FILE *fp, IR *ir) {
case IR_CMP: fprintf(fp, "\tCMP\t"); dump_vreg(fp, ir->opr1); fprintf(fp, " - "); dump_vreg(fp, ir->opr2); fprintf(fp, "\n"); break;
case IR_NEG: fprintf(fp, "\tNEG\t"); dump_vreg(fp, ir->dst); fprintf(fp, " = -"); dump_vreg(fp, ir->opr1); fprintf(fp, "\n"); break;
case IR_BITNOT: fprintf(fp, "\tBITNOT\t"); dump_vreg(fp, ir->dst); fprintf(fp, " = ~"); dump_vreg(fp, ir->opr1); fprintf(fp, "\n"); break;
case IR_COND: fprintf(fp, "\tCOND\t"); dump_vreg(fp, ir->dst); fprintf(fp, " = %s\n", kCond[ir->cond.kind]); break;
case IR_COND: fprintf(fp, "\tCOND\t"); dump_vreg(fp, ir->dst); fprintf(fp, " = %s\n", kCond[ir->cond.kind & (COND_MASK | COND_UNSIGNED)]); break;
case IR_JMP: fprintf(fp, "\tJ%s\t%.*s\n", kCond[ir->jmp.cond & (COND_MASK | COND_UNSIGNED)], NAMES(ir->jmp.bb->label)); break;
case IR_TJMP:
fprintf(fp, "\tTJMP\t");
Expand Down

0 comments on commit a1d15f7

Please sign in to comment.