From patchwork Wed Aug 24 11:59:37 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: 710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1386824wro; Wed, 24 Aug 2022 05:10:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR58HfWEd9zJ0GRjWwm6F75bEBwjP5ccxTIWZw7SwO5yMqZXpbch/PkKFZRyIkAEr5UMu2HW X-Received: by 2002:a50:9f44:0:b0:445:dfca:87da with SMTP id b62-20020a509f44000000b00445dfca87damr7442149edf.105.1661343046868; Wed, 24 Aug 2022 05:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661343046; cv=none; d=google.com; s=arc-20160816; b=q8m5rGqrSdqSotkdyHZNq9bVj+x1d2vxzqQhEPjdCuJLN6hBBuea7nJ46VuHPTIHCR 3wZZtKzSBQejO+CGmlSARLoE0JRYC53Dv0jZjQ910IpcN+hDyYlwfVgcyYHRgZffcYdw 8D+z17c8+8qE1qJh0B+lhcCyaF7p2Ubh18gGK0Z3w/HlhDu9TZOteyWT+KtVUlsxF9q2 DtJtyv+Iklw5WV16eDrF9nGbmeCyeNQZsxWBznvFC5+tPw4U4dpLmlAcrJxokmA9yh/A r/rzSLeQ4dPOEyafjbHQBZiso4MQ6Qb0VM4VTUm3Ct5yalMvgRCkglhdzYSPGu3YDoZy Br0w== 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=puZaanwb1A2g3ZEuqMIUgjURr1+LwMNAm7ixujYPsUs=; b=EUsalBeYcoP7rdZNpBL3jj078Xw43BomadgiMJQexEAvDMmLgiALJNT4IrTTNNy23b F9on0g8gxypzJ4FixI15r4gxEkBsn2eKZeHpTSgpDuETxw8Pf2fvLEMC8R9l96sUeR72 PubPhKrY4ZVyiNq8oI+HaeUZNO48Xssn/7+hEH4ksBz4nqN9SiMrmQWIdaETQFgDWS25 CyWWit56QwDbpgdDIo2uJbpPimxCM1m5PtzwJvJKmiG+BN2fBLFtq8IaiYgn9qTQKQAd K+d29qU1fRaYRRTpNW7xwzJeFOJccvTSSPkjcRe6T6HYFdz6WxEGT9V7lwpV/PMzvnBV O7Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@googlemail.com header.s=20210112 header.b=F4yY0RFH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gt37-20020a1709072da500b0073ccfb22163si2327912ejc.497.2022.08.24.05.10.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:10:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@googlemail.com header.s=20210112 header.b=F4yY0RFH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (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 C4F22396E060 for ; Wed, 24 Aug 2022 12:04:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id A7CC53836026; Wed, 24 Aug 2022 12:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7CC53836026 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-wm1-x329.google.com with SMTP id ay12so8657004wmb.1; Wed, 24 Aug 2022 05:00:55 -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=puZaanwb1A2g3ZEuqMIUgjURr1+LwMNAm7ixujYPsUs=; b=F4yY0RFHYIEKMLZrM6E6k0pf60eg5lCOv6DBk12m/opUUgl/BSO5oLas2NWkBJgPub FxJGJ+YO5zXXf6NtUBlJ3YUiVQ+zHF2DnQuLFrqUQbjm1/dnK2TnVLdp+Sh/+NJgAIwp Y3jvK1byPLdb3R0kOcGg4Gcv5cuyZK/q7dwUC6/n+9UD6CR0FxEt0/5Z4ULYRfqtBbAO G9efrCX88lksQlAXYH+p87Rk3yjfaqqNQzcuBXiSj2ADEoADTlBzPxHcgszQOSBh6xTI +2xYrZ06x4JwnGP0xcubzgHH0/eTRl0SP3yh9xnswjh9t5hlDjBK7j5LvJ+02CuJ1/BA Sh8g== 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=puZaanwb1A2g3ZEuqMIUgjURr1+LwMNAm7ixujYPsUs=; b=DnYByl2NYtI0RM47hFFs7gyvX3mSdRKjcvboxNJbhSJv987oU++XFLNiNCaD8+9L3r palkOgMNfO6DH1N+bEsbq0PlQtJ4labtlkCYTBR9rWflAPCpP8A2TPfX1ynTDlq3H1Sy IVRdA/rDtvl+yQPZVLdF0MBCffKXfMTnyGLngooXiUknc4KLpnBFHl5YVbNRjJo/tCU0 jMwM4Ai4sFkSXTF3LKBSmCH7yLYMl4uQHIymx1twt1KNpUNnXueFOa3PSd7Q6Kx0Hdsh 9CXdY44ImU0pd8D7GMQz8Ydt7LvY0j0PfxuwkiPph9aS5QiIILy3/b4qmJDBLmb6ei3c vRuA== X-Gm-Message-State: ACgBeo1XhWMk8PQEfstqUOB61K8ELP9yLHN6ZJvXggMzac77LR+AgVgJ lxzXOyEl8UXpLZY/bWgfaUkvt3HUhHQ= X-Received: by 2002:a05:600c:4fc2:b0:3a5:c491:5ee1 with SMTP id o2-20020a05600c4fc200b003a5c4915ee1mr4902135wmq.62.1661342454932; 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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:00:54 -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 18/37] gccrs: Add Base62 implementation Date: Wed, 24 Aug 2022 12:59:37 +0100 Message-Id: <20220824115956.737931-19-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.6 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: Arthur Cohen , gcc-rust@gcc.gnu.org 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?1742044446511825623?= X-GMAIL-MSGID: =?utf-8?q?1742044446511825623?= From: Arthur Cohen Used for V0 symbol mangling scheme which. --- gcc/rust/util/rust-base62.cc | 46 ++++++++++++++++++++++++++++++++++++ gcc/rust/util/rust-base62.h | 34 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 gcc/rust/util/rust-base62.cc create mode 100644 gcc/rust/util/rust-base62.h diff --git a/gcc/rust/util/rust-base62.cc b/gcc/rust/util/rust-base62.cc new file mode 100644 index 00000000000..bdab23338c3 --- /dev/null +++ b/gcc/rust/util/rust-base62.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// 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-base62.h" + +namespace Rust { + +std::string +base62_integer (uint64_t value) +{ + const static std::string base_64 + = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$"; + std::string buffer (128, '\0'); + size_t idx = 0; + size_t base = 62; + + do + { + buffer[idx] = base_64[(value % base)]; + idx++; + value = value / base; + } + while (value != 0); + + std::reverse (buffer.begin (), buffer.begin () + idx); + return buffer.substr (0, idx); +} + +} // namespace Rust + +// FIXME: Add unit testing using the selftest framework diff --git a/gcc/rust/util/rust-base62.h b/gcc/rust/util/rust-base62.h new file mode 100644 index 00000000000..fa610d3e5a4 --- /dev/null +++ b/gcc/rust/util/rust-base62.h @@ -0,0 +1,34 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// 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_BASE62_H +#define RUST_BASE62_H + +#include "rust-system.h" + +namespace Rust { + +/** + * Get the Base62 representation of an integer + */ +std::string +base62_integer (uint64_t value); + +} // namespace Rust + +#endif /* !RUST_BASE62_H */