From patchwork Tue Dec 6 10:13:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 30202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2739638wrr; Tue, 6 Dec 2022 02:24:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5bA2WSBzn60WSzau5vHQlQXbvbNdsHW5qxhHGmGu6z1uO93rBVWjXfpEbjLkt0KRID9XB8 X-Received: by 2002:a17:906:3a85:b0:7ab:afd4:d7ed with SMTP id y5-20020a1709063a8500b007abafd4d7edmr5222036ejd.228.1670322298555; Tue, 06 Dec 2022 02:24:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670322298; cv=none; d=google.com; s=arc-20160816; b=0YMSPXO8CzngP1u3phKhzuetItUvvXDo3DPypTfp+2T1YTzRd6bZxdeC5DJABtTLyk Oo8g+Jxkw4Dcd5iUYpMKGIKYpCsTZCda3s08shXsxIdl7xr0wxPvzWL3n5D0nhoy2uTR ybdIvEOFHFV1/wVBOSBz3pdgAJwwZCh4rNnpp6jjQRAqF0rYTonLtGee1ipDNCQV+AiC QebYOvH+CN9qIwCRp9Yioo5/laFJiTpUyjYNr6qI7qMxfvC8DOI9UwL9MHBhTXPVvtmF 5vo9M4zdxLQQa6krU3+jrMe+yzLngFhBMsduWrD56oEhqk72gMIllR4IOBzGilnbDY/o XGLg== 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=AsgNws29zGNI7It6xss78hPk/8LI8qLOWFBZSVXEht0=; b=ujQYLAtqXcgUP9xvkAXvsjkfmoYoGzgpQefOEF2SMnz1/Qa6TGNZ7ExjZL9LT0bIVa LiNxaP2tMHcsFlIAtib6vsdmY36ALOjPFgtkaKMJnfEGTtboiiar2c2Wt4rVZJwt9Ghv yhMTeu5uP+9rXhCp7BEWbH7q7DobalZEQhci+iYjJ5ILCl7wMbiS/4S3TXVDOUhRopVE A2q+jQ1dXXqeidj1oIq4M3B76EDt83eHYKZA6BL1q9svXs8fA+l39h55WDjrzZQlCAEY ZQsKzemMEm8ADeY/SvtLehDawGeLps/fOCoHNQ1qNvbO6fwSpxMp7UTpZlB7rnBcJe06 YHyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=KG7pnCHl; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w5-20020a50d785000000b004627741e339si1503577edi.113.2022.12.06.02.24.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 02:24:58 -0800 (PST) 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=pass header.i=@embecosm.com header.s=google header.b=KG7pnCHl; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BA593834C3A for ; Tue, 6 Dec 2022 10:18:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 0B7AB3959E78 for ; Tue, 6 Dec 2022 10:12:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B7AB3959E78 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-x32b.google.com with SMTP id n9-20020a05600c3b8900b003d0944dba41so7607657wms.4 for ; Tue, 06 Dec 2022 02:12:23 -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=AsgNws29zGNI7It6xss78hPk/8LI8qLOWFBZSVXEht0=; b=KG7pnCHl6YulVuKPK/Nc16jNKDyYP/hGfIqvhLNuEnTRV7eR8Q/as74GySeBPtmxZK CL60114X+Icb/klHYEdm95EFlyEfFZB7mlZ1oe+F+rEfnktytfB7DmwmZ7kPofk4D2xk WuKViZ++79mkDEClxdEvaIenvwyEs9apcJLph3a45lcRJ2wuWsCAnC2iBiivaQq8wfLT g4C+0vurG07Gxp82jnm55QDgAWPPN8ZsM33D0+L1G0kyzVYXjNPGyEDPBjEMOFocc1H5 IJXRk5OnxoA/NKczQni5kkVLh4PCNQzkc1yoL7lMCIsXjGwJJCD2znzkNqUKfv/JyOI2 r8mw== 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=AsgNws29zGNI7It6xss78hPk/8LI8qLOWFBZSVXEht0=; b=ZSunFSeh9hAdhuhd7lDtOeySWHqObNOX3oAJ6vk31xN5e3kcpoU3o6e9oCJFJgL5ob PqmeqFxLWABvMtOxx2JtX46PVwz15yuqyUTnll9FV3d1dcx8UbT2DtZPVo85rbj7lELF YEkgnPbWprNcfm7tNNVrbrCzgtveGqCFwpzgPJMwIp7Br6YAR9Nmx11H+KRjSOBA4yYm 09DqYP2A8vqTBYvNyd65/6PBV99RUxSfT9aaN3487OFvdJu1GLjckzHW5NWlsD4PZ4hU t02I+D8JqmVP4yLHbadh+wUvx86IEvn9YR9w/t5S6yFH5RZqLgUOrOZoEr6IUvVsDJcd 0FgA== X-Gm-Message-State: ANoB5pmYwaE94H3ZFdcBRtgIxdLFbkOiHcsD6YXtU9HUxdythpGBm9WJ K4dFfLn8BRL269Yxw5lTx84IgzqDkx8xAN82XQ== X-Received: by 2002:a05:600c:4e09:b0:3cf:55bd:4944 with SMTP id b9-20020a05600c4e0900b003cf55bd4944mr64945235wmq.64.1670321542490; Tue, 06 Dec 2022 02:12:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 02:12:22 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH Rust front-end v4 23/46] gccrs: Add Base62 implementation Date: Tue, 6 Dec 2022 11:13:55 +0100 Message-Id: <20221206101417.778807-24-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=-19.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=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?1751459874697818025?= X-GMAIL-MSGID: =?utf-8?q?1751459874697818025?= From: Arthur Cohen Used for V0 symbol mangling scheme which is still in development. --- 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 */