Generalize spvOperandTableNameLookup to take string length.
authorDavid Neto <dneto@google.com>
Wed, 16 Sep 2015 20:42:56 +0000 (16:42 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
This is preparation for parsing mask expressions.

source/operand.cpp
source/operand.h
source/text.cpp

index 819f591..f58b8c3 100644 (file)
@@ -1456,12 +1456,12 @@ spv_result_t spvOperandTableGet(spv_operand_table *pOperandTable) {
 
 spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
                                        const spv_operand_type_t type,
-                                       const char *name,
-                                       spv_operand_desc *pEntry) {
+                                       const char* name,
+                                       const size_t nameLength,
+                                       spv_operand_desc* pEntry) {
   if (!table) return SPV_ERROR_INVALID_TABLE;
   if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
 
-  const uint64_t nameLength = strlen(name);
   for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
     if (type == table->types[typeIndex].type) {
       for (uint64_t operandIndex = 0;
@@ -1469,7 +1469,7 @@ spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
         if (nameLength ==
                 strlen(table->types[typeIndex].entries[operandIndex].name) &&
             !strncmp(table->types[typeIndex].entries[operandIndex].name, name,
-                     strlen(name))) {
+                     nameLength)) {
           *pEntry = &table->types[typeIndex].entries[operandIndex];
           return SPV_SUCCESS;
         }
index b1bd8b9..f73c770 100644 (file)
@@ -45,12 +45,14 @@ using spv_operand_pattern_t = std::deque<spv_operand_type_t>;
 /// @param[in] table to lookup
 /// @param[in] type the operand group's type
 /// @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
 ///
 /// @return result code
 spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
                                        const spv_operand_type_t type,
                                        const char *name,
+                                       const size_t nameLength,
                                        spv_operand_desc *pEntry);
 
 /// @brief Find the operand with value in the table
index 9d04f1c..5776b1b 100644 (file)
@@ -539,7 +539,8 @@ spv_result_t spvTextEncodeOperand(
       // NOTE: All non literal operands are handled here using the operand
       // table.
       spv_operand_desc entry;
-      if (spvOperandTableNameLookup(operandTable, type, textValue, &entry)) {
+      if (spvOperandTableNameLookup(operandTable, type, textValue,
+                                    strlen(textValue), &entry)) {
         DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " '" << textValue
                    << "'.";
         return SPV_ERROR_INVALID_TEXT;