[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
Finn Plummer via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 14 13:59:36 PST 2025
================
@@ -162,5 +219,371 @@ std::optional<RootSignatureToken> RootSignatureLexer::PeekNextToken() {
return Result;
}
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
+ RootSignatureLexer &Lexer,
+ DiagnosticsEngine &Diags)
+ : Elements(Elements), Lexer(Lexer), Diags(Diags) {}
+
+bool RootSignatureParser::Parse() {
+ // Handle edge-case of empty RootSignature()
+ if (Lexer.EndOfBuffer())
+ return false;
+
+ // Iterate as many RootElements as possible
+ while (!ParseRootElement()) {
+ if (Lexer.EndOfBuffer())
+ return false;
+ if (ConsumeExpectedToken(TokenKind::pu_comma))
+ return true;
+ }
+
+ return true;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+ if (ConsumeExpectedToken(TokenKind::kw_DescriptorTable))
+ return true;
+
+ // Dispatch onto the correct parse method
+ switch (CurToken.Kind) {
+ case TokenKind::kw_DescriptorTable:
+ return ParseDescriptorTable();
+ default:
+ llvm_unreachable("Switch for an expected token was not provided");
----------------
inbelic wrote:
At the moment, we follow the pattern of `ConsumeExpectedToken({TokenKind1, ..., TokenKindN})` and then switch on the token kinds that were in that statement. `ConsumeExpectedToken` guards against any other token kind. So any new token kind is added we will never reach the default here, unless it is also added to the `ConsumeExpectedToken` statement.
Maybe there is a way we could define the macros to generate sub-sets of tokens? Although, I am of the opinion the current method guards against this sufficiently.
https://github.com/llvm/llvm-project/pull/122982
More information about the cfe-commits
mailing list