1 // Copyright (c) 2015-2016 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 #ifndef LIBSPIRV_TABLE_H_ 28 #define LIBSPIRV_TABLE_H_ 29 30 #include "spirv-tools/libspirv.h" 31 #include "spirv/1.1/spirv.h" 32 #include "spirv_definition.h" 33 34 typedef struct spv_opcode_desc_t { 35 const char* name; 36 const SpvOp opcode; 37 const spv_capability_mask_t 38 capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability) 39 // operandTypes[0..numTypes-1] describe logical operands for the instruction. 40 // The operand types include result id and result-type id, followed by 41 // the types of arguments. 42 uint16_t numTypes; 43 spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? 44 const bool hasResult; // Does the instruction have a result ID operand? 45 const bool hasType; // Does the instruction have a type ID operand? 46 } spv_opcode_desc_t; 47 48 typedef struct spv_operand_desc_t { 49 const char* name; 50 const uint32_t value; 51 const spv_capability_mask_t 52 capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability) 53 const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? 54 } spv_operand_desc_t; 55 56 typedef struct spv_operand_desc_group_t { 57 const spv_operand_type_t type; 58 const uint32_t count; 59 const spv_operand_desc_t* entries; 60 } spv_operand_desc_group_t; 61 62 typedef struct spv_ext_inst_desc_t { 63 const char* name; 64 const uint32_t ext_inst; 65 const spv_capability_mask_t 66 capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability) 67 const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? 68 } spv_ext_inst_desc_t; 69 70 typedef struct spv_ext_inst_group_t { 71 const spv_ext_inst_type_t type; 72 const uint32_t count; 73 const spv_ext_inst_desc_t* entries; 74 } spv_ext_inst_group_t; 75 76 typedef struct spv_opcode_table_t { 77 const uint32_t count; 78 const spv_opcode_desc_t* entries; 79 } spv_opcode_table_t; 80 81 typedef struct spv_operand_table_t { 82 const uint32_t count; 83 const spv_operand_desc_group_t* types; 84 } spv_operand_table_t; 85 86 typedef struct spv_ext_inst_table_t { 87 const uint32_t count; 88 const spv_ext_inst_group_t* groups; 89 } spv_ext_inst_table_t; 90 91 typedef const spv_opcode_desc_t* spv_opcode_desc; 92 typedef const spv_operand_desc_t* spv_operand_desc; 93 typedef const spv_ext_inst_desc_t* spv_ext_inst_desc; 94 95 typedef const spv_opcode_table_t* spv_opcode_table; 96 typedef const spv_operand_table_t* spv_operand_table; 97 typedef const spv_ext_inst_table_t* spv_ext_inst_table; 98 99 struct spv_context_t { 100 const spv_target_env target_env; 101 const spv_opcode_table opcode_table; 102 const spv_operand_table operand_table; 103 const spv_ext_inst_table ext_inst_table; 104 }; 105 106 // Populates *table with entries for env. 107 spv_result_t spvOpcodeTableGet(spv_opcode_table* table, spv_target_env env); 108 109 // Populates *table with entries for env. 110 spv_result_t spvOperandTableGet(spv_operand_table* table, spv_target_env env); 111 112 // Populates *table with entries for env. 113 spv_result_t spvExtInstTableGet(spv_ext_inst_table* table, spv_target_env env); 114 115 #endif // LIBSPIRV_TABLE_H_ 116