qimode_for_vec_perm
[official-gcc.git] / gcc / config / avr / avr-log.c
blobd1cf3dd003cc8c550c09f199fa895f84a336a762
1 /* Subroutines for log output for Atmel AVR back end.
2 Copyright (C) 2011-2017 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)
10 any later version.
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/>. */
21 #define IN_TARGET_CODE 1
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "function.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "tree-pass.h" /* for current_pass */
31 #include "memmodel.h"
32 #include "tm_p.h"
33 #include "print-tree.h"
35 /* This file supplies some functions for AVR back-end developers
36 with a printf-like interface. The functions are called through
37 macros `avr_dump', `avr_edump' or `avr_fdump' from avr-protos.h:
39 avr_fdump (FILE *stream, const char *fmt, ...);
40 avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
41 avr_dump (fmt, ...) is a shortcut for avr_fdump (dump_file, fmt, ...)
43 == known %-codes ==
45 b: bool
46 r: rtx
47 t: tree
48 T: tree (brief)
49 C: enum rtx_code
50 m: machine_mode
51 R: enum reg_class
52 L: insn list
53 H: location_t
55 == no arguments ==
57 A: call abort()
58 f: current_function_name()
59 F: caller (via __FUNCTION__)
60 P: Pass name and number
61 ?: Print caller, current function and pass info
62 !: Ditto, but only print if in a pass with static pass number,
63 else return.
65 == same as printf ==
67 %: %
68 c: char
69 s: string
70 d: int (decimal)
71 x: int (hex)
74 /* Set according to -mlog= option. */
75 avr_log_t avr_log;
77 /* The worker function implementing the %-codes */
78 static void avr_log_vadump (FILE*, const char*, va_list);
80 /* Wrapper for avr_log_vadump. If STREAM is NULL we are called by avr_dump,
81 i.e. output to dump_file if available. The 2nd argument is __FUNCTION__.
82 The 3rd argument is the format string. */
84 int
85 avr_vdump (FILE *stream, const char *caller, ...)
87 va_list ap;
89 if (stream == NULL && dump_file)
90 stream = dump_file;
92 va_start (ap, caller);
93 if (stream)
94 avr_log_vadump (stream, caller, ap);
95 va_end (ap);
97 return 1;
101 /* Worker function implementing the %-codes and forwarding to
102 respective print/dump function. */
104 static void
105 avr_log_vadump (FILE *file, const char *caller, va_list ap)
107 char bs[3] = {'\\', '?', '\0'};
109 /* 3rd proper argument is always the format string. */
110 const char *fmt = va_arg (ap, const char*);
112 while (*fmt)
114 switch (*fmt++)
116 default:
117 fputc (*(fmt-1), file);
118 break;
120 case '\\':
121 bs[1] = *fmt++;
122 fputs (bs, file);
123 break;
125 case '%':
126 switch (*fmt++)
128 case '%':
129 fputc ('%', file);
130 break;
132 case 't':
134 tree t = va_arg (ap, tree);
135 if (NULL_TREE == t)
136 fprintf (file, "<NULL-TREE>");
137 else
139 if (stderr == file)
140 debug_tree (t);
141 else
143 print_node (file, "", t, 0);
144 putc ('\n', file);
147 break;
150 case 'T':
152 tree t = va_arg (ap, tree);
153 if (NULL_TREE == t)
154 fprintf (file, "<NULL-TREE>");
155 else
156 print_node_brief (file, "", t, 3);
158 break;
160 case 'd':
161 fprintf (file, "%d", va_arg (ap, int));
162 break;
164 case 'x':
165 fprintf (file, "%x", va_arg (ap, int));
166 break;
168 case 'b':
169 fprintf (file, "%s", va_arg (ap, int) ? "true" : "false");
170 break;
172 case 'c':
173 fputc (va_arg (ap, int), file);
174 break;
176 case 'r':
177 print_inline_rtx (file, va_arg (ap, rtx), 0);
178 break;
180 case 'L':
182 rtx_insn *insn = safe_as_a <rtx_insn *> (va_arg (ap, rtx));
184 while (insn)
186 print_inline_rtx (file, insn, 0);
187 fprintf (file, "\n");
188 insn = NEXT_INSN (insn);
190 break;
193 case 'f':
194 if (cfun && cfun->decl)
195 fputs (current_function_name(), file);
196 break;
198 case 's':
200 const char *str = va_arg (ap, char*);
201 fputs (str ? str : "(null)", file);
203 break;
205 case 'm':
206 fputs (GET_MODE_NAME ((machine_mode) va_arg (ap, int)),
207 file);
208 break;
210 case 'C':
211 fputs (rtx_name[va_arg (ap, int)], file);
212 break;
214 case 'R':
215 fputs (reg_class_names[va_arg (ap, int)], file);
216 break;
218 case 'F':
219 fputs (caller, file);
220 break;
222 case 'H':
224 location_t loc = va_arg (ap, location_t);
226 if (BUILTINS_LOCATION == loc)
227 fprintf (file, "<BUILTIN-LOCATION>");
228 else if (UNKNOWN_LOCATION == loc)
229 fprintf (file, "<UNKNOWN-LOCATION>");
230 else
231 fprintf (file, "%s:%d",
232 LOCATION_FILE (loc), LOCATION_LINE (loc));
234 break;
237 case '!':
238 if (!current_pass)
239 return;
240 /* FALLTHRU */
242 case '?':
243 avr_vdump (file, caller, "%F[%f:%P]");
244 break;
246 case 'P':
247 if (current_pass)
248 fprintf (file, "%s(%d)",
249 current_pass->name,
250 current_pass->static_pass_number);
251 else
252 fprintf (file, "pass=?");
254 break;
256 case 'A':
257 fflush (file);
258 abort();
260 default:
261 /* Unknown %-code: Stop printing */
263 fprintf (file, "??? %%%c ???%s\n", *(fmt-1), fmt);
264 fmt = "";
266 break;
268 break; /* % */
272 fflush (file);
276 /* Called from avr.c:avr_option_override().
277 Parse argument of -mlog= and set respective fields in avr_log. */
279 void
280 avr_log_set_avr_log (void)
282 bool all = TARGET_ALL_DEBUG != 0;
284 if (all)
285 avr_log_details = "all";
287 if (all || avr_log_details)
289 /* Adding , at beginning and end of string makes searching easier. */
291 char *str = (char*) alloca (3 + strlen (avr_log_details));
292 bool info;
294 str[0] = ',';
295 strcat (stpcpy (str+1, avr_log_details), ",");
297 all |= strstr (str, ",all,") != NULL;
298 info = strstr (str, ",?,") != NULL;
300 if (info)
301 fprintf (stderr, "\n-mlog=");
303 #define SET_DUMP_DETAIL(S) \
304 do { \
305 avr_log.S = (all || strstr (str, "," #S ",") != NULL); \
306 if (info) \
307 fprintf (stderr, #S ","); \
308 } while (0)
310 SET_DUMP_DETAIL (address_cost);
311 SET_DUMP_DETAIL (builtin);
312 SET_DUMP_DETAIL (constraints);
313 SET_DUMP_DETAIL (insn_addresses);
314 SET_DUMP_DETAIL (legitimate_address_p);
315 SET_DUMP_DETAIL (legitimize_address);
316 SET_DUMP_DETAIL (legitimize_reload_address);
317 SET_DUMP_DETAIL (progmem);
318 SET_DUMP_DETAIL (rtx_costs);
320 #undef SET_DUMP_DETAIL
322 if (info)
323 fprintf (stderr, "?\n\n");