From patchwork Tue Jan 31 13:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 50919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2808055wrn; Tue, 31 Jan 2023 07:17:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXvWkEwJ/tsc3AAQqB5OJRw6Cmh/ZJ2MJG+0Bz1jhYYJFzNQWz++l2RsRWNFwP7wGT/3Y0lh X-Received: by 2002:a17:906:9601:b0:86b:935d:37f0 with SMTP id s1-20020a170906960100b0086b935d37f0mr54292426ejx.55.1675178222574; Tue, 31 Jan 2023 07:17:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675178222; cv=none; d=google.com; s=arc-20160816; b=NyGi7JSVaY1oP5tdFNH8VgXHcI8awGgqMMiig5NMs5bOM+IV12uGE47t0IuPUgHZgM RUtGGarNuL5Up6NqTGzLooPu9yXdo/Vr7Y60kpgWmpR7dTIAR0OUYCpr3/nvPaRPy6vf DnybDoWzNa3JGmM3DCiJ/iNeICkZDiu3JYxf8CC97mS32f602K/kqef3bNkwskjyxDX9 n6kZS8AEARQoeqGTY7xaWL16xUwv6MRVqs5eT+44fNC3LbKb5rkDm/HhBq0zkB6wjO4n u/PVnSE/SfNC9WTycu6zGx41vZnLB/2CU6usC7VzAF9hmxCxFeRfWK+9tLvY3ys0+n1c Cfhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=L3317EO5kXFvGGnq8KgoHbFOtqhBfgoPZl+rK4r9Dbc=; b=QD5kJnsQygPA/updy5w1q2vW1p5nqKYMQbGyzP71bIgcqNUb9N0eoUoAFqKV4KpUey cw6kj8VfFWjM5NPCWrgT73aU/LCFWD4fsxCUvd+KE9Zje8fQimFYTjXPYuFsqltnDgyz yGtsDlT4Rf3CO/M9Owb6fLmm9K/9Ct54D0hxSvCsNogYb20umUCBFf0d6xySOV88ZNrj S/6FFRzvHSC+la7TDmRZcdyc0gzyy1IglY2cVdatAtLDyn/tvD/TqHsiHg0JRpQj7K15 j+M2LaF5HZarMCdutgjjvDitcJ87/fNUpiEJQ+P7yll7+LWF1xOBVJyGjnHoe+/fyWjx lXuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QkVsVvXV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fy15-20020a1709069f0f00b007ae0e8f697fsi19058539ejc.652.2023.01.31.07.17.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:17:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QkVsVvXV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33EB13BF90EF for ; Tue, 31 Jan 2023 13:28:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 1553138923EC for ; Tue, 31 Jan 2023 13:27:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1553138923EC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ej1-x62e.google.com with SMTP id hx15so22040943ejc.11 for ; Tue, 31 Jan 2023 05:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=L3317EO5kXFvGGnq8KgoHbFOtqhBfgoPZl+rK4r9Dbc=; b=QkVsVvXV7UJAcVsUcIA/Sth1GbTrjhAn1+bAAxopi1iNAhz3Xmk7QfCq40vCLthTCK B6JB3veoWU4JU+2j2YE+XkEuDP2nN80CXGhmllmx1zdrZZ+sYQ3BSmPO/buMg9oV7uUR r/xUIi2WleW94hnU2J0X7V7nkRiCB0lBh+Mw+8//wPn6P8Xx78D4MDj9CKaVSrEbh4zx rvAzbjTnpkMRWiT8mlrersQ0Xgbt931bOZrw07BpCsYaA62uyv+cQzzBz0ukc+GqOQZ+ j5jix6HutqlomrZaxT2ub1tE+0YvZJyz0dK1aTa/bULH/AG0SBlM7K2DBE5xkViwR7DH aS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L3317EO5kXFvGGnq8KgoHbFOtqhBfgoPZl+rK4r9Dbc=; b=N+pCylM8I216aHeaHCPPJP4IXHFOR4VrCnjF/60jQXUuQ3qaKWaaRguiHBrAo/7MEm AbqF+iqywAyuLc9gqeiCCPwcR8A5KkHGKaMdRVFbkUdPC8TDa1AmRlQx6SmotXIOOFBv v/Db3NFIB44ryga7VP4XpnTLuAqdwV8qVZbPlkWOxzyiaUBYJCqno4+zchtRvXfQHix7 HZDdAafP0acGy+BNuUldMtUWk/d0qY0JFJUoEVHzTWVGRP6MfR+V+6p0je1HImPuFN7n ttKDzPFvkokyYCa3v1dCAqFxpYFlXQzrP9VFJofD6moGBldDRaGyDrOxNR7tyFlvABPi Rrjw== X-Gm-Message-State: AFqh2koF52gsbMOz9ICSl75OTzw1YGV23ekhmiq6L49gjwJX/Rw1zhtP tj9sCLEsYezt0FWFWcmvaRl9UHApvKzbCtxhMQ== X-Received: by 2002:adf:e9d2:0:b0:242:800:9a7f with SMTP id l18-20020adfe9d2000000b0024208009a7fmr47211433wrn.65.1675171211078; Tue, 31 Jan 2023 05:20:11 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id n9-20020a5d4c49000000b002bfb7c2430bsm14697480wrt.19.2023.01.31.05.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:20:10 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED] gccrs: backend: Expose Bvariable class through rust-gcc header Date: Tue, 31 Jan 2023 14:23:36 +0100 Message-Id: <20230131132335.661108-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-15.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756551679852498335?= X-GMAIL-MSGID: =?utf-8?q?1756551679852498335?= gcc/rust/ChangeLog: * rust-gcc.cc (class Bvariable): Move class to `rust-gcc.h` header. * rust-gcc.h: New file. Tested on x86_64-pc-linux-gnu, committed on master. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/rust-gcc.cc | 30 +---------------------- gcc/rust/rust-gcc.h | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 gcc/rust/rust-gcc.h diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index e3331d60e32..82b2d33977d 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -50,38 +50,10 @@ #include "rust-linemap.h" #include "rust-backend.h" #include "rust-object-export.h" +#include "rust-gcc.h" #include "backend/rust-tree.h" -// TODO: this will have to be significantly modified to work with Rust - -// Bvariable is a bit more complicated, because of zero-sized types. -// The GNU linker does not permit dynamic variables with zero size. -// When we see such a variable, we generate a version of the type with -// non-zero size. However, when referring to the global variable, we -// want an expression of zero size; otherwise, if, say, the global -// variable is passed to a function, we will be passing a -// non-zero-sized value to a zero-sized value, which can lead to a -// miscompilation. - -class Bvariable -{ -public: - Bvariable (tree t) : t_ (t), orig_type_ (NULL) {} - - Bvariable (tree t, tree orig_type) : t_ (t), orig_type_ (orig_type) {} - - // Get the tree for use as an expression. - tree get_tree (Location) const; - - // Get the actual decl; - tree get_decl () const { return this->t_; } - -private: - tree t_; - tree orig_type_; -}; - // Get the tree of a variable for use as an expression. If this is a // zero-sized global, create an expression that refers to the decl but // has zero size. diff --git a/gcc/rust/rust-gcc.h b/gcc/rust/rust-gcc.h new file mode 100644 index 00000000000..085c16d0f3b --- /dev/null +++ b/gcc/rust/rust-gcc.h @@ -0,0 +1,58 @@ +// rust-gcc.cc -- Rust frontend to gcc IR. +// Copyright (C) 2011-2022 Free Software Foundation, Inc. +// Contributed by Ian Lance Taylor, Google. +// forked from gccgo + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-system.h" + +// This has to be included outside of extern "C", so we have to +// include it here before tree.h includes it later. +#include + +#include "tree.h" +#include "rust-location.h" + +// TODO: this will have to be significantly modified to work with Rust + +// Bvariable is a bit more complicated, because of zero-sized types. +// The GNU linker does not permit dynamic variables with zero size. +// When we see such a variable, we generate a version of the type with +// non-zero size. However, when referring to the global variable, we +// want an expression of zero size; otherwise, if, say, the global +// variable is passed to a function, we will be passing a +// non-zero-sized value to a zero-sized value, which can lead to a +// miscompilation. + +class Bvariable +{ +public: + Bvariable (tree t) : t_ (t), orig_type_ (NULL) {} + + Bvariable (tree t, tree orig_type) : t_ (t), orig_type_ (orig_type) {} + + // Get the tree for use as an expression. + tree get_tree (Location) const; + + // Get the actual decl; + tree get_decl () const { return this->t_; } + +private: + tree t_; + tree orig_type_; +};