[clang] [llvm] [HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (PR #133302)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 27 13:44:10 PDT 2025


================
@@ -0,0 +1,188 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm::hlsl::rootsig;
+
+namespace clang {
+namespace hlsl {
+
+static std::string FormatTokenKinds(ArrayRef<TokenKind> Kinds) {
+  std::string TokenString;
+  llvm::raw_string_ostream Out(TokenString);
+  bool First = true;
+  for (auto Kind : Kinds) {
+    if (!First)
+      Out << ", ";
+    switch (Kind) {
+#define TOK(X, SPELLING)                                                       \
+  case TokenKind::X:                                                           \
+    Out << SPELLING;                                                           \
+    break;
+#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
+    }
+    First = false;
+  }
+
+  return TokenString;
+}
+
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
+                                         RootSignatureLexer &Lexer,
+                                         Preprocessor &PP)
+    : Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {}
+
+bool RootSignatureParser::Parse() {
+  // Iterate as many RootElements as possible
+  while (TryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
----------------
joaosaffran wrote:

nit: Something that makes me confuse with that approach is, how will that look once you add more RootElements? Will that become something like:
```C++
while (
TryConsumeExpectedToken(TokenKind::kw_DescriptorTable) || 
TryConsumeExpectedToken(TokenKind::kw_RootDescriptor) || 
TryConsumeExpectedToken(TokenKind::kw_RootConstant)) {
...
}
```

My expectation for that code would be something like: 
```C++
do{
// Parsing logic here
} while(TryConsumeExpectedToken(TokenKind::pu_comma));
```

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


More information about the llvm-commits mailing list