xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/analyzer/bar-chart.h (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1*4c3eb207Smrg /* Support for plotting bar charts in dumps.
2*4c3eb207Smrg    Copyright (C) 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 #ifndef GCC_ANALYZER_BAR_CHART_H
22*4c3eb207Smrg #define GCC_ANALYZER_BAR_CHART_H
23*4c3eb207Smrg 
24*4c3eb207Smrg namespace ana {
25*4c3eb207Smrg 
26*4c3eb207Smrg /* A class for printing bar charts to a pretty_printer.
27*4c3eb207Smrg 
28*4c3eb207Smrg    TODO(stage1): move to gcc subdir? */
29*4c3eb207Smrg 
30*4c3eb207Smrg class bar_chart
31*4c3eb207Smrg {
32*4c3eb207Smrg public:
33*4c3eb207Smrg   typedef unsigned long value_t;
34*4c3eb207Smrg 
35*4c3eb207Smrg   /* Add an item, taking a copy of NAME.  */
36*4c3eb207Smrg   void add_item (const char *name, value_t value);
37*4c3eb207Smrg 
38*4c3eb207Smrg   /* Print the data to PP.  */
39*4c3eb207Smrg   void print (pretty_printer *pp) const;
40*4c3eb207Smrg 
41*4c3eb207Smrg private:
42*4c3eb207Smrg   struct item
43*4c3eb207Smrg   {
itemitem44*4c3eb207Smrg     item (const char *name, value_t value)
45*4c3eb207Smrg     : m_name (xstrdup (name)), m_strlen (strlen (name)) , m_value (value) {}
~itemitem46*4c3eb207Smrg     ~item () { free (m_name); }
47*4c3eb207Smrg 
48*4c3eb207Smrg     char *m_name;
49*4c3eb207Smrg     size_t m_strlen;
50*4c3eb207Smrg     value_t m_value;
51*4c3eb207Smrg   };
52*4c3eb207Smrg 
53*4c3eb207Smrg   static void print_padding (pretty_printer *pp, size_t count);
54*4c3eb207Smrg 
55*4c3eb207Smrg   auto_delete_vec<item> m_items;
56*4c3eb207Smrg };
57*4c3eb207Smrg 
58*4c3eb207Smrg } // namespace ana
59*4c3eb207Smrg 
60*4c3eb207Smrg #endif /* GCC_ANALYZER_BAR_CHART_H */
61