Committed to dmalcolm/jit: Add a debug flag for dumping the generated assembler to stderr: GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE
This is technically an ABI change, since the value is added before some existing values, but we don't yet guarantee an ABI. gcc/jit/ * libgccjit.h (enum gcc_jit_bool_option): New value: GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE. * internal-api.c (gcc::jit::context::compile): Call dump_generated_code if the user has requested it. (gcc::jit::context::dump_generated_code): New, copying from the .s file to stderr. * internal-api.h (gcc::jit::context::dump_generated_code): New. --- gcc/jit/ChangeLog.jit | 12 ++++++++++++ gcc/jit/internal-api.c | 19 +++++++++++++++++++ gcc/jit/internal-api.h | 2 ++ gcc/jit/libgccjit.h | 4 ++++ 4 files changed, 37 insertions(+) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index 41f52f2..f4127d1 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,5 +1,17 @@ 2014-01-23 David Malcolm <dmalc...@redhat.com> + * libgccjit.h (enum gcc_jit_bool_option): New value: + GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE. + + * internal-api.c (gcc::jit::context::compile): Call + dump_generated_code if the user has requested it. + (gcc::jit::context::dump_generated_code): New, copying + from the .s file to stderr. + + * internal-api.h (gcc::jit::context::dump_generated_code): New. + +2014-01-23 David Malcolm <dmalc...@redhat.com> + * internal-api.h (gcc::jit::function): Add field "m_inner_bind_expr". * internal-api.c (gcc::jit::function::function): Create a BIND_EXPR diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index d0d49cc..869185a 100644 --- a/gcc/jit/internal-api.c +++ b/gcc/jit/internal-api.c @@ -1302,6 +1302,9 @@ compile () goto error; } + if (m_bool_options[GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE]) + dump_generated_code (); + timevar_push (TV_ASSEMBLE); /* Gross hacks follow: @@ -1398,6 +1401,22 @@ invoke_code_factory () } } +void +gcc::jit::context:: +dump_generated_code () +{ + char buf[4096]; + size_t sz; + FILE *f_in = fopen (m_path_s_file, "r"); + if (!f_in) + return; + + while ( (sz = fread (buf, 1, sizeof (buf), f_in)) ) + fwrite (buf, 1, sz, stderr); + + fclose (f_in); +} + static int line_comparator (const void *lhs, const void *rhs) { diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h index be1216a..b226c23 100644 --- a/gcc/jit/internal-api.h +++ b/gcc/jit/internal-api.h @@ -176,6 +176,8 @@ public: as_truth_value (tree expr, location *loc); private: + void dump_generated_code (); + source_file * get_source_file (const char *filename); diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 8a6682b..baf1541 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -158,6 +158,10 @@ enum gcc_jit_bool_option are performed. The dump resembles C code. */ GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, + /* If true, gcc_jit_context_compile will dump the final + generated code to stderr, in the form of assembly language. */ + GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, + /* If true, gcc_jit_context_compile will print information to stderr on the actions it is performing, followed by a profile showing the time taken and memory usage of each phase. -- 1.7.11.7