Skip to content

Commit 9e66a94

Browse files
committed
[Test] Refer to inst results.
Via `.result[idx]`.
1 parent 4d3c32d commit 9e66a94

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/SIL.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,8 @@ The following types of test arguments are supported:
43614361
Example: @function[foo].block[2]
43624362
- trace: @trace <-- the first ``debug_value [trace]`` in the current function
43634363
@trace[uint] <-- the ``debug_value [trace]`` at index ``uint``
4364+
- value: @{instruction}.result <-- the first result of the instruction
4365+
@{instruction}.result[uint] <-- the result at index ``uint`` produced by the instruction
43644366
@{function}.{trace} <-- the indicated trace in the indicated function
43654367
Example: @function[bar].trace
43664368
- argument: @argument <-_ the first argument of the current block

lib/SIL/Parser/ParseTestSpecification.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,28 @@ class ParseArgumentSpecification {
343343
return OperandArgument{operand};
344344
}
345345

346+
SILValue parseResultComponent(SILInstruction *within) {
347+
if (!consumePrefix("result"))
348+
return nullptr;
349+
if (empty()) {
350+
auto result = within->getResult(0);
351+
return result;
352+
}
353+
if (auto subscript = parseSubscript()) {
354+
auto index = subscript->get<unsigned long long>();
355+
auto result = within->getResult(index);
356+
return result;
357+
}
358+
llvm_unreachable("bad suffix after 'result'!?");
359+
}
360+
361+
llvm::Optional<Argument> parseResultReference(SILInstruction *within) {
362+
auto result = parseResultComponent(within);
363+
if (!result)
364+
return llvm::None;
365+
return ValueArgument{result};
366+
}
367+
346368
SILArgument *parseBlockArgumentComponent(SILBasicBlock *block) {
347369
if (!consumePrefix("argument"))
348370
return nullptr;
@@ -414,6 +436,8 @@ class ParseArgumentSpecification {
414436
return InstructionArgument{instruction};
415437
if (auto arg = parseOperandReference(instruction))
416438
return arg;
439+
if (auto res = parseResultReference(instruction))
440+
return res;
417441
llvm_unreachable("unhandled suffix after 'instruction'!?");
418442
}
419443

0 commit comments

Comments
 (0)