From patchwork Wed Aug 24 11:59:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: herron.philip@googlemail.com X-Patchwork-Id: 717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1388828wro; Wed, 24 Aug 2022 05:15:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Luzbac8c0tCGAS6AbapP+YcPBGVTuEpnCUvZZS8lz5yk0H/DfR/++MrmhCD3gG9mhtbp6 X-Received: by 2002:a17:907:e89:b0:73d:a99a:7943 with SMTP id ho9-20020a1709070e8900b0073da99a7943mr2636089ejc.682.1661343325296; Wed, 24 Aug 2022 05:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661343325; cv=none; d=google.com; s=arc-20160816; b=rgMhrvQGxjAhtALheKdmH2ze8SLA0pNugiQCwZfqRsLWYTDmACMYcmx+Z5Dy0J6jsN 2DtgqwXF8iLG9uC4gdMUjp7t9KB2p+uEkuTGf+14DEokCU6t/OzEv2KRZe6gxy2jlRyP bRq9Ck+5VncJo4W7wsfJ4I+o/76K6lLKOgzQdXCp7n/jhf/7nJ7SxWFTvVJFfU2XboD8 FJHzlVrbp0VfCF6y0qLdBP2x+WR5Q8e0AzhefKOU78RMUbEKXboVBIdiTx9PdXUBuqu+ UjaWmJOZsocZ7PJ4hDxcbhDAYwrJQ03VnwmhJju65HwUTsM8a4lR8IIRGX5AZ1tg3cOt F9gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature:dmarc-filter :delivered-to; bh=faMW4xAPda93TRGR2QHBH3TEDPQ193jx4GkOCpJopPc=; b=phGIWbgxtlfcFaRZi3a75HkWtTtgzEbrzjGWRT2N5XJCIRi7TuE1u92f7559WRbNcR 951WZknk5TRX5lxLHurNgQkPwSaSAfmMWUWaUROz/TsHie9C8dNy4Z0yllpcBEPBRvmX Rod3NjHgZHi7JOtZLcQVx0yxDNPTF2lJPtJmJ59lRs3yQhdMiKqCecjdFfYaf2E+GGnq uIFKkVdRQEFaJTumRCfskq7RbeyGtt+YPwE2/HlCSKUoLwo/m3nDqB72D7GqnWAPkxhp tBIrcxAXznkgVTdR0tcpYANgbzv6rMSzZGGh5n3rW0kWI5QwL43P0kjTVA7jtAA8i9hu osYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b="UD/DSZ7a"; 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"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d19-20020a056402401300b0044785ed87d7si1067691eda.404.2022.08.24.05.15.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:15:25 -0700 (PDT) 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=@googlemail.com header.s=20210112 header.b="UD/DSZ7a"; 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"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 015EB3897177 for ; Wed, 24 Aug 2022 12:05:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 121D23885C22; Wed, 24 Aug 2022 12:00:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 121D23885C22 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=googlemail.com Received: by mail-wr1-x42f.google.com with SMTP id b5so16204089wrr.5; Wed, 24 Aug 2022 05:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc; bh=faMW4xAPda93TRGR2QHBH3TEDPQ193jx4GkOCpJopPc=; b=UD/DSZ7aUXB51nEDg1Z0qQUK8duxWuWdbn/dJToc3vPQFjoPMSWOVuAVqIZ7uKTZ2z vPcZYcE8MrpF3PXZqj7ztpf9dM0sHO8BRjgiIWRUD0JHcffPRUFg1SsqMusu9Q0FLz+T X2e7PsHyRIo+iGUxFzIYa5iG8d3jAfpXuvXY4jGx4NNtQ/3FnbDDlOmQm9i7/VCol7Sl sKfLH7qkr+IKX3Li+qGD9jARl3kPsoa3lCckxpqxmSfLSlE9HLihSQ2XNoiTNV1OSn3I 4bQe/2iasEY9j7R/N8NNAVB73nsb9UiuvAXcVTTKDrwxMK8039ATtT0LpBeyIR8mJWG+ WiLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc; bh=faMW4xAPda93TRGR2QHBH3TEDPQ193jx4GkOCpJopPc=; b=gx+/X68j7+jhEAsteZ6yMNHA5jyPQOQATYxaqUHQguu8/B23fgWCxtQSeSRkcxjlMl LPzIDLMlvi5NKYSCdPWtI3BZW0xqo4HA0GMOU4hnUEA7M6DTC8HTXXoxJNoOaYtOE7Z/ p5wj+EwpSyVs+TZa8enNusZgO5D3qDb3DMNU9r8Y37NG6YuIdQOOZuftycZYqxj8mHIz MSXvBp0qGLcm93oEr95Un8iHaGAY8ZLlYJL9vddv1LFpvsy+gj1GDBl7y4BzHWx01xkd NKgNqttyhyljGOTwGaQZJTVXWQnQa0ULLVV9ts9My9H8d+9fqj98gbgtjxtae2Y1qVCj AKBA== X-Gm-Message-State: ACgBeo2ZhVEuq0JZHnTemSouc/kmVCYXlfoJsK7x9Ois4xSyEPePbCpK wjb0y5QEWKdXwlxwREr0+6BfbZvgwSc= X-Received: by 2002:a5d:648c:0:b0:220:7aa9:a13c with SMTP id o12-20020a5d648c000000b002207aa9a13cmr15504684wri.269.1661342454180; Wed, 24 Aug 2022 05:00:54 -0700 (PDT) Received: from localhost.localdomain ([86.14.124.218]) by smtp.gmail.com with ESMTPSA id cc19-20020a5d5c13000000b0022571d43d32sm1697676wrb.21.2022.08.24.05.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:00:53 -0700 (PDT) From: herron.philip@googlemail.com X-Google-Original-From: philip.herron@embecosm.com To: gcc-patches@gcc.gnu.org Subject: [PATCH Rust front-end v2 17/37] gccrs: Add Rust ABI enum helpers Date: Wed, 24 Aug 2022 12:59:36 +0100 Message-Id: <20220824115956.737931-18-philip.herron@embecosm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220824115956.737931-1-philip.herron@embecosm.com> References: <20220824115956.737931-1-philip.herron@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Reply-To: philip.herron@embecosm.com Cc: gcc-rust@gcc.gnu.org, Philip Herron 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?1742044739065834991?= X-GMAIL-MSGID: =?utf-8?q?1742044739065834991?= From: Philip Herron This is a simple helper over an enum of possible ABI options in Rust. --- gcc/rust/util/rust-abi.cc | 72 +++++++++++++++++++++++++++++++++++++++ gcc/rust/util/rust-abi.h | 45 ++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 gcc/rust/util/rust-abi.cc create mode 100644 gcc/rust/util/rust-abi.h diff --git a/gcc/rust/util/rust-abi.cc b/gcc/rust/util/rust-abi.cc new file mode 100644 index 00000000000..6477c3790af --- /dev/null +++ b/gcc/rust/util/rust-abi.cc @@ -0,0 +1,72 @@ +// 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-abi.h" + +namespace Rust { + +Rust::ABI +get_abi_from_string (const std::string &abi) +{ + if (abi.compare ("rust") == 0) + return Rust::ABI::RUST; + else if (abi.compare ("rust-intrinsic") == 0) + return Rust::ABI::INTRINSIC; + else if (abi.compare ("C") == 0) + return Rust::ABI::C; + else if (abi.compare ("cdecl") == 0) + return Rust::ABI::CDECL; + else if (abi.compare ("stdcall") == 0) + return Rust::ABI::STDCALL; + else if (abi.compare ("fastcall") == 0) + return Rust::ABI::FASTCALL; + else if (abi.compare ("sysv64") == 0) + return Rust::ABI::SYSV64; + else if (abi.compare ("win64") == 0) + return Rust::ABI::WIN64; + + return Rust::ABI::UNKNOWN; +} + +std::string +get_string_from_abi (Rust::ABI abi) +{ + switch (abi) + { + case Rust::ABI::RUST: + return "rust"; + case Rust::ABI::INTRINSIC: + return "rust-intrinsic"; + case Rust::ABI::C: + return "C"; + case Rust::ABI::CDECL: + return "cdecl"; + case Rust::ABI::STDCALL: + return "stdcall"; + case Rust::ABI::FASTCALL: + return "fastcall"; + case Rust::ABI::SYSV64: + return "sysv64"; + case Rust::ABI::WIN64: + return "win64"; + + case Rust::ABI::UNKNOWN: + return "unknown"; + } + return "unknown"; +} + +} // namespace Rust diff --git a/gcc/rust/util/rust-abi.h b/gcc/rust/util/rust-abi.h new file mode 100644 index 00000000000..d794cc35fb3 --- /dev/null +++ b/gcc/rust/util/rust-abi.h @@ -0,0 +1,45 @@ +// 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 +// . + +#ifndef RUST_ABI_OPTIONS_H +#define RUST_ABI_OPTIONS_H + +#include "rust-system.h" + +namespace Rust { + +enum ABI +{ + UNKNOWN, + RUST, + INTRINSIC, + C, + CDECL, + STDCALL, + FASTCALL, + WIN64, + SYSV64 +}; + +extern Rust::ABI +get_abi_from_string (const std::string &abi); + +extern std::string +get_string_from_abi (Rust::ABI abi); + +} // namespace Rust + +#endif // RUST_ABI_OPTIONS_H