[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
Justin Bogner via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Feb 13 00:05:40 PST 2025
================
@@ -93,6 +96,108 @@ class RootSignatureLexer {
}
};
+class RootSignatureParser {
+public:
+ RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
+ RootSignatureLexer &Lexer, DiagnosticsEngine &Diags);
+
+ /// Iterates over the provided tokens and constructs the in-memory
+ /// representations of the RootElements.
+ ///
+ /// The return value denotes if there was a failure and the method will
+ /// return on the first encountered failure, or, return false if it
+ /// can sucessfully reach the end of the tokens.
+ bool Parse();
+
+private:
+ // Root Element helpers
+ bool ParseRootElement();
+ bool ParseDescriptorTable();
+ bool ParseDescriptorTableClause();
+
+ /// Helper dispatch method
+ ///
+ /// These will switch on the Variant kind to dispatch to the respective Parse
+ /// method and store the parsed value back into Ref.
+ ///
+ /// It is helpful to have a generalized dispatch method so that when we need
+ /// to parse multiple optional parameters in any order, we can invoke this
+ /// method
+ bool ParseParam(llvm::hlsl::rootsig::ParamType Ref);
+
+ // Parse as many optional parameters as possible in any order
+ bool ParseOptionalParams(
+ llvm::SmallDenseMap<TokenKind, llvm::hlsl::rootsig::ParamType> &RefMap);
+
+ // Common parsing helpers
+ bool ParseRegister(llvm::hlsl::rootsig::Register *Reg);
+ bool ParseUInt(uint32_t *X);
+ bool
+ ParseDescriptorRangeOffset(llvm::hlsl::rootsig::DescriptorRangeOffset *X);
+
+ // Various flags/enum parsing helpers
+ template <bool AllowZero = false, typename EnumType>
+ bool ParseEnum(llvm::SmallDenseMap<TokenKind, EnumType> &EnumMap,
+ EnumType *Enum);
+ template <typename FlagType>
+ bool ParseFlags(llvm::SmallDenseMap<TokenKind, FlagType> &EnumMap,
+ FlagType *Enum);
+ bool
+ ParseDescriptorRangeFlags(llvm::hlsl::rootsig::DescriptorRangeFlags *Enum);
+ bool ParseShaderVisibility(llvm::hlsl::rootsig::ShaderVisibility *Enum);
+
+ /// Invoke the lexer to consume a token and update CurToken with the result
+ ///
+ /// Return value denotes if we were already at the last token.
+ ///
+ /// This is used to avoid having to constantly access the Lexer's CurToken
+ bool ConsumeNextToken() {
+ if (Lexer.ConsumeToken())
+ return true; // Report lexer err
----------------
bogner wrote:
This comment is confusing. Are you saying the caller should report an error, or that we should modify this function to do so?
https://github.com/llvm/llvm-project/pull/122982
More information about the llvm-branch-commits
mailing list