mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 19:50:05 +00:00
Generalize spvOperandTableNameLookup to take string length.
This is preparation for parsing mask expressions.
This commit is contained in:
parent
e3a19c0d63
commit
388c40d9c6
@ -1456,12 +1456,12 @@ spv_result_t spvOperandTableGet(spv_operand_table *pOperandTable) {
|
|||||||
|
|
||||||
spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
|
spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
|
||||||
const spv_operand_type_t type,
|
const spv_operand_type_t type,
|
||||||
const char *name,
|
const char* name,
|
||||||
spv_operand_desc *pEntry) {
|
const size_t nameLength,
|
||||||
|
spv_operand_desc* pEntry) {
|
||||||
if (!table) return SPV_ERROR_INVALID_TABLE;
|
if (!table) return SPV_ERROR_INVALID_TABLE;
|
||||||
if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
|
if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
|
||||||
|
|
||||||
const uint64_t nameLength = strlen(name);
|
|
||||||
for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
|
for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
|
||||||
if (type == table->types[typeIndex].type) {
|
if (type == table->types[typeIndex].type) {
|
||||||
for (uint64_t operandIndex = 0;
|
for (uint64_t operandIndex = 0;
|
||||||
@ -1469,7 +1469,7 @@ spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
|
|||||||
if (nameLength ==
|
if (nameLength ==
|
||||||
strlen(table->types[typeIndex].entries[operandIndex].name) &&
|
strlen(table->types[typeIndex].entries[operandIndex].name) &&
|
||||||
!strncmp(table->types[typeIndex].entries[operandIndex].name, name,
|
!strncmp(table->types[typeIndex].entries[operandIndex].name, name,
|
||||||
strlen(name))) {
|
nameLength)) {
|
||||||
*pEntry = &table->types[typeIndex].entries[operandIndex];
|
*pEntry = &table->types[typeIndex].entries[operandIndex];
|
||||||
return SPV_SUCCESS;
|
return SPV_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,14 @@ using spv_operand_pattern_t = std::deque<spv_operand_type_t>;
|
|||||||
/// @param[in] table to lookup
|
/// @param[in] table to lookup
|
||||||
/// @param[in] type the operand group's type
|
/// @param[in] type the operand group's type
|
||||||
/// @param[in] name of the operand to find
|
/// @param[in] name of the operand to find
|
||||||
|
/// @param[in] nameLength number of bytes of name to compare
|
||||||
/// @param[out] pEntry returned operand table entry
|
/// @param[out] pEntry returned operand table entry
|
||||||
///
|
///
|
||||||
/// @return result code
|
/// @return result code
|
||||||
spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
|
spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
|
||||||
const spv_operand_type_t type,
|
const spv_operand_type_t type,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
const size_t nameLength,
|
||||||
spv_operand_desc *pEntry);
|
spv_operand_desc *pEntry);
|
||||||
|
|
||||||
/// @brief Find the operand with value in the table
|
/// @brief Find the operand with value in the table
|
||||||
|
@ -539,7 +539,8 @@ spv_result_t spvTextEncodeOperand(
|
|||||||
// NOTE: All non literal operands are handled here using the operand
|
// NOTE: All non literal operands are handled here using the operand
|
||||||
// table.
|
// table.
|
||||||
spv_operand_desc entry;
|
spv_operand_desc entry;
|
||||||
if (spvOperandTableNameLookup(operandTable, type, textValue, &entry)) {
|
if (spvOperandTableNameLookup(operandTable, type, textValue,
|
||||||
|
strlen(textValue), &entry)) {
|
||||||
DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " '" << textValue
|
DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " '" << textValue
|
||||||
<< "'.";
|
<< "'.";
|
||||||
return SPV_ERROR_INVALID_TEXT;
|
return SPV_ERROR_INVALID_TEXT;
|
||||||
|
Loading…
Reference in New Issue
Block a user