================
@@ -5209,6 +5211,92 @@ void 
Parser::ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs) {
   }
 }
 
+void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) 
{
+  assert(Tok.is(tok::identifier) && "Not a Microsoft attribute list");
+  IdentifierInfo *RootSignatureIdent = Tok.getIdentifierInfo();
+  assert(RootSignatureIdent->getName() == "RootSignature" &&
+         "Not a Microsoft attribute list");
+
+  SourceLocation RootSignatureLoc = Tok.getLocation();
+  ConsumeToken();
+
+  // Ignore the left paren location for now.
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  if (T.consumeOpen()) {
+    Diag(Tok, diag::err_expected) << tok::l_paren;
+    return;
+  }
+
+  if (!isTokenStringLiteral()) {
+    Diag(Tok, diag::err_expected_string_literal)
+        << /*in attributes...*/ 4 << RootSignatureIdent->getName();
+    SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
+    if (Tok.is(tok::r_paren))
+      T.consumeClose();
+    return;
+  }
+
+  ExprResult StringResult = ParseUnevaluatedStringLiteralExpression();
+  if (StringResult.isInvalid()) {
+    SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
+    if (Tok.is(tok::r_paren))
+      T.consumeClose();
+    return;
+  }
+
+  ArgsVector Args;
+  if (auto Lit = dyn_cast<StringLiteral>(StringResult.get())) {
+    // Construct our identifier
+    StringRef Signature = Lit->getString();
+    auto Hash = llvm::hash_value(Signature);
+    std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
+    IdentifierInfo *DeclIdent = &(Actions.getASTContext().Idents.get(IdStr));
+
+    LookupResult R(Actions, DeclIdent, SourceLocation(),
+                   Sema::LookupOrdinaryName);
+    // Check if we have already found a decl of the same name, if we haven't
+    // then parse the root signature string and construct the in-memory 
elements
+    if (!Actions.LookupQualifiedName(R, Actions.CurContext)) {
+      // Invoke the root signature parser to construct the in-memory constructs
+      hlsl::RootSignatureLexer Lexer(Signature, RootSignatureLoc);
+      SmallVector<llvm::hlsl::rootsig::RootElement> Elements;
+      hlsl::RootSignatureParser Parser(Elements, Lexer, PP);
+      if (Parser.parse()) {
+        SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
+        if (Tok.is(tok::r_paren))
+          T.consumeClose();
+        return;
+      }
+
+      // Allocate the root elements onto ASTContext
+      unsigned N = Elements.size();
+      auto RootElements = MutableArrayRef<llvm::hlsl::rootsig::RootElement>(
+          ::new (Actions.getASTContext()) llvm::hlsl::rootsig::RootElement[N],
+          N);
+      for (unsigned I = 0; I < N; ++I)
+        RootElements[I] = Elements[I];
+
+      // Create the Root Signature
+      auto *SignatureDecl = HLSLRootSignatureDecl::Create(
+          Actions.getASTContext(), /*FIXME?*/ Actions.CurContext,
----------------
bogner wrote:

Leftover FIXME

https://github.com/llvm/llvm-project/pull/137690
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to