From 68ecca49a7bfe5d606910db13f5f79da7eb879ec Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 13 Mar 2015 16:51:25 -0400 Subject: [PATCH 23/26] FIXME: move jit/jit-logging.h/c to logging.h.c --- gcc/Makefile.in | 1 + .../docs/internals/test-hello-world.exe.log.txt | 10 +- gcc/jit/dummy-frontend.c | 6 +- gcc/jit/jit-common.h | 3 +- gcc/jit/jit-logging.c | 139 +-------------- gcc/jit/jit-logging.h | 154 +--------------- gcc/jit/jit-playback.c | 46 ++--- gcc/jit/jit-recording.c | 17 +- gcc/jit/jit-recording.h | 2 +- gcc/jit/jit-result.c | 10 +- gcc/jit/jit-tempdir.c | 6 +- gcc/jit/jit-tempdir.h | 2 +- gcc/jit/libgccjit.c | 137 +++++++------- gcc/logging.c | 165 +++++++++++++++++ gcc/logging.h | 196 +++++++++++++++++++++ 15 files changed, 489 insertions(+), 405 deletions(-) create mode 100644 gcc/logging.c create mode 100644 gcc/logging.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 1ba0475..9317e12 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1372,6 +1372,7 @@ OBJS = \ langhooks.o \ lcm.o \ lists.o \ + logging.o \ loop-doloop.o \ loop-init.o \ loop-invariant.o \ diff --git a/gcc/jit/docs/internals/test-hello-world.exe.log.txt b/gcc/jit/docs/internals/test-hello-world.exe.log.txt index 0bab86c..545bfff 100644 --- a/gcc/jit/docs/internals/test-hello-world.exe.log.txt +++ b/gcc/jit/docs/internals/test-hello-world.exe.log.txt @@ -73,8 +73,8 @@ JIT: exiting: gcc::jit::playback::context::context(gcc::jit::recording::contex JIT: entering: gcc::jit::playback::compile_to_memory::compile_to_memory(gcc::jit::recording::context*) JIT: exiting: gcc::jit::playback::compile_to_memory::compile_to_memory(gcc::jit::recording::context*) JIT: entering: void gcc::jit::playback::context::compile() -JIT: entering: gcc::jit::tempdir::tempdir(gcc::jit::logger*, int) -JIT: exiting: gcc::jit::tempdir::tempdir(gcc::jit::logger*, int) +JIT: entering: gcc::jit::tempdir::tempdir(gcc::logger*, int) +JIT: exiting: gcc::jit::tempdir::tempdir(gcc::logger*, int) JIT: entering: bool gcc::jit::tempdir::create() JIT: m_path_template: /tmp/libgccjit-XXXXXX JIT: m_path_tempdir: /tmp/libgccjit-CKq1M9 @@ -140,8 +140,8 @@ JIT: exiting: void gcc::jit::playback::context::invoke_driver(const char*, JIT: exiting: void gcc::jit::playback::context::convert_to_dso(const char*) JIT: entering: gcc::jit::result* gcc::jit::playback::context::dlopen_built_dso() JIT: GCC_JIT_BOOL_OPTION_DEBUGINFO was set: handing over tempdir to jit::result -JIT: entering: gcc::jit::result::result(gcc::jit::logger*, void*, gcc::jit::tempdir*) -JIT: exiting: gcc::jit::result::result(gcc::jit::logger*, void*, gcc::jit::tempdir*) +JIT: entering: gcc::jit::result::result(gcc::logger*, void*, gcc::jit::tempdir*) +JIT: exiting: gcc::jit::result::result(gcc::logger*, void*, gcc::jit::tempdir*) JIT: exiting: gcc::jit::result* gcc::jit::playback::context::dlopen_built_dso() JIT: exiting: virtual void gcc::jit::playback::compile_to_memory::postprocess(const char*) JIT: entering: void gcc::jit::playback::context::release_mutex() @@ -173,4 +173,4 @@ JIT: removing tempdir: /tmp/libgccjit-CKq1M9 JIT: exiting: gcc::jit::tempdir::~tempdir() JIT: exiting: virtual gcc::jit::result::~result() JIT: exiting: gcc_jit_result_release -JIT: gcc::jit::logger::~logger() +JIT: gcc::logger::~logger() diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c index 87f583f..80ade16 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); - JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); + GCC_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); - JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); + GCC_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); - JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); + GCC_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 1fc558c..a7f51e3 100644 --- a/gcc/jit/jit-common.h +++ b/gcc/jit/jit-common.h @@ -95,11 +95,12 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE + 1; namespace gcc { +class logger; + namespace jit { class result; class dump; -class logger; class builtins_manager; // declared within jit-builtins.h class tempdir; diff --git a/gcc/jit/jit-logging.c b/gcc/jit/jit-logging.c index 9c39f62..9f3330b 100644 --- a/gcc/jit/jit-logging.c +++ b/gcc/jit/jit-logging.c @@ -25,147 +25,16 @@ along with GCC; see the file COPYING3. If not see #include "jit-logging.h" -namespace gcc { - -namespace jit { - /* Implementation of class gcc::jit::logger. */ /* The constructor for gcc::jit::logger, used by gcc_jit_context_set_logfile. */ -logger::logger (FILE *f_out, - int, /* flags */ - int /* verbosity */) : - m_refcount (0), - m_f_out (f_out), - m_indent_level (0), - m_log_refcount_changes (false) +gcc::jit::logger::logger (FILE *f_out, + int flags, + int verbosity) : + gcc::logger (f_out, flags, verbosity, "JIT") { /* Begin the log by writing the GCC version. */ print_version (f_out, "JIT:", false); } - -/* The destructor for gcc::jit::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::jit::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::jit::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) -{ - fprintf (m_f_out, "JIT: "); - 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::jit::log_user. */ - -/* The constructor for gcc::jit::log_user. */ - -log_user::log_user (logger *logger) : m_logger (logger) -{ - if (m_logger) - m_logger->incref("log_user ctor"); -} - -/* The destructor for gcc::jit::log_user. */ - -log_user::~log_user () -{ - if (m_logger) - m_logger->decref("log_user dtor"); -} - -/* Set the logger for a gcc::jit::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::jit - -} // namespace gcc diff --git a/gcc/jit/jit-logging.h b/gcc/jit/jit-logging.h index bd82e7b..dedd350 100644 --- a/gcc/jit/jit-logging.h +++ b/gcc/jit/jit-logging.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef JIT_LOGGING_H #define JIT_LOGGING_H -#include "jit-common.h" +#include "logging.h" namespace gcc { @@ -30,164 +30,14 @@ namespace jit { /* A gcc::jit::logger encapsulates a logging stream: a way to send lines of pertinent information to a FILE *. */ -class logger +class logger : public gcc::logger { public: logger (FILE *f_out, int flags, int verbosity); - ~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; -}; - -/* 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. */ - -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::jit::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::jit::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::jit::log_user is something that potentially uses a - gcc::jit::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::jit } // namespace gcc -/* If the given logger is non-NULL, log entry/exit of this scope to - it, identifying it using __PRETTY_FUNCTION__. */ - -#define JIT_LOG_SCOPE(LOGGER) \ - gcc::jit::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 JIT_LOG_FUNC(LOGGER) \ - gcc::jit::log_scope s (LOGGER, __func__) - #endif /* JIT_LOGGING_H */ diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index c0f10c9..d20fe37 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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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; - JIT_LOG_SCOPE (m_ctxt->get_logger ()); + GCC_LOG_SCOPE (m_ctxt->get_logger ()); FOR_EACH_VEC_ELT (m_blocks, i, b) { @@ -1368,7 +1368,7 @@ void playback::function:: postprocess () { - JIT_LOG_SCOPE (m_ctxt->get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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. */ - JIT_LOG_SCOPE (get_logger ()); + GCC_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. */ - JIT_LOG_SCOPE (get_logger ()); + GCC_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 *argvec, const char *ctxt_progname, vec *requested_dumps) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 *requested_dumps) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); int i; recording::requested_dump *d; @@ -2367,7 +2367,7 @@ void playback::context:: convert_to_dso (const char *ctxt_progname) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 *argvec) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 *argvec) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 *argvec) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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. */ - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); int i; source_file *file; diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index e356c14..56efc85 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" #include "pretty-print.h" #include "toplev.h" +#include "logging.h" #include @@ -508,7 +509,7 @@ recording::context::context (context *parent_ctxt) recording::context::~context () { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); int i; memento *m; FOR_EACH_VEC_ELT (m_mementos, i, m) @@ -551,7 +552,7 @@ recording::context::record (memento *m) void recording::context::replay_into (replayer *r) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); int i; memento *m; @@ -609,7 +610,7 @@ recording::context::replay_into (replayer *r) void recording::context::disassociate_from_playback () { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); int i; memento *m; @@ -1225,7 +1226,7 @@ recording::context::enable_dump (const char *dumpname, result * recording::context::compile () { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); log_all_options (); @@ -1255,7 +1256,7 @@ void recording::context::compile_to_file (enum gcc_jit_output_kind output_kind, const char *output_path) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); log_all_options (); @@ -1296,7 +1297,7 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap) const char *errmsg; bool has_ownership; - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); len = vasprintf (&malloced_msg, fmt, ap); if (malloced_msg == NULL || len < 0) @@ -1542,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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); reproducer r (*this, path); /* Generate the "ancestry" of this context, as a list. */ @@ -1744,7 +1745,7 @@ recording::context::get_all_requested_dumps (vec *ou void recording::context::validate () { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); if (m_parent_ctxt) m_parent_ctxt->validate (); diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 8e5bd52..4acaae6 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -21,8 +21,8 @@ along with GCC; see the file COPYING3. If not see #ifndef JIT_RECORDING_H #define JIT_RECORDING_H +#include "logging.h" #include "jit-common.h" -#include "jit-logging.h" class timer; diff --git a/gcc/jit/jit-result.c b/gcc/jit/jit-result.c index cb5a061..4f54497 100644 --- a/gcc/jit/jit-result.c +++ b/gcc/jit/jit-result.c @@ -21,9 +21,9 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "logging.h" #include "jit-common.h" -#include "jit-logging.h" #include "jit-result.h" #include "jit-tempdir.h" @@ -38,7 +38,7 @@ result(logger *logger, void *dso_handle, tempdir *tempdir_) : m_dso_handle (dso_handle), m_tempdir (tempdir_) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); } /* gcc::jit::result's destructor. @@ -47,7 +47,7 @@ result(logger *logger, void *dso_handle, tempdir *tempdir_) : result::~result() { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); dlclose (m_dso_handle); @@ -69,7 +69,7 @@ void * result:: get_code (const char *funcname) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); void *code; const char *error; @@ -96,7 +96,7 @@ void * result:: get_global (const char *name) { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); void *global; const char *error; diff --git a/gcc/jit/jit-tempdir.c b/gcc/jit/jit-tempdir.c index cac161b..5a1461b 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) { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_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 () { - JIT_LOG_SCOPE (get_logger ()); + GCC_LOG_SCOPE (get_logger ()); if (m_keep_intermediates) fprintf (stderr, "intermediate files written to %s\n", m_path_tempdir); diff --git a/gcc/jit/jit-tempdir.h b/gcc/jit/jit-tempdir.h index 586ac5d..e942e10 100644 --- a/gcc/jit/jit-tempdir.h +++ b/gcc/jit/jit-tempdir.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef JIT_TEMPDIR_H #define JIT_TEMPDIR_H -#include "jit-logging.h" +#include "logging.h" namespace gcc { diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index b5e72f4..54ccca2 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "libgccjit.h" #include "jit-recording.h" #include "jit-result.h" +#include "jit-logging.h" /* The opaque types used by the public API are actually subclasses of the gcc::jit::recording classes. */ @@ -356,7 +357,7 @@ void gcc_jit_context_release (gcc_jit_context *ctxt) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); ctxt->log ("deleting ctxt: %p", (void *)ctxt); delete ctxt; } @@ -371,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"); - JIT_LOG_FUNC (parent_ctxt->get_logger ()); + GCC_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); @@ -391,7 +392,7 @@ gcc_jit_context_new_location (gcc_jit_context *ctxt, int column) { RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); return (gcc_jit_location *)ctxt->new_location (filename, line, column, true); } @@ -434,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL_PRINTF1 ( (type >= GCC_JIT_TYPE_VOID && type <= GCC_JIT_TYPE_FILE_PTR), @@ -456,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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); @@ -517,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -540,7 +541,7 @@ gcc_jit_context_new_field (gcc_jit_context *ctxt, const char *name) { RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -583,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name"); if (num_fields) @@ -619,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name"); @@ -654,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL_PRINTF1 ( NULL == struct_type->get_fields (), ctxt, loc, @@ -697,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name"); if (num_fields) @@ -736,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (return_type, ctxt, loc, "NULL return_type"); RETURN_NULL_IF_FAIL ( @@ -770,7 +771,7 @@ gcc_jit_context_new_param (gcc_jit_context *ctxt, const char *name) { RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -836,7 +837,7 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt, int is_variadic) { RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL_PRINTF1 ( ((kind >= GCC_JIT_FUNCTION_EXPORTED) @@ -911,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL (name, ctxt, NULL, "NULL name"); return static_cast (ctxt->get_builtin_function (name)); @@ -942,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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, @@ -967,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL (path, ctxt, NULL, "NULL path"); func->dump_to_dot (path); @@ -984,7 +985,7 @@ gcc_jit_function_new_block (gcc_jit_function *func, const char *name) { RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function"); - JIT_LOG_FUNC (func->get_context ()->get_logger ()); + GCC_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"); @@ -1035,7 +1036,7 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt, const char *name) { RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL_PRINTF1 ( ((kind >= GCC_JIT_GLOBAL_EXPORTED) @@ -1133,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type); return ((gcc_jit_rvalue *)ctxt @@ -1148,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type); return ((gcc_jit_rvalue *)ctxt @@ -1166,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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); @@ -1183,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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); @@ -1201,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type); return ((gcc_jit_rvalue *)ctxt @@ -1220,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type"); RETURN_NULL_IF_FAIL_PRINTF1 ( pointer_type->is_pointer (), @@ -1243,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type"); RETURN_NULL_IF_FAIL_PRINTF1 ( pointer_type->is_pointer (), @@ -1265,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_NULL_IF_FAIL (value, ctxt, NULL, "NULL value"); return (gcc_jit_rvalue *)ctxt->new_string_literal (value); @@ -1285,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL_PRINTF1 ( (op >= GCC_JIT_UNARY_OP_MINUS @@ -1324,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL_PRINTF1 ( valid_binary_op_p (op), @@ -1360,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL_PRINTF1 ( (op >= GCC_JIT_COMPARISON_EQ @@ -1396,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (func, ctxt, loc, "NULL function"); if (numargs) @@ -1469,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (fn_ptr, ctxt, loc, "NULL fn_ptr"); if (numargs) @@ -1599,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -1627,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -1688,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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, @@ -1720,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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, @@ -1751,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"); - JIT_LOG_FUNC (ptr->get_context ()->get_logger ()); + GCC_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 = @@ -1788,7 +1789,7 @@ gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue, gcc_jit_location *loc) { RETURN_NULL_IF_FAIL (rvalue, NULL, loc, "NULL rvalue"); - JIT_LOG_FUNC (rvalue->get_context ()->get_logger ()); + GCC_LOG_FUNC (rvalue->get_context ()->get_logger ()); /* LOC can be NULL. */ gcc::jit::recording::type *underlying_type = @@ -1821,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"); - JIT_LOG_FUNC (lvalue->get_context ()->get_logger ()); + GCC_LOG_FUNC (lvalue->get_context ()->get_logger ()); /* LOC can be NULL. */ return (gcc_jit_rvalue *)lvalue->get_address (loc); @@ -1840,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; - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED, ctxt, loc, @@ -1869,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue"); @@ -1897,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -1938,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue"); RETURN_IF_FAIL_PRINTF1 ( @@ -1996,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (boolval, ctxt, loc, "NULL boolval"); RETURN_IF_FAIL_PRINTF2 ( @@ -2050,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (text, ctxt, loc, "NULL text"); @@ -2070,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (target, ctxt, loc, "NULL target"); RETURN_IF_FAIL_PRINTF4 ( @@ -2100,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -2138,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ gcc::jit::recording::function *func = block->get_function (); RETURN_IF_FAIL_PRINTF2 ( @@ -2165,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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"); @@ -2487,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 (); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* LOC can be NULL. */ RETURN_IF_FAIL (expr, ctxt, loc, "NULL expr"); @@ -2544,7 +2545,7 @@ gcc_jit_context_set_str_option (gcc_jit_context *ctxt, const char *value) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* opt is checked by the inner function. value can be NULL. */ @@ -2563,7 +2564,7 @@ gcc_jit_context_set_int_option (gcc_jit_context *ctxt, int value) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* opt is checked by the inner function. */ ctxt->set_int_option (opt, value); @@ -2581,7 +2582,7 @@ gcc_jit_context_set_bool_option (gcc_jit_context *ctxt, int value) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); /* opt is checked by the inner function. */ ctxt->set_bool_option (opt, value); @@ -2598,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); ctxt->set_inner_bool_option ( gcc::jit::INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS, bool_value); @@ -2615,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); ctxt->set_inner_bool_option ( gcc::jit::INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER, bool_value); @@ -2632,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL (optname, ctxt, NULL, "NULL optname"); if (ctxt->get_logger ()) ctxt->get_logger ()->log ("optname: %s", optname); @@ -2652,7 +2653,7 @@ gcc_jit_context_enable_dump (gcc_jit_context *ctxt, char **out_ptr) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL (dumpname, ctxt, NULL, "NULL dumpname"); RETURN_IF_FAIL (out_ptr, ctxt, NULL, "NULL out_ptr"); @@ -2670,7 +2671,7 @@ gcc_jit_context_compile (gcc_jit_context *ctxt) { RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); ctxt->log ("in-memory compile of ctxt: %p", (void *)ctxt); @@ -2694,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL_PRINTF1 ( ((output_kind >= GCC_JIT_OUTPUT_KIND_ASSEMBLER) && (output_kind <= GCC_JIT_OUTPUT_KIND_EXECUTABLE)), @@ -2723,7 +2724,7 @@ gcc_jit_context_dump_to_file (gcc_jit_context *ctxt, int update_locations) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL (path, ctxt, NULL, "NULL path"); ctxt->dump_to_file (path, update_locations); } @@ -2737,11 +2738,11 @@ gcc_jit_context_set_logfile (gcc_jit_context *ctxt, int verbosity) { RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_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::jit::logger *logger; + gcc::logger *logger; if (logfile) logger = new gcc::jit::logger (logfile, flags, verbosity); else @@ -2760,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"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); RETURN_IF_FAIL (path, ctxt, NULL, "NULL path"); ctxt->dump_reproducer_to_file (path); } @@ -2775,7 +2776,7 @@ const char * gcc_jit_context_get_first_error (gcc_jit_context *ctxt) { RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context"); - JIT_LOG_FUNC (ctxt->get_logger ()); + GCC_LOG_FUNC (ctxt->get_logger ()); return ctxt->get_first_error (); } @@ -2804,7 +2805,7 @@ gcc_jit_result_get_code (gcc_jit_result *result, const char *fnname) { RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result"); - JIT_LOG_FUNC (result->get_logger ()); + GCC_LOG_FUNC (result->get_logger ()); RETURN_NULL_IF_FAIL (fnname, NULL, NULL, "NULL fnname"); result->log ("locating fnname: %s", fnname); @@ -2824,7 +2825,7 @@ gcc_jit_result_get_global (gcc_jit_result *result, const char *name) { RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result"); - JIT_LOG_FUNC (result->get_logger ()); + GCC_LOG_FUNC (result->get_logger ()); RETURN_NULL_IF_FAIL (name, NULL, NULL, "NULL name"); void *global = result->get_global (name); @@ -2842,7 +2843,7 @@ void gcc_jit_result_release (gcc_jit_result *result) { RETURN_IF_FAIL (result, NULL, NULL, "NULL result"); - JIT_LOG_FUNC (result->get_logger ()); + GCC_LOG_FUNC (result->get_logger ()); result->log ("deleting result: %p", (void *)result); delete result; } @@ -2961,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"); - JIT_LOG_FUNC (rvalue->get_context ()->get_logger ()); + GCC_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 new file mode 100644 index 0000000..2427297 --- /dev/null +++ b/gcc/logging.c @@ -0,0 +1,165 @@ +/* Internals of logging + Copyright (C) 2014-2016 Free Software Foundation, Inc. + Contributed by David Malcolm . + +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 +. */ + +#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 new file mode 100644 index 0000000..87b52de --- /dev/null +++ b/gcc/logging.h @@ -0,0 +1,196 @@ +/* Logging facilities. + Copyright (C) 2014-2016 Free Software Foundation, Inc. + Contributed by David Malcolm . + +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 +. */ + +#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 */ -- 1.8.5.3