#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"
namespace spvtools {
namespace opt {
namespace {
class NopifyPass : public Pass {
public:
const char* name() const override { return "NopifyPass"; }
Status Process() override {
bool modified = false;
context()->module()->ForEachInst(
[&modified](Instruction* inst) {
inst->ToNop();
modified = true;
},
false);
return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
}
};
using PassTestForLineDebugInfo = PassTest<::testing::Test>;
TEST_F(PassTestForLineDebugInfo, KeepLineDebugInfo) {
const char* text =
"OpCapability Shader "
"%1 = OpExtInstImport \"GLSL.std.450\" "
"OpMemoryModel Logical GLSL450 "
"OpEntryPoint Vertex %2 \"main\" "
"%3 = OpString \"minimal.vert\" "
"OpNoLine "
"OpLine %3 10 10 "
"%void = OpTypeVoid "
"OpLine %3 100 100 "
"%5 = OpTypeFunction %void "
"%2 = OpFunction %void None %5 "
"OpLine %3 1 1 "
"OpNoLine "
"OpLine %3 2 2 "
"OpLine %3 3 3 "
"%6 = OpLabel "
"OpLine %3 4 4 "
"OpNoLine "
"OpReturn "
"OpLine %3 4 4 "
"OpNoLine "
"OpFunctionEnd ";
const char* result_keep_nop =
"OpNop\n"
"OpNop\n"
"OpNop\n"
"OpNop\n"
"OpNop\n"
"OpNoLine\n"
"OpLine %3 10 10\n"
"OpNop\n"
"OpLine %3 100 100\n"
"OpNop\n"
"OpNop\n"
"OpLine %3 1 1\n"
"OpNoLine\n"
"OpLine %3 2 2\n"
"OpLine %3 3 3\n"
"OpNop\n"
"OpLine %3 4 4\n"
"OpNoLine\n"
"OpNop\n"
"OpLine %3 4 4\n"
"OpNoLine\n"
"OpNop\n";
SinglePassRunAndCheck<NopifyPass>(text, result_keep_nop,
false);
const char* result_skip_nop =
"OpNoLine\n"
"OpLine %3 10 10\n"
"OpLine %3 100 100\n"
"OpLine %3 1 1\n"
"OpNoLine\n"
"OpLine %3 2 2\n"
"OpLine %3 3 3\n"
"OpLine %3 4 4\n"
"OpNoLine\n"
"OpLine %3 4 4\n"
"OpNoLine\n";
SinglePassRunAndCheck<NopifyPass>(text, result_skip_nop,
true);
}
}
}
}