Skip to content

Commit

Permalink
Make spvOpcodeString part of the public API (#3174)
Browse files Browse the repository at this point in the history
Fixes #3138
  • Loading branch information
s-perron authored Feb 20, 2020
1 parent 03794b8 commit 4a80497
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,9 @@ SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t
spvDiagnosticPrint(const spv_diagnostic diagnostic);

// Gets the name of an instruction, without the "Op" prefix.
SPIRV_TOOLS_EXPORT const char* spvOpcodeString(const uint32_t opcode);

// The binary parser interface.

// A pointer to a function that accepts a parsed SPIR-V header.
Expand Down
10 changes: 7 additions & 3 deletions source/opcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
}
}

const char* spvOpcodeString(const SpvOp opcode) {
const char* spvOpcodeString(const uint32_t opcode) {
const auto beg = kOpcodeTableEntries;
const auto end = kOpcodeTableEntries + ARRAY_SIZE(kOpcodeTableEntries);
spv_opcode_desc_t needle = {"", opcode, 0, nullptr, 0, {},
false, false, 0, nullptr, ~0u, ~0u};
spv_opcode_desc_t needle = {"", static_cast<const SpvOp>(opcode),
0, nullptr,
0, {},
false, false,
0, nullptr,
~0u, ~0u};
auto comp = [](const spv_opcode_desc_t& lhs, const spv_opcode_desc_t& rhs) {
return lhs.opcode < rhs.opcode;
};
Expand Down
3 changes: 0 additions & 3 deletions source/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
const uint16_t word_count,
const spv_endianness_t endian, spv_instruction_t* inst);

// Gets the name of an instruction, without the "Op" prefix.
const char* spvOpcodeString(const SpvOp opcode);

// Determine if the given opcode is a scalar type. Returns zero if false,
// non-zero otherwise.
int32_t spvOpcodeIsScalarType(const SpvOp opcode);
Expand Down

0 comments on commit 4a80497

Please sign in to comment.