From 194e0cca3b6855295648980b061d8bdc6b3234fc Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 22 Jun 2020 20:49:34 +0000 Subject: [PATCH] [spirv-reader] Support OpNop An OpNop maps to nothing Bug: tint:3 Change-Id: Id73601d481971954dd4de706202b5229dcf39871 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23561 Reviewed-by: dan sinclair --- src/reader/spirv/function.cc | 3 +++ src/reader/spirv/function_misc_test.cc | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index d92862caab..840836bbb6 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -2421,6 +2421,9 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) { } switch (inst.opcode()) { + case SpvOpNop: + return true; + case SpvOpStore: { // TODO(dneto): Order of evaluation? auto lhs = MakeExpression(inst.GetSingleWordInOperand(0)); diff --git a/src/reader/spirv/function_misc_test.cc b/src/reader/spirv/function_misc_test.cc index 7e1e5f89dd..3cb8ddfcd0 100644 --- a/src/reader/spirv/function_misc_test.cc +++ b/src/reader/spirv/function_misc_test.cc @@ -26,6 +26,7 @@ namespace reader { namespace spirv { namespace { +using ::testing::Eq; using ::testing::HasSubstr; std::string CommonTypes() { @@ -277,7 +278,24 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { })")) << ToString(fe.ast_body()); } -// TODO(dneto): OpNop +TEST_F(SpvParserTestMiscInstruction, OpNop) { + const auto assembly = CommonTypes() + R"( + %100 = OpFunction %void None %voidfn + %entry = OpLabel + OpNop + OpReturn + OpFunctionEnd +)"; + auto* p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) + << p->error() << assembly; + FunctionEmitter fe(p, *spirv_function(100)); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Return{} +)")) + << ToString(fe.ast_body()); +} + // TODO(dneto): OpSizeof : requires Kernel (OpenCL) } // namespace