Branch data Line data Source code
1 : : /* Utilities for implementing "dump" functions for the diagnostics subsystem.
2 : : Copyright (C) 2025 Free Software Foundation, Inc.
3 : : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
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/>. */
20 : :
21 : :
22 : : #include "config.h"
23 : : #include "system.h"
24 : : #include "coretypes.h"
25 : : #include "diagnostics/dumping.h"
26 : :
27 : : namespace diagnostics {
28 : : namespace dumping {
29 : :
30 : : /* Emit indentation to OUTFILE for the start of a dump line. */
31 : :
32 : : void
33 : 0 : emit_indent (FILE *outfile, int indent)
34 : : {
35 : 0 : fprintf (outfile, "%*s", indent, "");
36 : 0 : }
37 : :
38 : : /* Emit an indented line to OUTFILE showing a heading. */
39 : :
40 : : void
41 : 0 : emit_heading (FILE *outfile, int indent,
42 : : const char *text)
43 : : {
44 : 0 : emit_indent (outfile, indent);
45 : 0 : fprintf (outfile, "%s:\n", text);
46 : 0 : }
47 : :
48 : : /* Various functions that emit an indented line to OUTFILE
49 : : showing "label: value". */
50 : :
51 : : void
52 : 0 : emit_string_field (FILE *outfile, int indent,
53 : : const char *label, const char *value)
54 : : {
55 : 0 : emit_indent (outfile, indent);
56 : 0 : fprintf (outfile, "%s: %s\n", label, value);
57 : 0 : }
58 : :
59 : : void
60 : 0 : emit_bool_field (FILE *outfile, int indent,
61 : : const char *label, bool value)
62 : : {
63 : 0 : emit_string_field (outfile, indent, label,
64 : : value ? "true" : "false");
65 : 0 : }
66 : :
67 : : void
68 : 0 : emit_size_t_field (FILE *outfile, int indent,
69 : : const char *label, size_t value)
70 : : {
71 : 0 : emit_indent (outfile, indent);
72 : 0 : fprintf (outfile, "%s: " HOST_SIZE_T_PRINT_DEC "\n", label, value);
73 : 0 : }
74 : :
75 : : void
76 : 0 : emit_int_field (FILE *outfile, int indent,
77 : : const char *label, int value)
78 : : {
79 : 0 : emit_indent (outfile, indent);
80 : 0 : fprintf (outfile, "%s: %i\n", label, value);
81 : 0 : }
82 : :
83 : : void
84 : 0 : emit_unsigned_field (FILE *outfile, int indent,
85 : : const char *label, unsigned value)
86 : : {
87 : 0 : emit_indent (outfile, indent);
88 : 0 : fprintf (outfile, "%s: %u\n", label, value);
89 : 0 : }
90 : :
91 : : /* Emit an indented line to OUTFILE reading "(none)". */
92 : :
93 : : void
94 : 0 : emit_none (FILE *outfile, int indent)
95 : : {
96 : 0 : emit_indent (outfile, indent);
97 : 0 : fprintf (outfile, "(none)\n");
98 : 0 : }
99 : :
100 : :
101 : : } // namespace dumping {
102 : : } // namespace diagnostics
|