From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id E9A9E384B0C9 for ; Wed, 26 Oct 2022 08:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9A9E384B0C9 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-wr1-x434.google.com with SMTP id y16so14583593wrt.12 for ; Wed, 26 Oct 2022 01:15:51 -0700 (PDT) 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=HXY1VQj+qlqxlyK8u3QopKNF7sLqu0zbsyHVt6GfWxI=; b=O794GBz144+5AntZ6qo5o+PGDynQftyhjFHGAPLZSZIvktq18VltdU3m+lPYlincmH i4kdqySUPYAnMgDgAHmnRlCi202cqbK5Zv4ZovqlFiWq3kLQfLd6ypVbNCWWBmx/BnHL +NKPNrd//spNjlxKvLvy+WB3eqkgIongXOYor5UhW4VBu8XHWUwM03Sh8vAAC/KcYYS5 MeqS0ckqEblzX6Y7iGVlrnvvPZo7w4lv8I08NIacZ0VbqdThnXpPUSdBhG0IVRE331An CGNtfjy74hrYnldha0aDXSWyB5WYm55apUFMLrn+UCHoX+QdDv7XTcPpjlrsf+6sqmnY 4J6g== 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=HXY1VQj+qlqxlyK8u3QopKNF7sLqu0zbsyHVt6GfWxI=; b=hS6T50p9GIYeCXw+yi9t6QWFwcLfIBw5RSy9KOha+fsrRnmt8uN2gvy4TC5boGAH3H /zwfrw/DT3BVLFUpapmYdEHu3FrTTmlV10Y3riV+aogluaHTxMyZ8uYT5o0M0C/f6B1W 2uG6onbx4tGGQwDyLurbuvVqtsskkWiIGN8IPzTEIcxOEN0bcQlbYh9/OFSa4FWYN841 rZoOWWVcMcGgiqBiLDhhhgB4GMeeXrHU/jL74gGgXaJHHvz7W8aOh45hU23eGeekCa68 YS/Yc6WGhTzWtZjTJ+wKn+U20tII0pO+sSyCr0qsjUWMiDRh0BLv9KSC3k1pjfG7GAg+ 1okw== X-Gm-Message-State: ACrzQf2YijMb7UE60fe/SIlrbveYR3LxCd4hiCHrmUkzWGV/yZt1fVWo +uQNJle7WOhdqmlGPFYLsTvi X-Google-Smtp-Source: AMsMyM7it9DDswif4Let8Uyofwy84yewPIqq/UYDiJeHZboAmWzukgiSjcMqyZT/TkjByj0hzPQeKA== X-Received: by 2002:adf:ed01:0:b0:230:d7c8:9a91 with SMTP id a1-20020adfed01000000b00230d7c89a91mr28521332wro.511.1666772150714; Wed, 26 Oct 2022 01:15:50 -0700 (PDT) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.googlemail.com with ESMTPSA id q16-20020a05600c46d000b003c6f426467fsm1134310wmo.40.2022.10.26.01.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 01:15:50 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org Subject: [PATCH Rust front-end v3 22/46] gccrs: Add Rust ABI enum helpers Date: Wed, 26 Oct 2022 10:17:47 +0200 Message-Id: <20221026081811.602573-23-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221026081811.602573-1-arthur.cohen@embecosm.com> References: <20221026081811.602573-1-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 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 List-Id: 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 -- 2.37.2