From d62f022c92fcc3ebe2269273628943a0089683fd Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 13 Aug 2026 06:19:30 +0800 Subject: [CodeGen] Align MIR parser and printer ownership --- backend/lib/MIR/MIRParserUtilities.h | 85 ------------------------------------ 1 file changed, 85 deletions(-) delete mode 100644 backend/lib/MIR/MIRParserUtilities.h (limited to 'backend/lib/MIR/MIRParserUtilities.h') diff --git a/backend/lib/MIR/MIRParserUtilities.h b/backend/lib/MIR/MIRParserUtilities.h deleted file mode 100644 index 2f69548..0000000 --- a/backend/lib/MIR/MIRParserUtilities.h +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later - -// NOLINTNEXTLINE(llvm-header-guard) -#ifndef RCC_LIB_MIR_MIRPARSERUTILITIES_H -#define RCC_LIB_MIR_MIRPARSERUTILITIES_H - -#include -#include -#include -#include -#include - -namespace rcc::mir::parser_detail { - -[[nodiscard]] inline std::string_view trim(std::string_view Text) noexcept { - while (!Text.empty() && (Text.front() == ' ' || Text.front() == '\t' || Text.front() == '\r' || - Text.front() == '\n')) { - Text.remove_prefix(1); - } - while (!Text.empty() && (Text.back() == ' ' || Text.back() == '\t' || Text.back() == '\r' || - Text.back() == '\n')) { - Text.remove_suffix(1); - } - return Text; -} - -[[nodiscard]] inline bool parseUnsigned(std::string_view Text, std::uint64_t &Value) noexcept { - Text = trim(Text); - int Base = 10; - if (Text.starts_with("0x") || Text.starts_with("0X")) { - Text.remove_prefix(2); - Base = 16; - } - if (Text.empty()) - return false; - const auto [End, Error] = std::from_chars(Text.data(), Text.data() + Text.size(), Value, Base); - return Error == std::errc{} && End == Text.data() + Text.size(); -} - -[[nodiscard]] inline bool parseSigned(std::string_view Text, std::int64_t &Value) noexcept { - Text = trim(Text); - if (Text.empty()) - return false; - const auto [End, Error] = std::from_chars(Text.data(), Text.data() + Text.size(), Value, 10); - return Error == std::errc{} && End == Text.data() + Text.size(); -} - -[[nodiscard]] inline bool parseUnsigned32(std::string_view Text, std::uint32_t &Value) noexcept { - std::uint64_t Wide = 0; - if (!parseUnsigned(Text, Wide) || Wide > std::numeric_limits::max()) - return false; - Value = static_cast(Wide); - return true; -} - -[[nodiscard]] inline bool parseBool(std::string_view Text, bool &Value) noexcept { - if (Text == "true") { - Value = true; - return true; - } - if (Text == "false") { - Value = false; - return true; - } - return false; -} - -[[nodiscard]] inline std::optional -parsePrefixedID(std::string_view Text, std::string_view Prefix) noexcept { - Text = trim(Text); - if (!Text.starts_with(Prefix)) - return std::nullopt; - Text.remove_prefix(Prefix.size()); - const std::size_t Suffix = Text.find_first_of(". \t"); - if (Suffix != std::string_view::npos) - Text = Text.substr(0, Suffix); - std::uint32_t ID = 0; - if (!parseUnsigned32(Text, ID)) - return std::nullopt; - return ID; -} - -} // namespace rcc::mir::parser_detail - -#endif // RCC_LIB_MIR_MIRPARSERUTILITIES_H -- cgit v1.2.3