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: 64008 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1EBFD396FA28 for ; Tue, 31 Jan 2023 13:27:53 +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-Google-Smtp-Source: AMrXdXuPesVZc1boV8rWhmruBkCNXCwqv/TH5KfU0f7YbhqofKvoh1Tk81rrUJGC3AurskMACdA5Vw== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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_; +};