================
@@ -89,37 +88,178 @@ bool RootSignatureParser::parseDescriptorTableClause() {
CurToken.TokKind == TokenKind::kw_UAV ||
CurToken.TokKind == TokenKind::kw_Sampler) &&
"Expects to only be invoked starting at given keyword");
+ TokenKind ParamKind = CurToken.TokKind; // retain for diagnostics
DescriptorTableClause Clause;
- switch (CurToken.TokKind) {
+ TokenKind ExpectedRegister;
+ switch (ParamKind) {
default:
llvm_unreachable("Switch for consumed token was not provided");
case TokenKind::kw_CBV:
Clause.Type = ClauseType::CBuffer;
+ ExpectedRegister = TokenKind::bReg;
break;
case TokenKind::kw_SRV:
Clause.Type = ClauseType::SRV;
+ ExpectedRegister = TokenKind::tReg;
break;
case TokenKind::kw_UAV:
Clause.Type = ClauseType::UAV;
+ ExpectedRegister = TokenKind::uReg;
break;
case TokenKind::kw_Sampler:
Clause.Type = ClauseType::Sampler;
+ ExpectedRegister = TokenKind::sReg;
break;
}
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
- CurToken.TokKind))
+ ParamKind))
return true;
- if (consumeExpectedToken(TokenKind::pu_r_paren, diag::err_expected_after,
- CurToken.TokKind))
+ llvm::SmallDenseMap<TokenKind, ParamType> Params = {
----------------
inbelic wrote:
For descriptor table clauses specifically it will grow to 6 params, which would
be maintainable as a struct. But if we want to reuse the `parseParams` logic
for `StaticSampler` then a common state struct would be around ~20 members.
Notably, this mapping also serves as a mapping to which parse method should be
invoked based on the encountered token, it is not immediately clear how we
would retain that info using the optionals struct. Although maybe you are
implicitly suggesting that we don't have such a generic `parseParams` method.
If we are concerned about dynamic allocations/lookup, the size of this mapping
is known statically, so we could also do something like:
```
template <usize N>
struct ParamMap {
TokenKind Kinds[N];
ParamType Types[N];
bool Mandatory[N];
bool Seen[N];
}
```
WDYT?
https://github.com/llvm/llvm-project/pull/133800
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits