1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002, 2007 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
49 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
54 lf_file_references references
;
62 lf_file_references references
,
63 lf_file_type type
, const char *program
)
65 /* create a file object */
66 lf
*new_lf
= ZALLOC (lf
);
67 ASSERT (new_lf
!= NULL
);
68 new_lf
->references
= references
;
70 new_lf
->name
= (real_name
== NULL
? name
: real_name
);
71 new_lf
->program
= program
;
72 /* attach to stdout if pipe */
73 if (!strcmp (name
, "-"))
75 new_lf
->stream
= stdout
;
79 /* create a new file */
80 new_lf
->stream
= fopen (name
, "w");
81 if (new_lf
->stream
== NULL
)
94 if (file
->stream
!= stdout
)
96 if (fclose (file
->stream
))
98 perror ("lf_close.fclose");
107 lf_putchr (lf
*file
, const char chr
)
113 file
->line_blank
= 1;
115 else if (file
->line_blank
)
118 for (pad
= file
->indent
; pad
> 0; pad
--)
119 putc (' ', file
->stream
);
121 file
->line_blank
= 0;
123 putc (chr
, file
->stream
);
129 lf_write (lf
*file
, const char *string
, int strlen_string
)
133 for (i
= 0; i
< strlen_string
; i
++)
134 nr
+= lf_putchr (file
, string
[i
]);
140 lf_indent_suppress (lf
*file
)
142 file
->line_blank
= 0;
147 lf_putstr (lf
*file
, const char *string
)
153 for (chp
= string
; *chp
!= '\0'; chp
++)
155 nr
+= lf_putchr (file
, *chp
);
162 do_lf_putunsigned (lf
*file
, unsigned u
)
167 nr
+= do_lf_putunsigned (file
, u
/ 10);
168 nr
+= lf_putchr (file
, (u
% 10) + '0');
175 lf_putint (lf
*file
, int decimal
)
179 nr
+= lf_putchr (file
, '0');
180 else if (decimal
< 0)
182 nr
+= lf_putchr (file
, '-');
183 nr
+= do_lf_putunsigned (file
, -decimal
);
185 else if (decimal
> 0)
187 nr
+= do_lf_putunsigned (file
, decimal
);
196 lf_printf (lf
*file
, const char *fmt
, ...)
203 vsprintf (buf
, fmt
, ap
);
204 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
205 ASSERT (strlen (buf
) < sizeof (buf
));
206 nr
+= lf_putstr (file
, buf
);
213 lf_print__line_ref (lf
*file
, line_ref
*line
)
215 return lf_print__external_ref (file
, line
->line_nr
, line
->file_name
);
219 lf_print__external_ref (lf
*file
, int line_nr
, const char *file_name
)
222 switch (file
->references
)
224 case lf_include_references
:
225 lf_indent_suppress (file
);
226 nr
+= lf_putstr (file
, "#line ");
227 nr
+= lf_putint (file
, line_nr
);
228 nr
+= lf_putstr (file
, " \"");
229 nr
+= lf_putstr (file
, file_name
);
230 nr
+= lf_putstr (file
, "\"\n");
232 case lf_omit_references
:
233 nr
+= lf_putstr (file
, "/* ");
234 nr
+= lf_putstr (file
, file_name
);
235 nr
+= lf_putstr (file
, ":");
236 nr
+= lf_putint (file
, line_nr
);
237 nr
+= lf_putstr (file
, "*/\n");
244 lf_print__internal_ref (lf
*file
)
247 nr
+= lf_print__external_ref (file
, file
->line_nr
+ 2, file
->name
);
248 /* line_nr == last_line, want to number from next */
253 lf_indent (lf
*file
, int delta
)
255 file
->indent
+= delta
;
260 lf_print__gnu_copyleft (lf
*file
)
267 nr
+= lf_printf (file
, "\
268 /* This file is part of GDB.\n\
270 Copyright 2002 Free Software Foundation, Inc.\n\
272 This program is free software; you can redistribute it and/or modify\n\
273 it under the terms of the GNU General Public License as published by\n\
274 the Free Software Foundation; either version 2 of the License, or\n\
275 (at your option) any later version.\n\
277 This program is distributed in the hope that it will be useful,\n\
278 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
279 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
280 GNU General Public License for more details.\n\
282 You should have received a copy of the GNU General Public License\n\
283 along with this program; if not, write to the Free Software\n\
284 Foundation, Inc., 59 Temple Place - Suite 330,\n\
285 Boston, MA 02111-1307, USA.\n\
289 This file was generated by the program %s */\n\
290 ", filter_filename (file
->program
));
301 lf_putbin (lf
*file
, int decimal
, int width
)
306 for (bit
= 1 << (width
- 1); bit
!= 0; bit
>>= 1)
309 nr
+= lf_putchr (file
, '1');
311 nr
+= lf_putchr (file
, '0');
317 lf_print__this_file_is_empty (lf
*file
, const char *reason
)
324 nr
+= lf_printf (file
,
325 "/* This generated file (%s) is intentionally left blank",
328 nr
+= lf_printf (file
, " - %s", reason
);
329 nr
+= lf_printf (file
, " */\n");
332 ERROR ("Bad switch");
338 lf_print__ucase_filename (lf
*file
)
341 const char *chp
= file
->name
;
347 nr
+= lf_putchr (file
, toupper (ch
));
350 nr
+= lf_putchr (file
, '_');
352 nr
+= lf_putchr (file
, ch
);
359 lf_print__file_start (lf
*file
)
366 nr
+= lf_print__gnu_copyleft (file
);
367 nr
+= lf_printf (file
, "\n");
368 nr
+= lf_printf (file
, "#ifndef ");
369 nr
+= lf_print__ucase_filename (file
);
370 nr
+= lf_printf (file
, "\n");
371 nr
+= lf_printf (file
, "#define ");
372 nr
+= lf_print__ucase_filename (file
);
373 nr
+= lf_printf (file
, "\n");
374 nr
+= lf_printf (file
, "\n");
384 lf_print__file_finish (lf
*file
)
391 nr
+= lf_printf (file
, "\n");
392 nr
+= lf_printf (file
, "#endif /* _");
393 nr
+= lf_print__ucase_filename (file
);
394 nr
+= lf_printf (file
, "_*/\n");
404 lf_print__function_type (lf
*file
,
406 const char *prefix
, const char *trailing_space
)
409 nr
+= lf_printf (file
, "%s\\\n(%s)", prefix
, type
);
410 if (trailing_space
!= NULL
)
411 nr
+= lf_printf (file
, "%s", trailing_space
);
416 lf_print__function_type_function (lf
*file
,
417 print_function
* print_type
,
419 const char *trailing_space
)
422 nr
+= lf_printf (file
, "%s\\\n(", prefix
);
423 nr
+= print_type (file
);
424 nr
+= lf_printf (file
, ")");
425 if (trailing_space
!= NULL
)
426 nr
+= lf_printf (file
, "%s", trailing_space
);