1 /* Subroutines for log output for Atmel AVR back end.
2 Copyright (C) 2011 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"
31 #include "tree-pass.h"
33 /* This file supplies some functions for AVR back-end developers
34 with a printf-like interface. The functions are called through
35 macros avr_edump or avr_fdump from avr-protos.h:
37 avr_edump (const char * fmt, ...);
39 avr_fdump (FILE * stream, const char * fmt, ...);
41 avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
58 f: current_function_name()
59 F: caller (via __FUNCTION__)
60 P: Pass name and number
61 ?: Print caller, current function and pass info
72 /* Set according to -mlog= option. */
75 /* The caller as of __FUNCTION__ */
76 static const char *avr_log_caller = "?";
78 /* The worker function implementing the %-codes */
79 static void avr_log_vadump (FILE*, const char*, va_list);
81 /* As we have no variadic macros, avr_edump maps to a call to
82 avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and
83 returns a function pointer to avr_log_fdump_e. avr_fdump_e
84 gets the printf-like arguments and calls avr_log_vadump, the
85 worker function. avr_fdump works the same way. */
87 /* Provide avr_log_fdump_e/f so that avr_log_set_caller_e/_f can return
91 avr_log_fdump_e (const char *fmt, ...)
96 avr_log_vadump (stderr, fmt, ap);
103 avr_log_fdump_f (FILE *stream, const char *fmt, ...)
109 avr_log_vadump (stream, fmt, ap);
115 /* Macros avr_edump/avr_fdump map to calls of the following two functions,
116 respectively. You don't need to call them directly. */
119 avr_log_set_caller_e (const char *caller)
122 avr_log_caller = caller;
124 return avr_log_fdump_e;
128 avr_log_set_caller_f (const char *caller)
129 )(FILE*, const char*, ...)
131 avr_log_caller = caller;
133 return avr_log_fdump_f;
136 /* Worker function implementing the %-codes and forwarding to
137 respective print/dump function. */
140 avr_log_vadump (FILE *file, const char *fmt, va_list ap)
142 char bs[3] = {'\\', '?', '\0'};
149 fputc (*(fmt-1), file);
166 tree t = va_arg (ap, tree);
168 fprintf (file, "<NULL-TREE>");
175 print_node (file, "", t, 0);
183 print_node_brief (file, "", va_arg (ap, tree), 3);
187 fprintf (file, "%d", va_arg (ap, int));
191 fprintf (file, "%x", va_arg (ap, int));
195 fprintf (file, "%s", va_arg (ap, int) ? "true" : "false");
199 fputc (va_arg (ap, int), file);
203 print_inline_rtx (file, va_arg (ap, rtx), 0);
208 rtx insn = va_arg (ap, rtx);
212 print_inline_rtx (file, insn, 0);
213 fprintf (file, "\n");
214 insn = NEXT_INSN (insn);
220 if (cfun && cfun->decl)
221 fputs (current_function_name(), file);
226 const char *str = va_arg (ap, char*);
227 fputs (str ? str : "(null)", file);
232 fputs (GET_MODE_NAME (va_arg (ap, enum machine_mode)), file);
236 fputs (rtx_name[va_arg (ap, enum rtx_code)], file);
240 fputs (reg_class_names[va_arg (ap, enum reg_class)], file);
244 fputs (avr_log_caller, file);
249 location_t loc = va_arg (ap, location_t);
251 if (BUILTINS_LOCATION == loc)
252 fprintf (file, "<BUILTIN-LOCATION");
253 else if (UNKNOWN_LOCATION == loc)
254 fprintf (file, "<UNKNOWN-LOCATION>");
256 fprintf (file, "%s:%d",
257 LOCATION_FILE (loc), LOCATION_LINE (loc));
268 avr_log_fdump_f (file, "%F[%f:%P]");
273 fprintf (file, "%s(%d)",
275 current_pass->static_pass_number);
277 fprintf (file, "pass=?");
286 /* Unknown %-code: Stop printing */
288 fprintf (file, "??? %%%c ???%s\n", *(fmt-1), fmt);
301 /* Called from avr.c:avr_option_override().
302 Parse argument of -mlog= and set respective fields in avr_log. */
305 avr_log_set_avr_log (void)
309 /* Adding , at beginning and end of string makes searching easier. */
311 char *str = (char*) alloca (3 + strlen (avr_log_details));
314 strcat (stpcpy (str+1, avr_log_details), ",");
316 #define SET_DUMP_DETAIL(S) \
317 avr_log.S = (TARGET_ALL_DEBUG \
318 || NULL != strstr (str, "," #S ",") \
319 || NULL != strstr (str, ",all,"))
321 SET_DUMP_DETAIL (rtx_costs);
322 SET_DUMP_DETAIL (legitimate_address_p);
323 SET_DUMP_DETAIL (legitimize_address);
324 SET_DUMP_DETAIL (legitimize_reload_address);
325 SET_DUMP_DETAIL (constraints);
326 SET_DUMP_DETAIL (address_cost);
328 #undef SET_DUMP_DETAIL