Add whitelist filtering for debug comments in SPIRV-Remap.
This commit is contained in:
@@ -160,15 +160,30 @@ namespace spv {
|
||||
}
|
||||
|
||||
// Is this an opcode we should remove when using --strip?
|
||||
bool spirvbin_t::isStripOp(spv::Op opCode) const
|
||||
bool spirvbin_t::isStripOp(spv::Op opCode, unsigned start) const
|
||||
{
|
||||
switch (opCode) {
|
||||
case spv::OpSource:
|
||||
case spv::OpSourceExtension:
|
||||
case spv::OpName:
|
||||
case spv::OpMemberName:
|
||||
case spv::OpLine: return true;
|
||||
default: return false;
|
||||
case spv::OpLine :
|
||||
{
|
||||
const spv::Id target = asId(start + 1);
|
||||
const std::string name = literalString(start + 2);
|
||||
|
||||
std::vector<std::string>::const_iterator it;
|
||||
for (it = stripWhiteList.begin(); it < stripWhiteList.end(); it++)
|
||||
{
|
||||
if (name.find(*it) != std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +387,7 @@ namespace spv {
|
||||
process(
|
||||
[&](spv::Op opCode, unsigned start) {
|
||||
// remember opcodes we want to strip later
|
||||
if (isStripOp(opCode))
|
||||
if (isStripOp(opCode, start))
|
||||
stripInst(start);
|
||||
return true;
|
||||
},
|
||||
@@ -1494,8 +1509,10 @@ namespace spv {
|
||||
}
|
||||
|
||||
// remap from a memory image
|
||||
void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, std::uint32_t opts)
|
||||
void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, const std::vector<std::string>& whiteListStrings,
|
||||
std::uint32_t opts)
|
||||
{
|
||||
stripWhiteList = whiteListStrings;
|
||||
spv.swap(in_spv);
|
||||
remap(opts);
|
||||
spv.swap(in_spv);
|
||||
|
||||
Reference in New Issue
Block a user