1 /* Subroutines for log output for Atmel AVR back end.
2 Copyright (C) 2011-2014 Free Software Foundation, Inc.
3 Contributed by Georg-Johann Lay (avr@gjlay.de)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "print-tree.h"
34 #include "hard-reg-set.h"
37 #include "tree-pass.h" /* for current_pass */
39 /* This file supplies some functions for AVR back-end developers
40 with a printf-like interface. The functions are called through
41 macros avr_edump or avr_fdump from avr-protos.h:
43 avr_edump (const char *fmt, ...);
45 avr_fdump (FILE *stream, const char *fmt, ...);
47 avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
64 f: current_function_name()
65 F: caller (via __FUNCTION__)
66 P: Pass name and number
67 ?: Print caller, current function and pass info
68 !: Ditto, but only print if in a pass with static pass number,
80 /* Set according to -mlog= option. */
83 /* The caller as of __FUNCTION__ */
84 static const char *avr_log_caller = "?";
86 /* The worker function implementing the %-codes */
87 static void avr_log_vadump (FILE*, const char*, va_list);
89 /* As we have no variadic macros, avr_edump maps to a call to
90 avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and
91 returns a function pointer to avr_log_fdump_e. avr_log_fdump_e
92 gets the printf-like arguments and calls avr_log_vadump, the
93 worker function. avr_fdump works the same way. */
95 /* Provide avr_log_fdump_e/f so that avr_log_set_caller_e/_f can return
99 avr_log_fdump_e (const char *fmt, ...)
104 avr_log_vadump (stderr, fmt, ap);
111 avr_log_fdump_f (FILE *stream, const char *fmt, ...)
117 avr_log_vadump (stream, fmt, ap);
123 /* Macros avr_edump/avr_fdump map to calls of the following two functions,
124 respectively. You don't need to call them directly. */
127 avr_log_set_caller_e (const char *caller)
130 avr_log_caller = caller;
132 return avr_log_fdump_e;
136 avr_log_set_caller_f (const char *caller)
137 )(FILE*, const char*, ...)
139 avr_log_caller = caller;
141 return avr_log_fdump_f;
145 /* Worker function implementing the %-codes and forwarding to
146 respective print/dump function. */
149 avr_log_vadump (FILE *file, const char *fmt, va_list ap)
151 char bs[3] = {'\\', '?', '\0'};
158 fputc (*(fmt-1), file);
175 tree t = va_arg (ap, tree);
177 fprintf (file, "<NULL-TREE>");
184 print_node (file, "", t, 0);
192 print_node_brief (file, "", va_arg (ap, tree), 3);
196 fprintf (file, "%d", va_arg (ap, int));
200 fprintf (file, "%x", va_arg (ap, int));
204 fprintf (file, "%s", va_arg (ap, int) ? "true" : "false");
208 fputc (va_arg (ap, int), file);
212 print_inline_rtx (file, va_arg (ap, rtx), 0);
217 rtx_insn *insn = safe_as_a <rtx_insn *> (va_arg (ap, rtx));
221 print_inline_rtx (file, insn, 0);
222 fprintf (file, "\n");
223 insn = NEXT_INSN (insn);
229 if (cfun && cfun->decl)
230 fputs (current_function_name(), file);
235 const char *str = va_arg (ap, char*);
236 fputs (str ? str : "(null)", file);
241 fputs (GET_MODE_NAME ((enum machine_mode) va_arg (ap, int)),
246 fputs (rtx_name[va_arg (ap, int)], file);
250 fputs (reg_class_names[va_arg (ap, int)], file);
254 fputs (avr_log_caller, file);
259 location_t loc = va_arg (ap, location_t);
261 if (BUILTINS_LOCATION == loc)
262 fprintf (file, "<BUILTIN-LOCATION>");
263 else if (UNKNOWN_LOCATION == loc)
264 fprintf (file, "<UNKNOWN-LOCATION>");
266 fprintf (file, "%s:%d",
267 LOCATION_FILE (loc), LOCATION_LINE (loc));
278 avr_log_fdump_f (file, "%F[%f:%P]");
283 fprintf (file, "%s(%d)",
285 current_pass->static_pass_number);
287 fprintf (file, "pass=?");
296 /* Unknown %-code: Stop printing */
298 fprintf (file, "??? %%%c ???%s\n", *(fmt-1), fmt);
311 /* Called from avr.c:avr_option_override().
312 Parse argument of -mlog= and set respective fields in avr_log. */
315 avr_log_set_avr_log (void)
317 bool all = TARGET_ALL_DEBUG != 0;
319 if (all || avr_log_details)
321 /* Adding , at beginning and end of string makes searching easier. */
323 char *str = (char*) alloca (3 + strlen (avr_log_details));
327 strcat (stpcpy (str+1, avr_log_details), ",");
329 all |= NULL != strstr (str, ",all,");
330 info = NULL != strstr (str, ",?,");
333 fprintf (stderr, "\n-mlog=");
335 #define SET_DUMP_DETAIL(S) \
337 avr_log.S = (all || NULL != strstr (str, "," #S ",")); \
339 fprintf (stderr, #S ","); \
342 SET_DUMP_DETAIL (address_cost);
343 SET_DUMP_DETAIL (builtin);
344 SET_DUMP_DETAIL (constraints);
345 SET_DUMP_DETAIL (legitimate_address_p);
346 SET_DUMP_DETAIL (legitimize_address);
347 SET_DUMP_DETAIL (legitimize_reload_address);
348 SET_DUMP_DETAIL (progmem);
349 SET_DUMP_DETAIL (rtx_costs);
351 #undef SET_DUMP_DETAIL
354 fprintf (stderr, "?\n\n");