|
28 | 28 | #include "clang/Basic/SourceLocation.h"
|
29 | 29 | #include "clang/Basic/Specifiers.h"
|
30 | 30 | #include "clang/Basic/TargetInfo.h"
|
| 31 | +#include "clang/Parse/ParseHLSLRootSignature.h" |
31 | 32 | #include "clang/Sema/Initialization.h"
|
32 | 33 | #include "clang/Sema/ParsedAttr.h"
|
33 | 34 | #include "clang/Sema/Sema.h"
|
@@ -941,6 +942,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS,
|
941 | 942 | << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
|
942 | 943 | }
|
943 | 944 |
|
| 945 | +void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) { |
| 946 | + if (AL.getNumArgs() != 1) { |
| 947 | + Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; |
| 948 | + return; |
| 949 | + } |
| 950 | + |
| 951 | + StringRef Signature; |
| 952 | + if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature)) |
| 953 | + return; |
| 954 | + |
| 955 | + SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc(); |
| 956 | + // TODO(#126565): pass down below to lexer when fp is supported |
| 957 | + // llvm::RoundingMode RM = SemaRef.CurFPFeatures.getRoundingMode(); |
| 958 | + hlsl::RootSignatureLexer Lexer(Signature, Loc); |
| 959 | + SmallVector<llvm::hlsl::rootsig::RootElement> Elements; |
| 960 | + hlsl::RootSignatureParser Parser(Elements, Lexer, SemaRef.getPreprocessor()); |
| 961 | + |
| 962 | + if (Parser.parse()) |
| 963 | + return; |
| 964 | + |
| 965 | + // Allocate elements onto AST context |
| 966 | + unsigned N = Elements.size(); |
| 967 | + auto RootElements = MutableArrayRef<llvm::hlsl::rootsig::RootElement>( |
| 968 | + ::new (getASTContext()) llvm::hlsl::rootsig::RootElement[N], N); |
| 969 | + for (unsigned I = 0; I < N; ++I) |
| 970 | + RootElements[I] = Elements[I]; |
| 971 | + |
| 972 | + // Set elements |
| 973 | + auto *Result = ::new (getASTContext()) |
| 974 | + HLSLRootSignatureAttr(getASTContext(), AL, Signature); |
| 975 | + Result->setElements(ArrayRef<llvm::hlsl::rootsig::RootElement>(RootElements)); |
| 976 | + D->addAttr(Result); |
| 977 | +} |
| 978 | + |
944 | 979 | void SemaHLSL::handleNumThreadsAttr(Decl *D, const ParsedAttr &AL) {
|
945 | 980 | llvm::VersionTuple SMVersion =
|
946 | 981 | getASTContext().getTargetInfo().getTriple().getOSVersion();
|
|
0 commit comments