From patchwork Wed Jan 29 16:21:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 315153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3FEEC2C0383 for ; Thu, 30 Jan 2014 03:33:01 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=yWXAW7JovLE9 1OYXGxBKdIDHUoJ4h9WVlQg3/6sZswCtDleAr0DrYL3Sj3DCi1U8wLVsDm7PNqzW GK+jWbpON/AuohD25ODhAvfQW3ENDhpqFAC8dMU973+OU5/4U9MJkiJ8WgP06xXs STjrThSvIGnNBSVosBhGeaHrw3Uv2k0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=zpPYkc51XpOjNAgfYv qiSXzv9yA=; b=iF+rf8uNLVgH01y9272oT8AdTTpu1GESE/SDJ/mI+uZ8OqZFXa S0D+GGUFre279ST5HeQdiXTlFtxwz8V2rFa7x1mdN96i210uRqeKY8hPoV39SrZl PCacc71L0TVYLvkFLwJrLal+B8CPPxI7mwI3j+TEEZvcXCCrg9yqn2oPE= Received: (qmail 9768 invoked by alias); 29 Jan 2014 16:32:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9748 invoked by uid 89); 29 Jan 2014 16:32:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS, T_FILL_THIS_FORM_SHORT, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jan 2014 16:32:49 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0TGWfWq009270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 29 Jan 2014 11:32:48 -0500 Received: from surprise.redhat.com (vpn-233-129.phx2.redhat.com [10.3.233.129]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0TGNDTK027585; Wed, 29 Jan 2014 11:23:14 -0500 From: David Malcolm To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [jit] API change: access fields via (gcc_jit_field *) rather than by name Date: Wed, 29 Jan 2014 11:21:57 -0500 Message-Id: <1391012517-23297-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Committed to branch dmalcolm/jit: Currently there's almost no type-checking within libgccjit - if client code uses the API in such a way as to generate bogus code, this is likely to violate assumptions made later on within GCC proper, leading to errors deep inside GCC (e.g. with internal compiler error: verify_gimple failed when converting tree to gimple, when expanding gimple to RTL, or indeed in other places; see the results of test-fuzzer.c for examples). The API will be more developer-friendly if we catch such type errors at the API boundary (similar to how the other language frontends enforce these assumptions). As a step towards this, change the API for accessing fields to use gcc_jit_field pointers, rather than passing field name as strings, avoiding the need to do a lookup in the replay code, and allowing for the possibility of directly examining the type of the field when implementing type-checking. gcc/jit/ * libgccjit.h (gcc_jit_lvalue_access_field): Require a (gcc_jit_field *) rather than a field name. (gcc_jit_rvalue_access_field): Likewise. (gcc_jit_rvalue_dereference_field): Likewise. * libgccjit.c (gcc_jit_lvalue_access_field): Require a (gcc_jit_field *) rather than a field name. (gcc_jit_rvalue_access_field): Likewise. (gcc_jit_rvalue_dereference_field): Likewise. * internal-api.c (gcc::jit::recording::rvalue::access_field): Require a field rather than a fieldname string. (gcc::jit::recording::rvalue::dereference_field): Likewise. (gcc::jit::recording::lvalue::access_field): Likewise. (gcc::jit::recording::access_field_of_lvalue::replay_into): Update given that this now has a field, rather than a fieldname. (gcc::jit::recording::access_field_rvalue::replay_into): Likewise. (gcc::jit::recording::dereference_field_rvalue::replay_into): Likewise. (get_field): Delete, as we no longer need to convert from (struct, identifier) pairs to fields, instead directly using fields. (gcc::jit::playback::context::new_field_access): Require a field rather than a fieldname, removing the need to look up the field by name within the struct. (gcc::jit::playback::lvalue::access_field): Likewise. (gcc::jit::playback::rvalue::access_field): Likewise. (gcc::jit::playback::rvalue::dereference_field): Likewise. * internal-api.h (gcc::jit::recording::rvalue::access_field): Require a field rather than a fieldname string. (gcc::jit::recording::rvalue::dereference_field): Likewise. (gcc::jit::recording::lvalue::access_field): Likewise. (gcc::jit::recording::access_field_of_lvalue::access_field_of_lvalue): Likewise. (gcc::jit::recording::access_field_of_lvalue::m_fieldname): Drop string field in favor of... (gcc::jit::recording::access_field_of_lvalue::m_field): ..."field" field, as it were. (gcc::jit::recording::access_field_of_rvalue::access_field_of_rvalue): Likewise. (gcc::jit::recording::access_field_of_rvalue::m_fieldname): Drop string field in favor of... (gcc::jit::recording::access_field_of_rvalue::m_field): ..."field" field. (gcc::jit::recording::dereference_field_rvalue:: dereference_field_rvalue): Likewise. (gcc::jit::recording::dereference_field_rvalue::m_fieldname): Drop string field in favor of... (gcc::jit::recording::dereference_field_rvalue::m_field): ..."field" field. (gcc::jit::playback::context::new_field_access): Require a field rather than a fieldname string. (gcc::jit::playback::context::access_field): Likewise. (gcc::jit::playback::context::dereference_field): Likewise. (gcc::jit::playback::rvalue::access_field): gcc/testsuite/ * jit.dg/test-accessing-struct.c (create_code): Update for API change for accessing fields in terms of gcc_jit_field pointers rather than by name. * jit.dg/test-nested-contexts.c (make_calc_discriminant): Likewise. (make_test_quadratic): Likewise. * jit.dg/test-quadratic.c (make_calc_discriminant): Likewise. (make_test_quadratic): Likewise. * jit.dg/test-reading-struct.c (create_code): Likewise. * jit.dg/test-types.c: Likewise. --- gcc/jit/ChangeLog.jit | 66 ++++++++++ gcc/jit/internal-api.c | 59 +++------ gcc/jit/internal-api.h | 34 ++--- gcc/jit/libgccjit.c | 18 +-- gcc/jit/libgccjit.h | 6 +- gcc/testsuite/ChangeLog.jit | 12 ++ gcc/testsuite/jit.dg/test-accessing-struct.c | 6 +- gcc/testsuite/jit.dg/test-nested-contexts.c | 20 +-- gcc/testsuite/jit.dg/test-quadratic.c | 20 +-- gcc/testsuite/jit.dg/test-reading-struct.c | 8 +- gcc/testsuite/jit.dg/test-types.c | 185 ++++++++++++++++----------- 11 files changed, 268 insertions(+), 166 deletions(-) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index 67856f4..36e69e4 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,3 +1,69 @@ +2014-01-29 David Malcolm + + * libgccjit.h (gcc_jit_lvalue_access_field): Require + a (gcc_jit_field *) rather than a field name. + (gcc_jit_rvalue_access_field): Likewise. + (gcc_jit_rvalue_dereference_field): Likewise. + + * libgccjit.c (gcc_jit_lvalue_access_field): Require + a (gcc_jit_field *) rather than a field name. + (gcc_jit_rvalue_access_field): Likewise. + (gcc_jit_rvalue_dereference_field): Likewise. + + * internal-api.c (gcc::jit::recording::rvalue::access_field): + Require a field rather than a fieldname string. + (gcc::jit::recording::rvalue::dereference_field): Likewise. + (gcc::jit::recording::lvalue::access_field): Likewise. + + (gcc::jit::recording::access_field_of_lvalue::replay_into): Update + given that this now has a field, rather than a fieldname. + (gcc::jit::recording::access_field_rvalue::replay_into): Likewise. + (gcc::jit::recording::dereference_field_rvalue::replay_into): Likewise. + + (get_field): Delete, as we no longer need to convert + from (struct, identifier) pairs to fields, instead directly using + fields. + + (gcc::jit::playback::context::new_field_access): Require a field + rather than a fieldname, removing the need to look up the field by + name within the struct. + + (gcc::jit::playback::lvalue::access_field): Likewise. + (gcc::jit::playback::rvalue::access_field): Likewise. + (gcc::jit::playback::rvalue::dereference_field): Likewise. + + * internal-api.h (gcc::jit::recording::rvalue::access_field): + Require a field rather than a fieldname string. + (gcc::jit::recording::rvalue::dereference_field): Likewise. + (gcc::jit::recording::lvalue::access_field): Likewise. + + (gcc::jit::recording::access_field_of_lvalue::access_field_of_lvalue): + Likewise. + (gcc::jit::recording::access_field_of_lvalue::m_fieldname): Drop + string field in favor of... + (gcc::jit::recording::access_field_of_lvalue::m_field): + ..."field" field, as it were. + + (gcc::jit::recording::access_field_of_rvalue::access_field_of_rvalue): + Likewise. + (gcc::jit::recording::access_field_of_rvalue::m_fieldname): Drop + string field in favor of... + (gcc::jit::recording::access_field_of_rvalue::m_field): + ..."field" field. + + (gcc::jit::recording::dereference_field_rvalue:: + dereference_field_rvalue): Likewise. + (gcc::jit::recording::dereference_field_rvalue::m_fieldname): Drop + string field in favor of... + (gcc::jit::recording::dereference_field_rvalue::m_field): + ..."field" field. + + (gcc::jit::playback::context::new_field_access): Require a field + rather than a fieldname string. + (gcc::jit::playback::context::access_field): Likewise. + (gcc::jit::playback::context::dereference_field): Likewise. + (gcc::jit::playback::rvalue::access_field): + 2014-01-28 David Malcolm * libgccjit.h (gcc_jit_context_new_child_context): New function. diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index 30c578c..39d434f 100644 --- a/gcc/jit/internal-api.c +++ b/gcc/jit/internal-api.c @@ -552,22 +552,20 @@ recording::struct_::replay_into (replayer *r) recording::rvalue * recording::rvalue::access_field (recording::location *loc, - const char *fieldname) + field *field) { recording::rvalue *result = - new access_field_rvalue (m_ctxt, loc, this, - new_string (fieldname)); + new access_field_rvalue (m_ctxt, loc, this, field); m_ctxt->record (result); return result; } recording::lvalue * recording::rvalue::dereference_field (recording::location *loc, - const char *fieldname) + field *field) { recording::lvalue *result = - new dereference_field_rvalue (m_ctxt, loc, this, - new_string (fieldname)); + new dereference_field_rvalue (m_ctxt, loc, this, field); m_ctxt->record (result); return result; } @@ -585,11 +583,10 @@ recording::rvalue::dereference (recording::location *loc) recording::lvalue * recording::lvalue::access_field (recording::location *loc, - const char *fieldname) + field *field) { recording::lvalue *result = - new access_field_of_lvalue (m_ctxt, loc, this, - new_string (fieldname)); + new access_field_of_lvalue (m_ctxt, loc, this, field); m_ctxt->record (result); return result; } @@ -881,7 +878,8 @@ recording::access_field_of_lvalue::replay_into (replayer *) set_playback_obj ( m_lvalue->playback_lvalue () ->access_field (playback_location (m_loc), - m_fieldname->c_str ())); + m_field->playback_field ())); + } void @@ -890,7 +888,7 @@ recording::access_field_rvalue::replay_into (replayer *) set_playback_obj ( m_rvalue->playback_rvalue () ->access_field (playback_location (m_loc), - m_fieldname->c_str ())); + m_field->playback_field ())); } void @@ -899,7 +897,7 @@ recording::dereference_field_rvalue::replay_into (replayer *) set_playback_obj ( m_rvalue->playback_rvalue ()-> dereference_field (playback_location (m_loc), - m_fieldname->c_str ())); + m_field->playback_field ())); } void @@ -1673,23 +1671,14 @@ new_array_lookup (location *loc, } } -static tree -get_field (tree type, tree component) -{ - for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) - if (DECL_NAME (field) == component) - return field; - return NULL; -} - tree playback::context:: new_field_access (location *loc, tree datum, - const char *fieldname) + field *field) { gcc_assert (datum); - gcc_assert (fieldname); + gcc_assert (field); /* Compare with c/c-typeck.c:lookup_field, build_indirect_ref, and build_component_ref. */ @@ -1697,15 +1686,9 @@ new_field_access (location *loc, gcc_assert (type); gcc_assert (TREE_CODE (type) != POINTER_TYPE); - tree component = get_identifier (fieldname); - tree field = get_field (type, component); - if (!field) - { - add_error ("field not found: \"%s\"", fieldname); - return NULL; - } - tree ref = build3 (COMPONENT_REF, TREE_TYPE (field), datum, - field, NULL_TREE); + tree t_field = field->as_tree (); + tree ref = build3 (COMPONENT_REF, TREE_TYPE (t_field), datum, + t_field, NULL_TREE); if (loc) set_tree_location (ref, loc); return ref; @@ -1728,10 +1711,10 @@ new_dereference (tree ptr, playback::lvalue * playback::lvalue:: access_field (location *loc, - const char *fieldname) + field *field) { tree datum = as_tree (); - tree ref = get_context ()->new_field_access (loc, datum, fieldname); + tree ref = get_context ()->new_field_access (loc, datum, field); if (!ref) return NULL; return new lvalue (get_context (), ref); @@ -1740,10 +1723,10 @@ access_field (location *loc, playback::rvalue * playback::rvalue:: access_field (location *loc, - const char *fieldname) + field *field) { tree datum = as_tree (); - tree ref = get_context ()->new_field_access (loc, datum, fieldname); + tree ref = get_context ()->new_field_access (loc, datum, field); if (!ref) return NULL; return new rvalue (get_context (), ref); @@ -1752,13 +1735,13 @@ access_field (location *loc, playback::lvalue * playback::rvalue:: dereference_field (location *loc, - const char *fieldname) + field *field) { tree ptr = as_tree (); tree datum = get_context ()->new_dereference (ptr, loc); if (!datum) return NULL; - tree ref = get_context ()->new_field_access (loc, datum, fieldname); + tree ref = get_context ()->new_field_access (loc, datum, field); if (!ref) return NULL; return new lvalue (get_context (), ref); diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h index db7e048..66d8cdb 100644 --- a/gcc/jit/internal-api.h +++ b/gcc/jit/internal-api.h @@ -472,11 +472,11 @@ public: } rvalue * access_field (location *loc, - const char *fieldname); + field *field); lvalue * dereference_field (location *loc, - const char *fieldname); + field *field); lvalue * dereference (location *loc); @@ -501,7 +501,7 @@ public: lvalue * access_field (location *loc, - const char *fieldname); + field *field); rvalue * get_address (location *loc); @@ -844,17 +844,17 @@ public: access_field_of_lvalue (context *ctxt, location *loc, lvalue *val, - string *fieldname) + field *field) : lvalue (ctxt, loc), m_lvalue (val), - m_fieldname (fieldname) + m_field (field) {} void replay_into (replayer *r); private: lvalue *m_lvalue; - string *m_fieldname; + field *m_field; }; class access_field_rvalue : public rvalue @@ -863,16 +863,17 @@ public: access_field_rvalue (context *ctxt, location *loc, rvalue *val, - string *fieldname) + field *field) : rvalue (ctxt, loc), m_rvalue (val), - m_fieldname (fieldname) {} + m_field (field) + {} void replay_into (replayer *r); private: rvalue *m_rvalue; - string *m_fieldname; + field *m_field; }; class dereference_field_rvalue : public lvalue @@ -881,16 +882,17 @@ public: dereference_field_rvalue (context *ctxt, location *loc, rvalue *val, - string *fieldname) + field *field) : lvalue (ctxt, loc), m_rvalue (val), - m_fieldname (fieldname) {} + m_field (field) + {} void replay_into (replayer *r); private: rvalue *m_rvalue; - string *m_fieldname; + field *m_field; }; class dereference_rvalue : public lvalue @@ -1306,7 +1308,7 @@ public: tree new_field_access (location *loc, tree datum, - const char *fieldname); + field *field); tree new_dereference (tree ptr, location *loc); @@ -1519,11 +1521,11 @@ public: rvalue * access_field (location *loc, - const char *fieldname); + field *field); lvalue * dereference_field (location *loc, - const char *fieldname); + field *field); lvalue * dereference (location *loc); @@ -1545,7 +1547,7 @@ public: lvalue * access_field (location *loc, - const char *fieldname); + field *field); rvalue * get_address (location *loc); diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index 7d1f9ae..ded581e 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -447,34 +447,34 @@ gcc_jit_context_new_array_lookup (gcc_jit_context *ctxt, gcc_jit_lvalue * gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_, gcc_jit_location *loc, - const char *fieldname) + gcc_jit_field *field) { RETURN_NULL_IF_FAIL (struct_, NULL, "NULL struct"); - RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname"); + RETURN_NULL_IF_FAIL (field, NULL, "NULL field"); - return (gcc_jit_lvalue *)struct_->access_field (loc, fieldname); + return (gcc_jit_lvalue *)struct_->access_field (loc, field); } gcc_jit_rvalue * gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_, gcc_jit_location *loc, - const char *fieldname) + gcc_jit_field *field) { RETURN_NULL_IF_FAIL (struct_, NULL, "NULL struct"); - RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname"); + RETURN_NULL_IF_FAIL (field, NULL, "NULL field"); - return (gcc_jit_rvalue *)struct_->access_field (loc, fieldname); + return (gcc_jit_rvalue *)struct_->access_field (loc, field); } gcc_jit_lvalue * gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr, gcc_jit_location *loc, - const char *fieldname) + gcc_jit_field *field) { RETURN_NULL_IF_FAIL (ptr, NULL, "NULL ptr"); - RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname"); + RETURN_NULL_IF_FAIL (field, NULL, "NULL field"); - return (gcc_jit_lvalue *)ptr->dereference_field (loc, fieldname); + return (gcc_jit_lvalue *)ptr->dereference_field (loc, field); } gcc_jit_lvalue * diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 8384a58..6a19b29 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -568,7 +568,7 @@ gcc_jit_context_new_array_lookup (gcc_jit_context *ctxt, extern gcc_jit_lvalue * gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_, gcc_jit_location *loc, - const char *fieldname); + gcc_jit_field *field); /* Accessing a field of an rvalue of struct type, analogous to: (EXPR).field @@ -576,7 +576,7 @@ gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_, extern gcc_jit_rvalue * gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_, gcc_jit_location *loc, - const char *fieldname); + gcc_jit_field *field); /* Accessing a field of an rvalue of pointer type, analogous to: (EXPR)->field @@ -584,7 +584,7 @@ gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_, extern gcc_jit_lvalue * gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr, gcc_jit_location *loc, - const char *fieldname); + gcc_jit_field *field); /* Dereferencing a pointer; analogous to: *(EXPR) diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit index 6b7413c..a225efd 100644 --- a/gcc/testsuite/ChangeLog.jit +++ b/gcc/testsuite/ChangeLog.jit @@ -1,3 +1,15 @@ +2014-01-29 David Malcolm + + * jit.dg/test-accessing-struct.c (create_code): Update for API change + for accessing fields in terms of gcc_jit_field pointers rather than + by name. + * jit.dg/test-nested-contexts.c (make_calc_discriminant): Likewise. + (make_test_quadratic): Likewise. + * jit.dg/test-quadratic.c (make_calc_discriminant): Likewise. + (make_test_quadratic): Likewise. + * jit.dg/test-reading-struct.c (create_code): Likewise. + * jit.dg/test-types.c: Likewise. + 2014-01-28 David Malcolm * jit.dg/harness.h (test_jit): Add the possibility of turning off diff --git a/gcc/testsuite/jit.dg/test-accessing-struct.c b/gcc/testsuite/jit.dg/test-accessing-struct.c index 031916a..b28adeb 100644 --- a/gcc/testsuite/jit.dg/test-accessing-struct.c +++ b/gcc/testsuite/jit.dg/test-accessing-struct.c @@ -67,12 +67,12 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_f), NULL, - "x")), + x)), gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_f), NULL, - "y"))); + y))); /* f->z = ... */ gcc_jit_function_add_assignment ( @@ -81,7 +81,7 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_f), NULL, - "z"), + z), sum); } diff --git a/gcc/testsuite/jit.dg/test-nested-contexts.c b/gcc/testsuite/jit.dg/test-nested-contexts.c index 14f90e7..eaedd75 100644 --- a/gcc/testsuite/jit.dg/test-nested-contexts.c +++ b/gcc/testsuite/jit.dg/test-nested-contexts.c @@ -180,17 +180,17 @@ make_calc_discriminant (struct top_level *top_level, gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "a")); + NULL, top_level->a)); gcc_jit_rvalue *q_b = gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "b")); + NULL, top_level->b)); gcc_jit_rvalue *q_c = gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "c")); + NULL, top_level->c)); gcc_jit_function_add_assignment ( middle_level->calc_discriminant, NULL, @@ -199,7 +199,7 @@ make_calc_discriminant (struct top_level *top_level, gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), NULL, - "discriminant"), + top_level->discriminant), /* (q->b * q->b) - (4 * q->a * q->c) */ gcc_jit_context_new_binary_op ( @@ -270,17 +270,17 @@ make_test_quadratic (struct top_level *top_level, /* q.a = a; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "a"), + gcc_jit_lvalue_access_field (q, NULL, top_level->a), gcc_jit_param_as_rvalue (a)); /* q.b = b; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "b"), + gcc_jit_lvalue_access_field (q, NULL, top_level->b), gcc_jit_param_as_rvalue (b)); /* q.c = c; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "c"), + gcc_jit_lvalue_access_field (q, NULL, top_level->c), gcc_jit_param_as_rvalue (c)); /* calc_discriminant (&q); */ gcc_jit_rvalue *address_of_q = gcc_jit_lvalue_get_address (q, NULL); @@ -318,7 +318,7 @@ make_test_quadratic (struct top_level *top_level, gcc_jit_rvalue_access_field ( gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"), + top_level->discriminant), top_level->zero), on_positive_discriminant, on_nonpositive_discriminant); @@ -334,7 +334,7 @@ make_test_quadratic (struct top_level *top_level, gcc_jit_rvalue *discriminant_of_q = gcc_jit_rvalue_access_field (gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"); + top_level->discriminant); gcc_jit_function_add_assignment ( test_quadratic, NULL, s, @@ -429,7 +429,7 @@ make_test_quadratic (struct top_level *top_level, gcc_jit_rvalue_access_field ( gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"), + top_level->discriminant), top_level->zero), on_zero_discriminant, on_negative_discriminant); diff --git a/gcc/testsuite/jit.dg/test-quadratic.c b/gcc/testsuite/jit.dg/test-quadratic.c index fad4b72..9b02c06 100644 --- a/gcc/testsuite/jit.dg/test-quadratic.c +++ b/gcc/testsuite/jit.dg/test-quadratic.c @@ -157,17 +157,17 @@ make_calc_discriminant (struct quadratic_test *testcase) gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "a")); + NULL, testcase->a)); gcc_jit_rvalue *q_b = gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "b")); + NULL, testcase->b)); gcc_jit_rvalue *q_c = gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), - NULL, "c")); + NULL, testcase->c)); gcc_jit_function_add_assignment ( testcase->calc_discriminant, NULL, @@ -176,7 +176,7 @@ make_calc_discriminant (struct quadratic_test *testcase) gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_q), NULL, - "discriminant"), + testcase->discriminant), /* (q->b * q->b) - (4 * q->a * q->c) */ gcc_jit_context_new_binary_op ( @@ -245,17 +245,17 @@ make_test_quadratic (struct quadratic_test *testcase) /* q.a = a; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "a"), + gcc_jit_lvalue_access_field (q, NULL, testcase->a), gcc_jit_param_as_rvalue (a)); /* q.b = b; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "b"), + gcc_jit_lvalue_access_field (q, NULL, testcase->b), gcc_jit_param_as_rvalue (b)); /* q.c = c; */ gcc_jit_function_add_assignment ( test_quadratic, NULL, - gcc_jit_lvalue_access_field (q, NULL, "c"), + gcc_jit_lvalue_access_field (q, NULL, testcase->c), gcc_jit_param_as_rvalue (c)); /* calc_discriminant (&q); */ gcc_jit_rvalue *address_of_q = gcc_jit_lvalue_get_address (q, NULL); @@ -293,7 +293,7 @@ make_test_quadratic (struct quadratic_test *testcase) gcc_jit_rvalue_access_field ( gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"), + testcase->discriminant), testcase->zero), on_positive_discriminant, on_nonpositive_discriminant); @@ -309,7 +309,7 @@ make_test_quadratic (struct quadratic_test *testcase) gcc_jit_rvalue *discriminant_of_q = gcc_jit_rvalue_access_field (gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"); + testcase->discriminant); gcc_jit_function_add_assignment ( test_quadratic, NULL, s, @@ -404,7 +404,7 @@ make_test_quadratic (struct quadratic_test *testcase) gcc_jit_rvalue_access_field ( gcc_jit_lvalue_as_rvalue (q), NULL, - "discriminant"), + testcase->discriminant), testcase->zero), on_zero_discriminant, on_negative_discriminant); diff --git a/gcc/testsuite/jit.dg/test-reading-struct.c b/gcc/testsuite/jit.dg/test-reading-struct.c index eeb6321..fd53f84 100644 --- a/gcc/testsuite/jit.dg/test-reading-struct.c +++ b/gcc/testsuite/jit.dg/test-reading-struct.c @@ -72,12 +72,12 @@ create_code (gcc_jit_context *ctxt, void *user_data) gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_f), NULL, - "x")), + x)), gcc_jit_lvalue_as_rvalue ( gcc_jit_rvalue_dereference_field ( gcc_jit_param_as_rvalue (param_f), NULL, - "y")))); + y)))); /* Build "test_writing". */ gcc_jit_function *fn_test_writing = @@ -96,13 +96,13 @@ create_code (gcc_jit_context *ctxt, void *user_data) /* tmp.x = 5; */ gcc_jit_function_add_assignment ( fn_test_writing, NULL, - gcc_jit_lvalue_access_field (local_tmp, NULL, "x"), + gcc_jit_lvalue_access_field (local_tmp, NULL, x), gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 5)); /* tmp.y = 7; */ gcc_jit_function_add_assignment ( fn_test_writing, NULL, - gcc_jit_lvalue_access_field (local_tmp, NULL, "y"), + gcc_jit_lvalue_access_field (local_tmp, NULL, y), gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 7)); /* return test_reading (&tmp); */ diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c index 1d5758d..90b5f6e 100644 --- a/gcc/testsuite/jit.dg/test-types.c +++ b/gcc/testsuite/jit.dg/test-types.c @@ -37,46 +37,6 @@ struct zoo FILE *m_FILE_ptr; }; -/* Now describe the struct in libgccjit terms. */ -struct field -{ - enum gcc_jit_types type_; - const char *name; -}; - -const struct field fields[] = { - {GCC_JIT_TYPE_VOID_PTR, "m_void_ptr"}, - - {GCC_JIT_TYPE_CHAR, "m_char"}, - {GCC_JIT_TYPE_SIGNED_CHAR, "m_signed_char"}, - {GCC_JIT_TYPE_UNSIGNED_CHAR, "m_unsigned_char"}, - - {GCC_JIT_TYPE_SHORT, "m_short"}, - {GCC_JIT_TYPE_UNSIGNED_SHORT, "m_unsigned_short"}, - - {GCC_JIT_TYPE_INT, "m_int"}, - {GCC_JIT_TYPE_UNSIGNED_INT, "m_unsigned_int"}, - - {GCC_JIT_TYPE_LONG, "m_long"}, - {GCC_JIT_TYPE_UNSIGNED_LONG, "m_unsigned_long"}, - - {GCC_JIT_TYPE_LONG_LONG, "m_long_long"}, - {GCC_JIT_TYPE_UNSIGNED_LONG_LONG, "m_unsigned_long_long"}, - - {GCC_JIT_TYPE_FLOAT, "m_float"}, - {GCC_JIT_TYPE_DOUBLE, "m_double"}, - {GCC_JIT_TYPE_LONG_DOUBLE, "m_long_double"}, - - {GCC_JIT_TYPE_CONST_CHAR_PTR, "m_const_char_ptr"}, - - {GCC_JIT_TYPE_SIZE_T, "m_size_t"}, - - {GCC_JIT_TYPE_FILE_PTR, "m_FILE_ptr"}, - -}; - -#define NUM_FIELDS (sizeof(fields)/sizeof(fields[0])) - int test_int = 42; int *test_ptr = &test_int; @@ -94,22 +54,101 @@ create_code (gcc_jit_context *ctxt, void *user_data) z->m_field = ...some data; } */ - int i; gcc_jit_type *void_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); - gcc_jit_field *zoo_fields[NUM_FIELDS]; - for (i = 0; i < NUM_FIELDS; i++) - zoo_fields[i] = - gcc_jit_context_new_field ( - ctxt, NULL, - gcc_jit_context_get_type (ctxt, fields[i].type_), - fields[i].name); + +#define CREATE_FIELD(TYPE, NAME) \ + gcc_jit_context_new_field ( \ + ctxt, NULL, \ + gcc_jit_context_get_type (ctxt, TYPE), \ + NAME) + + gcc_jit_field *field_m_void_ptr = + CREATE_FIELD (GCC_JIT_TYPE_VOID_PTR, "m_void_ptr"); + + gcc_jit_field *field_m_char = + CREATE_FIELD (GCC_JIT_TYPE_CHAR, "m_char"); + gcc_jit_field *field_m_signed_char = + CREATE_FIELD (GCC_JIT_TYPE_SIGNED_CHAR, "m_signed_char"); + gcc_jit_field *field_m_unsigned_char = + CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_CHAR, "m_unsigned_char"); + + gcc_jit_field *field_m_short = + CREATE_FIELD (GCC_JIT_TYPE_SHORT, "m_short"); + gcc_jit_field *field_m_unsigned_short = + CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_SHORT, "m_unsigned_short"); + + gcc_jit_field *field_m_int = + CREATE_FIELD (GCC_JIT_TYPE_INT, "m_int"); + gcc_jit_field *field_m_unsigned_int = + CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_INT, "m_unsigned_int"); + + gcc_jit_field *field_m_long = + CREATE_FIELD (GCC_JIT_TYPE_LONG, "m_long"); + gcc_jit_field *field_m_unsigned_long = + CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_LONG, "m_unsigned_long"); + + gcc_jit_field *field_m_long_long = + CREATE_FIELD (GCC_JIT_TYPE_LONG_LONG, "m_long_long"); + gcc_jit_field *field_m_unsigned_long_long = + CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_LONG_LONG, "m_unsigned_long_long"); + + gcc_jit_field *field_m_float = + CREATE_FIELD (GCC_JIT_TYPE_FLOAT, "m_float"); + gcc_jit_field *field_m_double = + CREATE_FIELD (GCC_JIT_TYPE_DOUBLE, "m_double"); + gcc_jit_field *field_m_long_double = + CREATE_FIELD (GCC_JIT_TYPE_LONG_DOUBLE, "m_long_double"); + + gcc_jit_field *field_m_const_char_ptr = + CREATE_FIELD (GCC_JIT_TYPE_CONST_CHAR_PTR, "m_const_char_ptr"); + + gcc_jit_field *field_m_size_t = + CREATE_FIELD (GCC_JIT_TYPE_SIZE_T, "m_size_t"); + + gcc_jit_field *field_m_FILE_ptr = + CREATE_FIELD (GCC_JIT_TYPE_FILE_PTR, "m_FILE_ptr"); + +#undef CREATE_FIELD + + gcc_jit_field *zoo_fields[] = { + field_m_void_ptr, + + field_m_char, + field_m_signed_char, + field_m_unsigned_char, + + field_m_short, + field_m_unsigned_short, + + field_m_int, + field_m_unsigned_int, + + field_m_long, + field_m_unsigned_long, + + field_m_long_long, + field_m_unsigned_long_long, + + field_m_float, + field_m_double, + field_m_long_double, + + field_m_const_char_ptr, + + field_m_size_t, + + field_m_FILE_ptr + }; + gcc_jit_type *zoo_type = - gcc_jit_context_new_struct_type (ctxt, - NULL, - "zoo", - NUM_FIELDS, - zoo_fields); + gcc_jit_context_new_struct_type ( + ctxt, + NULL, + "zoo", + sizeof (zoo_fields) / sizeof (zoo_fields[0]), + zoo_fields); + gcc_jit_type *zoo_ptr_type = gcc_jit_type_get_pointer (zoo_type); @@ -125,111 +164,111 @@ create_code (gcc_jit_context *ctxt, void *user_data) 0); /* Write to the various fields of param "z". */ -#define ASSIGN(FIELDNAME, EXPR) \ +#define ASSIGN(FIELD, EXPR) \ gcc_jit_function_add_assignment ( \ test_fn, NULL, \ gcc_jit_rvalue_dereference_field ( \ gcc_jit_param_as_rvalue (param_z), \ NULL, \ - (FIELDNAME)), \ + (FIELD)), \ (EXPR)); ASSIGN( - "m_void_ptr", + field_m_void_ptr, gcc_jit_context_new_rvalue_from_ptr ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR), test_ptr)) - ASSIGN("m_char", + ASSIGN(field_m_char, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR), 'V')) - ASSIGN("m_signed_char", + ASSIGN(field_m_signed_char, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SIGNED_CHAR), -37)) - ASSIGN("m_unsigned_char", + ASSIGN(field_m_unsigned_char, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_CHAR), 200)) - ASSIGN("m_short", + ASSIGN(field_m_short, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SHORT), -900)) - ASSIGN("m_unsigned_short", + ASSIGN(field_m_unsigned_short, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_SHORT), 0x3000)) - ASSIGN("m_int", + ASSIGN(field_m_int, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT), -0x2000)) - ASSIGN("m_unsigned_int", + ASSIGN(field_m_unsigned_int, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_INT), 1234567)) - ASSIGN("m_long", + ASSIGN(field_m_long, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG), -5)) - ASSIGN("m_unsigned_long", + ASSIGN(field_m_unsigned_long, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_LONG), 12345678)) - ASSIGN("m_long_long", + ASSIGN(field_m_long_long, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG_LONG), -42)) - ASSIGN("m_unsigned_long_long", + ASSIGN(field_m_unsigned_long_long, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_LONG_LONG), 123456789)) - ASSIGN("m_float", + ASSIGN(field_m_float, gcc_jit_context_new_rvalue_from_double ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT), 3.141)) - ASSIGN("m_double", + ASSIGN(field_m_double, gcc_jit_context_new_rvalue_from_double ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE), 3.141)) - ASSIGN("m_long_double", + ASSIGN(field_m_long_double, gcc_jit_context_new_rvalue_from_double ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG_DOUBLE), 3.141)) - ASSIGN("m_const_char_ptr", + ASSIGN(field_m_const_char_ptr, gcc_jit_context_new_rvalue_from_ptr ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR), (char *)test_string)) - ASSIGN("m_size_t", + ASSIGN(field_m_size_t, gcc_jit_context_new_rvalue_from_int ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SIZE_T), sizeof (struct zoo))) - ASSIGN("m_FILE_ptr", + ASSIGN(field_m_FILE_ptr, gcc_jit_context_new_rvalue_from_ptr ( ctxt, gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FILE_PTR),