From 89069993d74498866e3d2a258d5aad140f0c03a7 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 6 Jan 2017 11:46:37 -0500
Subject: [PATCH 24/26] FIXME: move logging from gcc to libcpp

---
 gcc/Makefile.in          |   4 +-
 gcc/jit/dummy-frontend.c |   6 +-
 gcc/jit/jit-common.h     |   4 +-
 gcc/jit/jit-logging.c    |   2 +-
 gcc/jit/jit-logging.h    |   2 +-
 gcc/jit/jit-playback.c   |  46 +++++------
 gcc/jit/jit-recording.c  |  16 ++--
 gcc/jit/jit-result.c     |   8 +-
 gcc/jit/jit-tempdir.c    |   6 +-
 gcc/jit/libgccjit.c      | 136 ++++++++++++++++----------------
 gcc/logging.c            | 165 ---------------------------------------
 gcc/logging.h            | 196 -----------------------------------------------
 libcpp/Makefile.in       |   6 +-
 libcpp/include/logging.h | 195 ++++++++++++++++++++++++++++++++++++++++++++++
 libcpp/logging.c         | 162 +++++++++++++++++++++++++++++++++++++++
 15 files changed, 475 insertions(+), 479 deletions(-)
 delete mode 100644 gcc/logging.c
 delete mode 100644 gcc/logging.h
 create mode 100644 libcpp/include/logging.h
 create mode 100644 libcpp/logging.c

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9317e12..b3cb855 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -968,7 +968,8 @@ SYSTEM_H = system.h hwint.h $(srcdir)/../include/libiberty.h \
 	$(srcdir)/../include/safe-ctype.h $(srcdir)/../include/filenames.h
 PREDICT_H = predict.h predict.def
 CPPLIB_H = $(srcdir)/../libcpp/include/line-map.h \
-	$(srcdir)/../libcpp/include/cpplib.h
+	$(srcdir)/../libcpp/include/cpplib.h \
+	$(srcdir)/../libcpp/include/logging.h
 INPUT_H = $(srcdir)/../libcpp/include/line-map.h input.h
 OPTS_H = $(INPUT_H) $(VEC_H) opts.h $(OBSTACK_H)
 SYMTAB_H = $(srcdir)/../libcpp/include/symtab.h $(OBSTACK_H)
@@ -1372,7 +1373,6 @@ OBJS = \
 	langhooks.o \
 	lcm.o \
 	lists.o \
-	logging.o \
 	loop-doloop.o \
 	loop-init.o \
 	loop-invariant.o \
diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c
index 80ade16..31c679a 100644
--- a/gcc/jit/dummy-frontend.c
+++ b/gcc/jit/dummy-frontend.c
@@ -100,7 +100,7 @@ jit_begin_diagnostic (diagnostic_context */*context*/,
 		      diagnostic_info */*diagnostic*/)
 {
   gcc_assert (gcc::jit::active_playback_ctxt);
-  GCC_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
+  LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
 
   /* No-op (apart from logging); the real error-handling is done in the
      "end_diagnostic" hook.  */
@@ -113,7 +113,7 @@ jit_end_diagnostic (diagnostic_context *context,
 		    diagnostic_info *diagnostic)
 {
   gcc_assert (gcc::jit::active_playback_ctxt);
-  GCC_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
+  LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
 
   /* Delegate to the playback context (and thence to the
      recording context).  */
@@ -126,7 +126,7 @@ static bool
 jit_langhook_init (void)
 {
   gcc_assert (gcc::jit::active_playback_ctxt);
-  GCC_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
+  LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
 
   static bool registered_root_tab = false;
   if (!registered_root_tab)
diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index a7f51e3..e13c6ae 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -93,10 +93,10 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE + 1;
 
    End of comment for inclusion in the docs.  */
 
-namespace gcc {
-
 class logger;
 
+namespace gcc {
+
 namespace jit {
 
 class result;
diff --git a/gcc/jit/jit-logging.c b/gcc/jit/jit-logging.c
index 9f3330b..9c10146 100644
--- a/gcc/jit/jit-logging.c
+++ b/gcc/jit/jit-logging.c
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 gcc::jit::logger::logger (FILE *f_out,
 			  int flags,
 			  int verbosity) :
-  gcc::logger (f_out, flags, verbosity, "JIT")
+  ::logger (f_out, flags, verbosity, "JIT")
 {
   /* Begin the log by writing the GCC version.  */
   print_version (f_out, "JIT:", false);
diff --git a/gcc/jit/jit-logging.h b/gcc/jit/jit-logging.h
index dedd350..a6bc47d 100644
--- a/gcc/jit/jit-logging.h
+++ b/gcc/jit/jit-logging.h
@@ -30,7 +30,7 @@ namespace jit {
 /* A gcc::jit::logger encapsulates a logging stream: a way to send
    lines of pertinent information to a FILE *.  */
 
-class logger : public gcc::logger
+class logger : public ::logger
 {
  public:
   logger (FILE *f_out, int flags, int verbosity);
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index d20fe37..cf9f36d 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -83,7 +83,7 @@ playback::context::context (recording::context *ctxt)
     m_char_array_type_node (NULL),
     m_const_char_ptr (NULL)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   m_functions.create (0);
   m_globals.create (0);
   m_source_files.create (0);
@@ -94,7 +94,7 @@ playback::context::context (recording::context *ctxt)
 
 playback::context::~context ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   /* Normally the playback::context is responsible for cleaning up the
      tempdir (including "fake.so" within the filesystem).
@@ -1341,7 +1341,7 @@ build_stmt_list ()
   int i;
   block *b;
 
-  GCC_LOG_SCOPE (m_ctxt->get_logger ());
+  LOG_SCOPE (m_ctxt->get_logger ());
 
   FOR_EACH_VEC_ELT (m_blocks, i, b)
     {
@@ -1368,7 +1368,7 @@ void
 playback::function::
 postprocess ()
 {
-  GCC_LOG_SCOPE (m_ctxt->get_logger ());
+  LOG_SCOPE (m_ctxt->get_logger ());
 
   if (m_ctxt->get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE))
     debug_tree (m_stmt_list);
@@ -1750,7 +1750,7 @@ void
 playback::context::
 compile ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   const char *ctxt_progname;
 
@@ -1839,7 +1839,7 @@ playback::compile_to_memory::compile_to_memory (recording::context *ctxt) :
   playback::context (ctxt),
   m_result (NULL)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 }
 
 /*  Implementation of the playback::context::process vfunc for compiling
@@ -1851,7 +1851,7 @@ playback::compile_to_memory::compile_to_memory (recording::context *ctxt) :
 void
 playback::compile_to_memory::postprocess (const char *ctxt_progname)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   convert_to_dso (ctxt_progname);
   if (errors_occurred ())
     return;
@@ -1870,7 +1870,7 @@ playback::compile_to_file::compile_to_file (recording::context *ctxt,
   m_output_kind (output_kind),
   m_output_path (output_path)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 }
 
 /*  Implementation of the playback::context::process vfunc for compiling
@@ -1883,7 +1883,7 @@ playback::compile_to_file::compile_to_file (recording::context *ctxt,
 void
 playback::compile_to_file::postprocess (const char *ctxt_progname)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   /* The driver takes different actions based on the filename, so
      we provide a filename with an appropriate suffix for the
@@ -1976,7 +1976,7 @@ void
 playback::compile_to_file::copy_file (const char *src_path,
 				      const char *dst_path)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   if (get_logger ())
     {
       get_logger ()->log ("src_path: %s", src_path);
@@ -2092,7 +2092,7 @@ playback::context::acquire_mutex ()
   auto_timevar tv (get_timer (), TV_JIT_ACQUIRING_MUTEX);
 
   /* Acquire the big GCC mutex. */
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   pthread_mutex_lock (&jit_mutex);
   gcc_assert (NULL == active_playback_ctxt);
   active_playback_ctxt = this;
@@ -2104,7 +2104,7 @@ void
 playback::context::release_mutex ()
 {
   /* Release the big GCC mutex. */
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   gcc_assert (active_playback_ctxt == this);
   active_playback_ctxt = NULL;
   pthread_mutex_unlock (&jit_mutex);
@@ -2132,7 +2132,7 @@ make_fake_args (vec <char *> *argvec,
 		const char *ctxt_progname,
 		vec <recording::requested_dump> *requested_dumps)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
 #define ADD_ARG(arg) argvec->safe_push (xstrdup (arg))
 #define ADD_ARG_TAKE_OWNERSHIP(arg) argvec->safe_push (arg)
@@ -2279,7 +2279,7 @@ void
 playback::context::
 extract_any_requested_dumps (vec <recording::requested_dump> *requested_dumps)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   int i;
   recording::requested_dump *d;
@@ -2367,7 +2367,7 @@ void
 playback::context::
 convert_to_dso (const char *ctxt_progname)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   invoke_driver (ctxt_progname,
 		 m_tempdir->get_path_s_file (),
@@ -2388,7 +2388,7 @@ invoke_driver (const char *ctxt_progname,
 	       bool shared,
 	       bool run_linker)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   bool embedded_driver
     = !get_inner_bool_option (INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER);
@@ -2453,7 +2453,7 @@ void
 playback::context::
 invoke_embedded_driver (const vec <char *> *argvec)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   driver d (true, /* can_finalize */
 	    false); /* debug */
   int result = d.main (argvec->length (),
@@ -2468,7 +2468,7 @@ playback::context::
 invoke_external_driver (const char *ctxt_progname,
 			vec <char *> *argvec)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   const char *errmsg;
   int exit_status = 0;
   int err = 0;
@@ -2528,7 +2528,7 @@ void
 playback::context::
 add_multilib_driver_arguments (vec <char *> *argvec)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   /* Add copies of the arguments in multilib_defaults_raw to argvec,
      prepending each with a "-".  */
@@ -2545,7 +2545,7 @@ result *
 playback::context::
 dlopen_built_dso ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   auto_timevar load_timevar (get_timer (), TV_LOAD);
   void *handle = NULL;
   const char *error = NULL;
@@ -2607,7 +2607,7 @@ void
 playback::context::
 replay ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   /* Adapted from c-common.c:c_common_nodes_and_builtins.  */
   tree array_domain_type = build_index_type (size_int (200));
   m_char_array_type_node
@@ -2669,7 +2669,7 @@ void
 playback::context::
 dump_generated_code ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   char buf[4096];
   size_t sz;
   FILE *f_in = fopen (get_path_s_file (), "r");
@@ -2755,7 +2755,7 @@ handle_locations ()
      imposed by the linemap API.
 
      line_table is a global.  */
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   int i;
   source_file *file;
 
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index 56efc85..9a515ab 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -509,7 +509,7 @@ recording::context::context (context *parent_ctxt)
 
 recording::context::~context ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   int i;
   memento *m;
   FOR_EACH_VEC_ELT (m_mementos, i, m)
@@ -552,7 +552,7 @@ recording::context::record (memento *m)
 void
 recording::context::replay_into (replayer *r)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   int i;
   memento *m;
 
@@ -610,7 +610,7 @@ recording::context::replay_into (replayer *r)
 void
 recording::context::disassociate_from_playback ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   int i;
   memento *m;
 
@@ -1226,7 +1226,7 @@ recording::context::enable_dump (const char *dumpname,
 result *
 recording::context::compile ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   log_all_options ();
 
@@ -1256,7 +1256,7 @@ void
 recording::context::compile_to_file (enum gcc_jit_output_kind output_kind,
 				     const char *output_path)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   log_all_options ();
 
@@ -1297,7 +1297,7 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
   const char *errmsg;
   bool has_ownership;
 
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   len = vasprintf (&malloced_msg, fmt, ap);
   if (malloced_msg == NULL || len < 0)
@@ -1543,7 +1543,7 @@ recording::context::log_inner_bool_option (enum inner_bool_option opt) const
 void
 recording::context::dump_reproducer_to_file (const char *path)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
   reproducer r (*this, path);
 
   /* Generate the "ancestry" of this context, as a list.  */
@@ -1745,7 +1745,7 @@ recording::context::get_all_requested_dumps (vec <recording::requested_dump> *ou
 void
 recording::context::validate ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   if (m_parent_ctxt)
     m_parent_ctxt->validate ();
diff --git a/gcc/jit/jit-result.c b/gcc/jit/jit-result.c
index 4f54497..88e0e6a 100644
--- a/gcc/jit/jit-result.c
+++ b/gcc/jit/jit-result.c
@@ -38,7 +38,7 @@ result(logger *logger, void *dso_handle, tempdir *tempdir_) :
   m_dso_handle (dso_handle),
   m_tempdir (tempdir_)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 }
 
 /* gcc::jit::result's destructor.
@@ -47,7 +47,7 @@ result(logger *logger, void *dso_handle, tempdir *tempdir_) :
 
 result::~result()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   dlclose (m_dso_handle);
 
@@ -69,7 +69,7 @@ void *
 result::
 get_code (const char *funcname)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   void *code;
   const char *error;
@@ -96,7 +96,7 @@ void *
 result::
 get_global (const char *name)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   void *global;
   const char *error;
diff --git a/gcc/jit/jit-tempdir.c b/gcc/jit/jit-tempdir.c
index 5a1461b..b3aefee 100644
--- a/gcc/jit/jit-tempdir.c
+++ b/gcc/jit/jit-tempdir.c
@@ -75,7 +75,7 @@ gcc::jit::tempdir::tempdir (logger *logger, int keep_intermediates)
     m_path_s_file (NULL),
     m_path_so_file (NULL)
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 }
 
 /* Do the real work of creating the on-disk tempdir.
@@ -85,7 +85,7 @@ gcc::jit::tempdir::tempdir (logger *logger, int keep_intermediates)
 bool
 gcc::jit::tempdir::create ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   m_path_template = make_tempdir_path_template ();
   if (!m_path_template)
@@ -115,7 +115,7 @@ gcc::jit::tempdir::create ()
 
 gcc::jit::tempdir::~tempdir ()
 {
-  GCC_LOG_SCOPE (get_logger ());
+  LOG_SCOPE (get_logger ());
 
   if (m_keep_intermediates)
     fprintf (stderr, "intermediate files written to %s\n", m_path_tempdir);
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 54ccca2..4bd56bd 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -357,7 +357,7 @@ void
 gcc_jit_context_release (gcc_jit_context *ctxt)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   ctxt->log ("deleting ctxt: %p", (void *)ctxt);
   delete ctxt;
 }
@@ -372,7 +372,7 @@ gcc_jit_context *
 gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt)
 {
   RETURN_NULL_IF_FAIL (parent_ctxt, NULL, NULL, "NULL parent ctxt");
-  GCC_LOG_FUNC (parent_ctxt->get_logger ());
+  LOG_FUNC (parent_ctxt->get_logger ());
   parent_ctxt->log ("parent_ctxt: %p", (void *)parent_ctxt);
   gcc_jit_context *child_ctxt = new gcc_jit_context (parent_ctxt);
   child_ctxt->log ("new child_ctxt: %p", (void *)child_ctxt);
@@ -392,7 +392,7 @@ gcc_jit_context_new_location (gcc_jit_context *ctxt,
 			      int column)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   return (gcc_jit_location *)ctxt->new_location (filename, line, column, true);
 }
 
@@ -435,7 +435,7 @@ gcc_jit_context_get_type (gcc_jit_context *ctxt,
 			  enum gcc_jit_types type)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_PRINTF1 (
     (type >= GCC_JIT_TYPE_VOID
      && type <= GCC_JIT_TYPE_FILE_PTR),
@@ -457,7 +457,7 @@ gcc_jit_context_get_int_type (gcc_jit_context *ctxt,
 			      int num_bytes, int is_signed)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (num_bytes >= 0, ctxt, NULL, "negative size");
 
   return (gcc_jit_type *)ctxt->get_int_type (num_bytes, is_signed);
@@ -518,7 +518,7 @@ gcc_jit_context_new_array_type (gcc_jit_context *ctxt,
 				int num_elements)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (element_type, ctxt, loc, "NULL type");
   RETURN_NULL_IF_FAIL (num_elements >= 0, ctxt, NULL, "negative size");
@@ -541,7 +541,7 @@ gcc_jit_context_new_field (gcc_jit_context *ctxt,
 			   const char *name)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
   RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -584,7 +584,7 @@ gcc_jit_context_new_struct_type (gcc_jit_context *ctxt,
 				 gcc_jit_field **fields)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
   if (num_fields)
@@ -620,7 +620,7 @@ gcc_jit_context_new_opaque_struct (gcc_jit_context *ctxt,
 				   const char *name)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
 
@@ -655,7 +655,7 @@ gcc_jit_struct_set_fields (gcc_jit_struct *struct_type,
 {
   RETURN_IF_FAIL (struct_type, NULL, loc, "NULL struct_type");
   gcc::jit::recording::context *ctxt = struct_type->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL_PRINTF1 (
     NULL == struct_type->get_fields (), ctxt, loc,
@@ -698,7 +698,7 @@ gcc_jit_context_new_union_type (gcc_jit_context *ctxt,
 				gcc_jit_field **fields)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
   if (num_fields)
@@ -737,7 +737,7 @@ gcc_jit_context_new_function_ptr_type (gcc_jit_context *ctxt,
 				       int is_variadic)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (return_type, ctxt, loc, "NULL return_type");
   RETURN_NULL_IF_FAIL (
@@ -771,7 +771,7 @@ gcc_jit_context_new_param (gcc_jit_context *ctxt,
 			   const char *name)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
   RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -837,7 +837,7 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt,
 			      int is_variadic)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     ((kind >= GCC_JIT_FUNCTION_EXPORTED)
@@ -912,7 +912,7 @@ gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt,
 				      const char *name)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (name, ctxt, NULL, "NULL name");
 
   return static_cast <gcc_jit_function *> (ctxt->get_builtin_function (name));
@@ -943,7 +943,7 @@ gcc_jit_function_get_param (gcc_jit_function *func, int index)
 {
   RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");
   gcc::jit::recording::context *ctxt = func->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (index >= 0, ctxt, NULL, "negative index");
   int num_params = func->get_params ().length ();
   RETURN_NULL_IF_FAIL_PRINTF3 (index < num_params,
@@ -968,7 +968,7 @@ gcc_jit_function_dump_to_dot (gcc_jit_function *func,
 {
   RETURN_IF_FAIL (func, NULL, NULL, "NULL function");
   gcc::jit::recording::context *ctxt = func->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
 
   func->dump_to_dot (path);
@@ -985,7 +985,7 @@ gcc_jit_function_new_block (gcc_jit_function *func,
 			    const char *name)
 {
   RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");
-  GCC_LOG_FUNC (func->get_context ()->get_logger ());
+  LOG_FUNC (func->get_context ()->get_logger ());
   RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
 		       func->get_context (), NULL,
 		       "cannot add block to an imported function");
@@ -1036,7 +1036,7 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt,
 			    const char *name)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     ((kind >= GCC_JIT_GLOBAL_EXPORTED)
@@ -1134,7 +1134,7 @@ gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,
 				     int value)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
 
   return ((gcc_jit_rvalue *)ctxt
@@ -1149,7 +1149,7 @@ gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt,
 				      long value)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
 
   return ((gcc_jit_rvalue *)ctxt
@@ -1167,7 +1167,7 @@ gcc_jit_context_zero (gcc_jit_context *ctxt,
 		      gcc_jit_type *numeric_type)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
 
   return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0);
@@ -1184,7 +1184,7 @@ gcc_jit_context_one (gcc_jit_context *ctxt,
 		     gcc_jit_type *numeric_type)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
 
   return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1);
@@ -1202,7 +1202,7 @@ gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt,
 					double value)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
 
   return ((gcc_jit_rvalue *)ctxt
@@ -1221,7 +1221,7 @@ gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt,
 				     void *value)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
   RETURN_NULL_IF_FAIL_PRINTF1 (
     pointer_type->is_pointer (),
@@ -1244,7 +1244,7 @@ gcc_jit_context_null (gcc_jit_context *ctxt,
 		      gcc_jit_type *pointer_type)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
   RETURN_NULL_IF_FAIL_PRINTF1 (
     pointer_type->is_pointer (),
@@ -1266,7 +1266,7 @@ gcc_jit_context_new_string_literal (gcc_jit_context *ctxt,
 				    const char *value)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (value, ctxt, NULL, "NULL value");
 
   return (gcc_jit_rvalue *)ctxt->new_string_literal (value);
@@ -1286,7 +1286,7 @@ gcc_jit_context_new_unary_op (gcc_jit_context *ctxt,
 			      gcc_jit_rvalue *rvalue)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     (op >= GCC_JIT_UNARY_OP_MINUS
@@ -1325,7 +1325,7 @@ gcc_jit_context_new_binary_op (gcc_jit_context *ctxt,
 			       gcc_jit_rvalue *a, gcc_jit_rvalue *b)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     valid_binary_op_p (op),
@@ -1361,7 +1361,7 @@ gcc_jit_context_new_comparison (gcc_jit_context *ctxt,
 				gcc_jit_rvalue *a, gcc_jit_rvalue *b)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     (op >= GCC_JIT_COMPARISON_EQ
@@ -1397,7 +1397,7 @@ gcc_jit_context_new_call (gcc_jit_context *ctxt,
 			  int numargs , gcc_jit_rvalue **args)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (func, ctxt, loc, "NULL function");
   if (numargs)
@@ -1470,7 +1470,7 @@ gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt,
 				      int numargs, gcc_jit_rvalue **args)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (fn_ptr, ctxt, loc, "NULL fn_ptr");
   if (numargs)
@@ -1600,7 +1600,7 @@ gcc_jit_context_new_cast (gcc_jit_context *ctxt,
 			  gcc_jit_type *type)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
   RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
@@ -1628,7 +1628,7 @@ gcc_jit_context_new_array_access (gcc_jit_context *ctxt,
 				  gcc_jit_rvalue *index)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (ptr, ctxt, loc, "NULL ptr");
   RETURN_NULL_IF_FAIL (index, ctxt, loc, "NULL index");
@@ -1689,7 +1689,7 @@ gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
 {
   RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
   gcc::jit::recording::context *ctxt = struct_->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (field, ctxt, loc, "NULL field");
   RETURN_NULL_IF_FAIL_PRINTF1 (field->get_container (), field->m_ctxt, loc,
@@ -1721,7 +1721,7 @@ gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
 {
   RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
   gcc::jit::recording::context *ctxt = struct_->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (field, ctxt, loc, "NULL field");
   RETURN_NULL_IF_FAIL_PRINTF1 (field->get_container (), field->m_ctxt, loc,
@@ -1752,7 +1752,7 @@ gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr,
 				  gcc_jit_field *field)
 {
   RETURN_NULL_IF_FAIL (ptr, NULL, loc, "NULL ptr");
-  GCC_LOG_FUNC (ptr->get_context ()->get_logger ());
+  LOG_FUNC (ptr->get_context ()->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (field, NULL, loc, "NULL field");
   gcc::jit::recording::type *underlying_type =
@@ -1789,7 +1789,7 @@ gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue,
 			    gcc_jit_location *loc)
 {
   RETURN_NULL_IF_FAIL (rvalue, NULL, loc, "NULL rvalue");
-  GCC_LOG_FUNC (rvalue->get_context ()->get_logger ());
+  LOG_FUNC (rvalue->get_context ()->get_logger ());
   /* LOC can be NULL.  */
 
   gcc::jit::recording::type *underlying_type =
@@ -1822,7 +1822,7 @@ gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue,
 			    gcc_jit_location *loc)
 {
   RETURN_NULL_IF_FAIL (lvalue, NULL, loc, "NULL lvalue");
-  GCC_LOG_FUNC (lvalue->get_context ()->get_logger ());
+  LOG_FUNC (lvalue->get_context ()->get_logger ());
   /* LOC can be NULL.  */
 
   return (gcc_jit_rvalue *)lvalue->get_address (loc);
@@ -1841,7 +1841,7 @@ gcc_jit_function_new_local (gcc_jit_function *func,
 {
   RETURN_NULL_IF_FAIL (func, NULL, loc, "NULL function");
   gcc::jit::recording::context *ctxt = func->m_ctxt;
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
 		       ctxt, loc,
@@ -1870,7 +1870,7 @@ gcc_jit_block_add_eval (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
 
@@ -1898,7 +1898,7 @@ gcc_jit_block_add_assignment (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue");
   RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
@@ -1939,7 +1939,7 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue");
   RETURN_IF_FAIL_PRINTF1 (
@@ -1997,7 +1997,7 @@ gcc_jit_block_end_with_conditional (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (boolval, ctxt, loc, "NULL boolval");
   RETURN_IF_FAIL_PRINTF2 (
@@ -2051,7 +2051,7 @@ gcc_jit_block_add_comment (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (text, ctxt, loc, "NULL text");
 
@@ -2071,7 +2071,7 @@ gcc_jit_block_end_with_jump (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (target, ctxt, loc, "NULL target");
   RETURN_IF_FAIL_PRINTF4 (
@@ -2101,7 +2101,7 @@ gcc_jit_block_end_with_return (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   gcc::jit::recording::function *func = block->get_function ();
   RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
@@ -2139,7 +2139,7 @@ gcc_jit_block_end_with_void_return (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   gcc::jit::recording::function *func = block->get_function ();
   RETURN_IF_FAIL_PRINTF2 (
@@ -2166,7 +2166,7 @@ gcc_jit_context_new_case (gcc_jit_context *ctxt,
 			  gcc_jit_block *block)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_NULL_IF_FAIL (min_value, ctxt, NULL, "NULL min_value");
   RETURN_NULL_IF_FAIL (max_value, ctxt, NULL, "NULL max_value");
   RETURN_NULL_IF_FAIL (block, ctxt, NULL, "NULL block");
@@ -2488,7 +2488,7 @@ gcc_jit_block_end_with_switch (gcc_jit_block *block,
 {
   RETURN_IF_NOT_VALID_BLOCK (block, loc);
   gcc::jit::recording::context *ctxt = block->get_context ();
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* LOC can be NULL.  */
   RETURN_IF_FAIL (expr, ctxt, loc,
 		  "NULL expr");
@@ -2545,7 +2545,7 @@ gcc_jit_context_set_str_option (gcc_jit_context *ctxt,
 				const char *value)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* opt is checked by the inner function.
      value can be NULL.  */
 
@@ -2564,7 +2564,7 @@ gcc_jit_context_set_int_option (gcc_jit_context *ctxt,
 				int value)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* opt is checked by the inner function.  */
 
   ctxt->set_int_option (opt, value);
@@ -2582,7 +2582,7 @@ gcc_jit_context_set_bool_option (gcc_jit_context *ctxt,
 				 int value)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   /* opt is checked by the inner function.  */
 
   ctxt->set_bool_option (opt, value);
@@ -2599,7 +2599,7 @@ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt,
 						   int bool_value)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   ctxt->set_inner_bool_option (
     gcc::jit::INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS,
     bool_value);
@@ -2616,7 +2616,7 @@ gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt,
 					      int bool_value)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   ctxt->set_inner_bool_option (
     gcc::jit::INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER,
     bool_value);
@@ -2633,7 +2633,7 @@ gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt,
 					 const char *optname)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL (optname, ctxt, NULL, "NULL optname");
   if (ctxt->get_logger ())
     ctxt->get_logger ()->log ("optname: %s", optname);
@@ -2653,7 +2653,7 @@ gcc_jit_context_enable_dump (gcc_jit_context *ctxt,
 			     char **out_ptr)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL (dumpname, ctxt, NULL, "NULL dumpname");
   RETURN_IF_FAIL (out_ptr, ctxt, NULL, "NULL out_ptr");
 
@@ -2671,7 +2671,7 @@ gcc_jit_context_compile (gcc_jit_context *ctxt)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
 
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
 
   ctxt->log ("in-memory compile of ctxt: %p", (void *)ctxt);
 
@@ -2695,7 +2695,7 @@ gcc_jit_context_compile_to_file (gcc_jit_context *ctxt,
 				 const char *output_path)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL_PRINTF1 (
     ((output_kind >= GCC_JIT_OUTPUT_KIND_ASSEMBLER)
      && (output_kind <= GCC_JIT_OUTPUT_KIND_EXECUTABLE)),
@@ -2724,7 +2724,7 @@ gcc_jit_context_dump_to_file (gcc_jit_context *ctxt,
 			      int update_locations)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
   ctxt->dump_to_file (path, update_locations);
 }
@@ -2738,11 +2738,11 @@ gcc_jit_context_set_logfile (gcc_jit_context *ctxt,
 			     int verbosity)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL ((flags == 0), ctxt, NULL, "flags must be 0 for now");
   RETURN_IF_FAIL ((verbosity == 0), ctxt, NULL, "verbosity must be 0 for now");
 
-  gcc::logger *logger;
+  logger *logger;
   if (logfile)
     logger = new gcc::jit::logger (logfile, flags, verbosity);
   else
@@ -2761,7 +2761,7 @@ gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt,
 					 const char *path)
 {
   RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
   RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
   ctxt->dump_reproducer_to_file (path);
 }
@@ -2776,7 +2776,7 @@ const char *
 gcc_jit_context_get_first_error (gcc_jit_context *ctxt)
 {
   RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
-  GCC_LOG_FUNC (ctxt->get_logger ());
+  LOG_FUNC (ctxt->get_logger ());
 
   return ctxt->get_first_error ();
 }
@@ -2805,7 +2805,7 @@ gcc_jit_result_get_code (gcc_jit_result *result,
 			 const char *fnname)
 {
   RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result");
-  GCC_LOG_FUNC (result->get_logger ());
+  LOG_FUNC (result->get_logger ());
   RETURN_NULL_IF_FAIL (fnname, NULL, NULL, "NULL fnname");
 
   result->log ("locating fnname: %s", fnname);
@@ -2825,7 +2825,7 @@ gcc_jit_result_get_global (gcc_jit_result *result,
 			   const char *name)
 {
   RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result");
-  GCC_LOG_FUNC (result->get_logger ());
+  LOG_FUNC (result->get_logger ());
   RETURN_NULL_IF_FAIL (name, NULL, NULL, "NULL name");
 
   void *global = result->get_global (name);
@@ -2843,7 +2843,7 @@ void
 gcc_jit_result_release (gcc_jit_result *result)
 {
   RETURN_IF_FAIL (result, NULL, NULL, "NULL result");
-  GCC_LOG_FUNC (result->get_logger ());
+  LOG_FUNC (result->get_logger ());
   result->log ("deleting result: %p", (void *)result);
   delete result;
 }
@@ -2962,7 +2962,7 @@ gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *rvalue,
 					   int require_tail_call)
 {
   RETURN_IF_FAIL (rvalue, NULL, NULL, "NULL call");
-  GCC_LOG_FUNC (rvalue->get_context ()->get_logger ());
+  LOG_FUNC (rvalue->get_context ()->get_logger ());
 
   /* Verify that it's a call.  */
   gcc::jit::recording::base_call *call = rvalue->dyn_cast_base_call ();
diff --git a/gcc/logging.c b/gcc/logging.c
deleted file mode 100644
index 2427297..0000000
--- a/gcc/logging.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/* Internals of logging
-   Copyright (C) 2014-2016 Free Software Foundation, Inc.
-   Contributed by David Malcolm <dmalcolm@redhat.com>.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
-
-GCC is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-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/>.  */
-
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "logging.h"
-
-namespace gcc {
-
-/* Implementation of class gcc::logger.  */
-
-/* The constructor for gcc::logger.  */
-
-logger::logger (FILE *f_out,
-		int, /* flags */
-		int /* verbosity */,
-		const char *prefix) :
-  m_refcount (0),
-  m_f_out (f_out),
-  m_indent_level (0),
-  m_log_refcount_changes (false),
-  m_prefix (prefix)
-{
-}
-
-/* The destructor for gcc::logger, invoked via
-   the decref method when the refcount hits zero.
-   Note that we do not close the underlying FILE * (m_f_out).  */
-
-logger::~logger ()
-{
-  /* This should be the last message emitted.  */
-  log ("%s", __PRETTY_FUNCTION__);
-  gcc_assert (m_refcount == 0);
-}
-
-/* Increment the reference count of the gcc::logger.  */
-
-void
-logger::incref (const char *reason)
-{
-  m_refcount++;
-  if (m_log_refcount_changes)
-    log ("%s: reason: %s refcount now %i ",
-	 __PRETTY_FUNCTION__, reason, m_refcount);
-}
-
-/* Decrement the reference count of the gcc::logger,
-   deleting it if nothing is referring to it.  */
-
-void
-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);
-  if (0 == m_refcount)
-    delete this;
-}
-
-/* Write a formatted message to the log, by calling the log_va method.  */
-
-void
-logger::log (const char *fmt, ...)
-{
-  va_list ap;
-  va_start (ap, fmt);
-  log_va (fmt, ap);
-  va_end (ap);
-}
-
-/* Write an indented line to the log file.
-
-   We explicitly flush after each line: if something crashes the process,
-   we want the logfile/stream to contain the most up-to-date hint about the
-   last thing that was happening, without it being hidden in an in-process
-   buffer.  */
-
-void
-logger::log_va (const char *fmt, va_list ap)
-{
-  if (m_prefix)
-    fprintf (m_f_out, "%s: ", m_prefix);
-  for (int i = 0; i < m_indent_level; i++)
-    fputc (' ', m_f_out);
-  vfprintf (m_f_out, fmt, ap);
-  fprintf (m_f_out, "\n");
-  fflush (m_f_out);
-}
-
-/* Record the entry within a particular scope, indenting subsequent
-   log lines accordingly.  */
-
-void
-logger::enter_scope (const char *scope_name)
-{
-  log ("entering: %s", scope_name);
-  m_indent_level += 1;
-}
-
-/* Record the exit from a particular scope, restoring the indent level to
-   before the scope was entered.  */
-
-void
-logger::exit_scope (const char *scope_name)
-{
-  if (m_indent_level)
-    m_indent_level -= 1;
-  else
-    log ("(mismatching indentation)");
-  log ("exiting: %s", scope_name);
-}
-
-/* Implementation of class gcc::log_user.  */
-
-/* The constructor for gcc::log_user.  */
-
-log_user::log_user (logger *logger) : m_logger (logger)
-{
-  if (m_logger)
-    m_logger->incref("log_user ctor");
-}
-
-/* The destructor for gcc::log_user.  */
-
-log_user::~log_user ()
-{
-  if (m_logger)
-    m_logger->decref("log_user dtor");
-}
-
-/* Set the logger for a gcc::log_user, managing the reference counts
-   of the old and new logger (either of which might be NULL).  */
-
-void
-log_user::set_logger (logger *logger)
-{
-  if (logger)
-    logger->incref ("log_user::set_logger");
-  if (m_logger)
-    m_logger->decref ("log_user::set_logger");
-  m_logger = logger;
-}
-
-} // namespace gcc
diff --git a/gcc/logging.h b/gcc/logging.h
deleted file mode 100644
index 87b52de..0000000
--- a/gcc/logging.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/* Logging facilities.
-   Copyright (C) 2014-2016 Free Software Foundation, Inc.
-   Contributed by David Malcolm <dmalcolm@redhat.com>.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
-
-GCC is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-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/>.  */
-
-#ifndef LOGGING_H
-#define LOGGING_H
-
-#ifdef GCC_VERSION
-#if GCC_VERSION >= 4001
-#define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N))))
-#else
-#define GNU_PRINTF(M, N)
-#endif
-#endif
-
-namespace gcc {
-
-/* 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 char *prefix);
-  ~logger ();
-
-  void incref (const char *reason);
-  void decref (const char *reason);
-
-  void log (const char *fmt, ...)
-    GNU_PRINTF(2, 3);
-  void log_va (const char *fmt, va_list ap)
-    GNU_PRINTF(2, 0);
-
-  void enter_scope (const char *scope_name);
-  void exit_scope (const char *scope_name);
-
-private:
-  int m_refcount;
-  FILE *m_f_out;
-  int m_indent_level;
-  bool m_log_refcount_changes;
-  const char *m_prefix;
-};
-
-/* The class gcc::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.  */
-
-class log_scope
-{
-public:
-  log_scope (logger *logger, const char *name);
-  ~log_scope ();
-
- private:
-  logger *m_logger;
-  const char *m_name;
-};
-
-/* The constructor for gcc::log_scope.
-
-   The normal case is that the logger is NULL, in which case this should
-   be largely a no-op.
-
-   If we do have a logger, notify it that we're entering the given scope.
-   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)
-{
-  if (m_logger)
-    {
-      m_logger->incref ("log_scope ctor");
-      m_logger->enter_scope (m_name);
-    }
-}
-
-/* The destructor for gcc::log_scope; essentially the opposite of
-   the constructor.  */
-
-inline
-log_scope::~log_scope ()
-{
-  if (m_logger)
-    {
-      m_logger->exit_scope (m_name);
-      m_logger->decref ("log_scope dtor");
-    }
-}
-
-/* A gcc::log_user is something that potentially uses a
-   gcc::logger (which could be NULL).
-
-   It is the base class for each of:
-
-      - class gcc::jit::recording::context
-
-      - class gcc::jit::playback::context
-
-      - class gcc::jit::tempdir
-
-      - class gcc::jit::result
-
-   The log_user class keeps the reference-count of a logger up-to-date.  */
-
-class log_user
-{
- public:
-  log_user (logger *logger);
-  ~log_user ();
-
-  logger * get_logger () const { return m_logger; }
-  void set_logger (logger * logger);
-
-  void log (const char *fmt, ...) const
-    GNU_PRINTF(2, 3);
-
-  void enter_scope (const char *scope_name);
-  void exit_scope (const char *scope_name);
-
- private:
-  logger *m_logger;
-};
-
-/* A shortcut for calling log from a context/result, handling the common
-   case where the underlying logger is NULL via a no-op.  */
-
-inline void
-log_user::log (const char *fmt, ...) const
-{
-  if (m_logger)
-    {
-      va_list ap;
-      va_start (ap, fmt);
-      m_logger->log_va (fmt, ap);
-      va_end (ap);
-    }
-}
-
-/* A shortcut for recording entry into a scope from a context/result,
-   handling the common case where the underlying logger is NULL via
-   a no-op.  */
-
-inline void
-log_user::enter_scope (const char *scope_name)
-{
-  if (m_logger)
-    m_logger->enter_scope (scope_name);
-}
-
-/* A shortcut for recording exit from a scope from a context/result,
-   handling the common case where the underlying logger is NULL via
-   a no-op.  */
-
-inline void
-log_user::exit_scope (const char *scope_name)
-{
-  if (m_logger)
-    m_logger->exit_scope (scope_name);
-}
-
-} // namespace gcc
-
-/* If the given logger is non-NULL, log entry/exit of this scope to
-   it, identifying it using __PRETTY_FUNCTION__.  */
-
-#define GCC_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 GCC_LOG_FUNC(LOGGER) \
-  gcc::log_scope s (LOGGER, __func__)
-
-#endif /* LOGGING_H */
diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
index 0bd3787..336969a 100644
--- a/libcpp/Makefile.in
+++ b/libcpp/Makefile.in
@@ -85,11 +85,11 @@ DEPMODE = $(CXXDEPMODE)
 
 libcpp_a_OBJS = charset.o directives.o directives-only.o errors.o \
 	expr.o files.o identifiers.o init.o lex.o line-map.o macro.o \
-	mkdeps.o pch.o symtab.o traditional.o
+	mkdeps.o pch.o symtab.o traditional.o logging.o
 
 libcpp_a_SOURCES = charset.c directives.c directives-only.c errors.c \
 	expr.c files.c identifiers.c init.c lex.c line-map.c macro.c \
-	mkdeps.c pch.c symtab.c traditional.c
+	mkdeps.c pch.c symtab.c traditional.c logging.c
 
 all: libcpp.a $(USED_CATALOGS)
 
@@ -263,7 +263,7 @@ po/$(PACKAGE).pot: $(libcpp_a_SOURCES)
 
 TAGS_SOURCES = $(libcpp_a_SOURCES) internal.h ucnid.h \
     include/line-map.h include/symtab.h include/cpp-id-data.h \
-    include/cpplib.h include/mkdeps.h system.h
+    include/cpplib.h include/mkdeps.h include/logging.h system.h
 
 TAGS: $(TAGS_SOURCES)
 	cd $(srcdir) && etags $(TAGS_SOURCES)
diff --git a/libcpp/include/logging.h b/libcpp/include/logging.h
new file mode 100644
index 0000000..44cb006
--- /dev/null
+++ b/libcpp/include/logging.h
@@ -0,0 +1,195 @@
+/* Logging facilities.
+   Copyright (C) 2014-2017 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.
+
+ In other words, you are welcome to use, share and improve this program.
+ You are forbidden to forbid anyone else to use, share and improve
+ what you give them.   Help stamp out software-hoarding!  */
+
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#ifdef GCC_VERSION
+#if GCC_VERSION >= 4001
+#define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N))))
+#else
+#define GNU_PRINTF(M, N)
+#endif
+#endif
+
+/* A 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 char *prefix);
+  ~logger ();
+
+  void incref (const char *reason);
+  void decref (const char *reason);
+
+  void log (const char *fmt, ...)
+    GNU_PRINTF(2, 3);
+  void log_va (const char *fmt, va_list ap)
+    GNU_PRINTF(2, 0);
+
+  void enter_scope (const char *scope_name);
+  void exit_scope (const char *scope_name);
+
+private:
+  int m_refcount;
+  FILE *m_f_out;
+  int m_indent_level;
+  bool m_log_refcount_changes;
+  const char *m_prefix;
+};
+
+/* The class 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.  */
+
+class log_scope
+{
+public:
+  log_scope (logger *logger, const char *name);
+  ~log_scope ();
+
+ private:
+  logger *m_logger;
+  const char *m_name;
+};
+
+/* The constructor for log_scope.
+
+   The normal case is that the logger is NULL, in which case this should
+   be largely a no-op.
+
+   If we do have a logger, notify it that we're entering the given scope.
+   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)
+{
+  if (m_logger)
+    {
+      m_logger->incref ("log_scope ctor");
+      m_logger->enter_scope (m_name);
+    }
+}
+
+/* The destructor for log_scope; essentially the opposite of
+   the constructor.  */
+
+inline
+log_scope::~log_scope ()
+{
+  if (m_logger)
+    {
+      m_logger->exit_scope (m_name);
+      m_logger->decref ("log_scope dtor");
+    }
+}
+
+/* A log_user is something that potentially uses a
+   logger (which could be NULL).
+
+   It is the base class for each of:
+
+      - class gcc::jit::recording::context
+
+      - class gcc::jit::playback::context
+
+      - class gcc::jit::tempdir
+
+      - class gcc::jit::result
+
+   The log_user class keeps the reference-count of a logger up-to-date.  */
+
+class log_user
+{
+ public:
+  log_user (logger *logger);
+  ~log_user ();
+
+  logger * get_logger () const { return m_logger; }
+  void set_logger (logger * logger);
+
+  void log (const char *fmt, ...) const
+    GNU_PRINTF(2, 3);
+
+  void enter_scope (const char *scope_name);
+  void exit_scope (const char *scope_name);
+
+ private:
+  logger *m_logger;
+};
+
+/* A shortcut for calling log from a context/result, handling the common
+   case where the underlying logger is NULL via a no-op.  */
+
+inline void
+log_user::log (const char *fmt, ...) const
+{
+  if (m_logger)
+    {
+      va_list ap;
+      va_start (ap, fmt);
+      m_logger->log_va (fmt, ap);
+      va_end (ap);
+    }
+}
+
+/* A shortcut for recording entry into a scope from a context/result,
+   handling the common case where the underlying logger is NULL via
+   a no-op.  */
+
+inline void
+log_user::enter_scope (const char *scope_name)
+{
+  if (m_logger)
+    m_logger->enter_scope (scope_name);
+}
+
+/* A shortcut for recording exit from a scope from a context/result,
+   handling the common case where the underlying logger is NULL via
+   a no-op.  */
+
+inline void
+log_user::exit_scope (const char *scope_name)
+{
+  if (m_logger)
+    m_logger->exit_scope (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__)
+
+/* 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__)
+
+#endif /* LOGGING_H */
diff --git a/libcpp/logging.c b/libcpp/logging.c
new file mode 100644
index 0000000..5397ecd
--- /dev/null
+++ b/libcpp/logging.c
@@ -0,0 +1,162 @@
+/* Internals of logging
+   Copyright (C) 2014-2017 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.
+
+ In other words, you are welcome to use, share and improve this program.
+ You are forbidden to forbid anyone else to use, share and improve
+ what you give them.   Help stamp out software-hoarding!  */
+
+#include "config.h"
+#include "system.h"
+#include "logging.h"
+
+/* Implementation of class logger.  */
+
+/* The constructor for logger.  */
+
+logger::logger (FILE *f_out,
+		int, /* flags */
+		int /* verbosity */,
+		const char *prefix) :
+  m_refcount (0),
+  m_f_out (f_out),
+  m_indent_level (0),
+  m_log_refcount_changes (false),
+  m_prefix (prefix)
+{
+}
+
+/* The destructor for logger, invoked via
+   the decref method when the refcount hits zero.
+   Note that we do not close the underlying FILE * (m_f_out).  */
+
+logger::~logger ()
+{
+  /* This should be the last message emitted.  */
+  log ("%s", __PRETTY_FUNCTION__);
+  gcc_assert (m_refcount == 0);
+}
+
+/* Increment the reference count of the logger.  */
+
+void
+logger::incref (const char *reason)
+{
+  m_refcount++;
+  if (m_log_refcount_changes)
+    log ("%s: reason: %s refcount now %i ",
+	 __PRETTY_FUNCTION__, reason, m_refcount);
+}
+
+/* Decrement the reference count of the logger,
+   deleting it if nothing is referring to it.  */
+
+void
+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);
+  if (0 == m_refcount)
+    delete this;
+}
+
+/* Write a formatted message to the log, by calling the log_va method.  */
+
+void
+logger::log (const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  log_va (fmt, ap);
+  va_end (ap);
+}
+
+/* Write an indented line to the log file.
+
+   We explicitly flush after each line: if something crashes the process,
+   we want the logfile/stream to contain the most up-to-date hint about the
+   last thing that was happening, without it being hidden in an in-process
+   buffer.  */
+
+void
+logger::log_va (const char *fmt, va_list ap)
+{
+  if (m_prefix)
+    fprintf (m_f_out, "%s: ", m_prefix);
+  for (int i = 0; i < m_indent_level; i++)
+    fputc (' ', m_f_out);
+  vfprintf (m_f_out, fmt, ap);
+  fprintf (m_f_out, "\n");
+  fflush (m_f_out);
+}
+
+/* Record the entry within a particular scope, indenting subsequent
+   log lines accordingly.  */
+
+void
+logger::enter_scope (const char *scope_name)
+{
+  log ("entering: %s", scope_name);
+  m_indent_level += 1;
+}
+
+/* Record the exit from a particular scope, restoring the indent level to
+   before the scope was entered.  */
+
+void
+logger::exit_scope (const char *scope_name)
+{
+  if (m_indent_level)
+    m_indent_level -= 1;
+  else
+    log ("(mismatching indentation)");
+  log ("exiting: %s", scope_name);
+}
+
+/* Implementation of class log_user.  */
+
+/* The constructor for log_user.  */
+
+log_user::log_user (logger *logger) : m_logger (logger)
+{
+  if (m_logger)
+    m_logger->incref("log_user ctor");
+}
+
+/* The destructor for log_user.  */
+
+log_user::~log_user ()
+{
+  if (m_logger)
+    m_logger->decref("log_user dtor");
+}
+
+/* Set the logger for a log_user, managing the reference counts
+   of the old and new logger (either of which might be NULL).  */
+
+void
+log_user::set_logger (logger *logger)
+{
+  if (logger)
+    logger->incref ("log_user::set_logger");
+  if (m_logger)
+    m_logger->decref ("log_user::set_logger");
+  m_logger = logger;
+}
-- 
1.8.5.3

