summaryrefslogtreecommitdiff
path: root/gcc/testsuite/jit.dg/harness.h
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-13 22:14:46 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-13 22:14:46 +0000
commitc97b0d1d2ea95895b0ed843dfc3de3686c6f7e35 (patch)
treec0d87a4832ffd8054d13953a55395ade2a0f8583 /gcc/testsuite/jit.dg/harness.h
parentb5ea8a034bcbe76d0217e27acc3926110a1324ae (diff)
downloadgcc-c97b0d1d2ea95895b0ed843dfc3de3686c6f7e35.tar.gz
jit: New API entrypoint: gcc_jit_context_dump_reproducer_to_file
gcc/jit/ChangeLog: * docs/cp/topics/contexts.rst (Debugging): Add gccjit::context::dump_reproducer_to_file. * docs/internals/index.rst (Design notes): New section, discussing input validation and gcc_jit_context_dump_reproducer_to_file. * docs/topics/contexts.rst (Debugging): Add gcc_jit_context_dump_reproducer_to_file. * docs/_build/texinfo/libgccjit.texi: Regenerate. * jit-common.h (gcc::jit::dump::get_context): New accessor. * jit-recording.c: Include "hash-map.h". Within namespace ::gcc::jit... (dump::write): Flush each line. (dump::make_location): Pass false for new param "created_by_user". (class allocator): New class. (allocator::~allocator): New function. (allocator::xstrdup_printf): New function. (allocator::xstrdup_printf_va): New function. (class reproducer): New subclass of dump. (reproducer::reproducer): New function. (reproducer::write_params): New function. (reproducer::write_args): New function. (reproducer::make_identifier): New function. (reproducer::make_tmp_identifier): New function. (reproducer::get_identifier): New pair of functions. (reproducer::get_identifier_as_rvalue): New function. (reproducer::get_identifier_as_lvalue): New function. (reproducer::get_identifier_as_type): New function. (reproducer::xstrdup_printf): New function. (recording::context::context): Initialize m_toplevel_ctxt. (recording::context::new_location): Add param created_by_user. (str_option_reproducer_strings): New table of strings. (int_option_reproducer_strings): Likewise. (bool_option_reproducer_strings): Likewise. (get_type_enum_strings): Likewise. (names_of_function_kinds): Likewise. (global_kind_reproducer_strings): Likewise. (unary_op_reproducer_strings): Likewise. (binary_op_reproducer_strings): Likewise. (comparison_reproducer_strings): Likewise. Within namespace ::gcc::jit::recording::... (context::dump_reproducer_to_file): New function. (string::write_reproducer): Likewise. (location::write_reproducer): Likewise. (type::access_as_type): Likewise. (memento_of_get_type::write_reproducer): Likewise. (memento_of_get_pointer::write_reproducer): Likewise. (memento_of_get_const::write_reproducer): Likewise. (memento_of_get_volatile::write_reproducer): Likewise. (array_type::write_reproducer): Likewise. (function_type::write_reproducer): Likewise. (function_type::write_deferred_reproducer): Likewise. (field::write_reproducer): Likewise. (struct_::access_as_type): Likewise. (struct_::write_reproducer): Likewise. (union_::write_reproducer): Likewise. (fields::write_reproducer): Likewise. (rvalue::access_as_rvalue): Likewise. (lvalue::access_as_rvalue): Likewise. (lvalue::access_as_lvalue): Likewise. (param::access_as_rvalue): Likewise. (param::access_as_lvalue): Likewise. (param::write_reproducer): Likewise. (function::write_reproducer): Likewise. (block::write_reproducer): Likewise. (global::write_reproducer): Likewise. (memento_of_new_rvalue_from_const <int>::write_reproducer): Likewise. (memento_of_new_rvalue_from_const <long>::write_reproducer): Likewise. (memento_of_new_rvalue_from_const <double>::write_reproducer): Likewise. (memento_of_new_rvalue_from_const <void *>::write_reproducer): Likewise. (memento_of_new_string_literal::write_reproducer): Likewise. (unary_op::write_reproducer): Likewise. (binary_op::write_reproducer): Likewise. (comparison::write_reproducer): Likewise. (cast::write_reproducer): Likewise. (call::write_reproducer): Likewise. (call_through_ptr::write_reproducer): Likewise. (array_access::write_reproducer): Likewise. (access_field_of_lvalue::write_reproducer): Likewise. (access_field_rvalue::write_reproducer): Likewise. (dereference_field_rvalue::write_reproducer): Likewise. (dereference_rvalue::write_reproducer): Likewise. (get_address_of_lvalue::write_reproducer): Likewise. (local::write_reproducer): Likewise. (eval::write_reproducer): Likewise. (assignment::write_reproducer): Likewise. (assignment_op::write_reproducer): Likewise. (comment::write_reproducer): Likewise. (conditional::write_reproducer): Likewise. (jump::write_reproducer): Likewise. (return_::write_reproducer): Likewise. * jit-recording.h (gcc::jit::reproducer): New forward declararion. Within namespace ::gcc::jit::recording::... (context::new_location): Add "created_by_user" param. (context::dump_reproducer_to_file): New method. (context::m_toplevel_ctxt): New field. (memento::write_reproducer): New pure virtual function. (memento::dyn_cast_location): New virtual function. (string::write_reproducer): (location::location): Add "created_by_user" param. (location::dyn_cast_location): New function. (location::created_by_user): New accessor. (location::write_reproducer): New function. (location::m_created_by_user): New field. (type::access_as_type): New virtual function. (location::write_reproducer): Likewise. (type::access_as_type): Likewise. (memento_of_get_type::write_reproducer): Likewise. (memento_of_get_pointer::write_reproducer): Likewise. (memento_of_get_const::write_reproducer): Likewise. (memento_of_get_volatile::write_reproducer): Likewise. (array_type::write_reproducer): Likewise. (function_type::write_reproducer): Likewise. (function_type::write_deferred_reproducer): Likewise. (field::write_reproducer): Likewise. (struct_::access_as_type): Likewise. (struct_::write_reproducer): Likewise. (union_::write_reproducer): Likewise. (union_::m_fields): Remove stray unused field. (fields::length): New accessor. (fields::get_field): New accessor. (fields::write_reproducer): New function. (rvalue::access_as_rvalue): Likewise. (lvalue::access_as_rvalue): Likewise. (lvalue::access_as_lvalue): Likewise. (param::access_as_rvalue): Likewise. (param::access_as_lvalue): Likewise. (param::write_reproducer): Likewise. (function::write_reproducer): Likewise. (block::write_reproducer): Likewise. (global::write_reproducer): Likewise. (memento_of_new_rvalue_from_const <HOST_TYPE>::write_reproducer): Likewise. (memento_of_new_string_literal::write_reproducer): Likewise. (unary_op::write_reproducer): Likewise. (binary_op::write_reproducer): Likewise. (comparison::write_reproducer): Likewise. (cast::write_reproducer): Likewise. (call::write_reproducer): Likewise. (call_through_ptr::write_reproducer): Likewise. (array_access::write_reproducer): Likewise. (access_field_of_lvalue::write_reproducer): Likewise. (access_field_rvalue::write_reproducer): Likewise. (dereference_field_rvalue::write_reproducer): Likewise. (dereference_rvalue::write_reproducer): Likewise. (get_address_of_lvalue::write_reproducer): Likewise. (local::write_reproducer): Likewise. (eval::write_reproducer): Likewise. (assignment::write_reproducer): Likewise. (assignment_op::write_reproducer): Likewise. (comment::write_reproducer): Likewise. (conditional::write_reproducer): Likewise. (jump::write_reproducer): Likewise. (return_::write_reproducer): Likewise. * libgccjit++.h (gccjit::context::dump_reproducer_to_file): New. * libgccjit.c (gcc_jit_context_new_location): Pass "true" as param "created_by_user". (gcc_jit_context_dump_reproducer_to_file): New API entrypoint. * libgccjit.h (gcc_jit_context_dump_reproducer_to_file): New API entrypoint. * libgccjit.map (gcc_jit_context_dump_reproducer_to_file): New API entrypoint. gcc/testsuite/ChangeLog: * jit.dg/harness.h (set_up_logging): Move string concatenation into... (concat_strings): New function. (dump_reproducer): New function. (test_jit): Call dump_reproducer. * jit.dg/jit.exp (is_testcase_meant_to_generate_a_reproducer): New function. (jit-dg-test): Delete any generated reproducer from previous runs. Verify that a generated reproducer was created, and verify that it compiles. * jit.dg/test-nested-contexts.c (main): Call gcc_jit_context_dump_reproducer_to_file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219564 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/jit.dg/harness.h')
-rw-r--r--gcc/testsuite/jit.dg/harness.h47
1 files changed, 36 insertions, 11 deletions
diff --git a/gcc/testsuite/jit.dg/harness.h b/gcc/testsuite/jit.dg/harness.h
index 1252af5e4c7..6bbe7a7b283 100644
--- a/gcc/testsuite/jit.dg/harness.h
+++ b/gcc/testsuite/jit.dg/harness.h
@@ -250,6 +250,23 @@ static void set_options (gcc_jit_context *ctxt, const char *argv0)
0);
}
+/* Concatenate two strings. The result must be released using "free". */
+
+char *
+concat_strings (const char *prefix, const char *suffix)
+{
+ char *result = (char *)malloc (strlen (prefix) + strlen (suffix) + 1);
+ if (!result)
+ {
+ fail ("malloc failure");
+ return NULL;
+ }
+ strcpy (result, prefix);
+ strcpy (result + strlen (prefix), suffix);
+ result[strlen (prefix) + strlen (suffix)] = '\0';
+ return result;
+}
+
#ifndef TEST_ESCHEWS_TEST_JIT
/* Set up logging to a logfile of the form "test-FOO.exe.log.txt".
@@ -271,18 +288,9 @@ set_up_logging (gcc_jit_context *ctxt, const char *argv0)
FILE *logfile = NULL;
/* Build a logfile name of the form "test-FOO.exe.log.txt". */
- logfile_name = (char *)malloc (strlen (argv0)
- + strlen (logfile_name_suffix)
- + 1);
+ logfile_name = concat_strings (argv0, logfile_name_suffix);
if (!logfile_name)
- {
- fail ("malloc failure");
- return NULL;
- }
- strcpy (logfile_name, argv0);
- strcpy (logfile_name + strlen (argv0), logfile_name_suffix);
- logfile_name[strlen (argv0) + strlen (logfile_name_suffix)] = '\0';
-
+ return NULL;
logfile = fopen (logfile_name, "w");
CHECK_NON_NULL (logfile);
free (logfile_name);
@@ -293,6 +301,21 @@ set_up_logging (gcc_jit_context *ctxt, const char *argv0)
return logfile;
}
+/* Exercise the API entrypoint:
+ gcc_jit_context_dump_reproducer_to_file
+ by calling it on the context, using the path expected by jit.exp. */
+static void
+dump_reproducer (gcc_jit_context *ctxt, const char *argv0)
+{
+ char *reproducer_name;
+ reproducer_name = concat_strings (argv0, ".reproducer.c");
+ if (!reproducer_name)
+ return;
+ note ("%s: writing reproducer to %s", test, reproducer_name);
+ gcc_jit_context_dump_reproducer_to_file (ctxt, reproducer_name);
+ free (reproducer_name);
+}
+
/* Run one iteration of the test. */
static void
test_jit (const char *argv0, void *user_data)
@@ -314,6 +337,8 @@ test_jit (const char *argv0, void *user_data)
create_code (ctxt, user_data);
+ dump_reproducer (ctxt, argv0);
+
/* This actually calls into GCC and runs the build, all
in a mutex for now. */
result = gcc_jit_context_compile (ctxt);