Skip to content

Commit d5b19cb

Browse files
committed
[HLSL][RootSignature] Implement Parsing of Descriptor Tables
- Defines the in-memory data layout for the Descriptor Table Clauses, its dependent flags/enums and parent RootElement in HLSLRootSignature.h - Implements a Parser and its required Parsing methods in ParseHLSLRootSignature
1 parent 6a11fba commit d5b19cb

File tree

4 files changed

+621
-0
lines changed

4 files changed

+621
-0
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "llvm/ADT/StringRef.h"
2222
#include "llvm/ADT/StringSwitch.h"
2323

24+
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
25+
2426
namespace llvm {
2527
namespace hlsl {
2628
namespace root_signature {
@@ -89,6 +91,72 @@ class RootSignatureLexer {
8991
}
9092
};
9193

94+
class RootSignatureParser {
95+
public:
96+
RootSignatureParser(SmallVector<RootElement> &Elements,
97+
const SmallVector<RootSignatureToken> &Tokens);
98+
99+
// Iterates over the provided tokens and constructs the in-memory
100+
// representations of the RootElements.
101+
//
102+
// The return value denotes if there was a failure and the method will
103+
// return on the first encountered failure, or, return false if it
104+
// can sucessfully reach the end of the tokens.
105+
bool Parse();
106+
107+
private:
108+
bool ReportError(); // TODO: Implement this to report error through Diags
109+
110+
// Root Element helpers
111+
bool ParseRootElement();
112+
bool ParseDescriptorTable();
113+
bool ParseDescriptorTableClause();
114+
115+
// Common parsing helpers
116+
bool ParseRegister(Register &Register);
117+
118+
// Various flags/enum parsing helpers
119+
bool ParseDescriptorRangeFlags(DescriptorRangeFlags &Flags);
120+
bool ParseShaderVisibility(ShaderVisibility &Flag);
121+
122+
// Increment the token iterator if we have not reached the end.
123+
// Return value denotes if we were already at the last token.
124+
bool ConsumeNextToken();
125+
126+
// Attempt to retrieve the next token, if TokenKind is invalid then there was
127+
// no next token.
128+
RootSignatureToken PeekNextToken();
129+
130+
// Peek if the next token is of the expected kind.
131+
//
132+
// Return value denotes if it failed to match the expected kind, either it is
133+
// the end of the stream or it didn't match any of the expected kinds.
134+
bool PeekExpectedToken(TokenKind Expected);
135+
bool PeekExpectedToken(ArrayRef<TokenKind> AnyExpected);
136+
137+
// Consume the next token and report an error if it is not of the expected
138+
// kind.
139+
//
140+
// Return value denotes if it failed to match the expected kind, either it is
141+
// the end of the stream or it didn't match any of the expected kinds.
142+
bool ConsumeExpectedToken(TokenKind Expected);
143+
bool ConsumeExpectedToken(ArrayRef<TokenKind> AnyExpected);
144+
145+
// Peek if the next token is of the expected kind and if it is then consume
146+
// it.
147+
//
148+
// Return value denotes if it failed to match the expected kind, either it is
149+
// the end of the stream or it didn't match any of the expected kinds. It will
150+
// not report an error if there isn't a match.
151+
bool TryConsumeExpectedToken(TokenKind Expected);
152+
bool TryConsumeExpectedToken(ArrayRef<TokenKind> Expected);
153+
154+
private:
155+
SmallVector<RootElement> &Elements;
156+
SmallVector<RootSignatureToken>::const_iterator CurTok;
157+
SmallVector<RootSignatureToken>::const_iterator LastTok;
158+
};
159+
92160
} // namespace root_signature
93161
} // namespace hlsl
94162
} // namespace llvm

0 commit comments

Comments
 (0)