]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dump-context.h
2018-10-04 Bernd Edlinger <bernd.edlinger@hotmail.de>
[thirdparty/gcc.git] / gcc / dump-context.h
CommitLineData
38cf91e5 1/* Support code for handling the various dump_* calls in dumpfile.h
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21
22#ifndef GCC_DUMP_CONTEXT_H
23#define GCC_DUMP_CONTEXT_H 1
24
bffe1cb4 25#include "dumpfile.h"
71e711b7 26#include "pretty-print.h"
27
38cf91e5 28/* A class for handling the various dump_* calls.
29
30 In particular, this class has responsibility for consolidating
31 the "dump_*" calls into optinfo instances (delimited by "dump_*_loc"
32 calls), and emitting them.
33
34 Putting this in a class (rather than as global state) allows
35 for selftesting of this code. */
36
37class dump_context
38{
39 friend class temp_dump_context;
40 public:
41 static dump_context &get () { return *s_current; }
42
43 ~dump_context ();
44
71e711b7 45 void refresh_dumps_are_enabled ();
46
291c13cb 47 void dump_loc (dump_flags_t dump_kind, const dump_location_t &loc);
48
38cf91e5 49 void dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
50 gimple *gs, int spc);
51
52 void dump_gimple_stmt_loc (dump_flags_t dump_kind,
53 const dump_location_t &loc,
54 dump_flags_t extra_dump_flags,
55 gimple *gs, int spc);
56
57 void dump_gimple_expr (dump_flags_t dump_kind,
58 dump_flags_t extra_dump_flags,
59 gimple *gs, int spc);
60
61 void dump_gimple_expr_loc (dump_flags_t dump_kind,
62 const dump_location_t &loc,
63 dump_flags_t extra_dump_flags,
64 gimple *gs,
65 int spc);
66
67 void dump_generic_expr (dump_flags_t dump_kind,
68 dump_flags_t extra_dump_flags,
69 tree t);
70
71 void dump_generic_expr_loc (dump_flags_t dump_kind,
72 const dump_location_t &loc,
73 dump_flags_t extra_dump_flags,
74 tree t);
75
76 void dump_printf_va (dump_flags_t dump_kind, const char *format,
bffe1cb4 77 va_list *ap) ATTRIBUTE_GCC_DUMP_PRINTF (3, 0);
38cf91e5 78
79 void dump_printf_loc_va (dump_flags_t dump_kind, const dump_location_t &loc,
bffe1cb4 80 const char *format, va_list *ap)
81 ATTRIBUTE_GCC_DUMP_PRINTF (4, 0);
38cf91e5 82
83 template<unsigned int N, typename C>
84 void dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value);
85
86 void dump_symtab_node (dump_flags_t dump_kind, symtab_node *node);
87
88 /* Managing nested scopes. */
89 unsigned int get_scope_depth () const;
90 void begin_scope (const char *name, const dump_location_t &loc);
91 void end_scope ();
92
93 /* For use in selftests; if true then optinfo_enabled_p is true. */
94 bool forcibly_enable_optinfo_p () const
95 {
96 return m_forcibly_enable_optinfo;
97 }
98
99 void end_any_optinfo ();
100
71e711b7 101 void emit_item (optinfo_item *item, dump_flags_t dump_kind);
102
38cf91e5 103 private:
104 optinfo &ensure_pending_optinfo ();
105 optinfo &begin_next_optinfo (const dump_location_t &loc);
106
107 /* For use in selftests; if true then optinfo_enabled_p is true. */
108 bool m_forcibly_enable_optinfo;
109
110 /* The current nesting depth of dump scopes, for showing nesting
111 via indentation). */
112 unsigned int m_scope_depth;
113
114 /* The optinfo currently being accumulated since the last dump_*_loc call,
115 if any. */
116 optinfo *m_pending;
117
71e711b7 118 /* For use in selftests: if non-NULL, then items are to be printed
119 to this, using the given flags. */
120 pretty_printer *m_test_pp;
121 dump_flags_t m_test_pp_flags;
122
38cf91e5 123 /* The currently active dump_context, for use by the dump_* API calls. */
124 static dump_context *s_current;
125
126 /* The default active context. */
127 static dump_context s_default;
128};
129
130#if CHECKING_P
131
132/* An RAII-style class for use in selftests for temporarily using a different
133 dump_context. */
134
135class temp_dump_context
136{
137 public:
71e711b7 138 temp_dump_context (bool forcibly_enable_optinfo,
139 dump_flags_t test_pp_flags);
38cf91e5 140 ~temp_dump_context ();
141
142 /* Support for selftests. */
143 optinfo *get_pending_optinfo () const { return m_context.m_pending; }
71e711b7 144 const char *get_dumped_text ();
38cf91e5 145
146 private:
71e711b7 147 pretty_printer m_pp;
38cf91e5 148 dump_context m_context;
149 dump_context *m_saved;
38cf91e5 150};
151
152#endif /* CHECKING_P */
153
154#endif /* GCC_DUMP_CONTEXT_H */