1 // Copyright (c) 2015-2016 The Khronos Group Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SOURCE_TABLE_H_ 16 #define SOURCE_TABLE_H_ 17 18 #include "source/extensions.h" 19 #include "source/latest_version_spirv_header.h" 20 #include "spirv-tools/libspirv.hpp" 21 22 typedef struct spv_opcode_desc_t { 23 const char* name; 24 const spv::Op opcode; 25 const uint32_t numAliases; 26 const char** aliases; 27 const uint32_t numCapabilities; 28 const spv::Capability* capabilities; 29 // operandTypes[0..numTypes-1] describe logical operands for the instruction. 30 // The operand types include result id and result-type id, followed by 31 // the types of arguments. 32 const uint16_t numTypes; 33 spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? 34 const bool hasResult; // Does the instruction have a result ID operand? 35 const bool hasType; // Does the instruction have a type ID operand? 36 // A set of extensions that enable this feature. If empty then this operand 37 // value is in core and its availability is subject to minVersion. The 38 // assembler, binary parser, and disassembler ignore this rule, so you can 39 // freely process invalid modules. 40 const uint32_t numExtensions; 41 const spvtools::Extension* extensions; 42 // Minimal core SPIR-V version required for this feature, if without 43 // extensions. ~0u means reserved for future use. ~0u and non-empty extension 44 // lists means only available in extensions. 45 const uint32_t minVersion; 46 const uint32_t lastVersion; 47 } spv_opcode_desc_t; 48 49 typedef struct spv_operand_desc_t { 50 const char* name; 51 const uint32_t value; 52 const uint32_t numAliases; 53 const char** aliases; 54 const uint32_t numCapabilities; 55 const spv::Capability* capabilities; 56 // A set of extensions that enable this feature. If empty then this operand 57 // value is in core and its availability is subject to minVersion. The 58 // assembler, binary parser, and disassembler ignore this rule, so you can 59 // freely process invalid modules. 60 const uint32_t numExtensions; 61 const spvtools::Extension* extensions; 62 const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? 63 // Minimal core SPIR-V version required for this feature, if without 64 // extensions. ~0u means reserved for future use. ~0u and non-empty extension 65 // lists means only available in extensions. 66 const uint32_t minVersion; 67 const uint32_t lastVersion; 68 } spv_operand_desc_t; 69 70 typedef struct spv_operand_desc_group_t { 71 const spv_operand_type_t type; 72 const uint32_t count; 73 const spv_operand_desc_t* entries; 74 } spv_operand_desc_group_t; 75 76 typedef struct spv_ext_inst_desc_t { 77 const char* name; 78 const uint32_t ext_inst; 79 const uint32_t numCapabilities; 80 const spv::Capability* capabilities; 81 const spv_operand_type_t operandTypes[40]; // vksp needs at least 40 82 } spv_ext_inst_desc_t; 83 84 typedef struct spv_ext_inst_group_t { 85 const spv_ext_inst_type_t type; 86 const uint32_t count; 87 const spv_ext_inst_desc_t* entries; 88 } spv_ext_inst_group_t; 89 90 typedef struct spv_opcode_table_t { 91 const uint32_t count; 92 const spv_opcode_desc_t* entries; 93 } spv_opcode_table_t; 94 95 typedef struct spv_operand_table_t { 96 const uint32_t count; 97 const spv_operand_desc_group_t* types; 98 } spv_operand_table_t; 99 100 typedef struct spv_ext_inst_table_t { 101 const uint32_t count; 102 const spv_ext_inst_group_t* groups; 103 } spv_ext_inst_table_t; 104 105 typedef const spv_opcode_desc_t* spv_opcode_desc; 106 typedef const spv_operand_desc_t* spv_operand_desc; 107 typedef const spv_ext_inst_desc_t* spv_ext_inst_desc; 108 109 typedef const spv_opcode_table_t* spv_opcode_table; 110 typedef const spv_operand_table_t* spv_operand_table; 111 typedef const spv_ext_inst_table_t* spv_ext_inst_table; 112 113 struct spv_context_t { 114 const spv_target_env target_env; 115 const spv_opcode_table opcode_table; 116 const spv_operand_table operand_table; 117 const spv_ext_inst_table ext_inst_table; 118 spvtools::MessageConsumer consumer; 119 }; 120 121 namespace spvtools { 122 123 // Sets the message consumer to |consumer| in the given |context|. The original 124 // message consumer will be overwritten. 125 void SetContextMessageConsumer(spv_context context, MessageConsumer consumer); 126 } // namespace spvtools 127 128 // Populates *table with entries for env. 129 spv_result_t spvOpcodeTableGet(spv_opcode_table* table, spv_target_env env); 130 131 // Populates *table with entries for env. 132 spv_result_t spvOperandTableGet(spv_operand_table* table, spv_target_env env); 133 134 // Populates *table with entries for env. 135 spv_result_t spvExtInstTableGet(spv_ext_inst_table* table, spv_target_env env); 136 137 #endif // SOURCE_TABLE_H_ 138