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: 61512 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 E73B33834C34 for ; Tue, 6 Dec 2022 10:18:41 +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-Google-Smtp-Source: AA0mqf4J9x/mszlQYFnVfIli/IG5z9qaXaiR3ink4usiD9pw1blyYxkNALagRivUoqD0d/PE14lndQ== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 */