[llvm] [DataLayout] Refactor parsing of "p" specification (PR #104583)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 05:16:12 PDT 2024
================
@@ -288,6 +288,54 @@ static Error parseAddrSpace(StringRef Str, unsigned &AddrSpace) {
return Error::success();
}
+/// Attempts to parse a size component of a specification.
+static Error parseSize(StringRef Str, unsigned &BitWidth,
+ StringRef Name = "size") {
+ if (Str.empty())
+ return createStringError(Name + " component cannot be empty");
+
+ if (!to_integer(Str, BitWidth, 10) || BitWidth == 0 || !isUInt<24>(BitWidth))
+ return createStringError(Name + " must be a non-zero 24-bit integer");
+
+ return Error::success();
+}
+
+/// Attempts to parse an alignment component of a specification.
+///
+/// On success, returns the value converted to byte amount in \p Alignment.
+/// If the value is zero and \p AllowZero is true, \p Alignment is set to one.
+///
+/// Return an error in a number of cases:
+/// - \p Str is empty or contains characters other than decimal digits;
+/// - the value is zero and \p AllowZero is false;
+/// - the value is too large;
+/// - the value is not a multiple of the byte width;
+/// - the value converted to byte amount is not not a power of two.
+static Error parseAlignment(StringRef Str, Align &Alignment, StringRef Name,
+ bool AllowZero = false) {
----------------
s-barannikov wrote:
This is true. It is used in subsequent patches (there will be two or three).
Should I remove it for now?
https://github.com/llvm/llvm-project/pull/104583
More information about the llvm-commits
mailing list