@@ -1,3 +1,11 @@
+2014-01-21 David Malcolm <dmalcolm@redhat.com>
+
+ * internal-api.c (gcc::jit::function::add_comment): New.
+ * internal-api.h (gcc::jit::function::add_comment): New.
+ * libgccjit.c (gcc_jit_function_add_comment): New.
+ * libgccjit.h (gcc_jit_function_add_comment): New.
+ * libgccjit.map: Add gcc_jit_function_add_comment.
+
2013-10-24 David Malcolm <dmalcolm@redhat.com>
* internal-api.c (gcc::jit::function::add_eval): Handle non-NULL
@@ -923,6 +923,27 @@ add_assignment (location *loc,
void
gcc::jit::function::
+add_comment (location *loc,
+ const char *text)
+{
+ gcc_assert (m_kind != GCC_JIT_FUNCTION_IMPORTED);
+
+ /* Wrap the text in C-style comment delimiters. */
+ size_t sz =
+ (3 /* opening delim */
+ + strlen (text)
+ + 3 /* closing delim */
+ + 1 /* terminator */);
+ char *wrapped = (char *)ggc_internal_alloc_stat (sz);
+ snprintf (wrapped, sz, "/* %s */", text);
+
+ /* For now we simply implement this by adding a dummy label with a name
+ containing the given text. */
+ add_label (loc, wrapped);
+}
+
+void
+gcc::jit::function::
add_conditional (location *loc,
rvalue *boolval,
label *on_true,
@@ -319,6 +319,10 @@ public:
rvalue *rvalue);
void
+ add_comment (location *loc,
+ const char *text);
+
+ void
add_conditional (location *loc,
rvalue *boolval,
label *on_true,
@@ -639,6 +639,17 @@ gcc_jit_function_add_conditional (gcc_jit_function *func,
}
void
+gcc_jit_function_add_comment (gcc_jit_function *func,
+ gcc_jit_location *loc,
+ const char *text)
+{
+ RETURN_IF_NOT_FUNC_DEFINITION (func);
+ RETURN_IF_FAIL (text, NULL, "NULL text");
+
+ func->add_comment (loc, text);
+}
+
+void
gcc_jit_function_add_jump (gcc_jit_function *func,
gcc_jit_location *loc,
gcc_jit_label *target)
@@ -668,6 +668,19 @@ gcc_jit_function_add_assignment_op (gcc_jit_function *func,
enum gcc_jit_binary_op op,
gcc_jit_rvalue *rvalue);
+/* Add a no-op textual comment to the internal representation of the
+ code. It will be optimized away, but will be visible in the dumps
+ seen via
+ GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE
+ and
+ GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE,
+ and thus may be of use when debugging how your project's internal
+ representation gets converted to the libgccjit IR. */
+extern void
+gcc_jit_function_add_comment (gcc_jit_function *func,
+ gcc_jit_location *loc,
+ const char *text);
+
/* Add evaluation of an rvalue, branching on the result to the
appropriate label.
@@ -30,6 +30,7 @@
gcc_jit_context_zero;
gcc_jit_function_add_assignment;
gcc_jit_function_add_assignment_op;
+ gcc_jit_function_add_comment;
gcc_jit_function_add_conditional;
gcc_jit_function_add_eval;
gcc_jit_function_add_jump;
@@ -1,3 +1,8 @@
+2014-01-21 David Malcolm <dmalcolm@redhat.com>
+
+ * jit.dg/test-hello-world.c (code_making_callback): Add usage of
+ gcc_jit_function_add_comment.
+
2013-10-24 David Malcolm <dmalcolm@redhat.com>
* jit.dg/harness.h (main): Wrap with #ifndef TEST_PROVIDES_MAIN
@@ -12,6 +12,7 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data)
void
hello_world (const char *name)
{
+ // a test comment
printf ("hello %s\n", name);
}
*/
@@ -43,6 +44,10 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data)
args[0] = gcc_jit_context_new_string_literal (ctxt, "hello %s\n");
args[1] = gcc_jit_param_as_rvalue (param_name);
+ gcc_jit_function_add_comment (
+ func, NULL,
+ "a test comment");
+
gcc_jit_function_add_eval (
func, NULL,
gcc_jit_context_new_call (ctxt,