Files
ww/cmd/wwc/err.c
Hojun-Cho 1657bdeda3 ww: import toolchain — C bootstrap + ww-side self-host (phases 0-10)
C bootstrap (phases 0-9):
  cmd/wwc, cmd/6c, cmd/6a, cmd/6l, cmd/ww, rt, lib/*.

ww-side self-host (phase 10):
  selfhost/cmd/wwc — ww-cgen frontend; bootstrap fixed point.
  selfhost/cmd/6a  — assembler; byte-identical to C 6a (test 991).
  selfhost/cmd/6l  — linker w/ archive (.a) support; byte-identical
                     to C 6l (test 992).
  selfhost/cmd/ww  — driver (build/run/version); byte-identical to
                     C ww (test 993).

make test: 15/15. make bootstrap: ww2.s == ww3.s, ww2.o == ww3.o,
ww2 == ww3 byte-identical, with the full ww-tooled chain.
2026-05-11 02:17:47 +09:00

77 lines
1.2 KiB
C

/*
* err.c — diagnostics.
*
* fatal prints, sets exit(1).
* errorf prints with source location, increments nerrors.
* warnf prints with source location, increments nwarnings.
*
* Plan 9 style: short, no levels beyond fatal/error/warn, no colour.
*/
#include "ww.h"
#include <stdlib.h>
#include <string.h>
Pos noPos = { "<none>", 0, 0 };
int nerrors;
int nwarnings;
FILE *errout; /* set by main; defaults to stderr */
static FILE *
out(void)
{
return errout ? errout : stderr;
}
static void
prefix(Pos p)
{
FILE *f = out();
if (p.file == NULL)
p = noPos;
if (p.line > 0)
fprintf(f, "%s:%d:%d: ", p.file, p.line, p.col);
else
fprintf(f, "%s: ", p.file);
}
void
fatal(const char *fmt, ...)
{
FILE *f = out();
va_list ap;
fprintf(f, "ww: ");
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
exit(1);
}
void
errorf(Pos p, const char *fmt, ...)
{
FILE *f = out();
va_list ap;
prefix(p);
fprintf(f, "error: ");
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
nerrors++;
}
void
warnf(Pos p, const char *fmt, ...)
{
FILE *f = out();
va_list ap;
prefix(p);
fprintf(f, "warning: ");
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
nwarnings++;
}