1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2021 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/>. */
38 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
43 lf_file_references references
;
51 lf_file_references references
,
52 lf_file_type type
, const char *program
)
54 /* create a file object */
55 lf
*new_lf
= ZALLOC (lf
);
56 ASSERT (new_lf
!= NULL
);
57 new_lf
->references
= references
;
59 new_lf
->name
= (real_name
== NULL
? name
: real_name
);
60 new_lf
->program
= program
;
61 /* attach to stdout if pipe */
62 if (!strcmp (name
, "-"))
64 new_lf
->stream
= stdout
;
68 /* create a new file */
69 new_lf
->stream
= fopen (name
, "w");
70 if (new_lf
->stream
== NULL
)
81 lf_get_file_type (const lf
*file
)
90 if (file
->stream
!= stdout
)
92 if (fclose (file
->stream
))
94 perror ("lf_close.fclose");
103 lf_putchr (lf
*file
, const char chr
)
109 file
->line_blank
= 1;
111 else if (file
->line_blank
)
114 for (pad
= file
->indent
; pad
> 0; pad
--)
115 putc (' ', file
->stream
);
117 file
->line_blank
= 0;
119 putc (chr
, file
->stream
);
125 lf_write (lf
*file
, const char *string
, int strlen_string
)
129 for (i
= 0; i
< strlen_string
; i
++)
130 nr
+= lf_putchr (file
, string
[i
]);
136 lf_indent_suppress (lf
*file
)
138 file
->line_blank
= 0;
143 lf_putstr (lf
*file
, const char *string
)
149 for (chp
= string
; *chp
!= '\0'; chp
++)
151 nr
+= lf_putchr (file
, *chp
);
158 do_lf_putunsigned (lf
*file
, unsigned u
)
163 nr
+= do_lf_putunsigned (file
, u
/ 10);
164 nr
+= lf_putchr (file
, (u
% 10) + '0');
171 lf_putint (lf
*file
, int decimal
)
175 nr
+= lf_putchr (file
, '0');
176 else if (decimal
< 0)
178 nr
+= lf_putchr (file
, '-');
179 nr
+= do_lf_putunsigned (file
, -decimal
);
181 else if (decimal
> 0)
183 nr
+= do_lf_putunsigned (file
, decimal
);
192 lf_printf (lf
*file
, const char *fmt
, ...)
199 vsprintf (buf
, fmt
, ap
);
200 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
201 ASSERT (strlen (buf
) < sizeof (buf
));
202 nr
+= lf_putstr (file
, buf
);
209 lf_print__line_ref (lf
*file
, line_ref
*line
)
211 return lf_print__external_ref (file
, line
->line_nr
, line
->file_name
);
215 lf_print__external_ref (lf
*file
, int line_nr
, const char *file_name
)
218 switch (file
->references
)
220 case lf_include_references
:
221 lf_indent_suppress (file
);
222 nr
+= lf_putstr (file
, "#line ");
223 nr
+= lf_putint (file
, line_nr
);
224 nr
+= lf_putstr (file
, " \"");
225 nr
+= lf_putstr (file
, file_name
);
226 nr
+= lf_putstr (file
, "\"\n");
228 case lf_omit_references
:
229 nr
+= lf_putstr (file
, "/* ");
230 nr
+= lf_putstr (file
, file_name
);
231 nr
+= lf_putstr (file
, ":");
232 nr
+= lf_putint (file
, line_nr
);
233 nr
+= lf_putstr (file
, "*/\n");
240 lf_print__internal_ref (lf
*file
)
243 nr
+= lf_print__external_ref (file
, file
->line_nr
+ 2, file
->name
);
244 /* line_nr == last_line, want to number from next */
249 lf_indent (lf
*file
, int delta
)
251 file
->indent
+= delta
;
256 lf_print__gnu_copyleft (lf
*file
)
263 nr
+= lf_printf (file
, "\
264 /* This file is part of GDB.\n\
266 Copyright 2002, 2007 Free Software Foundation, Inc.\n\
268 This program is free software; you can redistribute it and/or modify\n\
269 it under the terms of the GNU General Public License as published by\n\
270 the Free Software Foundation; either version 3 of the License, or\n\
271 (at your option) any later version.\n\
273 This program is distributed in the hope that it will be useful,\n\
274 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
275 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
276 GNU General Public License for more details.\n\
278 You should have received a copy of the GNU General Public License\n\
279 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
283 This file was generated by the program %s */\n\
284 ", filter_filename (file
->program
));
295 lf_putbin (lf
*file
, int decimal
, int width
)
300 for (bit
= 1 << (width
- 1); bit
!= 0; bit
>>= 1)
303 nr
+= lf_putchr (file
, '1');
305 nr
+= lf_putchr (file
, '0');
311 lf_print__this_file_is_empty (lf
*file
, const char *reason
)
318 nr
+= lf_printf (file
,
319 "/* This generated file (%s) is intentionally left blank",
322 nr
+= lf_printf (file
, " - %s", reason
);
323 nr
+= lf_printf (file
, " */\n");
326 ERROR ("Bad switch");
332 lf_print__ucase_filename (lf
*file
)
335 const char *chp
= file
->name
;
341 nr
+= lf_putchr (file
, toupper (ch
));
344 nr
+= lf_putchr (file
, '_');
346 nr
+= lf_putchr (file
, ch
);
353 lf_print__file_start (lf
*file
)
360 nr
+= lf_print__gnu_copyleft (file
);
361 nr
+= lf_printf (file
, "\n");
362 nr
+= lf_printf (file
, "#ifndef ");
363 nr
+= lf_print__ucase_filename (file
);
364 nr
+= lf_printf (file
, "\n");
365 nr
+= lf_printf (file
, "#define ");
366 nr
+= lf_print__ucase_filename (file
);
367 nr
+= lf_printf (file
, "\n");
368 nr
+= lf_printf (file
, "\n");
378 lf_print__file_finish (lf
*file
)
385 nr
+= lf_printf (file
, "\n");
386 nr
+= lf_printf (file
, "#endif /* _");
387 nr
+= lf_print__ucase_filename (file
);
388 nr
+= lf_printf (file
, "_*/\n");
398 lf_print__function_type (lf
*file
,
400 const char *prefix
, const char *trailing_space
)
403 nr
+= lf_printf (file
, "%s\\\n(%s)", prefix
, type
);
404 if (trailing_space
!= NULL
)
405 nr
+= lf_printf (file
, "%s", trailing_space
);
410 lf_print__function_type_function (lf
*file
,
411 print_function
* print_type
,
413 const char *trailing_space
)
416 nr
+= lf_printf (file
, "%s\\\n(", prefix
);
417 nr
+= print_type (file
);
418 nr
+= lf_printf (file
, ")");
419 if (trailing_space
!= NULL
)
420 nr
+= lf_printf (file
, "%s", trailing_space
);