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: 61520 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 8A8833810ADA for ; Tue, 6 Dec 2022 10:21:38 +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-Google-Smtp-Source: AA0mqf55GXqfrfkqZpDlPkuD6C2Rofkdxba6Mu7DgN2L8QiWuVDhJZIbdifmMo/AWw/LI6fCASgd3A== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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