summaryrefslogtreecommitdiffhomepage
path: root/ir/be/bediagnostic.c
diff options
context:
space:
mode:
authorChristoph Mallon <mallon@cs.uni-saarland.de>2015-02-16 11:38:51 +0100
committerChristoph Mallon <mallon@cs.uni-saarland.de>2015-04-27 13:18:45 +0200
commitf444ac1088814d7ef643dbd234687786de2bbba1 (patch)
tree9c114d1cfab9f38c9ddecce9cd976e441f579e09 /ir/be/bediagnostic.c
parent8398a784cdef0e073f4b0568671a42892a4442d1 (diff)
be: Add be_errorf() and be_warningf() for more consistent error reporting in the backend.
Diffstat (limited to 'ir/be/bediagnostic.c')
-rw-r--r--ir/be/bediagnostic.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/ir/be/bediagnostic.c b/ir/be/bediagnostic.c
new file mode 100644
index 0000000..9e0f1d2
--- /dev/null
+++ b/ir/be/bediagnostic.c
@@ -0,0 +1,53 @@
+/*
+ * This file is part of libFirm.
+ * Copyright (C) 2015 University of Karlsruhe.
+ */
+#include <stdarg.h>
+
+#include "bediagnostic.h"
+#include "dbginfo.h"
+#include "irnode_t.h"
+#include "irprintf.h"
+
+static void be_vdiagnosticf(ir_node const *const node, char const *const kind, char const *const fmt, va_list ap)
+{
+ FILE *const out = stderr;
+
+ if (node) {
+ ir_fprintf(out, "%+F", node);
+
+ dbg_info *const dbgi = get_irn_dbg_info(node);
+ src_loc_t const loc = ir_retrieve_dbg_info(dbgi);
+ if (loc.file) {
+ ir_fprintf(out, " (%s", loc.file);
+ if (loc.line != 0) {
+ ir_fprintf(out, ":%u", loc.line);
+ if (loc.column != 0)
+ ir_fprintf(out, ":%u", loc.column);
+ }
+ fputc(')', out);
+ }
+
+ fputs(": ", out);
+ }
+
+ ir_fprintf(out, "%s: ", kind);
+ ir_vfprintf(out, fmt, ap);
+ fputc('\n', out);
+}
+
+void be_errorf(ir_node const *const node, char const *const fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ be_vdiagnosticf(node, "error", fmt, ap);
+ va_end(ap);
+}
+
+void be_warningf(ir_node const *const node, char const *const fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ be_vdiagnosticf(node, "warning", fmt, ap);
+ va_end(ap);
+}