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);
|
||||
|
||||
@@ -118,7 +118,8 @@ public:
|
||||
virtual ~spirvbin_t() { }
|
||||
|
||||
// remap on an existing binary in memory
|
||||
void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
|
||||
void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
|
||||
std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// Type for error/log handler functions
|
||||
typedef std::function<void(const std::string&)> errorfn_t;
|
||||
@@ -180,6 +181,8 @@ private:
|
||||
unsigned typeSizeInWords(spv::Id id) const;
|
||||
unsigned idTypeSizeInWords(spv::Id id) const;
|
||||
|
||||
bool isStripOp(spv::Op opCode, unsigned start) const;
|
||||
|
||||
spv::Id& asId(unsigned word) { return spv[word]; }
|
||||
const spv::Id& asId(unsigned word) const { return spv[word]; }
|
||||
spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
|
||||
@@ -249,6 +252,8 @@ private:
|
||||
|
||||
std::vector<spirword_t> spv; // SPIR words
|
||||
|
||||
std::vector<std::string> stripWhiteList;
|
||||
|
||||
namemap_t nameMap; // ID names from OpName
|
||||
|
||||
// Since we want to also do binary ops, we can't use std::vector<bool>. we could use
|
||||
|
||||
Reference in New Issue
Block a user