1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2016 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
47 int line_nr; /* nr complete lines written, curr line is line_nr+1 */
52 lf_file_references references;
60 lf_file_references references,
61 lf_file_type type, const char *program)
63 /* create a file object */
64 lf *new_lf = ZALLOC (lf);
65 ASSERT (new_lf != NULL);
66 new_lf->references = references;
68 new_lf->name = (real_name == NULL ? name : real_name);
69 new_lf->program = program;
70 /* attach to stdout if pipe */
71 if (!strcmp (name, "-"))
73 new_lf->stream = stdout;
77 /* create a new file */
78 new_lf->stream = fopen (name, "w");
79 if (new_lf->stream == NULL)
92 if (file->stream != stdout)
94 if (fclose (file->stream))
96 perror ("lf_close.fclose");
105 lf_putchr (lf *file, const char chr)
111 file->line_blank = 1;
113 else if (file->line_blank)
116 for (pad = file->indent; pad > 0; pad--)
117 putc (' ', file->stream);
119 file->line_blank = 0;
121 putc (chr, file->stream);
127 lf_write (lf *file, const char *string, int strlen_string)
131 for (i = 0; i < strlen_string; i++)
132 nr += lf_putchr (file, string[i]);
138 lf_indent_suppress (lf *file)
140 file->line_blank = 0;
145 lf_putstr (lf *file, const char *string)
151 for (chp = string; *chp != '\0'; chp++)
153 nr += lf_putchr (file, *chp);
160 do_lf_putunsigned (lf *file, unsigned u)
165 nr += do_lf_putunsigned (file, u / 10);
166 nr += lf_putchr (file, (u % 10) + '0');
173 lf_putint (lf *file, int decimal)
177 nr += lf_putchr (file, '0');
178 else if (decimal < 0)
180 nr += lf_putchr (file, '-');
181 nr += do_lf_putunsigned (file, -decimal);
183 else if (decimal > 0)
185 nr += do_lf_putunsigned (file, decimal);
194 lf_printf (lf *file, const char *fmt, ...)
201 vsprintf (buf, fmt, ap);
202 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
203 ASSERT (strlen (buf) < sizeof (buf));
204 nr += lf_putstr (file, buf);
211 lf_print__line_ref (lf *file, line_ref *line)
213 return lf_print__external_ref (file, line->line_nr, line->file_name);
217 lf_print__external_ref (lf *file, int line_nr, const char *file_name)
220 switch (file->references)
222 case lf_include_references:
223 lf_indent_suppress (file);
224 nr += lf_putstr (file, "#line ");
225 nr += lf_putint (file, line_nr);
226 nr += lf_putstr (file, " \"");
227 nr += lf_putstr (file, file_name);
228 nr += lf_putstr (file, "\"\n");
230 case lf_omit_references:
231 nr += lf_putstr (file, "/* ");
232 nr += lf_putstr (file, file_name);
233 nr += lf_putstr (file, ":");
234 nr += lf_putint (file, line_nr);
235 nr += lf_putstr (file, "*/\n");
242 lf_print__internal_ref (lf *file)
245 nr += lf_print__external_ref (file, file->line_nr + 2, file->name);
246 /* line_nr == last_line, want to number from next */
251 lf_indent (lf *file, int delta)
253 file->indent += delta;
258 lf_print__gnu_copyleft (lf *file)
265 nr += lf_printf (file, "\
266 /* This file is part of GDB.\n\
268 Copyright 2002, 2007 Free Software Foundation, Inc.\n\
270 This program is free software; you can redistribute it and/or modify\n\
271 it under the terms of the GNU General Public License as published by\n\
272 the Free Software Foundation; either version 3 of the License, or\n\
273 (at your option) any later version.\n\
275 This program is distributed in the hope that it will be useful,\n\
276 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
277 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
278 GNU General Public License for more details.\n\
280 You should have received a copy of the GNU General Public License\n\
281 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
285 This file was generated by the program %s */\n\
286 ", filter_filename (file->program));
297 lf_putbin (lf *file, int decimal, int width)
302 for (bit = 1 << (width - 1); bit != 0; bit >>= 1)
305 nr += lf_putchr (file, '1');
307 nr += lf_putchr (file, '0');
313 lf_print__this_file_is_empty (lf *file, const char *reason)
320 nr += lf_printf (file,
321 "/* This generated file (%s) is intentionally left blank",
324 nr += lf_printf (file, " - %s", reason);
325 nr += lf_printf (file, " */\n");
328 ERROR ("Bad switch");
334 lf_print__ucase_filename (lf *file)
337 const char *chp = file->name;
343 nr += lf_putchr (file, toupper (ch));
346 nr += lf_putchr (file, '_');
348 nr += lf_putchr (file, ch);
355 lf_print__file_start (lf *file)
362 nr += lf_print__gnu_copyleft (file);
363 nr += lf_printf (file, "\n");
364 nr += lf_printf (file, "#ifndef ");
365 nr += lf_print__ucase_filename (file);
366 nr += lf_printf (file, "\n");
367 nr += lf_printf (file, "#define ");
368 nr += lf_print__ucase_filename (file);
369 nr += lf_printf (file, "\n");
370 nr += lf_printf (file, "\n");
380 lf_print__file_finish (lf *file)
387 nr += lf_printf (file, "\n");
388 nr += lf_printf (file, "#endif /* _");
389 nr += lf_print__ucase_filename (file);
390 nr += lf_printf (file, "_*/\n");
400 lf_print__function_type (lf *file,
402 const char *prefix, const char *trailing_space)
405 nr += lf_printf (file, "%s\\\n(%s)", prefix, type);
406 if (trailing_space != NULL)
407 nr += lf_printf (file, "%s", trailing_space);
412 lf_print__function_type_function (lf *file,
413 print_function * print_type,
415 const char *trailing_space)
418 nr += lf_printf (file, "%s\\\n(", prefix);
419 nr += print_type (file);
420 nr += lf_printf (file, ")");
421 if (trailing_space != NULL)
422 nr += lf_printf (file, "%s", trailing_space);