meta: add ivy-diag library

ivy-diag is used for generating and emitting diagnostic messages during compilation.
This commit is contained in:
2025-05-08 10:48:23 +01:00
parent 8e8637882d
commit c459f50e67
13 changed files with 1151 additions and 0 deletions

26
diag/write.c Normal file
View File

@@ -0,0 +1,26 @@
#include "write.h"
#include <ivy/diag.h>
extern struct diag_writer pretty_writer;
static const struct diag_writer *writers[] = {
[IVY_DIAG_FORMAT_PRETTY] = &pretty_writer,
};
static const size_t nr_writers = sizeof writers / sizeof writers[0];
enum ivy_status diag_write(
struct ivy_diag_ctx *ctx, struct ivy_diag *diag,
enum ivy_diag_format format, struct ivy_diag_stream *stream)
{
if (format < 0 || format >= nr_writers) {
return IVY_ERR_INVALID_VALUE;
}
const struct diag_writer *writer = writers[format];
if (!writer) {
return IVY_ERR_INVALID_VALUE;
}
return writer->write(ctx, diag, stream);
}