1 /* Subroutines for log output for Atmel AVR back end.
2 Copyright (C) 2011-2013 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"
32 #include "tree-pass.h" /* for current_pass */
34 /* This file supplies some functions for AVR back-end developers
35 with a printf-like interface. The functions are called through
36 macros avr_edump or avr_fdump from avr-protos.h:
38 avr_edump (const char *fmt, ...);
40 avr_fdump (FILE *stream, const char *fmt, ...);
42 avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
59 f: current_function_name()
60 F: caller (via __FUNCTION__)
61 P: Pass name and number
62 ?: Print caller, current function and pass info
63 !: Ditto, but only print if in a pass with static pass number,
75 /* Set according to -mlog= option. */
78 /* The caller as of __FUNCTION__ */
79 static const char *avr_log_caller
= "?";
81 /* The worker function implementing the %-codes */
82 static void avr_log_vadump (FILE*, const char*, va_list);
84 /* As we have no variadic macros, avr_edump maps to a call to
85 avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and
86 returns a function pointer to avr_log_fdump_e. avr_log_fdump_e
87 gets the printf-like arguments and calls avr_log_vadump, the
88 worker function. avr_fdump works the same way. */
90 /* Provide avr_log_fdump_e/f so that avr_log_set_caller_e/_f can return
94 avr_log_fdump_e (const char *fmt
, ...)
99 avr_log_vadump (stderr
, fmt
, ap
);
106 avr_log_fdump_f (FILE *stream
, const char *fmt
, ...)
112 avr_log_vadump (stream
, fmt
, ap
);
118 /* Macros avr_edump/avr_fdump map to calls of the following two functions,
119 respectively. You don't need to call them directly. */
122 avr_log_set_caller_e (const char *caller
)
125 avr_log_caller
= caller
;
127 return avr_log_fdump_e
;
131 avr_log_set_caller_f (const char *caller
)
132 )(FILE*, const char*, ...)
134 avr_log_caller
= caller
;
136 return avr_log_fdump_f
;
140 /* Worker function implementing the %-codes and forwarding to
141 respective print/dump function. */
144 avr_log_vadump (FILE *file
, const char *fmt
, va_list ap
)
146 char bs
[3] = {'\\', '?', '\0'};
153 fputc (*(fmt
-1), file
);
170 tree t
= va_arg (ap
, tree
);
172 fprintf (file
, "<NULL-TREE>");
179 print_node (file
, "", t
, 0);
187 print_node_brief (file
, "", va_arg (ap
, tree
), 3);
191 fprintf (file
, "%d", va_arg (ap
, int));
195 fprintf (file
, "%x", va_arg (ap
, int));
199 fprintf (file
, "%s", va_arg (ap
, int) ? "true" : "false");
203 fputc (va_arg (ap
, int), file
);
207 print_inline_rtx (file
, va_arg (ap
, rtx
), 0);
212 rtx insn
= va_arg (ap
, rtx
);
216 print_inline_rtx (file
, insn
, 0);
217 fprintf (file
, "\n");
218 insn
= NEXT_INSN (insn
);
224 if (cfun
&& cfun
->decl
)
225 fputs (current_function_name(), file
);
230 const char *str
= va_arg (ap
, char*);
231 fputs (str
? str
: "(null)", file
);
236 fputs (GET_MODE_NAME ((enum machine_mode
) va_arg (ap
, int)),
241 fputs (rtx_name
[va_arg (ap
, int)], file
);
245 fputs (reg_class_names
[va_arg (ap
, int)], file
);
249 fputs (avr_log_caller
, file
);
254 location_t loc
= va_arg (ap
, location_t
);
256 if (BUILTINS_LOCATION
== loc
)
257 fprintf (file
, "<BUILTIN-LOCATION>");
258 else if (UNKNOWN_LOCATION
== loc
)
259 fprintf (file
, "<UNKNOWN-LOCATION>");
261 fprintf (file
, "%s:%d",
262 LOCATION_FILE (loc
), LOCATION_LINE (loc
));
273 avr_log_fdump_f (file
, "%F[%f:%P]");
278 fprintf (file
, "%s(%d)",
280 current_pass
->static_pass_number
);
282 fprintf (file
, "pass=?");
291 /* Unknown %-code: Stop printing */
293 fprintf (file
, "??? %%%c ???%s\n", *(fmt
-1), fmt
);
306 /* Called from avr.c:avr_option_override().
307 Parse argument of -mlog= and set respective fields in avr_log. */
310 avr_log_set_avr_log (void)
312 bool all
= TARGET_ALL_DEBUG
!= 0;
314 if (all
|| avr_log_details
)
316 /* Adding , at beginning and end of string makes searching easier. */
318 char *str
= (char*) alloca (3 + strlen (avr_log_details
));
322 strcat (stpcpy (str
+1, avr_log_details
), ",");
324 all
|= NULL
!= strstr (str
, ",all,");
325 info
= NULL
!= strstr (str
, ",?,");
328 fprintf (stderr
, "\n-mlog=");
330 #define SET_DUMP_DETAIL(S) \
332 avr_log.S = (all || NULL != strstr (str, "," #S ",")); \
334 fprintf (stderr, #S ","); \
337 SET_DUMP_DETAIL (address_cost
);
338 SET_DUMP_DETAIL (builtin
);
339 SET_DUMP_DETAIL (constraints
);
340 SET_DUMP_DETAIL (legitimate_address_p
);
341 SET_DUMP_DETAIL (legitimize_address
);
342 SET_DUMP_DETAIL (legitimize_reload_address
);
343 SET_DUMP_DETAIL (progmem
);
344 SET_DUMP_DETAIL (rtx_costs
);
346 #undef SET_DUMP_DETAIL
349 fprintf (stderr
, "?\n\n");