Skip to content

Commit 197624d

Browse files
committed
Refactor error diagnostic functions
1 parent 457bddc commit 197624d

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/arm-codegen.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
126126
elf_offset += 4;
127127
return;
128128
default:
129-
error_no_loc("Unknown opcode");
129+
fatal("Unknown opcode");
130130
}
131131
}
132132

@@ -434,8 +434,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
434434
else if (rm == 4)
435435
rm = 0xFFFFFFFF;
436436
else
437-
error_no_loc(
438-
"Unsupported truncation operation with invalid target size");
437+
fatal("Unsupported truncation operation with invalid target size");
439438

440439
emit(__and_i(__AL, rd, rn, rm));
441440
return;
@@ -444,7 +443,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
444443
emit(__sxtb(__AL, rd, rn, 0));
445444
return;
446445
default:
447-
error_no_loc("Unknown opcode");
446+
fatal("Unknown opcode");
448447
}
449448
}
450449

src/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ int __teq(arm_reg rd)
358358
int __sxtb(arm_cond_t cond, arm_reg rd, arm_reg rm, int rotation)
359359
{
360360
if (rotation != 0 && rotation != 8 && rotation != 16 && rotation != 24)
361-
error_no_loc("SXTB rotation must be 0, 8, 16, or 24");
361+
fatal("SXTB rotation must be 0, 8, 16, or 24");
362362

363363
return arm_encode(cond, 106, 0xF, rd,
364364
rm | ((rotation >> 3) << 10) | (0x7 << 4));

src/globals.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ void global_release()
10171017
}
10181018

10191019
/* Reports an error without specifying a position */
1020-
void error_no_loc(char *msg)
1020+
void fatal(char *msg)
10211021
{
10221022
printf("[Error]: %s\n", msg);
10231023
abort();
@@ -1054,8 +1054,8 @@ void error(char *msg)
10541054
/* TODO: figure out the corresponding C source file path and report line
10551055
* number.
10561056
*/
1057-
printf("Error %s at source location %d\n%s\n", msg, SOURCE->size,
1058-
diagnostic);
1057+
printf("[Error]: %s\nOccurs at source location %d.\n%s\n", msg,
1058+
SOURCE->size, diagnostic);
10591059
abort();
10601060
}
10611061

src/riscv-codegen.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
100100
elf_offset += 12;
101101
return;
102102
default:
103-
error_no_loc("Unknown opcode");
103+
fatal("Unknown opcode");
104104
}
105105
}
106106

@@ -409,8 +409,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
409409
else if (ph2_ir->src1 == 4)
410410
rs2 = 0xFFFFFFFF;
411411
else
412-
error_no_loc(
413-
"Unsupported truncation operation with invalid target size");
412+
fatal("Unsupported truncation operation with invalid target size");
414413

415414
emit(__andi(rd, rs1, rs2));
416415
return;
@@ -423,7 +422,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
423422
/* emit(__sext_b(rd, rs1)); */
424423
return;
425424
default:
426-
error_no_loc("Unknown opcode");
425+
fatal("Unknown opcode");
427426
}
428427
}
429428

0 commit comments

Comments
 (0)