|
21 | 21 | #include "llvm/ADT/StringRef.h"
|
22 | 22 | #include "llvm/ADT/StringSwitch.h"
|
23 | 23 |
|
| 24 | +#include "llvm/Frontend/HLSL/HLSLRootSignature.h" |
| 25 | + |
24 | 26 | namespace llvm {
|
25 | 27 | namespace hlsl {
|
26 | 28 | namespace root_signature {
|
@@ -89,6 +91,72 @@ class RootSignatureLexer {
|
89 | 91 | }
|
90 | 92 | };
|
91 | 93 |
|
| 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 | + |
92 | 160 | } // namespace root_signature
|
93 | 161 | } // namespace hlsl
|
94 | 162 | } // namespace llvm
|
|
0 commit comments