From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 92ED9384B823 for ; Wed, 26 Oct 2022 08:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92ED9384B823 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-x42d.google.com with SMTP id y16so14583660wrt.12 for ; Wed, 26 Oct 2022 01:15:52 -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=E+JfbcPE7GN8Q3OtEWeM23VsN1UWCLKBGz1xKS0CM2E=; b=Kv5wYQEQj3AN/Y22vbRGjSBSDZzMjB5MP68uPlAGJMBXJzCC1oLEC18s+DEdtQ4qbL yusWuwLuvRxuKn3fQeUNBna56NgFuoJQY2v5jySYgv0wPfuOoccQY6x1JPk6rRxPDNP5 LxBIUssYEDSt5/pcCUNdCvS98t7ZPIj9jZpFuWRUx8j6EJ8y9kbfCusf4s300oGuzTWm lR4UtkB9daA2xdYV+YJBUYPtIQZT07V7kXBn82ohM4kph9x+Z387jPglxNd9wf1jqoir NrBo6j3VULtL5arc5bBdU/Tufd5Xvjk9hVGxbyaPc54O57BE9gY2C7UFT8RXHhIIteOf E3CA== 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=E+JfbcPE7GN8Q3OtEWeM23VsN1UWCLKBGz1xKS0CM2E=; b=olAtjRth2Scha4Xp3Ks0ww/y8ed6TN3ny8sJV8XEuFwn4jGUpQgQkeAgWkw6AplemS SQo32tT4o+7ZF5I7m3mTId3LDuxuoD9+vHfQ14h87Gr7PEIIbCUBk3IVbCGdmex4XHqT H9y5iYedv1Oh4X6xZk/oWfgqmA6RNXUb9dEIBeDnscfc6ZzJh2+baUZ/2GheVnR8mEmx D4tE9OnbHQieiTKQpoyM3LkQR7xx2bzx/AVjuK0V4I6A4eGwipjY70DviXniv7u+CWF3 e+HXmkDu877ELTHqXJbn1WbHwbV/U7vsnBStu08hACxfYcdSMcdhuBHRewROaAZtACIA VquQ== X-Gm-Message-State: ACrzQf0GpaE3ktXpxWPkczThAqxoPppXMrOworwTCWv0FnnBZkf4PJiA GyCB9zymbKYdZIB3ILwKCu9yOCJByEvc6JJBCw== X-Google-Smtp-Source: AMsMyM41ey2NoTj4o10JQ8LkbtZFdKSCRVVgeDFDNWSAThJnh4FTdydcmjT2kRULJz3S1Ooju8CxmQ== X-Received: by 2002:a05:6000:154b:b0:22e:64fa:dc24 with SMTP id 11-20020a056000154b00b0022e64fadc24mr28936878wry.113.1666772151412; Wed, 26 Oct 2022 01:15:51 -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:51 -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 23/46] gccrs: Add Base62 implementation Date: Wed, 26 Oct 2022 10:17:48 +0200 Message-Id: <20221026081811.602573-24-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: 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 */ -- 2.37.2