On Mon, 2021-03-08 at 11:04 -0700, Philip Herron wrote:
"Extract a common logger from the analyzer framework", surely?
^^^^
> In development of the Rust FE logging is useful in debugging. Instead
> of
> rolling our own logger it became clear the loggers part of analyzer
> and jit
> projects could be extracted and made generic so they could be reused
> in
> other projects.
>
> To test this patch make check-jit was invoked, for analyzer the
> following
> flags were used -fanalyzer -fdump-analyzer -fanalyzer-verbosity=4.
>
> gcc/ChangeLog:
>
> 2021-03-8 Philip Herron <[email protected]>
>
> * logging.h: added new generic logger based off analyzer's
> logger
> * logging.c: Likewise
>
> gcc/analyzer/ChangeLog:
>
> 2021-03-8 Philip Herron <[email protected]>
>
> * analyzer-logging.h: has been extract out to gcc/logging.h
> * analyzer-logging.c: Likewise
FWIW the analyzer parts look OK to me, though I think you need a global
reviewer to approve this.
Also, the commit message is now out-of-date, since this is no longer
refactoring the jit logging code, just the analyzer logger.
The ChangeLog entries look like they need a bit of reformatting.
Dave
> ---
> gcc/Makefile.in | 3 +-
> gcc/analyzer/analysis-plan.cc | 2 +-
> gcc/analyzer/analysis-plan.h | 2 +-
> gcc/analyzer/analyzer.h | 7 +-
> gcc/analyzer/checker-path.cc | 2 +-
> gcc/analyzer/complexity.cc | 2 +-
> gcc/analyzer/diagnostic-manager.cc | 2 +-
> gcc/analyzer/diagnostic-manager.h | 2 +-
> gcc/analyzer/engine.cc | 10 +-
> gcc/analyzer/exploded-graph.h | 4 +-
> gcc/analyzer/pending-diagnostic.cc | 2 +-
> gcc/analyzer/program-point.cc | 2 +-
> gcc/analyzer/program-state.cc | 2 +-
> gcc/analyzer/region-model-impl-calls.cc | 2 +-
> gcc/analyzer/region-model-manager.cc | 2 +-
> gcc/analyzer/region-model-reachability.cc | 2 +-
> gcc/analyzer/region-model.cc | 2 +-
> gcc/analyzer/region.cc | 2 +-
> gcc/analyzer/sm-file.cc | 2 +-
> gcc/analyzer/sm-malloc.cc | 2 +-
> gcc/analyzer/sm-pattern-test.cc | 2 +-
> gcc/analyzer/sm-sensitive.cc | 2 +-
> gcc/analyzer/sm-signal.cc | 2 +-
> gcc/analyzer/sm-taint.cc | 2 +-
> gcc/analyzer/sm.cc | 2 +-
> gcc/analyzer/sm.h | 2 +-
> gcc/analyzer/state-purge.cc | 4 +-
> gcc/analyzer/state-purge.h | 2 +-
> gcc/analyzer/store.cc | 2 +-
> gcc/analyzer/supergraph.cc | 2 +-
> gcc/analyzer/supergraph.h | 8 +-
> gcc/analyzer/svalue.cc | 2 +-
> .../analyzer-logging.cc => logging.c} | 37 +++----
> .../analyzer-logging.h => logging.h} | 100 +++++++++-------
> --
> 34 files changed, 111 insertions(+), 114 deletions(-)
> rename gcc/{analyzer/analyzer-logging.cc => logging.c} (87%)
> rename gcc/{analyzer/analyzer-logging.h => logging.h} (71%)
>
> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index a63c5d9cab6..408ef6e3f0b 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -1244,7 +1244,6 @@ C_COMMON_OBJS = c-family/c-common.o c-family/c-
> cppbuiltin.o c-family/c-dump.o \
> ANALYZER_OBJS = \
> analyzer/analysis-plan.o \
> analyzer/analyzer.o \
> - analyzer/analyzer-logging.o \
> analyzer/analyzer-pass.o \
> analyzer/analyzer-selftests.o \
> analyzer/bar-chart.o \
> @@ -1710,7 +1709,7 @@ OBJS-libcommon = diagnostic.o diagnostic-
> color.o diagnostic-show-locus.o \
> pretty-print.o intl.o \
> sbitmap.o \
> vec.o input.o version.o hash-table.o ggc-none.o memory-
> block.o \
> - selftest.o selftest-diagnostic.o sort.o
> + selftest.o selftest-diagnostic.o sort.o logging.o
>
> # Objects in libcommon-target.a, used by drivers and by the core
> # compiler and containing target-dependent code.
> diff --git a/gcc/analyzer/analysis-plan.cc b/gcc/analyzer/analysis-
> plan.cc
> index 7dfc48e9c3e..40d325976ca 100644
> --- a/gcc/analyzer/analysis-plan.cc
> +++ b/gcc/analyzer/analysis-plan.cc
> @@ -30,7 +30,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-core.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/analysis-plan.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> diff --git a/gcc/analyzer/analysis-plan.h b/gcc/analyzer/analysis-
> plan.h
> index 1d10b772833..51fc5f6d460 100644
> --- a/gcc/analyzer/analysis-plan.h
> +++ b/gcc/analyzer/analysis-plan.h
> @@ -31,7 +31,7 @@ namespace ana {
> - which callgraph edges should use call summaries
> TODO: the above is a work-in-progress. */
>
> -class analysis_plan : public log_user
> +class analysis_plan : public gcc::log_user
> {
> public:
> analysis_plan (const supergraph &sg, logger *logger);
> diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h
> index f50ac662516..2c2982e8adb 100644
> --- a/gcc/analyzer/analyzer.h
> +++ b/gcc/analyzer/analyzer.h
> @@ -23,6 +23,12 @@ along with GCC; see the file COPYING3. If not see
>
> class graphviz_out;
>
> +namespace gcc {
> + class logger;
> +}
> +
> +using gcc::logger;
> +
> namespace ana {
>
> /* Forward decls of common types, with indentation to show
> inheritance. */
> @@ -98,7 +104,6 @@ class rewind_info_t;
>
> class engine;
> class state_machine;
> -class logger;
> class visitor;
>
> /* Forward decls of functions. */
> diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-
> path.cc
> index e6e3ec18688..ca138336fd3 100644
> --- a/gcc/analyzer/checker-path.cc
> +++ b/gcc/analyzer/checker-path.cc
> @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see
> #include "shortest-paths.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "sbitmap.h"
> #include "bitmap.h"
> diff --git a/gcc/analyzer/complexity.cc b/gcc/analyzer/complexity.cc
> index ece4272ff6e..2b374eeccd3 100644
> --- a/gcc/analyzer/complexity.cc
> +++ b/gcc/analyzer/complexity.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "options.h"
> #include "cgraph.h"
> #include "cfg.h"
> diff --git a/gcc/analyzer/diagnostic-manager.cc
> b/gcc/analyzer/diagnostic-manager.cc
> index 7f20841768b..46a39a5d7fe 100644
> --- a/gcc/analyzer/diagnostic-manager.cc
> +++ b/gcc/analyzer/diagnostic-manager.cc
> @@ -39,7 +39,7 @@ along with GCC; see the file COPYING3. If not see
> #include "ordered-hash-map.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
> #include "analyzer/diagnostic-manager.h"
> diff --git a/gcc/analyzer/diagnostic-manager.h
> b/gcc/analyzer/diagnostic-manager.h
> index c55807851fd..60d6aaa1163 100644
> --- a/gcc/analyzer/diagnostic-manager.h
> +++ b/gcc/analyzer/diagnostic-manager.h
> @@ -87,7 +87,7 @@ class path_builder;
> This also lets us compute shortest_paths once, rather than
> per-diagnostic. */
>
> -class diagnostic_manager : public log_user
> +class diagnostic_manager : public gcc::log_user
> {
> public:
> diagnostic_manager (logger *logger, engine *eng, int verbosity);
> diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
> index 5339ea39712..c41435d4c28 100644
> --- a/gcc/analyzer/engine.cc
> +++ b/gcc/analyzer/engine.cc
> @@ -39,7 +39,7 @@ along with GCC; see the file COPYING3. If not see
> #include "selftest.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/call-string.h"
> #include "analyzer/program-point.h"
> #include "analyzer/store.h"
> @@ -350,7 +350,7 @@ public:
> return NULL_TREE;
> }
>
> - log_user m_logger;
> + gcc::log_user m_logger;
> exploded_graph &m_eg;
> const exploded_node *m_enode_for_diag;
> const program_state *m_old_state;
> @@ -3243,7 +3243,7 @@ exploded_graph::log_stats () const
> ++iter)
> {
> function *fn = (*iter).first;
> - log_scope s (logger, function_name (fn));
> + gcc::log_scope s (logger, function_name (fn));
> (*iter).second->log (logger);
> }
>
> @@ -4817,10 +4817,10 @@ run_checkers ()
> }
>
> {
> - log_user the_logger (NULL);
> + gcc::log_user the_logger (NULL);
> if (dump_fout)
> the_logger.set_logger (new logger (dump_fout, 0, 0,
> - *global_dc->printer));
> + global_dc->printer));
> LOG_SCOPE (the_logger.get_logger ());
>
> impl_run_checkers (the_logger.get_logger ());
> diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-
> graph.h
> index 871cb78b73a..bbabdc65fa0 100644
> --- a/gcc/analyzer/exploded-graph.h
> +++ b/gcc/analyzer/exploded-graph.h
> @@ -69,7 +69,7 @@ class impl_region_model_context : public
> region_model_context
> void on_escaped_function (tree fndecl) FINAL OVERRIDE;
>
> exploded_graph *m_eg;
> - log_user m_logger;
> + gcc::log_user m_logger;
> const exploded_node *m_enode_for_diag;
> const program_state *m_old_state;
> program_state *m_new_state;
> @@ -814,7 +814,7 @@ private:
>
> const supergraph &m_sg;
>
> - log_user m_logger;
> + gcc::log_user m_logger;
>
> /* Map from point/state to exploded node.
> To avoid duplication we store point_and_state
> diff --git a/gcc/analyzer/pending-diagnostic.cc
> b/gcc/analyzer/pending-diagnostic.cc
> index adff25130fd..855ca7dece1 100644
> --- a/gcc/analyzer/pending-diagnostic.cc
> +++ b/gcc/analyzer/pending-diagnostic.cc
> @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "diagnostic-event-id.h"
> #include "analyzer/sm.h"
> diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-
> point.cc
> index d8cfc61975e..e8c22388243 100644
> --- a/gcc/analyzer/program-point.cc
> +++ b/gcc/analyzer/program-point.cc
> @@ -36,7 +36,7 @@ along with GCC; see the file COPYING3. If not see
> #include "gimple-iterator.h"
> #include "digraph.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/supergraph.h"
> #include "analyzer/program-point.h"
> #include "sbitmap.h"
> diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-
> state.cc
> index e427fff59d6..d5c521adcec 100644
> --- a/gcc/analyzer/program-state.cc
> +++ b/gcc/analyzer/program-state.cc
> @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "sbitmap.h"
> #include "bitmap.h"
> diff --git a/gcc/analyzer/region-model-impl-calls.cc
> b/gcc/analyzer/region-model-impl-calls.cc
> index f83c12b5cb7..7e0ff1bf257 100644
> --- a/gcc/analyzer/region-model-impl-calls.cc
> +++ b/gcc/analyzer/region-model-impl-calls.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/region-model-manager.cc
> b/gcc/analyzer/region-model-manager.cc
> index dfd2413e914..fca4c8179d7 100644
> --- a/gcc/analyzer/region-model-manager.cc
> +++ b/gcc/analyzer/region-model-manager.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/region-model-reachability.cc
> b/gcc/analyzer/region-model-reachability.cc
> index 087185b4e45..79217339acc 100644
> --- a/gcc/analyzer/region-model-reachability.cc
> +++ b/gcc/analyzer/region-model-reachability.cc
> @@ -41,7 +41,7 @@ along with GCC; see the file COPYING3. If not see
> #include "selftest.h"
> #include "function.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-
> model.cc
> index 96ed549adf6..2b6aac24e91 100644
> --- a/gcc/analyzer/region-model.cc
> +++ b/gcc/analyzer/region-model.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc
> index 6db1fc91afd..c63aede909e 100644
> --- a/gcc/analyzer/region.cc
> +++ b/gcc/analyzer/region.cc
> @@ -46,7 +46,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
> index 48ef4aa2334..61352461d4a 100644
> --- a/gcc/analyzer/sm-file.cc
> +++ b/gcc/analyzer/sm-file.cc
> @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
> #include "analyzer/function-set.h"
> diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
> index ef250c80915..d3f202da5b1 100644
> --- a/gcc/analyzer/sm-malloc.cc
> +++ b/gcc/analyzer/sm-malloc.cc
> @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
> #include "tristate.h"
> diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-
> pattern-test.cc
> index 43b847559f8..574df06c48a 100644
> --- a/gcc/analyzer/sm-pattern-test.cc
> +++ b/gcc/analyzer/sm-pattern-test.cc
> @@ -34,7 +34,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
>
> diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-
> sensitive.cc
> index 95172f08922..f8f1eca5911 100644
> --- a/gcc/analyzer/sm-sensitive.cc
> +++ b/gcc/analyzer/sm-sensitive.cc
> @@ -34,7 +34,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
>
> diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
> index d7e7e7cab04..83a2ef9e8de 100644
> --- a/gcc/analyzer/sm-signal.cc
> +++ b/gcc/analyzer/sm-signal.cc
> @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
> #include "sbitmap.h"
> diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc
> index 2b2792e5edb..c6e5330869a 100644
> --- a/gcc/analyzer/sm-taint.cc
> +++ b/gcc/analyzer/sm-taint.cc
> @@ -34,7 +34,7 @@ along with GCC; see the file COPYING3. If not see
> #include "json.h"
> #include "analyzer/analyzer.h"
> #include "diagnostic-event-id.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
> #include "analyzer/pending-diagnostic.h"
>
> diff --git a/gcc/analyzer/sm.cc b/gcc/analyzer/sm.cc
> index 2d227dd1be0..9b5de4345cc 100644
> --- a/gcc/analyzer/sm.cc
> +++ b/gcc/analyzer/sm.cc
> @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see
> #include "tree-diagnostic.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/sm.h"
>
> #if ENABLE_ANALYZER
> diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h
> index 8d4d030394a..ce6e15f2f7c 100644
> --- a/gcc/analyzer/sm.h
> +++ b/gcc/analyzer/sm.h
> @@ -35,7 +35,7 @@ extern bool any_pointer_p (tree var);
> Manages a set of state objects, and has various virtual functions
> for pattern-matching on statements. */
>
> -class state_machine : public log_user
> +class state_machine : public gcc::log_user
> {
> public:
> /* States are represented by immutable objects, owned by the state
> diff --git a/gcc/analyzer/state-purge.cc b/gcc/analyzer/state-
> purge.cc
> index 70a09ed581f..4a577255231 100644
> --- a/gcc/analyzer/state-purge.cc
> +++ b/gcc/analyzer/state-purge.cc
> @@ -47,7 +47,7 @@ along with GCC; see the file COPYING3. If not see
> #include "cgraph.h"
> #include "analyzer/supergraph.h"
> #include "analyzer/program-point.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "analyzer/state-purge.h"
>
> #if ENABLE_ANALYZER
> @@ -198,7 +198,7 @@
> state_purge_per_ssa_name::state_purge_per_ssa_name (const
> state_purge_map &map,
>
> /* Process worklist by walking backwards until we reach the def
> stmt. */
> {
> - log_scope s (map.get_logger (), "processing worklist");
> + gcc::log_scope s (map.get_logger (), "processing worklist");
> while (worklist.length () > 0)
> {
> function_point point = worklist.pop ();
> diff --git a/gcc/analyzer/state-purge.h b/gcc/analyzer/state-purge.h
> index 879013dbc17..174325290e5 100644
> --- a/gcc/analyzer/state-purge.h
> +++ b/gcc/analyzer/state-purge.h
> @@ -74,7 +74,7 @@ namespace ana {
> different points in the program, so that we can simplify
> program_state
> objects, in the hope of reducing state-blowup. */
>
> -class state_purge_map : public log_user
> +class state_purge_map : public gcc::log_user
> {
> public:
> typedef ordered_hash_map<tree, state_purge_per_ssa_name *> map_t;
> diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc
> index 53b6e21aa75..c2ab1fc9bd6 100644
> --- a/gcc/analyzer/store.cc
> +++ b/gcc/analyzer/store.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "ordered-hash-map.h"
> #include "options.h"
> #include "cgraph.h"
> diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc
> index 4b934568db6..eaa965901d7 100644
> --- a/gcc/analyzer/supergraph.cc
> +++ b/gcc/analyzer/supergraph.cc
> @@ -51,7 +51,7 @@ along with GCC; see the file COPYING3. If not see
> #include "cfg.h"
> #include "digraph.h"
> #include "analyzer/supergraph.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
>
> #if ENABLE_ANALYZER
>
> diff --git a/gcc/analyzer/supergraph.h b/gcc/analyzer/supergraph.h
> index fc4a753c5a4..b9dcd1df100 100644
> --- a/gcc/analyzer/supergraph.h
> +++ b/gcc/analyzer/supergraph.h
> @@ -21,6 +21,12 @@ along with GCC; see the file COPYING3. If not see
> #ifndef GCC_ANALYZER_SUPERGRAPH_H
> #define GCC_ANALYZER_SUPERGRAPH_H
>
> +namespace gcc {
> +class logger;
> +}
> +
> +using gcc::logger;
> +
> using namespace ana;
>
> namespace ana {
> @@ -38,8 +44,6 @@ class superedge;
> class supercluster;
> class dot_annotator;
>
> -class logger;
> -
> /* An enum for discriminating between superedge subclasses. */
>
> enum edge_kind
> diff --git a/gcc/analyzer/svalue.cc b/gcc/analyzer/svalue.cc
> index d6305a37b9a..81e93dbde7f 100644
> --- a/gcc/analyzer/svalue.cc
> +++ b/gcc/analyzer/svalue.cc
> @@ -44,7 +44,7 @@ along with GCC; see the file COPYING3. If not see
> #include "function.h"
> #include "json.h"
> #include "analyzer/analyzer.h"
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
> #include "options.h"
> #include "cgraph.h"
> #include "cfg.h"
> diff --git a/gcc/analyzer/analyzer-logging.cc b/gcc/logging.c
> similarity index 87%
> rename from gcc/analyzer/analyzer-logging.cc
> rename to gcc/logging.c
> index 297319069f8..3c3ad7e0004 100644
> --- a/gcc/analyzer/analyzer-logging.cc
> +++ b/gcc/logging.c
> @@ -1,4 +1,4 @@
> -/* Hierarchical log messages for the analyzer.
> +/* Hierarchical log messages
> Copyright (C) 2014-2021 Free Software Foundation, Inc.
> Contributed by David Malcolm <[email protected]>.
>
> @@ -21,12 +21,11 @@ along with GCC; see the file COPYING3. If not
> see
> #include "config.h"
> #include "system.h"
> #include "coretypes.h"
> -#include "toplev.h" /* for print_version */
> +#include "toplev.h" /* for print_version */
> #include "pretty-print.h" /* for print_version */
> #include "diagnostic.h"
> #include "tree-diagnostic.h"
> -
> -#include "analyzer/analyzer-logging.h"
> +#include "logging.h"
>
> #if ENABLE_ANALYZER
>
> @@ -34,21 +33,16 @@ along with GCC; see the file COPYING3. If not
> see
> #pragma GCC diagnostic ignored "-Wformat-diag"
> #endif
>
> -namespace ana {
> +namespace gcc {
>
> /* Implementation of class logger. */
>
> /* ctor for logger. */
>
> -logger::logger (FILE *f_out,
> - int, /* flags */
> - int /* verbosity */,
> - const pretty_printer &reference_pp) :
> - m_refcount (0),
> - m_f_out (f_out),
> - m_indent_level (0),
> - m_log_refcount_changes (false),
> - m_pp (reference_pp.clone ())
> +logger::logger (FILE *f_out, int, /* flags */
> + int /* verbosity */, const pretty_printer
> *reference_pp)
> + : m_refcount (0), m_f_out (f_out), m_indent_level (0),
> + m_log_refcount_changes (false), m_pp (reference_pp->clone ())
> {
> pp_show_color (m_pp) = 0;
> pp_buffer (m_pp)->stream = f_out;
> @@ -80,8 +74,8 @@ logger::incref (const char *reason)
> {
> m_refcount++;
> if (m_log_refcount_changes)
> - log ("%s: reason: %s refcount now %i ",
> - __PRETTY_FUNCTION__, reason, m_refcount);
> + log ("%s: reason: %s refcount now %i ", __PRETTY_FUNCTION__,
> reason,
> + m_refcount);
> }
>
> /* Decrement the reference count of the logger,
> @@ -93,8 +87,8 @@ logger::decref (const char *reason)
> gcc_assert (m_refcount > 0);
> --m_refcount;
> if (m_log_refcount_changes)
> - log ("%s: reason: %s refcount now %i",
> - __PRETTY_FUNCTION__, reason, m_refcount);
> + log ("%s: reason: %s refcount now %i", __PRETTY_FUNCTION__,
> reason,
> + m_refcount);
> if (m_refcount == 0)
> delete this;
> }
> @@ -182,7 +176,6 @@ logger::enter_scope (const char *scope_name,
> const char *fmt, va_list *ap)
> inc_indent ();
> }
>
> -
> /* Record the exit from a particular scope, restoring the indent
> level to
> before the scope was entered. */
>
> @@ -203,7 +196,7 @@ logger::exit_scope (const char *scope_name)
> log_user::log_user (logger *logger) : m_logger (logger)
> {
> if (m_logger)
> - m_logger->incref("log_user ctor");
> + m_logger->incref ("log_user ctor");
> }
>
> /* The destructor for log_user. */
> @@ -211,7 +204,7 @@ log_user::log_user (logger *logger) : m_logger
> (logger)
> log_user::~log_user ()
> {
> if (m_logger)
> - m_logger->decref("log_user dtor");
> + m_logger->decref ("log_user dtor");
> }
>
> /* Set the logger for a log_user, managing the reference counts
> @@ -227,6 +220,6 @@ log_user::set_logger (logger *logger)
> m_logger = logger;
> }
>
> -} // namespace ana
> +} // namespace gcc
>
> #endif /* #if ENABLE_ANALYZER */
> diff --git a/gcc/analyzer/analyzer-logging.h b/gcc/logging.h
> similarity index 71%
> rename from gcc/analyzer/analyzer-logging.h
> rename to gcc/logging.h
> index 88b5f0a4a3f..0ce8d4fe137 100644
> --- a/gcc/analyzer/analyzer-logging.h
> +++ b/gcc/logging.h
> @@ -1,4 +1,4 @@
> -/* Hierarchical log messages for the analyzer.
> +/* GCC Logging
> Copyright (C) 2014-2021 Free Software Foundation, Inc.
> Contributed by David Malcolm <[email protected]>.
>
> @@ -18,44 +18,49 @@ You should have received a copy of the GNU
> General Public License
> along with GCC; see the file COPYING3. If not see
> <http://www.gnu.org/licenses/>. */
>
> -/* Adapted from jit-logging.h. */
> +#ifndef GCC_LOGGING_H
> +#define GCC_LOGGING_H
>
> -#ifndef ANALYZER_LOGGING_H
> -#define ANALYZER_LOGGING_H
> +#include "diagnostic-core.h"
>
> -namespace ana {
> +namespace gcc {
>
> -/* A logger encapsulates a logging stream: a way to send
> +/* A gcc::logger encapsulates a logging stream: a way to send
> lines of pertinent information to a FILE *. */
>
> class logger
> {
> - public:
> - logger (FILE *f_out, int flags, int verbosity, const
> pretty_printer &reference_pp);
> +public:
> + logger (FILE *f_out, int flags, int verbosity,
> + const pretty_printer *reference_pp);
> +
> ~logger ();
>
> void incref (const char *reason);
> void decref (const char *reason);
>
> - void log (const char *fmt, ...)
> - ATTRIBUTE_GCC_DIAG(2, 3);
> - void log_va (const char *fmt, va_list *ap)
> - ATTRIBUTE_GCC_DIAG(2, 0);
> + void log (const char *fmt, ...) ATTRIBUTE_GCC_DIAG (2, 3);
> + void log_va (const char *fmt, va_list *ap) ATTRIBUTE_GCC_DIAG (2,
> 0);
> void start_log_line ();
> - void log_partial (const char *fmt, ...)
> - ATTRIBUTE_GCC_DIAG(2, 3);
> - void log_va_partial (const char *fmt, va_list *ap)
> - ATTRIBUTE_GCC_DIAG(2, 0);
> + void log_partial (const char *fmt, ...) ATTRIBUTE_GCC_DIAG (2, 3);
> + void log_va_partial (const char *fmt, va_list *ap)
> ATTRIBUTE_GCC_DIAG (2, 0);
> void end_log_line ();
>
> void enter_scope (const char *scope_name);
> void enter_scope (const char *scope_name, const char *fmt, va_list
> *ap)
> - ATTRIBUTE_GCC_DIAG(3, 0);
> + ATTRIBUTE_GCC_DIAG (3, 0);
> void exit_scope (const char *scope_name);
> void inc_indent () { m_indent_level++; }
> void dec_indent () { m_indent_level--; }
>
> - pretty_printer *get_printer () const { return m_pp; }
> + bool has_pretty_printer () const { return m_pp != nullptr; }
> +
> + pretty_printer *get_printer () const
> + {
> + gcc_assert (m_pp != nullptr);
> + return m_pp;
> + }
> +
> FILE *get_file () const { return m_f_out; }
>
> private:
> @@ -68,7 +73,7 @@ private:
> pretty_printer *m_pp;
> };
>
> -/* The class log_scope is an RAII-style class intended to make
> +/* The class gcc::jit::log_scope is an RAII-style class intended to
> make
> it easy to notify a logger about entering and exiting the body of
> a
> given function. */
>
> @@ -77,10 +82,10 @@ class log_scope
> public:
> log_scope (logger *logger, const char *name);
> log_scope (logger *logger, const char *name, const char *fmt, ...)
> - ATTRIBUTE_GCC_DIAG(4, 5);
> + ATTRIBUTE_GCC_DIAG (4, 5);
> ~log_scope ();
>
> - private:
> +private:
> DISABLE_COPY_AND_ASSIGN (log_scope);
>
> logger *m_logger;
> @@ -96,10 +101,8 @@ public:
> We also need to hold a reference on it, to avoid a use-after-free
> when logging the cleanup of the owner of the logger. */
>
> -inline
> -log_scope::log_scope (logger *logger, const char *name) :
> - m_logger (logger),
> - m_name (name)
> +inline log_scope::log_scope (logger *logger, const char *name)
> + : m_logger (logger), m_name (name)
> {
> if (m_logger)
> {
> @@ -108,10 +111,9 @@ log_scope::log_scope (logger *logger, const char
> *name) :
> }
> }
>
> -inline
> -log_scope::log_scope (logger *logger, const char *name, const char
> *fmt, ...):
> - m_logger (logger),
> - m_name (name)
> +inline log_scope::log_scope (logger *logger, const char *name, const
> char *fmt,
> + ...)
> + : m_logger (logger), m_name (name)
> {
> if (m_logger)
> {
> @@ -123,12 +125,10 @@ log_scope::log_scope (logger *logger, const
> char *name, const char *fmt, ...):
> }
> }
>
> -
> /* The destructor for log_scope; essentially the opposite of
> the constructor. */
>
> -inline
> -log_scope::~log_scope ()
> +inline log_scope::~log_scope ()
> {
> if (m_logger)
> {
> @@ -143,15 +143,14 @@ log_scope::~log_scope ()
>
> class log_user
> {
> - public:
> +public:
> log_user (logger *logger);
> ~log_user ();
>
> - logger * get_logger () const { return m_logger; }
> - void set_logger (logger * logger);
> + logger *get_logger () const { return m_logger; }
> + void set_logger (logger *logger);
>
> - void log (const char *fmt, ...) const
> - ATTRIBUTE_GCC_DIAG(2, 3);
> + void log (const char *fmt, ...) const ATTRIBUTE_GCC_DIAG (2, 3);
>
> void start_log_line () const;
> void end_log_line () const;
> @@ -172,7 +171,7 @@ class log_user
> return m_logger->get_file ();
> }
>
> - private:
> +private:
> DISABLE_COPY_AND_ASSIGN (log_user);
>
> logger *m_logger;
> @@ -240,27 +239,24 @@ log_user::exit_scope (const char *scope_name)
> /* If the given logger is non-NULL, log entry/exit of this scope to
> it, identifying it using __PRETTY_FUNCTION__. */
>
> -#define LOG_SCOPE(LOGGER) \
> - log_scope s (LOGGER, __PRETTY_FUNCTION__)
> +#define LOG_SCOPE(LOGGER) gcc::log_scope s (LOGGER,
> __PRETTY_FUNCTION__)
>
> /* If the given logger is non-NULL, log entry/exit of this scope to
> it, identifying it using __func__. */
>
> -#define LOG_FUNC(LOGGER) \
> - log_scope s (LOGGER, __func__)
> +#define LOG_FUNC(LOGGER) gcc::log_scope s (LOGGER, __func__)
>
> -#define LOG_FUNC_1(LOGGER, FMT, A0) \
> - log_scope s (LOGGER, __func__, FMT, A0)
> +#define LOG_FUNC_1(LOGGER, FMT, A0) gcc::log_scope s (LOGGER,
> __func__, FMT, A0)
>
> -#define LOG_FUNC_2(LOGGER, FMT, A0, A1) \
> - log_scope s (LOGGER, __func__, FMT, A0, A1)
> +#define LOG_FUNC_2(LOGGER, FMT, A0,
> A1) \
> + gcc::log_scope s (LOGGER, __func__, FMT, A0, A1)
>
> -#define LOG_FUNC_3(LOGGER, FMT, A0, A1, A2) \
> - log_scope s (LOGGER, __func__, FMT, A0, A1, A2)
> +#define LOG_FUNC_3(LOGGER, FMT, A0, A1,
> A2) \
> + gcc::log_scope s (LOGGER, __func__, FMT, A0, A1, A2)
>
> -#define LOG_FUNC_4(LOGGER, FMT, A0, A1, A2, A3) \
> - log_scope s (LOGGER, __func__, FMT, A0, A1, A2, A3)
> +#define LOG_FUNC_4(LOGGER, FMT, A0, A1, A2,
> A3) \
> + gcc::log_scope s (LOGGER, __func__, FMT, A0, A1, A2, A3)
>
> -} // namespace ana
> +} // namespace gcc
>
> -#endif /* ANALYZER_LOGGING_H */
> +#endif /* GCC_LOGGING_H */