meta: add ivy-diag library
ivy-diag is used for generating and emitting diagnostic messages during compilation.
This commit is contained in:
26
diag/write.c
Normal file
26
diag/write.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user