[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

Damyan Pepper via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 23 16:23:33 PST 2025


================
@@ -148,6 +148,347 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+    SmallVector<RootElement> &Elements,
+    const SmallVector<RootSignatureToken> &Tokens)
+    : Elements(Elements) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::ReportError() { return true; }
+
+bool RootSignatureParser::Parse() {
+  // Handle edge-case of empty RootSignature()
+  if (CurTok == LastTok)
+    return false;
+
+  // Iterate as many RootElements as possible
+  bool HasComma = true;
+  while (HasComma &&
+         IsCurExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) {
+    if (ParseRootElement())
+      return true;
+    HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+    if (HasComma)
+      ConsumeNextToken();
+  }
+
+  if (HasComma)
+    return ReportError(); // report 'comma' denotes a required extra item
+
+  // Ensure that we are at the end of the tokens
+  CurTok++;
+  if (CurTok != LastTok)
+    return ReportError(); // report expected end of input but got more
+  return false;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+  // Dispatch onto the correct parse method
+  switch (CurTok->Kind) {
+  case TokenKind::kw_DescriptorTable:
+    return ParseDescriptorTable();
+  default:
+    llvm_unreachable("Switch for an expected token was not provided");
+    return true;
----------------
damyanp wrote:

Is the `return true` after `llvm_unreachable` the right thing to do here?  

https://github.com/llvm/llvm-project/pull/122982


More information about the llvm-branch-commits mailing list