1*4c3eb207Smrg /* Helper code for graphviz output.
2*4c3eb207Smrg Copyright (C) 2019-2020 Free Software Foundation, Inc.
3*4c3eb207Smrg Contributed by David Malcolm <dmalcolm@redhat.com>.
4*4c3eb207Smrg
5*4c3eb207Smrg This file is part of GCC.
6*4c3eb207Smrg
7*4c3eb207Smrg GCC is free software; you can redistribute it and/or modify it
8*4c3eb207Smrg under the terms of the GNU General Public License as published by
9*4c3eb207Smrg the Free Software Foundation; either version 3, or (at your option)
10*4c3eb207Smrg any later version.
11*4c3eb207Smrg
12*4c3eb207Smrg GCC is distributed in the hope that it will be useful, but
13*4c3eb207Smrg WITHOUT ANY WARRANTY; without even the implied warranty of
14*4c3eb207Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15*4c3eb207Smrg General Public License for more details.
16*4c3eb207Smrg
17*4c3eb207Smrg You should have received a copy of the GNU General Public License
18*4c3eb207Smrg along with GCC; see the file COPYING3. If not see
19*4c3eb207Smrg <http://www.gnu.org/licenses/>. */
20*4c3eb207Smrg
21*4c3eb207Smrg #include "config.h"
22*4c3eb207Smrg #include "system.h"
23*4c3eb207Smrg #include "coretypes.h"
24*4c3eb207Smrg #include "graphviz.h"
25*4c3eb207Smrg
26*4c3eb207Smrg /* graphviz_out's ctor, wrapping PP. */
27*4c3eb207Smrg
graphviz_out(pretty_printer * pp)28*4c3eb207Smrg graphviz_out::graphviz_out (pretty_printer *pp)
29*4c3eb207Smrg : m_pp (pp),
30*4c3eb207Smrg m_indent (0)
31*4c3eb207Smrg {
32*4c3eb207Smrg }
33*4c3eb207Smrg
34*4c3eb207Smrg /* Formatted print of FMT. */
35*4c3eb207Smrg
36*4c3eb207Smrg void
print(const char * fmt,...)37*4c3eb207Smrg graphviz_out::print (const char *fmt, ...)
38*4c3eb207Smrg {
39*4c3eb207Smrg text_info text;
40*4c3eb207Smrg va_list ap;
41*4c3eb207Smrg
42*4c3eb207Smrg va_start (ap, fmt);
43*4c3eb207Smrg text.err_no = errno;
44*4c3eb207Smrg text.args_ptr = ≈
45*4c3eb207Smrg text.format_spec = fmt;
46*4c3eb207Smrg pp_format (m_pp, &text);
47*4c3eb207Smrg pp_output_formatted_text (m_pp);
48*4c3eb207Smrg va_end (ap);
49*4c3eb207Smrg }
50*4c3eb207Smrg
51*4c3eb207Smrg /* Formatted print of FMT. The text is indented by the current
52*4c3eb207Smrg indent, and a newline is added. */
53*4c3eb207Smrg
54*4c3eb207Smrg void
println(const char * fmt,...)55*4c3eb207Smrg graphviz_out::println (const char *fmt, ...)
56*4c3eb207Smrg {
57*4c3eb207Smrg text_info text;
58*4c3eb207Smrg va_list ap;
59*4c3eb207Smrg
60*4c3eb207Smrg write_indent ();
61*4c3eb207Smrg
62*4c3eb207Smrg va_start (ap, fmt);
63*4c3eb207Smrg text.err_no = errno;
64*4c3eb207Smrg text.args_ptr = ≈
65*4c3eb207Smrg text.format_spec = fmt;
66*4c3eb207Smrg pp_format (m_pp, &text);
67*4c3eb207Smrg pp_output_formatted_text (m_pp);
68*4c3eb207Smrg va_end (ap);
69*4c3eb207Smrg
70*4c3eb207Smrg pp_newline (m_pp);
71*4c3eb207Smrg }
72*4c3eb207Smrg
73*4c3eb207Smrg /* Print the current indent to the underlying pp. */
74*4c3eb207Smrg
75*4c3eb207Smrg void
write_indent()76*4c3eb207Smrg graphviz_out::write_indent ()
77*4c3eb207Smrg {
78*4c3eb207Smrg for (int i = 0; i < m_indent * 2; ++i)
79*4c3eb207Smrg pp_space (m_pp);
80*4c3eb207Smrg }
81*4c3eb207Smrg
82*4c3eb207Smrg /* Write the start of an HTML-like row via <TR>, writing to the stream
83*4c3eb207Smrg so that followup text can be escaped. */
84*4c3eb207Smrg
85*4c3eb207Smrg void
begin_tr()86*4c3eb207Smrg graphviz_out::begin_tr ()
87*4c3eb207Smrg {
88*4c3eb207Smrg pp_string (m_pp, "<TR>");
89*4c3eb207Smrg pp_write_text_to_stream (m_pp);
90*4c3eb207Smrg }
91*4c3eb207Smrg
92*4c3eb207Smrg /* Write the end of an HTML-like row via </TR>, writing to the stream
93*4c3eb207Smrg so that followup text can be escaped. */
94*4c3eb207Smrg
95*4c3eb207Smrg void
end_tr()96*4c3eb207Smrg graphviz_out::end_tr ()
97*4c3eb207Smrg {
98*4c3eb207Smrg pp_string (m_pp, "</TR>");
99*4c3eb207Smrg pp_write_text_to_stream (m_pp);
100*4c3eb207Smrg }
101*4c3eb207Smrg
102*4c3eb207Smrg /* Write the start of an HTML-like <TD>, writing to the stream
103*4c3eb207Smrg so that followup text can be escaped. */
104*4c3eb207Smrg
105*4c3eb207Smrg void
begin_td()106*4c3eb207Smrg graphviz_out::begin_td ()
107*4c3eb207Smrg {
108*4c3eb207Smrg pp_string (m_pp, "<TD ALIGN=\"LEFT\">");
109*4c3eb207Smrg pp_write_text_to_stream (m_pp);
110*4c3eb207Smrg }
111*4c3eb207Smrg
112*4c3eb207Smrg /* Write the end of an HTML-like </TD>, writing to the stream
113*4c3eb207Smrg so that followup text can be escaped. */
114*4c3eb207Smrg
115*4c3eb207Smrg void
end_td()116*4c3eb207Smrg graphviz_out::end_td ()
117*4c3eb207Smrg {
118*4c3eb207Smrg pp_string (m_pp, "</TD>");
119*4c3eb207Smrg pp_write_text_to_stream (m_pp);
120*4c3eb207Smrg }
121*4c3eb207Smrg
122*4c3eb207Smrg /* Write the start of an HTML-like row via <TR><TD>, writing to the stream
123*4c3eb207Smrg so that followup text can be escaped. */
124*4c3eb207Smrg
125*4c3eb207Smrg void
begin_trtd()126*4c3eb207Smrg graphviz_out::begin_trtd ()
127*4c3eb207Smrg {
128*4c3eb207Smrg pp_string (m_pp, "<TR><TD ALIGN=\"LEFT\">");
129*4c3eb207Smrg pp_write_text_to_stream (m_pp);
130*4c3eb207Smrg }
131*4c3eb207Smrg
132*4c3eb207Smrg /* Write the end of an HTML-like row via </TD></TR>, writing to the stream
133*4c3eb207Smrg so that followup text can be escaped. */
134*4c3eb207Smrg
135*4c3eb207Smrg void
end_tdtr()136*4c3eb207Smrg graphviz_out::end_tdtr ()
137*4c3eb207Smrg {
138*4c3eb207Smrg pp_string (m_pp, "</TD></TR>");
139*4c3eb207Smrg pp_write_text_to_stream (m_pp);
140*4c3eb207Smrg }
141