From patchwork Tue Dec 6 10:13:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 30210 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2742226wrr; Tue, 6 Dec 2022 02:31:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5J0m24gdNnzZAzWt73LAXP+J8B6435442eZuM15AXvvnav54MtQZx8qIziUU7TiL9J7Qdk X-Received: by 2002:a05:6402:5513:b0:467:7026:515e with SMTP id fi19-20020a056402551300b004677026515emr77762569edb.26.1670322711344; Tue, 06 Dec 2022 02:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670322711; cv=none; d=google.com; s=arc-20160816; b=xnM0L1KkXOyEdJ77ehdNeX7ik+q19VGxzc8yP9YnSEWs1SuX1yWSZ7irAylafYprJs X3g1aR/KQCOzLEAlkh/2fRncPthJ836Qtreli6nKLl0y58MY5IsSjoU4cyMUu8XfzT5m 9asoN6MnIyHocmDDrBk6rGtHJ43jMsP490a5Gh9yieeY9Vk5JpEUFH4Yxj4U18PsY8VZ M1g0Nd+eHA8WYXPGyTpBQDmjP18HDqnaFjsYKxAMCmVxGG6YhijAzQ3xlvoTUd++vM1S uwAt7LRGYWf/x+h78wr1vBq9kyNww90pQ5Lh0tuguDyEfonMva4o2D19qe6Ju9a2co5z +Gkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=uamBpJccJPM/pLZMQhUK9TCoDCwfp4UuxbCqtqkMCzY=; b=DyKWtq/lTkJX2dsIWrlG+wBTWJs0I45gvxcdFwpSstvqHlYqKP8E+u7FoP/5nFi71S hKvyE/nR7QGGZb7NCPPwflUHR0OEzkzYtWTWFwbz05MMWEAQZYuhrcKJ95sLMGjCzxmW NKXonPWOxeITdVULuEOwAvSqhdGV94HzsC0CAW1SoYarZeJsQw/4H1fLtprFARmKSQqz vLeg2lq6nAnW/5T6ebdUkCmcCTTY9QWz6srkq3V24toa2DqvMnDA0Inbj3hN/n3RPmuB GnQ1CuQbJlQblZJsmJADaHpO8cgafsilqdT8phUd8bFR3zvcjdMqBcv4lCa/b6Mw1O9r CYHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WVAb7Mjc; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qk30-20020a1709077f9e00b007a7424836d5si13730169ejc.234.2022.12.06.02.31.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 02:31:51 -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=WVAb7Mjc; 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 454433871F93 for ; Tue, 6 Dec 2022 10:21:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id B8300395B42C for ; Tue, 6 Dec 2022 10:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8300395B42C 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-wm1-x32e.google.com with SMTP id m4-20020a05600c3b0400b003d1cb516ce0so249096wms.4 for ; Tue, 06 Dec 2022 02:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=uamBpJccJPM/pLZMQhUK9TCoDCwfp4UuxbCqtqkMCzY=; b=WVAb7Mjc/InDVKjAaVXkyJLt6XgP7vxHXgwy3YWONB5iattNOsYFp0H/WT0aWvi/2R DpE9LSU4RykFpzb/v71zDqjt0rb2yxUwGU/zJGx5QB1OJOZJzZI5IjKoWzwsXObgftS1 x/cXCot9lY2kt5wbGNjNsGHGuy3jYXk6pURtvh9MFLOW89GGiSRTSec/GjHiuV1Q6It0 3oK5QYv/eXWtCmjWAGViGMxjcxnVzUEJ14/aopKb/MdPd8UbncIP7bmSKXSxKSSODF1b +25XRyxgV7t+ecSRLzc2yqBKpto9hoFSK4EoujSsjiysKz/C7uxvOp8lZHgfpouiPFZA KcBw== 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:subject:date:message-id:reply-to; bh=uamBpJccJPM/pLZMQhUK9TCoDCwfp4UuxbCqtqkMCzY=; b=0gKmhANLRt8E3krtDKkfhFkVZZEKcppb4b5RELXT0Xe6EwVdbHEORSoAeIA1B8Q05X 0bxm2+ZsCnit0+QQn9/+iH7tNIOO4p3Ps+cjSBdrxtwB/PYaFSaMIBbvDltknsq2chFo jFpnWff40/B9pRkL6C+uddt2Gj4aLMdlRqzmYYTbYQw34NM4k+35ad3FZfzgYbLJVpbR TI7RtLIMP2F7s9377zQ+BKRtlF1n+Ax3+rk2TGuS06woHZ96ftwoJ0piwZLY18BjM9tn JCCBHmoj/KFytg4OFVx3Fwy8wL3it9zRrJhs47peXfaDPbCNQ0/uXeKnlQSdmPBR46Tb Cn2Q== X-Gm-Message-State: ANoB5pmLzV6IO94yQuSrzPl71X8r8s2bf67Ym5Ys6EpcVJ857Z1jtVSL kjO8CZo59vW5v+ipR49ExA71PEZALScr/JRqfA== X-Received: by 2002:a05:600c:21c8:b0:3c6:d9f0:9534 with SMTP id x8-20020a05600c21c800b003c6d9f09534mr46775255wmj.101.1670321541291; Tue, 06 Dec 2022 02:12:21 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.googlemail.com with ESMTPSA id r10-20020a05600c458a00b003cfd4a50d5asm27052699wmo.34.2022.12.06.02.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 02:12:20 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [PATCH Rust front-end v4 22/46] gccrs: Add Rust ABI enum helpers Date: Tue, 6 Dec 2022 11:13:54 +0100 Message-Id: <20221206101417.778807-23-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221206101417.778807-1-arthur.cohen@embecosm.com> References: <20221206101417.778807-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-16.1 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=unavailable 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: arthur.cohen@embecosm.com 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?1751460307479894593?= X-GMAIL-MSGID: =?utf-8?q?1751460307479894593?= 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