Committed to branch dmalcolm/jit: gcc/jit/ * libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BOOL.
* internal-api.h (gcc::jit::recording::comparison::comparison): Use GCC_JIT_TYPE_BOOL as the types of comparisons, rather than GCC_JIT_TYPE_INT. * internal-api.c (gcc::jit::recording::memento_of_get_type:: dereference): Handle GCC_JIT_TYPE_BOOL (with an error). (get_type_strings): Add GCC_JIT_TYPE_BOOL. (get_tree_node_for_type): Handle GCC_JIT_TYPE_BOOL. gcc/testsuite/ * jit.dg/test-types.c: Add test coverage for getting type GCC_JIT_TYPE_BOOL. * jit.dg/test-expressions.c (make_test_of_comparison): Convert return type from int to bool. (verify_comparisons): Likewise. --- gcc/jit/ChangeLog.jit | 13 +++++++++++++ gcc/jit/internal-api.c | 6 ++++++ gcc/jit/internal-api.h | 2 +- gcc/jit/libgccjit.h | 4 ++++ gcc/testsuite/ChangeLog.jit | 8 ++++++++ gcc/testsuite/jit.dg/test-expressions.c | 9 ++++++--- gcc/testsuite/jit.dg/test-types.c | 15 +++++++++++++++ 7 files changed, 53 insertions(+), 4 deletions(-) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index d331082..90c2e3f 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,5 +1,18 @@ 2014-02-11 David Malcolm <dmalc...@redhat.com> + * libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BOOL. + + * internal-api.h (gcc::jit::recording::comparison::comparison): Use + GCC_JIT_TYPE_BOOL as the types of comparisons, rather than + GCC_JIT_TYPE_INT. + + * internal-api.c (gcc::jit::recording::memento_of_get_type:: + dereference): Handle GCC_JIT_TYPE_BOOL (with an error). + (get_type_strings): Add GCC_JIT_TYPE_BOOL. + (get_tree_node_for_type): Handle GCC_JIT_TYPE_BOOL. + +2014-02-11 David Malcolm <dmalc...@redhat.com> + * internal-api.c (gcc::jit::recording::context::add_error_va): If GCC_JIT_STR_OPTION_PROGNAME is NULL, use "libgccjit.so", as per the comment in libgccjit.h diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index 6c66d3d..0f140fe 100644 --- a/gcc/jit/internal-api.c +++ b/gcc/jit/internal-api.c @@ -657,6 +657,7 @@ recording::memento_of_get_type::dereference () case GCC_JIT_TYPE_VOID_PTR: return m_ctxt->get_type (GCC_JIT_TYPE_VOID); + case GCC_JIT_TYPE_BOOL: case GCC_JIT_TYPE_CHAR: case GCC_JIT_TYPE_SIGNED_CHAR: case GCC_JIT_TYPE_UNSIGNED_CHAR: @@ -698,6 +699,8 @@ static const char * const get_type_strings[] = { "void", /* GCC_JIT_TYPE_VOID */ "void *", /* GCC_JIT_TYPE_VOID_PTR */ + "bool", /* GCC_JIT_TYPE_BOOL */ + "char", /* GCC_JIT_TYPE_CHAR */ "signed char", /* GCC_JIT_TYPE_SIGNED_CHAR */ "unsigned char", /* GCC_JIT_TYPE_UNSIGNED_CHAR */ @@ -1723,6 +1726,9 @@ get_tree_node_for_type (enum gcc_jit_types type_) case GCC_JIT_TYPE_VOID_PTR: return ptr_type_node; + case GCC_JIT_TYPE_BOOL: + return boolean_type_node; + case GCC_JIT_TYPE_CHAR: return char_type_node; case GCC_JIT_TYPE_SIGNED_CHAR: diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h index 55772a6..f285039 100644 --- a/gcc/jit/internal-api.h +++ b/gcc/jit/internal-api.h @@ -961,7 +961,7 @@ public: location *loc, enum gcc_jit_comparison op, rvalue *a, rvalue *b) - : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_INT)), /* FIXME: should be bool? */ + : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)), m_op (op), m_a (a), m_b (b) diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 976bcb2..a4ef65e 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -305,6 +305,10 @@ enum gcc_jit_types /* "void *". */ GCC_JIT_TYPE_VOID_PTR, + /* C++'s bool type; also C99's "_Bool" type, aka "bool" if using + stdbool.h. */ + GCC_JIT_TYPE_BOOL, + /* Various integer types. */ /* C's "char" (of some signedness) and the variants where the diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit index 25aff70..4d8f209 100644 --- a/gcc/testsuite/ChangeLog.jit +++ b/gcc/testsuite/ChangeLog.jit @@ -1,5 +1,13 @@ 2014-02-11 David Malcolm <dmalc...@redhat.com> + * jit.dg/test-types.c: Add test coverage for getting type + GCC_JIT_TYPE_BOOL. + * jit.dg/test-expressions.c (make_test_of_comparison): Convert + return type from int to bool. + (verify_comparisons): Likewise. + +2014-02-11 David Malcolm <dmalc...@redhat.com> + * jit.dg/test-error-unplaced-label.c (verify_code): Update expected error message to reflect commit 6cd4f82c5237cc328aea229cdaaa428ff09d6e98. diff --git a/gcc/testsuite/jit.dg/test-expressions.c b/gcc/testsuite/jit.dg/test-expressions.c index 36588c6..d2fd950 100644 --- a/gcc/testsuite/jit.dg/test-expressions.c +++ b/gcc/testsuite/jit.dg/test-expressions.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stdio.h> #include <stddef.h> +#include <stdbool.h> #include "libgccjit.h" @@ -319,7 +320,7 @@ make_test_of_comparison (gcc_jit_context *ctxt, const char *funcname) { /* Make a test function of the form: - T test_comparison_op (T a, T b) + bool test_comparison_op (T a, T b) { return a OP b; } @@ -329,10 +330,12 @@ make_test_of_comparison (gcc_jit_context *ctxt, gcc_jit_param *param_b = gcc_jit_context_new_param (ctxt, NULL, type, "b"); gcc_jit_param *params[] = {param_a, param_b}; + gcc_jit_type *bool_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL); gcc_jit_function *test_fn = gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED, - type, + bool_type, funcname, 2, params, 0); @@ -397,7 +400,7 @@ make_tests_of_comparisons (gcc_jit_context *ctxt) static void verify_comparisons (gcc_jit_result *result) { - typedef int (*test_fn) (int, int); + typedef bool (*test_fn) (int, int); test_fn test_COMPARISON_EQ_on_int = (test_fn)gcc_jit_result_get_code (result, diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c index 4782680..f6fc1b2 100644 --- a/gcc/testsuite/jit.dg/test-types.c +++ b/gcc/testsuite/jit.dg/test-types.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stdio.h> #include <stddef.h> +#include <stdbool.h> #include "libgccjit.h" @@ -10,6 +11,8 @@ struct zoo { void *m_void_ptr; + bool m_bool; + char m_char; signed char m_signed_char; unsigned char m_unsigned_char; @@ -68,6 +71,9 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_field *field_m_void_ptr = CREATE_FIELD (GCC_JIT_TYPE_VOID_PTR, "m_void_ptr"); + gcc_jit_field *field_m_bool = + CREATE_FIELD (GCC_JIT_TYPE_BOOL, "m_bool"); + gcc_jit_field *field_m_char = CREATE_FIELD (GCC_JIT_TYPE_CHAR, "m_char"); gcc_jit_field *field_m_signed_char = @@ -123,6 +129,8 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_field *zoo_fields[] = { field_m_void_ptr, + field_m_bool, + field_m_char, field_m_signed_char, field_m_unsigned_char, @@ -191,6 +199,11 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR), test_ptr)) + ASSIGN(field_m_bool, + gcc_jit_context_new_rvalue_from_int ( + ctxt, + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL), 1)) + ASSIGN(field_m_char, gcc_jit_context_new_rvalue_from_int ( ctxt, @@ -312,6 +325,8 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) /* Verify that it correctly wrote to the various fields. */ CHECK_VALUE (z.m_void_ptr, test_ptr); + CHECK_VALUE (z.m_bool, true); + CHECK_VALUE (z.m_char, 'V'); CHECK_VALUE (z.m_signed_char, -37); CHECK_VALUE (z.m_unsigned_char, 200); -- 1.7.11.7