Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 1 | // Copyright (c) 2015 The Khronos Group Inc. |
| 2 | // |
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | // copy of this software and/or associated documentation files (the |
| 5 | // "Materials"), to deal in the Materials without restriction, including |
| 6 | // without limitation the rights to use, copy, modify, merge, publish, |
| 7 | // distribute, sublicense, and/or sell copies of the Materials, and to |
| 8 | // permit persons to whom the Materials are furnished to do so, subject to |
| 9 | // the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included |
| 12 | // in all copies or substantial portions of the Materials. |
| 13 | // |
| 14 | // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
| 15 | // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
| 16 | // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
| 17 | // https://www.khronos.org/registry/ |
| 18 | // |
| 19 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 22 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 23 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 26 | |
| 27 | #include <libspirv/libspirv.h> |
David Neto | db901b6 | 2015-10-27 16:14:40 -0400 | [diff] [blame] | 28 | #include "endian.h" |
David Neto | b5dc8fc | 2015-10-06 16:22:00 -0400 | [diff] [blame] | 29 | #include "instruction.h" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 30 | #include "opcode.h" |
| 31 | |
| 32 | #include <assert.h> |
| 33 | #include <string.h> |
| 34 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 35 | namespace { |
| 36 | |
| 37 | // Descriptions of each opcode. Each entry describes the format of the |
| 38 | // instruction that follows a particular opcode. |
| 39 | // |
| 40 | // Most fields are initialized statically by including an automatically |
| 41 | // generated file. |
| 42 | // The operandTypes fields are initialized during spvOpcodeInitialize(). |
| 43 | // |
| 44 | // TODO(dneto): Some of the macros are quite unreadable. We could make |
| 45 | // good use of constexpr functions, but some compilers don't support that yet. |
| 46 | spv_opcode_desc_t opcodeTableEntries[] = { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 47 | #define EmptyList \ |
| 48 | {} |
| 49 | #define List(...) \ |
| 50 | { __VA_ARGS__ } |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 51 | #define Capability(X) SPV_CAPABILITY_AS_MASK(SpvCapability##X) |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 52 | #define Capability2(X, Y) Capability(X) | Capability(Y) |
| 53 | #define SpvCapabilityNone \ |
| 54 | 0 // Needed so Capability(None) still expands to valid syntax. |
| 55 | #define Instruction(Name, HasResult, HasType, NumLogicalOperands, \ |
| 56 | NumCapabilities, CapabilityRequired, IsVariable, \ |
| 57 | LogicalArgsList) \ |
| 58 | { \ |
| 59 | #Name, SpvOp##Name, \ |
| 60 | (NumCapabilities) ? (CapabilityRequired) : 0, 0, \ |
| 61 | {}, /* Filled in later. Operand list, including \ |
| 62 | result id and type id, if needed */ \ |
| 63 | HasResult, HasType, LogicalArgsList \ |
| 64 | } \ |
| 65 | , |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 66 | #include "opcode.inc" |
| 67 | #undef EmptyList |
| 68 | #undef List |
| 69 | #undef Capability |
Dejan Mircevski | 205408b | 2015-09-30 16:42:34 -0400 | [diff] [blame] | 70 | #undef Capability2 |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 71 | #undef CapabilityNone |
| 72 | #undef Instruction |
| 73 | }; |
| 74 | |
| 75 | // Has the opcodeTableEntries table been fully elaborated? |
| 76 | // That is, are the operandTypes fields initialized? |
| 77 | bool opcodeTableInitialized = false; |
| 78 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 79 | // Opcode API |
| 80 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 81 | // Converts the given operand class enum (from the SPIR-V document generation |
| 82 | // logic) to the operand type required by the parser. |
| 83 | // This only applies to logical operands. |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 84 | spv_operand_type_t convertOperandClassToType(SpvOp opcode, |
| 85 | OperandClass operandClass) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 86 | // The spec document generator uses OptionalOperandLiteral for several kinds |
| 87 | // of repeating values. Our parser needs more specific information about |
| 88 | // what is being repeated. |
| 89 | if (operandClass == OperandOptionalLiteral) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 90 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 91 | case SpvOpLoad: |
| 92 | case SpvOpStore: |
| 93 | case SpvOpCopyMemory: |
| 94 | case SpvOpCopyMemorySized: |
David Neto | 3fca4cd | 2015-09-17 17:39:45 -0400 | [diff] [blame] | 95 | // Expect an optional mask. When the Aligned bit is set in the mask, |
| 96 | // we will later add the expectation of a literal number operand. |
| 97 | return SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS; |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 98 | case SpvOpExecutionMode: |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 99 | return SPV_OPERAND_TYPE_VARIABLE_EXECUTION_MODE; |
| 100 | default: |
| 101 | break; |
| 102 | } |
Lei Zhang | b41d150 | 2015-09-14 15:22:23 -0400 | [diff] [blame] | 103 | } else if (operandClass == OperandVariableLiterals) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 104 | if (opcode == SpvOpConstant || opcode == SpvOpSpecConstant) |
Lei Zhang | b41d150 | 2015-09-14 15:22:23 -0400 | [diff] [blame] | 105 | return SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 108 | switch (operandClass) { |
| 109 | case OperandNone: |
| 110 | return SPV_OPERAND_TYPE_NONE; |
| 111 | case OperandId: |
| 112 | return SPV_OPERAND_TYPE_ID; |
| 113 | case OperandOptionalId: |
| 114 | return SPV_OPERAND_TYPE_OPTIONAL_ID; |
| 115 | case OperandOptionalImage: |
| 116 | return SPV_OPERAND_TYPE_OPTIONAL_IMAGE; |
| 117 | case OperandVariableIds: |
| 118 | return SPV_OPERAND_TYPE_VARIABLE_ID; |
David Neto | 561dc4e | 2015-09-25 14:23:29 -0400 | [diff] [blame] | 119 | // The spec only uses OptionalLiteral for an optional literal number. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 120 | case OperandOptionalLiteral: |
| 121 | return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER; |
| 122 | case OperandOptionalLiteralString: |
| 123 | return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING; |
David Neto | 561dc4e | 2015-09-25 14:23:29 -0400 | [diff] [blame] | 124 | // This is only used for sequences of literal numbers. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 125 | case OperandVariableLiterals: |
| 126 | return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER; |
David Neto | 445ce44 | 2015-10-15 15:22:06 -0400 | [diff] [blame] | 127 | case OperandLiteralNumber: |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 128 | if (opcode == SpvOpExtInst) { |
David Neto | 445ce44 | 2015-10-15 15:22:06 -0400 | [diff] [blame] | 129 | // We use a special operand type for the extension instruction number. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 130 | // For now, we assume there is only one LiteraNumber argument to |
| 131 | // OpExtInst, and it is the extension instruction argument. |
David Neto | 445ce44 | 2015-10-15 15:22:06 -0400 | [diff] [blame] | 132 | // See the ExtInst entry in opcode.inc |
| 133 | // TODO(dneto): Use a function to confirm the assumption, and to verify |
| 134 | // that the index into the operandClass is 1, as expected. |
| 135 | return SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER; |
| 136 | } |
| 137 | return SPV_OPERAND_TYPE_LITERAL_INTEGER; |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 138 | case OperandLiteralString: |
| 139 | return SPV_OPERAND_TYPE_LITERAL_STRING; |
| 140 | case OperandSource: |
| 141 | return SPV_OPERAND_TYPE_SOURCE_LANGUAGE; |
| 142 | case OperandExecutionModel: |
| 143 | return SPV_OPERAND_TYPE_EXECUTION_MODEL; |
| 144 | case OperandAddressing: |
| 145 | return SPV_OPERAND_TYPE_ADDRESSING_MODEL; |
| 146 | case OperandMemory: |
| 147 | return SPV_OPERAND_TYPE_MEMORY_MODEL; |
| 148 | case OperandExecutionMode: |
| 149 | return SPV_OPERAND_TYPE_EXECUTION_MODE; |
| 150 | case OperandStorage: |
| 151 | return SPV_OPERAND_TYPE_STORAGE_CLASS; |
| 152 | case OperandDimensionality: |
| 153 | return SPV_OPERAND_TYPE_DIMENSIONALITY; |
| 154 | case OperandSamplerAddressingMode: |
| 155 | return SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE; |
| 156 | case OperandSamplerFilterMode: |
| 157 | return SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE; |
| 158 | case OperandSamplerImageFormat: |
| 159 | return SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT; |
David Neto | 7cefb23 | 2015-09-28 15:33:49 -0400 | [diff] [blame] | 160 | case OperandImageChannelOrder: |
| 161 | // This is only used to describe the value generated by OpImageQueryOrder. |
| 162 | // It is not used as an operand. |
| 163 | break; |
| 164 | case OperandImageChannelDataType: |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 165 | // This is only used to describe the value generated by |
| 166 | // OpImageQueryFormat. It is not used as an operand. |
David Neto | 7cefb23 | 2015-09-28 15:33:49 -0400 | [diff] [blame] | 167 | break; |
| 168 | case OperandImageOperands: |
Dejan Mircevski | f8e091a | 2015-10-13 14:41:31 -0400 | [diff] [blame] | 169 | // This is not used in opcode.inc. It only exists to generate the |
| 170 | // corresponding spec section. In parsing, image operands meld into the |
| 171 | // OperandOptionalImage case. |
David Neto | 7cefb23 | 2015-09-28 15:33:49 -0400 | [diff] [blame] | 172 | break; |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 173 | case OperandFPFastMath: |
| 174 | return SPV_OPERAND_TYPE_FP_FAST_MATH_MODE; |
| 175 | case OperandFPRoundingMode: |
| 176 | return SPV_OPERAND_TYPE_FP_ROUNDING_MODE; |
| 177 | case OperandLinkageType: |
| 178 | return SPV_OPERAND_TYPE_LINKAGE_TYPE; |
| 179 | case OperandAccessQualifier: |
| 180 | return SPV_OPERAND_TYPE_ACCESS_QUALIFIER; |
| 181 | case OperandFuncParamAttr: |
| 182 | return SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE; |
| 183 | case OperandDecoration: |
| 184 | return SPV_OPERAND_TYPE_DECORATION; |
| 185 | case OperandBuiltIn: |
| 186 | return SPV_OPERAND_TYPE_BUILT_IN; |
| 187 | case OperandSelect: |
| 188 | return SPV_OPERAND_TYPE_SELECTION_CONTROL; |
| 189 | case OperandLoop: |
| 190 | return SPV_OPERAND_TYPE_LOOP_CONTROL; |
| 191 | case OperandFunction: |
| 192 | return SPV_OPERAND_TYPE_FUNCTION_CONTROL; |
| 193 | case OperandMemorySemantics: |
| 194 | return SPV_OPERAND_TYPE_MEMORY_SEMANTICS; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 195 | case OperandMemoryAccess: |
David Neto | 7cefb23 | 2015-09-28 15:33:49 -0400 | [diff] [blame] | 196 | // This case does not occur in the table for SPIR-V 0.99 Rev 32. |
David Neto | 3fca4cd | 2015-09-17 17:39:45 -0400 | [diff] [blame] | 197 | // We expect that it will become SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS, |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 198 | // and we can remove the special casing above for memory operation |
| 199 | // instructions. |
| 200 | break; |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 201 | case OperandScope: |
| 202 | return SPV_OPERAND_TYPE_EXECUTION_SCOPE; |
| 203 | case OperandGroupOperation: |
| 204 | return SPV_OPERAND_TYPE_GROUP_OPERATION; |
| 205 | case OperandKernelEnqueueFlags: |
| 206 | return SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS; |
| 207 | case OperandKernelProfilingInfo: |
| 208 | return SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO; |
| 209 | case OperandCapability: |
| 210 | return SPV_OPERAND_TYPE_CAPABILITY; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 211 | |
| 212 | // Used by GroupMemberDecorate |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 213 | case OperandVariableIdLiteral: |
| 214 | return SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 215 | |
| 216 | // Used by Switch |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 217 | case OperandVariableLiteralId: |
| 218 | return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 219 | |
| 220 | // These exceptional cases shouldn't occur. |
| 221 | case OperandCount: |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | assert(0 && "Unexpected operand class"); |
| 226 | return SPV_OPERAND_TYPE_NONE; |
| 227 | } |
| 228 | |
Lei Zhang | a94701d | 2015-09-14 10:05:37 -0400 | [diff] [blame] | 229 | } // anonymous namespace |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 230 | |
| 231 | // Finish populating the opcodeTableEntries array. |
| 232 | void spvOpcodeTableInitialize() { |
| 233 | // Compute the operandTypes field for each entry. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 234 | for (auto& opcode : opcodeTableEntries) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 235 | opcode.numTypes = 0; |
| 236 | // Type ID always comes first, if present. |
| 237 | if (opcode.hasType) |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 238 | opcode.operandTypes[opcode.numTypes++] = SPV_OPERAND_TYPE_TYPE_ID; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 239 | // Result ID always comes next, if present |
| 240 | if (opcode.hasResult) |
| 241 | opcode.operandTypes[opcode.numTypes++] = SPV_OPERAND_TYPE_RESULT_ID; |
Lei Zhang | a94701d | 2015-09-14 10:05:37 -0400 | [diff] [blame] | 242 | const uint16_t maxNumOperands = |
| 243 | sizeof(opcode.operandTypes) / sizeof(opcode.operandTypes[0]); |
| 244 | const uint16_t maxNumClasses = |
| 245 | sizeof(opcode.operandClass) / sizeof(opcode.operandClass[0]); |
| 246 | for (uint16_t classIndex = 0; |
| 247 | opcode.numTypes < maxNumOperands && classIndex < maxNumClasses; |
| 248 | classIndex++) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 249 | const OperandClass operandClass = opcode.operandClass[classIndex]; |
Lei Zhang | a94701d | 2015-09-14 10:05:37 -0400 | [diff] [blame] | 250 | opcode.operandTypes[opcode.numTypes++] = |
| 251 | convertOperandClassToType(opcode.opcode, operandClass); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 252 | // The OperandNone value is not explicitly represented in the .inc file. |
| 253 | // However, it is the zero value, and is created via implicit value |
| 254 | // initialization. |
| 255 | if (operandClass == OperandNone) { |
| 256 | opcode.numTypes--; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | // We should have written the terminating SPV_OPERAND_TYPE_NONE entry, but |
| 261 | // also without overflowing. |
Lei Zhang | a94701d | 2015-09-14 10:05:37 -0400 | [diff] [blame] | 262 | assert((opcode.numTypes < maxNumOperands) && |
| 263 | "Operand class list is too long. Expand " |
| 264 | "spv_opcode_desc_t.operandClass"); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 265 | } |
| 266 | opcodeTableInitialized = true; |
| 267 | } |
| 268 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 269 | const char* spvGeneratorStr(uint32_t generator) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 270 | switch (generator) { |
| 271 | case SPV_GENERATOR_KHRONOS: |
| 272 | return "Khronos"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 273 | case SPV_GENERATOR_LUNARG: |
| 274 | return "LunarG"; |
David Neto | 1780fc4 | 2015-10-26 15:43:12 -0400 | [diff] [blame] | 275 | case SPV_GENERATOR_VALVE: |
| 276 | return "Valve"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 277 | case SPV_GENERATOR_CODEPLAY: |
| 278 | return "Codeplay Software Ltd."; |
David Neto | 1780fc4 | 2015-10-26 15:43:12 -0400 | [diff] [blame] | 279 | case SPV_GENERATOR_NVIDIA: |
| 280 | return "NVIDIA"; |
| 281 | case SPV_GENERATOR_ARM: |
| 282 | return "ARM"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 283 | default: |
| 284 | return "Unknown"; |
| 285 | } |
| 286 | } |
| 287 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 288 | uint32_t spvOpcodeMake(uint16_t wordCount, SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 289 | return ((uint32_t)opcode) | (((uint32_t)wordCount) << 16); |
| 290 | } |
| 291 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 292 | void spvOpcodeSplit(const uint32_t word, uint16_t* pWordCount, SpvOp* pOpcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 293 | if (pWordCount) { |
| 294 | *pWordCount = (uint16_t)((0xffff0000 & word) >> 16); |
| 295 | } |
| 296 | if (pOpcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 297 | *pOpcode = (SpvOp)(0x0000ffff & word); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 301 | spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 302 | if (!pInstTable) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 303 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 304 | static spv_opcode_table_t table = { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 305 | sizeof(opcodeTableEntries) / sizeof(spv_opcode_desc_t), |
| 306 | opcodeTableEntries}; |
| 307 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 308 | // TODO(dneto): Consider thread safety of initialization. |
| 309 | // That is, ordering effects of the flag vs. the table updates. |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 310 | if (!opcodeTableInitialized) spvOpcodeTableInitialize(); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 311 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 312 | *pInstTable = &table; |
| 313 | |
| 314 | return SPV_SUCCESS; |
| 315 | } |
| 316 | |
| 317 | spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 318 | const char* name, |
| 319 | spv_opcode_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 320 | if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER; |
| 321 | if (!table) return SPV_ERROR_INVALID_TABLE; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 322 | |
| 323 | // TODO: This lookup of the Opcode table is suboptimal! Binary sort would be |
| 324 | // preferable but the table requires sorting on the Opcode name, but it's |
| 325 | // static |
| 326 | // const initialized and matches the order of the spec. |
| 327 | const size_t nameLength = strlen(name); |
| 328 | for (uint64_t opcodeIndex = 0; opcodeIndex < table->count; ++opcodeIndex) { |
| 329 | if (nameLength == strlen(table->entries[opcodeIndex].name) && |
| 330 | !strncmp(name, table->entries[opcodeIndex].name, nameLength)) { |
| 331 | // NOTE: Found out Opcode! |
| 332 | *pEntry = &table->entries[opcodeIndex]; |
| 333 | return SPV_SUCCESS; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return SPV_ERROR_INVALID_LOOKUP; |
| 338 | } |
| 339 | |
| 340 | spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 341 | const SpvOp opcode, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 342 | spv_opcode_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 343 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 344 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 345 | |
| 346 | // TODO: As above this lookup is not optimal. |
| 347 | for (uint64_t opcodeIndex = 0; opcodeIndex < table->count; ++opcodeIndex) { |
| 348 | if (opcode == table->entries[opcodeIndex].opcode) { |
| 349 | // NOTE: Found the Opcode! |
| 350 | *pEntry = &table->entries[opcodeIndex]; |
| 351 | return SPV_SUCCESS; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return SPV_ERROR_INVALID_LOOKUP; |
| 356 | } |
| 357 | |
Lei Zhang | dfc5008 | 2015-08-21 11:50:55 -0400 | [diff] [blame] | 358 | int16_t spvOpcodeResultIdIndex(spv_opcode_desc entry) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 359 | for (int16_t i = 0; i < entry->numTypes; ++i) { |
Lei Zhang | dfc5008 | 2015-08-21 11:50:55 -0400 | [diff] [blame] | 360 | if (SPV_OPERAND_TYPE_RESULT_ID == entry->operandTypes[i]) return i; |
| 361 | } |
| 362 | return SPV_OPERAND_INVALID_RESULT_ID_INDEX; |
| 363 | } |
| 364 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 365 | int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc entry) { |
David Neto | 9db3a53 | 2015-10-07 16:58:38 -0400 | [diff] [blame] | 366 | return entry->capabilities != 0; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 369 | void spvInstructionCopy(const uint32_t* words, const SpvOp opcode, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 370 | const uint16_t wordCount, const spv_endianness_t endian, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 371 | spv_instruction_t* pInst) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 372 | pInst->opcode = opcode; |
David Neto | b5dc8fc | 2015-10-06 16:22:00 -0400 | [diff] [blame] | 373 | pInst->words.resize(wordCount); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 374 | for (uint16_t wordIndex = 0; wordIndex < wordCount; ++wordIndex) { |
| 375 | pInst->words[wordIndex] = spvFixWord(words[wordIndex], endian); |
| 376 | if (!wordIndex) { |
| 377 | uint16_t thisWordCount; |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 378 | SpvOp thisOpcode; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 379 | spvOpcodeSplit(pInst->words[wordIndex], &thisWordCount, &thisOpcode); |
| 380 | assert(opcode == thisOpcode && wordCount == thisWordCount && |
| 381 | "Endianness failed!"); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 386 | const char* spvOpcodeString(const SpvOp opcode) { |
David Neto | 1bcd3d1 | 2015-11-02 16:03:12 -0500 | [diff] [blame^] | 387 | // Use the syntax table so it's sure to be complete. |
| 388 | #define Instruction(Name, ...) \ |
| 389 | case SpvOp##Name: \ |
| 390 | return #Name; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 391 | switch (opcode) { |
David Neto | 1bcd3d1 | 2015-11-02 16:03:12 -0500 | [diff] [blame^] | 392 | #include "opcode.inc" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 393 | default: |
| 394 | assert(0 && "Unreachable!"); |
| 395 | } |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 396 | return "unknown"; |
David Neto | 1bcd3d1 | 2015-11-02 16:03:12 -0500 | [diff] [blame^] | 397 | #undef Instruction |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 400 | int32_t spvOpcodeIsScalarType(const SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 401 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 402 | case SpvOpTypeInt: |
| 403 | case SpvOpTypeFloat: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 404 | return true; |
| 405 | default: |
| 406 | return false; |
| 407 | } |
| 408 | } |
| 409 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 410 | int32_t spvOpcodeIsConstant(const SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 411 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 412 | case SpvOpConstantTrue: |
| 413 | case SpvOpConstantFalse: |
| 414 | case SpvOpConstant: |
| 415 | case SpvOpConstantComposite: |
| 416 | case SpvOpConstantSampler: |
| 417 | // case SpvOpConstantNull: |
| 418 | case SpvOpConstantNull: |
| 419 | case SpvOpSpecConstantTrue: |
| 420 | case SpvOpSpecConstantFalse: |
| 421 | case SpvOpSpecConstant: |
| 422 | case SpvOpSpecConstantComposite: |
| 423 | // case SpvOpSpecConstantOp: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 424 | return true; |
| 425 | default: |
| 426 | return false; |
| 427 | } |
| 428 | } |
| 429 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 430 | int32_t spvOpcodeIsComposite(const SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 431 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 432 | case SpvOpTypeVector: |
| 433 | case SpvOpTypeMatrix: |
| 434 | case SpvOpTypeArray: |
| 435 | case SpvOpTypeStruct: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 436 | return true; |
| 437 | default: |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 442 | int32_t spvOpcodeAreTypesEqual(const spv_instruction_t* pTypeInst0, |
| 443 | const spv_instruction_t* pTypeInst1) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 444 | if (pTypeInst0->opcode != pTypeInst1->opcode) return false; |
| 445 | if (pTypeInst0->words[1] != pTypeInst1->words[1]) return false; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 446 | return true; |
| 447 | } |
| 448 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 449 | int32_t spvOpcodeIsPointer(const SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 450 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 451 | case SpvOpVariable: |
| 452 | case SpvOpAccessChain: |
| 453 | case SpvOpInBoundsAccessChain: |
| 454 | case SpvOpFunctionParameter: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 455 | return true; |
| 456 | default: |
| 457 | return false; |
| 458 | } |
| 459 | } |
| 460 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 461 | int32_t spvOpcodeIsObject(const SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 462 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 463 | case SpvOpConstantTrue: |
| 464 | case SpvOpConstantFalse: |
| 465 | case SpvOpConstant: |
| 466 | case SpvOpConstantComposite: |
| 467 | // TODO: case SpvOpConstantSampler: |
| 468 | case SpvOpConstantNull: |
| 469 | case SpvOpSpecConstantTrue: |
| 470 | case SpvOpSpecConstantFalse: |
| 471 | case SpvOpSpecConstant: |
| 472 | case SpvOpSpecConstantComposite: |
| 473 | // TODO: case SpvOpSpecConstantOp: |
| 474 | case SpvOpVariable: |
| 475 | case SpvOpAccessChain: |
| 476 | case SpvOpInBoundsAccessChain: |
| 477 | case SpvOpConvertFToU: |
| 478 | case SpvOpConvertFToS: |
| 479 | case SpvOpConvertSToF: |
| 480 | case SpvOpConvertUToF: |
| 481 | case SpvOpUConvert: |
| 482 | case SpvOpSConvert: |
| 483 | case SpvOpFConvert: |
| 484 | case SpvOpConvertPtrToU: |
| 485 | // TODO: case SpvOpConvertUToPtr: |
| 486 | case SpvOpPtrCastToGeneric: |
| 487 | // TODO: case SpvOpGenericCastToPtr: |
| 488 | case SpvOpBitcast: |
| 489 | // TODO: case SpvOpGenericCastToPtrExplicit: |
| 490 | case SpvOpSatConvertSToU: |
| 491 | case SpvOpSatConvertUToS: |
| 492 | case SpvOpVectorExtractDynamic: |
| 493 | case SpvOpCompositeConstruct: |
| 494 | case SpvOpCompositeExtract: |
| 495 | case SpvOpCopyObject: |
| 496 | case SpvOpTranspose: |
| 497 | case SpvOpSNegate: |
| 498 | case SpvOpFNegate: |
| 499 | case SpvOpNot: |
| 500 | case SpvOpIAdd: |
| 501 | case SpvOpFAdd: |
| 502 | case SpvOpISub: |
| 503 | case SpvOpFSub: |
| 504 | case SpvOpIMul: |
| 505 | case SpvOpFMul: |
| 506 | case SpvOpUDiv: |
| 507 | case SpvOpSDiv: |
| 508 | case SpvOpFDiv: |
| 509 | case SpvOpUMod: |
| 510 | case SpvOpSRem: |
| 511 | case SpvOpSMod: |
| 512 | case SpvOpVectorTimesScalar: |
| 513 | case SpvOpMatrixTimesScalar: |
| 514 | case SpvOpVectorTimesMatrix: |
| 515 | case SpvOpMatrixTimesVector: |
| 516 | case SpvOpMatrixTimesMatrix: |
| 517 | case SpvOpOuterProduct: |
| 518 | case SpvOpDot: |
| 519 | case SpvOpShiftRightLogical: |
| 520 | case SpvOpShiftRightArithmetic: |
| 521 | case SpvOpShiftLeftLogical: |
| 522 | case SpvOpBitwiseOr: |
| 523 | case SpvOpBitwiseXor: |
| 524 | case SpvOpBitwiseAnd: |
| 525 | case SpvOpAny: |
| 526 | case SpvOpAll: |
| 527 | case SpvOpIsNan: |
| 528 | case SpvOpIsInf: |
| 529 | case SpvOpIsFinite: |
| 530 | case SpvOpIsNormal: |
| 531 | case SpvOpSignBitSet: |
| 532 | case SpvOpLessOrGreater: |
| 533 | case SpvOpOrdered: |
| 534 | case SpvOpUnordered: |
| 535 | case SpvOpLogicalOr: |
| 536 | case SpvOpLogicalAnd: |
| 537 | case SpvOpSelect: |
| 538 | case SpvOpIEqual: |
| 539 | case SpvOpFOrdEqual: |
| 540 | case SpvOpFUnordEqual: |
| 541 | case SpvOpINotEqual: |
| 542 | case SpvOpFOrdNotEqual: |
| 543 | case SpvOpFUnordNotEqual: |
| 544 | case SpvOpULessThan: |
| 545 | case SpvOpSLessThan: |
| 546 | case SpvOpFOrdLessThan: |
| 547 | case SpvOpFUnordLessThan: |
| 548 | case SpvOpUGreaterThan: |
| 549 | case SpvOpSGreaterThan: |
| 550 | case SpvOpFOrdGreaterThan: |
| 551 | case SpvOpFUnordGreaterThan: |
| 552 | case SpvOpULessThanEqual: |
| 553 | case SpvOpSLessThanEqual: |
| 554 | case SpvOpFOrdLessThanEqual: |
| 555 | case SpvOpFUnordLessThanEqual: |
| 556 | case SpvOpUGreaterThanEqual: |
| 557 | case SpvOpSGreaterThanEqual: |
| 558 | case SpvOpFOrdGreaterThanEqual: |
| 559 | case SpvOpFUnordGreaterThanEqual: |
| 560 | case SpvOpDPdx: |
| 561 | case SpvOpDPdy: |
| 562 | case SpvOpFwidth: |
| 563 | case SpvOpDPdxFine: |
| 564 | case SpvOpDPdyFine: |
| 565 | case SpvOpFwidthFine: |
| 566 | case SpvOpDPdxCoarse: |
| 567 | case SpvOpDPdyCoarse: |
| 568 | case SpvOpFwidthCoarse: |
| 569 | case SpvOpReturnValue: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 570 | return true; |
| 571 | default: |
| 572 | return false; |
| 573 | } |
| 574 | } |
| 575 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 576 | int32_t spvOpcodeIsBasicTypeNullable(SpvOp opcode) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 577 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 578 | case SpvOpTypeBool: |
| 579 | case SpvOpTypeInt: |
| 580 | case SpvOpTypeFloat: |
| 581 | case SpvOpTypePointer: |
| 582 | case SpvOpTypeEvent: |
| 583 | case SpvOpTypeDeviceEvent: |
| 584 | case SpvOpTypeReserveId: |
| 585 | case SpvOpTypeQueue: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 586 | return true; |
| 587 | default: |
| 588 | return false; |
| 589 | } |
| 590 | } |
| 591 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 592 | int32_t spvInstructionIsInBasicBlock(const spv_instruction_t* pFirstInst, |
| 593 | const spv_instruction_t* pInst) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 594 | while (pFirstInst != pInst) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 595 | if (SpvOpFunction == pInst->opcode) break; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 596 | pInst--; |
| 597 | } |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 598 | if (SpvOpFunction != pInst->opcode) return false; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 599 | return true; |
| 600 | } |
| 601 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 602 | int32_t spvOpcodeIsValue(SpvOp opcode) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 603 | if (spvOpcodeIsPointer(opcode)) return true; |
| 604 | if (spvOpcodeIsConstant(opcode)) return true; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 605 | switch (opcode) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 606 | case SpvOpLoad: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 607 | // TODO: Other Opcode's resulting in a value |
| 608 | return true; |
| 609 | default: |
| 610 | return false; |
| 611 | } |
| 612 | } |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 613 | |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 614 | int32_t spvOpcodeGeneratesType(SpvOp op) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 615 | switch (op) { |
Lei Zhang | b36e704 | 2015-10-28 13:40:52 -0400 | [diff] [blame] | 616 | case SpvOpTypeVoid: |
| 617 | case SpvOpTypeBool: |
| 618 | case SpvOpTypeInt: |
| 619 | case SpvOpTypeFloat: |
| 620 | case SpvOpTypeVector: |
| 621 | case SpvOpTypeMatrix: |
| 622 | case SpvOpTypeImage: |
| 623 | case SpvOpTypeSampler: |
| 624 | case SpvOpTypeSampledImage: |
| 625 | case SpvOpTypeArray: |
| 626 | case SpvOpTypeRuntimeArray: |
| 627 | case SpvOpTypeStruct: |
| 628 | case SpvOpTypeOpaque: |
| 629 | case SpvOpTypePointer: |
| 630 | case SpvOpTypeFunction: |
| 631 | case SpvOpTypeEvent: |
| 632 | case SpvOpTypeDeviceEvent: |
| 633 | case SpvOpTypeReserveId: |
| 634 | case SpvOpTypeQueue: |
| 635 | case SpvOpTypePipe: |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 636 | return true; |
David Neto | aef608c | 2015-11-02 14:59:02 -0500 | [diff] [blame] | 637 | default: |
| 638 | // In particular, OpTypeForwardPointer does not generate a type, |
| 639 | // but declares a storage class for a pointer type generated |
| 640 | // by a different instruction. |
| 641 | break; |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 642 | } |
| 643 | return 0; |
| 644 | } |