[spirv-reader][ir] Split `Emit` into two methods.
This Cl splits out `EmitWithoutRegister` from the `Emit` method and
makes the `result_id` a required parameter to `Emit`. This makes it a
lot clearer that the result_id should be provided to `Emit`.
Bug: 42250952
Change-Id: I5c125bc4f507dcfcdc0179ea29d8b15b41d4d83a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/221794
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/spirv/reader/parser/parser.cc b/src/tint/lang/spirv/reader/parser/parser.cc
index 54823e4..3a70f3b 100644
--- a/src/tint/lang/spirv/reader/parser/parser.cc
+++ b/src/tint/lang/spirv/reader/parser/parser.cc
@@ -426,13 +426,18 @@
/// Emit an instruction to the current block.
/// @param inst the instruction to emit
- /// @param result_id an optional SPIR-V result ID to register the instruction result for
- void Emit(core::ir::Instruction* inst, uint32_t result_id = 0) {
+ /// @param result_id the SPIR-V result ID to register the instruction result for
+ void Emit(core::ir::Instruction* inst, uint32_t result_id) {
current_block_->Append(inst);
- if (result_id != 0) {
- TINT_ASSERT(inst->Results().Length() == 1u);
- AddValue(result_id, inst->Result(0));
- }
+ TINT_ASSERT(inst->Results().Length() == 1u);
+ AddValue(result_id, inst->Result(0));
+ }
+
+ /// Emit an instruction to the current block.
+ /// @param inst the instruction to emit
+ void EmitWithoutResult(core::ir::Instruction* inst) {
+ TINT_ASSERT(inst->Results().IsEmpty());
+ current_block_->Append(inst);
}
/// Emit the module-scope variables.
@@ -582,14 +587,15 @@
Emit(b_.Load(Value(inst.GetSingleWordOperand(2))), inst.result_id());
break;
case spv::Op::OpReturn:
- Emit(b_.Return(current_function_));
+ EmitWithoutResult(b_.Return(current_function_));
break;
case spv::Op::OpReturnValue:
- Emit(b_.Return(current_function_, Value(inst.GetSingleWordOperand(0))));
+ EmitWithoutResult(
+ b_.Return(current_function_, Value(inst.GetSingleWordOperand(0))));
break;
case spv::Op::OpStore:
- Emit(b_.Store(Value(inst.GetSingleWordOperand(0)),
- Value(inst.GetSingleWordOperand(1))));
+ EmitWithoutResult(b_.Store(Value(inst.GetSingleWordOperand(0)),
+ Value(inst.GetSingleWordOperand(1))));
break;
case spv::Op::OpVariable:
EmitVar(inst);