From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20058.outbound.protection.outlook.com [40.107.2.58]) by sourceware.org (Postfix) with ESMTPS id A37513857815; Thu, 15 Oct 2020 16:24:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A37513857815 Received: from AM6PR02CA0006.eurprd02.prod.outlook.com (2603:10a6:20b:6e::19) by DB7PR08MB3596.eurprd08.prod.outlook.com (2603:10a6:10:4a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Thu, 15 Oct 2020 16:24:00 +0000 Received: from AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::22) by AM6PR02CA0006.outlook.office365.com (2603:10a6:20b:6e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20 via Frontend Transport; Thu, 15 Oct 2020 16:24:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT057.mail.protection.outlook.com (10.152.17.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Thu, 15 Oct 2020 16:23:59 +0000 Received: ("Tessian outbound 7c188528bfe0:v64"); Thu, 15 Oct 2020 16:23:59 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 86ca04e08aad48a4 X-CR-MTA-TID: 64aa7808 Received: from a50daeddcd8e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 63418E4C-A7F6-4808-A93E-129E3AFB7638.1; Thu, 15 Oct 2020 16:23:22 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a50daeddcd8e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 15 Oct 2020 16:23:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhL211Wjxm/94KEqQwzI8NZYFv9WHD8CMaLIpqrXH7+axJdnK+XDaMO7bfu+Id34rWM/edj9cP2xh7Le/xdx6oyM5lHJ/WRBnYTQUGKJ7UIxzJBOG3OmHjl32AZV57cDHQ31lRJLxYu1VMeLWSnX8zrZGv/9ZIV5400DhG/1cGmFE21rEf0KUHFcHQbArT21lP0CoNKWrJi8Q9w7lEmakCwC6KkUKmSciXVKPc83JGu+jsdaOcm6+coI4hJhSV1otDa63rbr+AUPXAu4UQMEQSIqcT6aAeTab/QW6LzRTT2eeGhhR3qHHb1KvLlNA7Gcqyr+1YKN8ulJNzVB7HmpZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QU+IWh/PFNuF9GMwnhJFsPHy+mQeQAJkUFurJL8iv4I=; b=QvaPxE6GPhOYJ7RsRDEPpsWwJ8tmGNyKR3IMBADX7iBXt+3v2D2hGGPRx1lYNJgqMimXQ+YOrLVmxX1AkmIHuVXRVf+ukGtrXZZp/v2khjkOXZGzbJSnzUkbCIvUTHwG0g3Ty/G+dZWyJmM6CFO0BFFmkhXnByGbqlVlQnizWgKzMtX0pXP3WyN7M5di4cwFqf4YZLHqWlD5RIVzdQZaQKPfT0xWc/tTzGxsrGpZeCBXild1XpcOsv4etBaCf57JsBdIaDZufPH2A0CLfhWumulyHV3OE6jSV4goTmQDCd2Tp+/j98CyvnOYUguo7cWBO9IzlOcO/d9vaPrwfuEWVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB4900.eurprd08.prod.outlook.com (2603:10a6:20b:cc::10) by AM5PR0801MB2082.eurprd08.prod.outlook.com (2603:10a6:203:4b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.22; Thu, 15 Oct 2020 16:23:20 +0000 Received: from AM6PR08MB4900.eurprd08.prod.outlook.com ([fe80::b96e:941c:e829:3903]) by AM6PR08MB4900.eurprd08.prod.outlook.com ([fe80::b96e:941c:e829:3903%3]) with mapi id 15.20.3455.031; Thu, 15 Oct 2020 16:23:20 +0000 From: Andrea Corallo To: Antoni Boucher via Jit Cc: David Malcolm , Antoni Boucher , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libgccjit: add some reflection functions in the jit C api References: <20200902010120.crnx55ev635ceiey@bouanto-desktop.localdomain> <6fe2ea355403eb177c9632e076c11c792f23c791.camel@redhat.com> <9cd00fe5cb5c03184e3a5bd939447b30450a8ca7.camel@redhat.com> <20201015160226.cka4iq3w22jztopm@bouanto-desktop.localdomain> Date: Thu, 15 Oct 2020 18:23:18 +0200 In-Reply-To: <20201015160226.cka4iq3w22jztopm@bouanto-desktop.localdomain> (Antoni Boucher via Jit's message of "Thu, 15 Oct 2020 12:02:26 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Content-Type: text/plain X-Originating-IP: [217.140.106.37] X-ClientProxiedBy: LO2P265CA0181.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::25) To AM6PR08MB4900.eurprd08.prod.outlook.com (2603:10a6:20b:cc::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from e124257 (217.140.106.37) by LO2P265CA0181.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Thu, 15 Oct 2020 16:23:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0dc95a05-8218-4fb7-b399-08d87126b911 X-MS-TrafficTypeDiagnostic: AM5PR0801MB2082:|DB7PR08MB3596: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7219;OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 5a+rR5cRlJEpL0kvnd5rd0BiGdHxrQmbT0rlkMKEyw9P2ltqB/QmCvYLVU9v9hzQt4Gd0Yf/pM/QruMXVqwudxHKWQNFVpTzwd8XNTAdNuMPJZ1Rxo760/V0zqAXnkXZ30PiIQo7q3jQPISltElx/QpEJtlpPL4DcPqywYMN6EVzF88jXZkawR6ZI3RyhHVlf7v+vZzZBj195izvBX6pQ9wLbk+hMhovAkpBSY3XAhOOshg94BVzh8Wyc12W/dfimVIT85vfUgls4LG8XTDBOZhckpBJvRHdkM44GYpDxV6yQh7YxFSjiBGsC36Q5RlgopL+Cy80vi+8w9xRPPXFcpuUjZI4j/INr/fqRf479H8VBuSKWWV1f3Dto6DUvpTE X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB4900.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(396003)(39850400004)(346002)(136003)(30864003)(26005)(8936002)(2906002)(316002)(4326008)(956004)(54906003)(53546011)(2616005)(52116002)(6916009)(6496006)(66556008)(66476007)(66946007)(8676002)(34490700002)(44832011)(478600001)(5660300002)(83380400001)(36756003)(6486002)(186003)(16526019)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: zBzeiklGTZOd9FMRZ9irb9eThEsSWI4dp49r07RhAARO+AqMgcX5hVJ4ej5dVohNnOsFfseWYyktjsC2eDA9j5RPmXWncq03dt4AhG0/NUeyaIXwSE5PFysLYkZdqoITkX19SqjgKwBjWOalAgt44b8D2s6O/zDAl7Q3PThmyiJX1KXx1T6RjU1TdQVIJZA4m0TFchHYzds9sUH5s8Yi8ePnB50kOzB2WtiuLgIbh6DejgxUuwNEg31zbUR5W5m5SMGO4hUWMFEfJmLKdIlYWnT+X4vrDCuv2DwtABiQJCTi7WGtZWU9fPunm4rGqczlXDtFYjiBHFJUafddbpD3MWEe8IkALZmBNF4cnflaQlxXogHEPr3RO8BRbuYpB8t0Ow4iO/EpqdvHmf2+mggzsGNX/XnF4Fxw9BXpEDczzX5bMK6Oaw0+lczVVxpntO0lVd6UOdr8ZhloQp+U+73qrC/76GLcaZFzwDYt9ZHDFhN6bnSSOQUv8UAlbzYCPEP9SPvHZUUbV+QGnm+WZt5MMhOxzKjfFY7j69oL3f+I2kT12/RsuDA6tsz5mBPxvh3FH0vnDM4pZbl9B24pLjvyFGDGlDPNscI8GCd50Y+HEGoHoMi72wOf6M66Z3XkqZEyX6q6jB/JFBGSl4sjpjHwgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB2082 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 6f000564-42a2-4a99-ae93-08d87126a10f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6WlBreNwYS1MJ3SblaMNd1d7A63vVQVQmnPemYpOH31fi3jtM5vsU3yzIJZgZMWHEo8xCG4xDOPInnsP1RlxzD3MYtqFCgJw3YMWwQ5QOZr9AUjRECYzkPfQ0FmVFUAmF9gt4ZtbU1oCksNjYbOYY+GZ2qtrD9JdXk8O8jkZBp0jRLjHpx45xBCmYr4DdkX+bK3ffkoV6PaoMwJ1sa9bnDUky7c51f6iXIqpb4A+Drox9WiCx0nE7iEnwmDWtT+CNYaNZOysD/H4FnpwMkfFbjRnf5uvDEX+OzRnTU62Ox77q5ZnalW3QpeFH5dSIJ735kqinR6jzl5rnDANf18id2fbFZ4leNL4t3z4F4Vzn5owCg1r4H4mGdl73SJ9p01RBYbkw1Sv0ena6s5UViLPjw== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(376002)(346002)(39850400004)(396003)(46966005)(54906003)(6916009)(36906005)(5660300002)(316002)(53546011)(47076004)(44832011)(70206006)(6496006)(70586007)(82310400003)(30864003)(6486002)(86362001)(4326008)(36756003)(83380400001)(478600001)(16526019)(2616005)(2906002)(8676002)(336012)(450100002)(956004)(26005)(8936002)(186003)(81166007)(356005)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2020 16:23:59.9637 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0dc95a05-8218-4fb7-b399-08d87126b911 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3596 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Oct 2020 16:24:06 -0000 Antoni Boucher via Jit writes: Hi Antoni, Just had a quick look, please find some quite minor comments in line. > From b0edc9eb8e8d3ba9e1c6a8d061a8627c0b0cf102 Mon Sep 17 00:00:00 2001 > From: Antoni Boucher > Date: Sat, 1 Aug 2020 17:52:17 -0400 > Subject: [PATCH] This patch add some reflection functions in the jit C api > [PR96889] > > 2020-09-1 Antoni Boucher > > gcc/jit/ > PR target/96889 > * docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag. > * docs/topics/functions.rst: Add documentation for the > functions gcc_jit_function_get_return_type and > gcc_jit_function_get_param_count > * libgccjit.c: New functions: > * gcc_jit_function_get_return_type; > * gcc_jit_function_get_param_count; > * gcc_jit_function_type_get_return_type; > * gcc_jit_function_type_get_param_count; > * gcc_jit_function_type_get_param_type; > * gcc_jit_type_unqualified; > * gcc_jit_type_is_array; > * gcc_jit_type_is_bool; > * gcc_jit_type_is_function_ptr_type; > * gcc_jit_type_is_int; > * gcc_jit_type_is_pointer; > * gcc_jit_type_is_vector; > * gcc_jit_vector_type_get_element_type; > * gcc_jit_vector_type_get_num_units; > * gcc_jit_struct_get_field; > * gcc_jit_type_is_struct; > * gcc_jit_struct_get_field_count; > * libgccjit.h > * jit-recording.h: New functions (is_struct and is_vector) > * libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag. > > gcc/testsuite/ > PR target/96889 > * jit.dg/all-non-failing-tests.h: Add test-reflection.c. > * jit.dg/test-reflection.c: New test. > --- > gcc/jit/docs/topics/compatibility.rst | 41 +++ > gcc/jit/docs/topics/functions.rst | 10 + > gcc/jit/jit-recording.h | 16 ++ > gcc/jit/libgccjit.c | 254 +++++++++++++++++++ > gcc/jit/libgccjit.h | 117 +++++++++ > gcc/jit/libgccjit.map | 21 ++ > gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 + > gcc/testsuite/jit.dg/test-reflection.c | 89 +++++++ > 8 files changed, 558 insertions(+) > create mode 100644 gcc/testsuite/jit.dg/test-reflection.c > > diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst > index 6bfa101ed71..16f24d20a75 100644 > --- a/gcc/jit/docs/topics/compatibility.rst > +++ b/gcc/jit/docs/topics/compatibility.rst > @@ -226,3 +226,44 @@ entrypoints: > -------------------- > ``LIBGCCJIT_ABI_14`` covers the addition of > :func:`gcc_jit_global_set_initializer` > + > +.. _LIBGCCJIT_ABI_15: > + > +``LIBGCCJIT_ABI_15`` > +-------------------- > +``LIBGCCJIT_ABI_15`` covers the addition of reflection functions via API > +entrypoints: > + > + * :func:`gcc_jit_function_get_return_type` > + > + * :func:`gcc_jit_function_get_param_count` > + > + * :func:`gcc_jit_type_is_array` > + > + * :func:`gcc_jit_type_is_bool` > + > + * :func:`gcc_jit_type_is_int` > + > + * :func:`gcc_jit_type_is_pointer` > + > + * :func:`gcc_jit_type_is_struct` > + > + * :func:`gcc_jit_type_is_vector` > + > + * :func:`gcc_jit_type_unqualified` > + > + * :func:`gcc_jit_type_is_function_ptr_type` > + > + * :func:`gcc_jit_function_type_get_return_type` > + > + * :func:`gcc_jit_function_type_get_param_count` > + > + * :func:`gcc_jit_function_type_get_param_type` > + > + * :func:`gcc_jit_vector_type_get_num_units` > + > + * :func:`gcc_jit_vector_type_get_element_type` > + > + * :func:`gcc_jit_struct_get_field` > + > + * :func:`gcc_jit_struct_get_field_count` > diff --git a/gcc/jit/docs/topics/functions.rst b/gcc/jit/docs/topics/functions.rst > index eb40d64010e..9819c28cda2 100644 > --- a/gcc/jit/docs/topics/functions.rst > +++ b/gcc/jit/docs/topics/functions.rst > @@ -171,6 +171,16 @@ Functions > underlying string, so it is valid to pass in a pointer to an on-stack > buffer. > > +.. function:: size_t \ > + gcc_jit_function_get_param_count (gcc_jit_function *func) > + > + Get the number of parameters of the function. > + > +.. function:: gcc_jit_type \* > + gcc_jit_function_get_return_type (gcc_jit_function *func) > + > + Get the return type of the function. > + > Blocks > ------ > .. type:: gcc_jit_block > diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h > index 30e37aff387..525b8bc921d 100644 > --- a/gcc/jit/jit-recording.h > +++ b/gcc/jit/jit-recording.h > @@ -538,7 +538,9 @@ public: > virtual bool is_bool () const = 0; > virtual type *is_pointer () = 0; > virtual type *is_array () = 0; > + virtual struct_ *is_struct () { return NULL; } > virtual bool is_void () const { return false; } > + virtual vector_type *is_vector () { return NULL; } > virtual bool has_known_size () const { return true; } > > bool is_numeric () const > @@ -595,6 +597,8 @@ public: > bool is_bool () const FINAL OVERRIDE; > type *is_pointer () FINAL OVERRIDE { return dereference (); } > type *is_array () FINAL OVERRIDE { return NULL; } > + vector_type *is_vector () FINAL OVERRIDE { return NULL; } > + struct_ *is_struct () FINAL OVERRIDE { return NULL; } > bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; } > > public: > @@ -629,6 +633,8 @@ public: > bool is_bool () const FINAL OVERRIDE { return false; } > type *is_pointer () FINAL OVERRIDE { return m_other_type; } > type *is_array () FINAL OVERRIDE { return NULL; } > + vector_type *is_vector () FINAL OVERRIDE { return NULL; } > + struct_ *is_struct () FINAL OVERRIDE { return NULL; } > > private: > string * make_debug_string () FINAL OVERRIDE; > @@ -655,6 +661,7 @@ public: > bool is_bool () const FINAL OVERRIDE { return m_other_type->is_bool (); } > type *is_pointer () FINAL OVERRIDE { return m_other_type->is_pointer (); } > type *is_array () FINAL OVERRIDE { return m_other_type->is_array (); } > + struct_ *is_struct () FINAL OVERRIDE { return m_other_type->is_struct (); } > > protected: > type *m_other_type; > @@ -737,6 +744,8 @@ public: > > void replay_into (replayer *) FINAL OVERRIDE; > > + vector_type *is_vector () FINAL OVERRIDE { return this; } > + > private: > string * make_debug_string () FINAL OVERRIDE; > void write_reproducer (reproducer &r) FINAL OVERRIDE; > @@ -765,6 +774,8 @@ class array_type : public type > bool is_bool () const FINAL OVERRIDE { return false; } > type *is_pointer () FINAL OVERRIDE { return NULL; } > type *is_array () FINAL OVERRIDE { return m_element_type; } > + vector_type *is_vector () FINAL OVERRIDE { return NULL; } > + struct_ *is_struct () FINAL OVERRIDE { return NULL; } > int num_elements () { return m_num_elements; } > > void replay_into (replayer *) FINAL OVERRIDE; > @@ -799,6 +810,8 @@ public: > bool is_bool () const FINAL OVERRIDE { return false; } > type *is_pointer () FINAL OVERRIDE { return NULL; } > type *is_array () FINAL OVERRIDE { return NULL; } > + vector_type *is_vector () FINAL OVERRIDE { return NULL; } > + struct_ *is_struct () FINAL OVERRIDE { return NULL; } > > void replay_into (replayer *) FINAL OVERRIDE; > > @@ -912,6 +925,7 @@ public: > bool is_bool () const FINAL OVERRIDE { return false; } > type *is_pointer () FINAL OVERRIDE { return NULL; } > type *is_array () FINAL OVERRIDE { return NULL; } > + vector_type *is_vector () FINAL OVERRIDE { return NULL; } > > bool has_known_size () const FINAL OVERRIDE { return m_fields != NULL; } > > @@ -943,6 +957,8 @@ public: > > const char *access_as_type (reproducer &r) FINAL OVERRIDE; > > + struct_ *is_struct () FINAL OVERRIDE { return this; } > + > private: > string * make_debug_string () FINAL OVERRIDE; > void write_reproducer (reproducer &r) FINAL OVERRIDE; > diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c > index a00aefc7108..94a0f1955ec 100644 > --- a/gcc/jit/libgccjit.c > +++ b/gcc/jit/libgccjit.c > @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see > #include "config.h" > #include "system.h" > #include "coretypes.h" > +#include "tm.h" > #include "timevar.h" > #include "typed-splay-tree.h" > #include "cppbuiltin.h" > @@ -60,6 +61,14 @@ struct gcc_jit_struct : public gcc::jit::recording::struct_ > { > }; > > +struct gcc_jit_function_type : public gcc::jit::recording::function_type > +{ > +}; > + > +struct gcc_jit_vector_type : public gcc::jit::recording::vector_type > +{ > +}; > + > struct gcc_jit_field : public gcc::jit::recording::field > { > }; > @@ -510,6 +519,195 @@ gcc_jit_type_get_volatile (gcc_jit_type *type) > return (gcc_jit_type *)type->get_volatile (); > } > > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_array method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_type_is_array (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + > + return (gcc_jit_type *)type->is_array (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_bool method, in > + jit-recording.c. */ > + > +int > +gcc_jit_type_is_bool (gcc_jit_type *type) > +{ > + RETURN_VAL_IF_FAIL (type, FALSE, NULL, NULL, "NULL type"); > + > + return type->is_bool (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_pointer method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_type_is_pointer (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + > + return (gcc_jit_type *)type->is_pointer (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_int method, in > + jit-recording.c. */ > + > +int > +gcc_jit_type_is_int (gcc_jit_type *type) > +{ > + RETURN_VAL_IF_FAIL (type, FALSE, NULL, NULL, "NULL type"); > + > + return type->is_int (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_vector method, in > + jit-recording.c. */ > + > +gcc_jit_vector_type * > +gcc_jit_type_is_vector (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + gcc::jit::recording::vector_type *vector_type = type->is_vector(); ^^^ space here > + return (gcc_jit_vector_type *)vector_type; > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::is_struct method, in > + jit-recording.c. */ > + > +gcc_jit_struct * > +gcc_jit_type_is_struct (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + gcc::jit::recording::struct_ *struct_type = type->is_struct(); Likewise > + return (gcc_jit_struct *)struct_type; > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::vector_type::get_num_units method, in > + jit-recording.c. */ > + > +ssize_t > +gcc_jit_vector_type_get_num_units (gcc_jit_vector_type *vector_type) > +{ > + RETURN_VAL_IF_FAIL (vector_type, -1, NULL, NULL, "NULL vector_type"); > + return vector_type->get_num_units (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::vector_type::get_element_type method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type) > +{ > + RETURN_NULL_IF_FAIL (vector_type, NULL, NULL, "NULL vector_type"); > + return (gcc_jit_type *)vector_type->get_element_type (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::unqualified method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_type_unqualified (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + > + return (gcc_jit_type *)type->unqualified (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::type::dyn_cast_function_type method, in > + jit-recording.c. */ > + > +gcc_jit_function_type * > +gcc_jit_type_is_function_ptr_type (gcc_jit_type *type) > +{ > + RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type"); > + gcc::jit::recording::type *func_ptr_type = type->dereference (); > + RETURN_NULL_IF_FAIL (func_ptr_type, NULL, NULL, "NULL type"); > + gcc::jit::recording::function_type *func_type = func_ptr_type->dyn_cast_function_type(); Likewise (also exceeded 80 characters). > + RETURN_NULL_IF_FAIL (func_type, NULL, NULL, "NULL type"); > + > + return (gcc_jit_function_type *)func_type; > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::function_type::get_return_type method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_function_type_get_return_type (gcc_jit_function_type *function_type) > +{ > + RETURN_NULL_IF_FAIL (function_type, NULL, NULL, "NULL struct_type"); > + return (gcc_jit_type *)function_type->get_return_type (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::function_type::get_param_types method, in > + jit-recording.c. */ > + > +ssize_t > +gcc_jit_function_type_get_param_count (gcc_jit_function_type *function_type) > +{ > + RETURN_VAL_IF_FAIL (function_type, -1, NULL, NULL, "NULL struct_type"); > + return function_type->get_param_types ().length(); Likewise > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::function_type::get_param_types method, in > + jit-recording.c. */ > + > +gcc_jit_type * > +gcc_jit_function_type_get_param_type (gcc_jit_function_type *function_type, int index) Excedes 80 characters > +{ > + RETURN_NULL_IF_FAIL (function_type, NULL, NULL, "NULL struct_type"); > + int num_params = function_type->get_param_types ().length (); > + gcc::jit::recording::context *ctxt = function_type->m_ctxt; > + RETURN_NULL_IF_FAIL_PRINTF3 (index < num_params, > + ctxt, NULL, > + "index of %d is too large (%s has %d params)", > + index, > + function_type->get_debug_string (), > + num_params); > + return (gcc_jit_type *)function_type->get_param_types ()[index]; > +} > + > /* Public entrypoint. See description in libgccjit.h. > > After error-checking, the real work is done by the > @@ -731,6 +929,33 @@ gcc_jit_struct_set_fields (gcc_jit_struct *struct_type, > (gcc::jit::recording::field **)fields); > } > > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::fields::get_field method in > + jit-recording.c. */ > +extern gcc_jit_field * > +gcc_jit_struct_get_field (gcc_jit_struct *struct_type, > + int index) > +{ > + RETURN_NULL_IF_FAIL (struct_type, NULL, NULL, "NULL struct type"); > + return (gcc_jit_field *)struct_type->get_fields()->get_field(index); Space before ( > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, this calls the trivial > + gcc::jit::recording::struct_::get_fields method in > + jit-recording.h. */ > + > +ssize_t > +gcc_jit_struct_get_field_count (gcc_jit_struct *struct_type) > +{ > + RETURN_VAL_IF_FAIL (struct_type, -1, NULL, NULL, "NULL struct type"); > + return struct_type->get_fields()->length(); Likewise > +} > + > /* Public entrypoint. See description in libgccjit.h. > > After error-checking, the real work is done by the > @@ -1012,6 +1237,35 @@ gcc_jit_function_get_param (gcc_jit_function *func, int index) > return static_cast (func->get_param (index)); > } > > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::function::get_params method, in > + jit-recording.h. > + */ > + > +ssize_t > +gcc_jit_function_get_param_count (gcc_jit_function *func) > +{ > + RETURN_VAL_IF_FAIL (func, -1, NULL, NULL, "NULL function"); > + gcc::jit::recording::context *ctxt = func->m_ctxt; > + JIT_LOG_FUNC (ctxt->get_logger ()); > + return func->get_params ().length (); > +} > + > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::function::get_return_type method, in > + jit-recording.h. */ > + > +gcc_jit_type * > +gcc_jit_function_get_return_type (gcc_jit_function *func) > +{ > + RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function"); > + return (gcc_jit_type *)func->get_return_type (); > +} > + > /* Public entrypoint. See description in libgccjit.h. > > After error-checking, the real work is done by the > diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h > index 7134841bb07..b0a3d941e9c 100644 > --- a/gcc/jit/libgccjit.h > +++ b/gcc/jit/libgccjit.h > @@ -96,6 +96,12 @@ typedef struct gcc_jit_field gcc_jit_field; > the layout for, or an opaque type. */ > typedef struct gcc_jit_struct gcc_jit_struct; > > +/* A gcc_jit_function_type encapsulates a function type. */ > +typedef struct gcc_jit_function_type gcc_jit_function_type; > + > +/* A gcc_jit_vector_type encapsulates a vector type. */ > +typedef struct gcc_jit_vector_type gcc_jit_vector_type; > + > /* A gcc_jit_function encapsulates a function: either one that you're > creating yourself, or a reference to one that you're dynamically > linking to within the rest of the process. */ > @@ -586,6 +592,60 @@ gcc_jit_type_get_const (gcc_jit_type *type); > extern gcc_jit_type * > gcc_jit_type_get_volatile (gcc_jit_type *type); > > +/* Given type "T", return TRUE if the type is an array. */ > +extern gcc_jit_type * > +gcc_jit_type_is_array (gcc_jit_type *type); > + > +/* Given type "T", return TRUE if the type is a bool. */ > +extern int > +gcc_jit_type_is_bool (gcc_jit_type *type); > + > +/* Given type "T", return the function type if it is one. */ > +extern gcc_jit_function_type * > +gcc_jit_type_is_function_ptr_type (gcc_jit_type *type); > + > +/* Given a function type, return its return type. */ GNU stile wants dot + 2 spaces at the end of a comment. > +extern gcc_jit_type * > +gcc_jit_function_type_get_return_type (gcc_jit_function_type *function_type); > + > +/* Given a function type, return its number of parameters. */ Likewise > +extern ssize_t > +gcc_jit_function_type_get_param_count (gcc_jit_function_type *function_type); > + > +/* Given a function type, return the type of the specified parameter. */ Likewise > +extern gcc_jit_type * > +gcc_jit_function_type_get_param_type (gcc_jit_function_type *function_type, int index); Exceeds 80 characters > + > +/* Given type "T", return the type pointed by the pointer type > + * or NULL if it's not a pointer. */ > +extern gcc_jit_type * > +gcc_jit_type_is_pointer (gcc_jit_type *type); > + > +/* Given type "T", return TRUE if the type is an int. */ > +extern int > +gcc_jit_type_is_int (gcc_jit_type *type); > + > +/* Given type "T", return the unqualified type, i.e. for a > + * decorated type, return the type it wraps. */ > +extern gcc_jit_type * > +gcc_jit_type_unqualified (gcc_jit_type *type); > + > +/* Given type "T", return TRUE if the type is a vector type. */ > +extern gcc_jit_vector_type * > +gcc_jit_type_is_vector (gcc_jit_type *type); > + > +/* Given type "T", return the struct type or NULL. */ > +extern gcc_jit_struct * > +gcc_jit_type_is_struct (gcc_jit_type *type); > + > +/* Given a vector type, return the number of units it contains. */ One space more before */ > +extern ssize_t > +gcc_jit_vector_type_get_num_units (gcc_jit_vector_type *vector_type); > + > +/* Given a vector type, return the type of its elements. */ Likewise > +extern gcc_jit_type * > +gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type); > + > /* Given type "T", get type "T[N]" (for a constant N). */ > extern gcc_jit_type * > gcc_jit_context_new_array_type (gcc_jit_context *ctxt, > @@ -647,6 +707,15 @@ gcc_jit_struct_set_fields (gcc_jit_struct *struct_type, > int num_fields, > gcc_jit_field **fields); > > +/* Get a field by index. */ Likewise > +extern gcc_jit_field * > +gcc_jit_struct_get_field (gcc_jit_struct *struct_type, > + int index); > + > +/* Get the number of fields. */ Likewise > +extern ssize_t > +gcc_jit_struct_get_field_count (gcc_jit_struct *struct_type); > + > /* Unions work similarly to structs. */ > extern gcc_jit_type * > gcc_jit_context_new_union_type (gcc_jit_context *ctxt, > @@ -740,6 +809,14 @@ gcc_jit_function_as_object (gcc_jit_function *func); > extern gcc_jit_param * > gcc_jit_function_get_param (gcc_jit_function *func, int index); > > +/* Get the number of params of a function. */ > +extern ssize_t > +gcc_jit_function_get_param_count (gcc_jit_function *func); > + > +/* Get the return type of a function. */ > +extern gcc_jit_type * > +gcc_jit_function_get_return_type (gcc_jit_function *func); > + > /* Emit the function in graphviz format. */ > extern void > gcc_jit_function_dump_to_dot (gcc_jit_function *func, > @@ -1518,6 +1595,46 @@ gcc_jit_version_minor (void); > extern int > gcc_jit_version_patchlevel (void); > > +#define LIBGCCJIT_HAVE_gcc_jit_function_reflection > + > +/* Reflection functions to get the number of parameters, return type of > + a function and whether a type is a bool from the C API. > + > + This API entrypoint was added in LIBGCCJIT_ABI_15; you can test for its > + presence using > + #ifdef LIBGCCJIT_HAVE_gcc_jit_function_reflection > +*/ > +extern gcc_jit_type * > +gcc_jit_function_get_return_type (gcc_jit_function *func); > +extern ssize_t > +gcc_jit_function_get_param_count (gcc_jit_function *func); > +extern gcc_jit_type * > +gcc_jit_type_is_array (gcc_jit_type *type); > +extern int > +gcc_jit_type_is_bool (gcc_jit_type *type); > +extern gcc_jit_function_type * > +gcc_jit_type_is_function_ptr_type (gcc_jit_type *type); > +extern gcc_jit_type * > +gcc_jit_function_type_get_return_type (gcc_jit_function_type *function_type); > +extern ssize_t > +gcc_jit_function_type_get_param_count (gcc_jit_function_type *function_type); > +extern gcc_jit_type * > +gcc_jit_function_type_get_param_type (gcc_jit_function_type *function_type, int index); Exceeds 80 characters > +extern int > +gcc_jit_type_is_int (gcc_jit_type *type); > +extern gcc_jit_type * > +gcc_jit_type_is_pointer (gcc_jit_type *type); > +extern gcc_jit_vector_type * > +gcc_jit_type_is_vector (gcc_jit_type *type); > +extern gcc_jit_struct * > +gcc_jit_type_is_struct (gcc_jit_type *type); > +extern ssize_t > +gcc_jit_vector_type_get_num_units (gcc_jit_vector_type *vector_type); > +extern gcc_jit_type * > +gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type); > +extern gcc_jit_type * > +gcc_jit_type_unqualified (gcc_jit_type *type); Apologies for the nit picking :) Andrea