vc4/asm/report.c
2025-09-06 02:01:16 +02:00

39 lines
1.2 KiB
C

#include "report.h"
#include <stdio.h>
void loc_pretty_print(Loc loc, const char* text, size_t text_len)
{
const char* displacement_spaces
= " "
" "
" "
" ";
size_t line_start = loc.idx;
while (line_start > 0 && text[line_start] != '\n') {
line_start -= 1;
}
if (text[line_start] == '\n') {
line_start += 1;
}
size_t line_end = loc.idx + 1;
while (line_end < text_len && text[line_end] != '\n') {
line_end += 1;
}
const char* line = &text[line_start];
int line_len = (int)line_end - (int)line_start;
fprintf(stderr,
" \x1b[96m--> ./%s:%d:%d\n "
"\x1b[37m|\n\x1b[96m%5d\x1b[37m|\x1b[0m%.*s\n "
"\x1b[37m|%.*s\x1b[1;91m^\x1b[0m\n",
loc.filename,
loc.line,
loc.col,
loc.line,
line_len,
line,
loc.col - 1,
displacement_spaces);
}