1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2022 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/>. */
37 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
42 lf_file_references references
;
50 lf_file_references references
,
51 lf_file_type type
, const char *program
)
53 /* create a file object */
54 lf
*new_lf
= ZALLOC (lf
);
55 ASSERT (new_lf
!= NULL
);
56 new_lf
->references
= references
;
58 new_lf
->name
= (real_name
== NULL
? name
: real_name
);
59 new_lf
->program
= program
;
60 /* attach to stdout if pipe */
61 if (!strcmp (name
, "-"))
63 new_lf
->stream
= stdout
;
67 /* create a new file */
68 new_lf
->stream
= fopen (name
, "w");
69 if (new_lf
->stream
== NULL
)
80 lf_get_file_type (const lf
*file
)
89 if (file
->stream
!= stdout
)
91 if (fclose (file
->stream
))
93 perror ("lf_close.fclose");
102 lf_putchr (lf
*file
, const char chr
)
108 file
->line_blank
= 1;
110 else if (file
->line_blank
)
113 for (pad
= file
->indent
; pad
> 0; pad
--)
114 putc (' ', file
->stream
);
116 file
->line_blank
= 0;
118 putc (chr
, file
->stream
);
124 lf_write (lf
*file
, const char *string
, int strlen_string
)
128 for (i
= 0; i
< strlen_string
; i
++)
129 nr
+= lf_putchr (file
, string
[i
]);
135 lf_indent_suppress (lf
*file
)
137 file
->line_blank
= 0;
142 lf_putstr (lf
*file
, const char *string
)
148 for (chp
= string
; *chp
!= '\0'; chp
++)
150 nr
+= lf_putchr (file
, *chp
);
157 do_lf_putunsigned (lf
*file
, unsigned u
)
162 nr
+= do_lf_putunsigned (file
, u
/ 10);
163 nr
+= lf_putchr (file
, (u
% 10) + '0');
170 lf_putint (lf
*file
, int decimal
)
174 nr
+= lf_putchr (file
, '0');
175 else if (decimal
< 0)
177 nr
+= lf_putchr (file
, '-');
178 nr
+= do_lf_putunsigned (file
, -decimal
);
180 else if (decimal
> 0)
182 nr
+= do_lf_putunsigned (file
, decimal
);
191 lf_printf (lf
*file
, const char *fmt
, ...)
198 vsprintf (buf
, fmt
, ap
);
199 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
200 ASSERT (strlen (buf
) < sizeof (buf
));
201 nr
+= lf_putstr (file
, buf
);
208 lf_print__line_ref (lf
*file
, line_ref
*line
)
210 return lf_print__external_ref (file
, line
->line_nr
, line
->file_name
);
214 lf_print__external_ref (lf
*file
, int line_nr
, const char *file_name
)
217 switch (file
->references
)
219 case lf_include_references
:
220 lf_indent_suppress (file
);
221 nr
+= lf_putstr (file
, "#line ");
222 nr
+= lf_putint (file
, line_nr
);
223 nr
+= lf_putstr (file
, " \"");
224 nr
+= lf_putstr (file
, file_name
);
225 nr
+= lf_putstr (file
, "\"\n");
227 case lf_omit_references
:
228 nr
+= lf_putstr (file
, "/* ");
229 nr
+= lf_putstr (file
, file_name
);
230 nr
+= lf_putstr (file
, ":");
231 nr
+= lf_putint (file
, line_nr
);
232 nr
+= lf_putstr (file
, "*/\n");
239 lf_print__internal_ref (lf
*file
)
242 nr
+= lf_print__external_ref (file
, file
->line_nr
+ 2, file
->name
);
243 /* line_nr == last_line, want to number from next */
248 lf_indent (lf
*file
, int delta
)
250 file
->indent
+= delta
;
255 lf_print__gnu_copyleft (lf
*file
)
262 nr
+= lf_printf (file
, "\
263 /* This file is part of GDB.\n\
265 Copyright 2002, 2007 Free Software Foundation, Inc.\n\
267 This program is free software; you can redistribute it and/or modify\n\
268 it under the terms of the GNU General Public License as published by\n\
269 the Free Software Foundation; either version 3 of the License, or\n\
270 (at your option) any later version.\n\
272 This program is distributed in the hope that it will be useful,\n\
273 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
274 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
275 GNU General Public License for more details.\n\
277 You should have received a copy of the GNU General Public License\n\
278 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
282 This file was generated by the program %s */\n\
283 ", filter_filename (file
->program
));
294 lf_putbin (lf
*file
, int decimal
, int width
)
299 for (bit
= 1 << (width
- 1); bit
!= 0; bit
>>= 1)
302 nr
+= lf_putchr (file
, '1');
304 nr
+= lf_putchr (file
, '0');
310 lf_print__this_file_is_empty (lf
*file
, const char *reason
)
317 nr
+= lf_printf (file
,
318 "/* This generated file (%s) is intentionally left blank",
321 nr
+= lf_printf (file
, " - %s", reason
);
322 nr
+= lf_printf (file
, " */\n");
325 ERROR ("Bad switch");
331 lf_print__ucase_filename (lf
*file
)
334 const char *chp
= file
->name
;
340 nr
+= lf_putchr (file
, toupper (ch
));
343 nr
+= lf_putchr (file
, '_');
345 nr
+= lf_putchr (file
, ch
);
352 lf_print__file_start (lf
*file
)
359 nr
+= lf_print__gnu_copyleft (file
);
360 nr
+= lf_printf (file
, "\n");
361 nr
+= lf_printf (file
, "#ifndef ");
362 nr
+= lf_print__ucase_filename (file
);
363 nr
+= lf_printf (file
, "\n");
364 nr
+= lf_printf (file
, "#define ");
365 nr
+= lf_print__ucase_filename (file
);
366 nr
+= lf_printf (file
, "\n");
367 nr
+= lf_printf (file
, "\n");
377 lf_print__file_finish (lf
*file
)
384 nr
+= lf_printf (file
, "\n");
385 nr
+= lf_printf (file
, "#endif /* _");
386 nr
+= lf_print__ucase_filename (file
);
387 nr
+= lf_printf (file
, "_*/\n");
397 lf_print__function_type (lf
*file
,
399 const char *prefix
, const char *trailing_space
)
402 nr
+= lf_printf (file
, "%s\\\n(%s)", prefix
, type
);
403 if (trailing_space
!= NULL
)
404 nr
+= lf_printf (file
, "%s", trailing_space
);
409 lf_print__function_type_function (lf
*file
,
410 print_function
* print_type
,
412 const char *trailing_space
)
415 nr
+= lf_printf (file
, "%s\\\n(", prefix
);
416 nr
+= print_type (file
);
417 nr
+= lf_printf (file
, ")");
418 if (trailing_space
!= NULL
)
419 nr
+= lf_printf (file
, "%s", trailing_space
);