@@ -130,10 +130,10 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
130
130
TEST_F (ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
131
131
const llvm::StringLiteral Source = R"cc(
132
132
DescriptorTable(
133
- CBV(),
134
- SRV(),
135
- Sampler(),
136
- UAV()
133
+ CBV(b0 ),
134
+ SRV(space = 3, t42 ),
135
+ Sampler(s987, space = +2 ),
136
+ UAV(u4294967294 )
137
137
),
138
138
DescriptorTable()
139
139
)cc" ;
@@ -155,18 +155,34 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
155
155
RootElement Elem = Elements[0 ];
156
156
ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
157
157
ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::CBuffer);
158
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
159
+ RegisterType::BReg);
160
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 0u );
161
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 0u );
158
162
159
163
Elem = Elements[1 ];
160
164
ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
161
165
ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::SRV);
166
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
167
+ RegisterType::TReg);
168
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 42u );
169
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 3u );
162
170
163
171
Elem = Elements[2 ];
164
172
ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
165
173
ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::Sampler);
174
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
175
+ RegisterType::SReg);
176
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 987u );
177
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 2u );
166
178
167
179
Elem = Elements[3 ];
168
180
ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
169
181
ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::UAV);
182
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
183
+ RegisterType::UReg);
184
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 4294967294u );
185
+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 0u );
170
186
171
187
Elem = Elements[4 ];
172
188
ASSERT_TRUE (std::holds_alternative<DescriptorTable>(Elem));
@@ -176,6 +192,32 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
176
192
Elem = Elements[5 ];
177
193
ASSERT_TRUE (std::holds_alternative<DescriptorTable>(Elem));
178
194
ASSERT_EQ (std::get<DescriptorTable>(Elem).NumClauses , 0u );
195
+
196
+ ASSERT_TRUE (Consumer->isSatisfied ());
197
+ }
198
+
199
+ TEST_F (ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
200
+ // This test will checks we can handling trailing commas ','
201
+ const llvm::StringLiteral Source = R"cc(
202
+ DescriptorTable(
203
+ CBV(b0, ),
204
+ SRV(t42),
205
+ )
206
+ )cc" ;
207
+
208
+ TrivialModuleLoader ModLoader;
209
+ auto PP = createPP (Source, ModLoader);
210
+ auto TokLoc = SourceLocation ();
211
+
212
+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
213
+ SmallVector<RootElement> Elements;
214
+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
215
+
216
+ // Test no diagnostics produced
217
+ Consumer->setNoDiag ();
218
+
219
+ ASSERT_FALSE (Parser.parse ());
220
+
179
221
ASSERT_TRUE (Consumer->isSatisfied ());
180
222
}
181
223
@@ -237,6 +279,102 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
237
279
238
280
// Test correct diagnostic produced - end of stream
239
281
Consumer->setExpected (diag::err_expected_after);
282
+
283
+ ASSERT_TRUE (Parser.parse ());
284
+
285
+ ASSERT_TRUE (Consumer->isSatisfied ());
286
+ }
287
+
288
+ TEST_F (ParseHLSLRootSignatureTest, InvalidMissingParameterTest) {
289
+ // This test will check that the parsing fails due a mandatory
290
+ // parameter (register) not being specified
291
+ const llvm::StringLiteral Source = R"cc(
292
+ DescriptorTable(
293
+ CBV()
294
+ )
295
+ )cc" ;
296
+
297
+ TrivialModuleLoader ModLoader;
298
+ auto PP = createPP (Source, ModLoader);
299
+ auto TokLoc = SourceLocation ();
300
+
301
+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
302
+ SmallVector<RootElement> Elements;
303
+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
304
+
305
+ // Test correct diagnostic produced
306
+ Consumer->setExpected (diag::err_hlsl_rootsig_missing_param);
307
+ ASSERT_TRUE (Parser.parse ());
308
+
309
+ ASSERT_TRUE (Consumer->isSatisfied ());
310
+ }
311
+
312
+ TEST_F (ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryParameterTest) {
313
+ // This test will check that the parsing fails due the same mandatory
314
+ // parameter being specified multiple times
315
+ const llvm::StringLiteral Source = R"cc(
316
+ DescriptorTable(
317
+ CBV(b32, b84)
318
+ )
319
+ )cc" ;
320
+
321
+ TrivialModuleLoader ModLoader;
322
+ auto PP = createPP (Source, ModLoader);
323
+ auto TokLoc = SourceLocation ();
324
+
325
+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
326
+ SmallVector<RootElement> Elements;
327
+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
328
+
329
+ // Test correct diagnostic produced
330
+ Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
331
+ ASSERT_TRUE (Parser.parse ());
332
+
333
+ ASSERT_TRUE (Consumer->isSatisfied ());
334
+ }
335
+
336
+ TEST_F (ParseHLSLRootSignatureTest, InvalidRepeatedOptionalParameterTest) {
337
+ // This test will check that the parsing fails due the same optional
338
+ // parameter being specified multiple times
339
+ const llvm::StringLiteral Source = R"cc(
340
+ DescriptorTable(
341
+ CBV(space = 2, space = 0)
342
+ )
343
+ )cc" ;
344
+
345
+ TrivialModuleLoader ModLoader;
346
+ auto PP = createPP (Source, ModLoader);
347
+ auto TokLoc = SourceLocation ();
348
+
349
+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
350
+ SmallVector<RootElement> Elements;
351
+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
352
+
353
+ // Test correct diagnostic produced
354
+ Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
355
+ ASSERT_TRUE (Parser.parse ());
356
+
357
+ ASSERT_TRUE (Consumer->isSatisfied ());
358
+ }
359
+
360
+ TEST_F (ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
361
+ // This test will check that the lexing fails due to an integer overflow
362
+ const llvm::StringLiteral Source = R"cc(
363
+ DescriptorTable(
364
+ CBV(b4294967296)
365
+ )
366
+ )cc" ;
367
+
368
+ TrivialModuleLoader ModLoader;
369
+ auto PP = createPP (Source, ModLoader);
370
+ auto TokLoc = SourceLocation ();
371
+
372
+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
373
+ SmallVector<RootElement> Elements;
374
+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
375
+
376
+ // Test correct diagnostic produced
377
+ Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
240
378
ASSERT_TRUE (Parser.parse ());
241
379
242
380
ASSERT_TRUE (Consumer->isSatisfied ());
0 commit comments