aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-01-08 19:41:07 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-01-08 19:41:07 +0000
commiteb4c16eb849c4c06009186a4df409186d46f5e8d (patch)
treefb0c1dc7bb71ee82c586ff5bfaf5f70fad96ddb7 /gcc/jit/libgccjit.c
parentefa7df3c625146460d7ec345d32a4efb42be871b (diff)
downloadgcc-eb4c16eb849c4c06009186a4df409186d46f5e8d.zip
gcc-eb4c16eb849c4c06009186a4df409186d46f5e8d.tar.gz
gcc-eb4c16eb849c4c06009186a4df409186d46f5e8d.tar.bz2
New jit API entrypoint: gcc_jit_context_set_logfile
gcc/jit/ChangeLog: * Make-lang.in (jit_OBJS): Add jit/jit-logging.o. * docs/internals/index.rst (Overview of code structure): Mention gcc_jit_context_set_logfile, and embed the example logfile. * docs/internals/test-hello-world.exe.log.txt: New file: example of a logfile. * docs/topics/contexts.rst (Debugging): Add documentation for gcc_jit_context_set_logfile. * docs/_build/texinfo/libgccjit.texi: Regenerate. * dummy-frontend.c: Include "jit-logging.h". (jit_langhook_init): Assert that there is an active playback context. If it has a logger, log entry/exit to this function. (jit_langhook_write_globals): Likewise. * jit-common.h (gcc::jit::logger): New forward declaration. * jit-logging.c: New file. * jit-logging.h: New file. * jit-playback.c: Include "jit-logging.h". (gcc::jit::playback::context::context): Initialize the log_user base class from the recording context's logger (if any). Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::playback::context::~context): Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::playback::build_stmt_list): Likewise. (gcc::jit::playback::function::postprocess): Likewise. (gcc::jit::playback::context::compile): Likewise. Log the entry/exit to toplev::main and toplev::finalize. Log the fake argv passed to toplev::main. (gcc::jit::playback::context::acquire_mutex): Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::playback::context::release_mutex): Likewise. (gcc::jit::playback::context::make_fake_args): Likewise. (gcc::jit::playback::context::extract_any_requested_dumps): Likewise. (gcc::jit::playback::context::convert_to_dso): Likewise. Also, log the arguments that the driver is invoked with. (gcc::jit::playback::context::dlopen_built_dso): Likewise. Pass the logger to the result object. (gcc::jit::playback::context::replay): Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::playback::context::dump_generated_code): Likewise. (gcc::jit::playback::context::handle_locations): Likewise. * jit-playback.h (gcc::jit::playback::context): Make this be a subclass of gcc::jit::log_user. * jit-recording.c: Include "jit-logging.h". (gcc::jit::recording::context::context: Initialize the logger to NULL for root contexts, or to the parent's logger for child contexts. (gcc::jit::recording::context::~context): Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::recording::context::replay_into): Likewise. (gcc::jit::recording::context::disassociate_from_playback): Likewise. (gcc::jit::recording::context::compile): Likewise. (recording::context::add_error_va): Likewise. Also, log the error. (gcc::jit::recording::context::validate): Use JIT_LOG_SCOPE to log entry/exit from the function body. * jit-recording.h: Include "jit-logging.h". (gcc::jit::recording::context): Make this be a subclass of gcc::jit::log_user. * jit-result.c: Include "jit-common.h" and "jit-logging.h". (gcc::jit::result::result): Add logger param, recording it. Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::result::~result(): Use JIT_LOG_SCOPE to log entry/exit from the function body. (gcc::jit::result::get_code): Likewise. * jit-result.h (gcc::jit::result): Make this be a subclass of gcc::jit::log_user. (gcc::jit::result::result): Add logger parameter. * libgccjit++.h (gccjit::context::set_logfile): New function. * libgccjit.c: Include "jit-logging.h". (gcc_jit_context_acquire): Log the context. (gcc_jit_context_release): Use JIT_LOG_FUNC to log entry/exit from the function body, and log the context. (gcc_jit_context_new_child_context): Likewise, logging both contexts. (gcc_jit_context_new_location): Use JIT_LOG_FUNC to log entry/exit from the function body. (gcc_jit_context_get_type): Likewise. (gcc_jit_context_get_int_type): Likewise. (gcc_jit_context_new_array_type): Likewise. (gcc_jit_context_new_field): Likewise. (gcc_jit_context_new_struct_type): Likewise. (gcc_jit_context_new_opaque_struct): Likewise. (gcc_jit_struct_set_fields): Likewise. (gcc_jit_context_new_union_type): Likewise. (gcc_jit_context_new_function_ptr_type): Likewise. (gcc_jit_context_new_param): Likewise. (gcc_jit_context_new_function): Likewise. (gcc_jit_context_get_builtin_function): Likewise. (gcc_jit_function_get_param): Likewise. (gcc_jit_function_dump_to_dot): Likewise. (gcc_jit_function_new_block): Likewise. (gcc_jit_context_new_global): Likewise. (gcc_jit_context_new_rvalue_from_int): Likewise. (gcc_jit_context_zero): Likewise. (gcc_jit_context_one): Likewise. (gcc_jit_context_new_rvalue_from_double): Likewise. (gcc_jit_context_new_rvalue_from_ptr): Likewise. (gcc_jit_context_null): Likewise. (gcc_jit_context_new_string_literal): Likewise. (gcc_jit_context_new_unary_op): Likewise. (gcc_jit_context_new_binary_op): Likewise. (gcc_jit_context_new_comparison): Likewise. (gcc_jit_context_new_call): Likewise. (gcc_jit_context_new_call_through_ptr): Likewise. (gcc_jit_context_new_cast): Likewise. (gcc_jit_context_new_array_access): Likewise. (gcc_jit_lvalue_access_field): Likewise. (gcc_jit_rvalue_access_field): Likewise. (gcc_jit_rvalue_dereference_field): Likewise. (gcc_jit_rvalue_dereference): Likewise. (gcc_jit_lvalue_get_address): Likewise. (gcc_jit_function_new_local): Likewise. (gcc_jit_block_add_eval): Likewise. (gcc_jit_block_add_assignment): Likewise. (gcc_jit_block_add_assignment_op): Likewise. (gcc_jit_block_end_with_conditional): Likewise. (gcc_jit_block_add_comment): Likewise. (gcc_jit_block_end_with_jump): Likewise. (gcc_jit_block_end_with_return): Likewise. (gcc_jit_block_end_with_void_return): Likewise. (gcc_jit_context_set_str_option): Likewise. (gcc_jit_context_set_int_option): Likewise. (gcc_jit_context_set_bool_option): Likewise. (gcc_jit_context_enable_dump): Likewise. (gcc_jit_context_compile): Likewise. Also log the context, and the result. (gcc_jit_context_dump_to_file): Likewise. (gcc_jit_context_set_logfile): New function. (gcc_jit_context_get_first_error): Use JIT_LOG_FUNC to log entry/exit from the function body. (gcc_jit_result_get_code): Likewise. Also log the fnname) and the ptr to be returned. (gcc_jit_result_release): Likewise. Also log the result. * libgccjit.h: Include <stdio.h>, since we need FILE *. (gcc_jit_context_set_logfile): New declaration. * libgccjit.map (gcc_jit_context_set_logfile): New. gcc/testsuite/ChangeLog: * jit.dg/harness.h (set_up_logging): New function. (test_jit): Fail if gcc_jit_context_acquire fails. Call set_up_logging on the context, so that every testcase is logged to a particular file. * jit.dg/test-nested-contexts.c (main): Open a logfile, and call gcc_jit_context_set_logfile on the top-level context. From-SVN: r219357
Diffstat (limited to 'gcc/jit/libgccjit.c')
-rw-r--r--gcc/jit/libgccjit.c133
1 files changed, 115 insertions, 18 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 99b2d56..c0439617 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see
#include "libgccjit.h"
#include "jit-common.h"
+#include "jit-logging.h"
#include "jit-recording.h"
#include "jit-result.h"
@@ -323,7 +324,9 @@ compatible_types (gcc::jit::recording::type *ltype,
gcc_jit_context *
gcc_jit_context_acquire (void)
{
- return new gcc_jit_context (NULL);
+ gcc_jit_context *ctxt = new gcc_jit_context (NULL);
+ ctxt->log ("new top-level ctxt: %p", (void *)ctxt);
+ return ctxt;
}
/* Public entrypoint for releasing a gcc_jit_context.
@@ -333,6 +336,9 @@ gcc_jit_context_acquire (void)
void
gcc_jit_context_release (gcc_jit_context *ctxt)
{
+ RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt");
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ ctxt->log ("deleting ctxt: %p", (void *)ctxt);
delete ctxt;
}
@@ -345,7 +351,12 @@ gcc_jit_context_release (gcc_jit_context *ctxt)
gcc_jit_context *
gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt)
{
- return new gcc_jit_context (parent_ctxt);
+ RETURN_NULL_IF_FAIL (parent_ctxt, NULL, NULL, "NULL parent ctxt");
+ JIT_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);
+ return child_ctxt;
}
/* Public entrypoint. See description in libgccjit.h.
@@ -361,7 +372,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 ());
return (gcc_jit_location *)ctxt->new_location (filename, line, column);
}
@@ -404,6 +415,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 ());
RETURN_NULL_IF_FAIL_PRINTF1 (
(type >= GCC_JIT_TYPE_VOID
&& type <= GCC_JIT_TYPE_FILE_PTR),
@@ -425,6 +437,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 ());
RETURN_NULL_IF_FAIL (num_bytes >= 0, ctxt, NULL, "negative size");
return (gcc_jit_type *)ctxt->get_int_type (num_bytes, is_signed);
@@ -485,6 +498,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 ());
/* 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");
@@ -507,6 +521,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -543,6 +558,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
if (num_fields)
@@ -578,6 +594,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -611,8 +628,9 @@ gcc_jit_struct_set_fields (gcc_jit_struct *struct_type,
gcc_jit_field **fields)
{
RETURN_IF_FAIL (struct_type, NULL, loc, "NULL struct_type");
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = struct_type->m_ctxt;
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL_PRINTF1 (
NULL == struct_type->get_fields (), ctxt, loc,
"%s already has had fields set",
@@ -649,6 +667,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
if (num_fields)
@@ -687,6 +706,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (return_type, ctxt, loc, "NULL return_type");
RETURN_NULL_IF_FAIL (
@@ -720,6 +740,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -785,6 +806,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL_PRINTF1 (
((kind >= GCC_JIT_FUNCTION_EXPORTED)
@@ -846,6 +868,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 ());
RETURN_NULL_IF_FAIL (name, ctxt, NULL, "NULL name");
return static_cast <gcc_jit_function *> (ctxt->get_builtin_function (name));
@@ -876,6 +899,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 ());
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,
@@ -900,6 +924,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 ());
RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
func->dump_to_dot (path);
@@ -916,6 +941,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 ());
RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
func->get_context (), NULL,
"cannot add block to an imported function");
@@ -965,6 +991,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
@@ -1050,6 +1077,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 ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
return (gcc_jit_rvalue *)ctxt->new_rvalue_from_int (numeric_type, value);
@@ -1066,6 +1094,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 ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0);
@@ -1082,6 +1111,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 ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1);
@@ -1099,6 +1129,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 ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
return (gcc_jit_rvalue *)ctxt->new_rvalue_from_double (numeric_type, value);
@@ -1116,6 +1147,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 ());
RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
RETURN_NULL_IF_FAIL_PRINTF1 (
pointer_type->is_pointer (),
@@ -1137,6 +1169,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 ());
RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
RETURN_NULL_IF_FAIL_PRINTF1 (
pointer_type->is_pointer (),
@@ -1158,6 +1191,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 ());
RETURN_NULL_IF_FAIL (value, ctxt, NULL, "NULL value");
return (gcc_jit_rvalue *)ctxt->new_string_literal (value);
@@ -1177,6 +1211,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL_PRINTF1 (
(op >= GCC_JIT_UNARY_OP_MINUS
@@ -1215,6 +1250,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL_PRINTF1 (
valid_binary_op_p (op),
@@ -1250,6 +1286,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL_PRINTF1 (
(op >= GCC_JIT_COMPARISON_EQ
@@ -1285,6 +1322,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (func, ctxt, loc, "NULL function");
if (numargs)
@@ -1357,6 +1395,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (fn_ptr, ctxt, loc, "NULL fn_ptr");
if (numargs)
@@ -1486,6 +1525,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
@@ -1513,6 +1553,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (ptr, ctxt, loc, "NULL ptr");
RETURN_NULL_IF_FAIL (index, ctxt, loc, "NULL index");
@@ -1572,8 +1613,9 @@ gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
gcc_jit_field *field)
{
RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = struct_->m_ctxt;
+ JIT_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,
"field %s has not been placed in a struct",
@@ -1594,8 +1636,9 @@ gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
gcc_jit_field *field)
{
RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = struct_->m_ctxt;
+ JIT_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,
"field %s has not been placed in a struct",
@@ -1616,6 +1659,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 ());
/* LOC can be NULL. */
RETURN_NULL_IF_FAIL (field, NULL, loc, "NULL field");
gcc::jit::recording::type *underlying_type =
@@ -1652,6 +1696,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 ());
/* LOC can be NULL. */
gcc::jit::recording::type *underlying_type =
@@ -1684,6 +1729,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 ());
/* LOC can be NULL. */
return (gcc_jit_rvalue *)lvalue->get_address (loc);
@@ -1701,8 +1747,9 @@ gcc_jit_function_new_local (gcc_jit_function *func,
const char *name)
{
RETURN_NULL_IF_FAIL (func, NULL, loc, "NULL function");
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = func->m_ctxt;
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
ctxt, loc,
"Cannot add locals to an imported function");
@@ -1723,8 +1770,9 @@ gcc_jit_block_add_eval (gcc_jit_block *block,
gcc_jit_rvalue *rvalue)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
return block->add_eval (loc, rvalue);
@@ -1743,8 +1791,9 @@ gcc_jit_block_add_assignment (gcc_jit_block *block,
gcc_jit_rvalue *rvalue)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_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");
RETURN_IF_FAIL_PRINTF4 (
@@ -1775,8 +1824,9 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block,
gcc_jit_rvalue *rvalue)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue");
RETURN_IF_FAIL_PRINTF1 (
valid_binary_op_p (op),
@@ -1814,8 +1864,9 @@ gcc_jit_block_end_with_conditional (gcc_jit_block *block,
gcc_jit_block *on_false)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL (boolval, ctxt, loc, "NULL boolval");
RETURN_IF_FAIL_PRINTF2 (
is_bool (boolval), ctxt, loc,
@@ -1860,8 +1911,9 @@ gcc_jit_block_add_comment (gcc_jit_block *block,
const char *text)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL (text, ctxt, loc, "NULL text");
block->add_comment (loc, text);
@@ -1879,8 +1931,9 @@ gcc_jit_block_end_with_jump (gcc_jit_block *block,
gcc_jit_block *target)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
RETURN_IF_FAIL (target, ctxt, loc, "NULL target");
RETURN_IF_FAIL_PRINTF4 (
block->get_function () == target->get_function (),
@@ -1908,8 +1961,9 @@ gcc_jit_block_end_with_return (gcc_jit_block *block,
gcc_jit_rvalue *rvalue)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_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");
RETURN_IF_FAIL_PRINTF4 (
@@ -1938,8 +1992,9 @@ gcc_jit_block_end_with_void_return (gcc_jit_block *block,
gcc_jit_location *loc)
{
RETURN_IF_NOT_VALID_BLOCK (block, loc);
- /* LOC can be NULL. */
gcc::jit::recording::context *ctxt = block->get_context ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ /* LOC can be NULL. */
gcc::jit::recording::function *func = block->get_function ();
RETURN_IF_FAIL_PRINTF2 (
func->get_return_type () == ctxt->get_type (GCC_JIT_TYPE_VOID),
@@ -1968,6 +2023,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 ());
/* opt is checked by the inner function.
value can be NULL. */
@@ -1986,6 +2042,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 ());
/* opt is checked by the inner function. */
ctxt->set_int_option (opt, value);
@@ -2003,6 +2060,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 ());
/* opt is checked by the inner function. */
ctxt->set_bool_option (opt, value);
@@ -2020,6 +2078,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 ());
RETURN_IF_FAIL (dumpname, ctxt, NULL, "NULL dumpname");
RETURN_IF_FAIL (out_ptr, ctxt, NULL, "NULL out_ptr");
@@ -2037,7 +2096,16 @@ gcc_jit_context_compile (gcc_jit_context *ctxt)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
- return (gcc_jit_result *)ctxt->compile ();
+ JIT_LOG_FUNC (ctxt->get_logger ());
+
+ ctxt->log ("compiling ctxt: %p", (void *)ctxt);
+
+ gcc_jit_result *result = (gcc_jit_result *)ctxt->compile ();
+
+ ctxt->log ("%s: returning (gcc_jit_result *)%p",
+ __func__, (void *)result);
+
+ return result;
}
/* Public entrypoint. See description in libgccjit.h.
@@ -2052,10 +2120,32 @@ 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 ());
RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
ctxt->dump_to_file (path, update_locations);
}
+/* Public entrypoint. See description in libgccjit.h. */
+
+void
+gcc_jit_context_set_logfile (gcc_jit_context *ctxt,
+ FILE *logfile,
+ int flags,
+ int verbosity)
+{
+ RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
+ JIT_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;
+ if (logfile)
+ logger = new gcc::jit::logger (logfile, flags, verbosity);
+ else
+ logger = NULL;
+ ctxt->set_logger (logger);
+}
+
/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
@@ -2066,6 +2156,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 ());
return ctxt->get_first_error ();
}
@@ -2080,9 +2171,14 @@ 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 ());
RETURN_NULL_IF_FAIL (fnname, NULL, NULL, "NULL fnname");
- return result->get_code (fnname);
+ result->log ("locating fnname: %s", fnname);
+ void *code = result->get_code (fnname);
+ result->log ("%s: returning (void *)%p", __func__, code);
+
+ return code;
}
/* Public entrypoint. See description in libgccjit.h.
@@ -2094,6 +2190,7 @@ void
gcc_jit_result_release (gcc_jit_result *result)
{
RETURN_IF_FAIL (result, NULL, NULL, "NULL result");
-
+ JIT_LOG_FUNC (result->get_logger ());
+ result->log ("deleting result: %p", (void *)result);
delete result;
}