summaryrefslogtreecommitdiffhomepage
path: root/ir/be/bediagnostic.c
blob: c55881b4c437c4c30565d465bd0604941d5ed39b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * This file is part of libFirm.
 * Copyright (C) 2015 University of Karlsruhe.
 */
#include "bediagnostic.h"

#include "dbginfo.h"
#include "irnode_t.h"
#include "irprintf.h"
#include <stdarg.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);
}