• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LIBSPIRV_TABLE_H_
16 #define LIBSPIRV_TABLE_H_
17 
18 #include "spirv/1.2/spirv.h"
19 
20 #include "extensions.h"
21 #include "message.h"
22 #include "spirv-tools/libspirv.hpp"
23 
24 typedef struct spv_opcode_desc_t {
25   const char* name;
26   const SpvOp opcode;
27   const libspirv::CapabilitySet capabilities;
28   // operandTypes[0..numTypes-1] describe logical operands for the instruction.
29   // The operand types include result id and result-type id, followed by
30   // the types of arguments.
31   uint16_t numTypes;
32   spv_operand_type_t operandTypes[16];  // TODO: Smaller/larger?
33   const bool hasResult;  // Does the instruction have a result ID operand?
34   const bool hasType;    // Does the instruction have a type ID operand?
35 } spv_opcode_desc_t;
36 
37 typedef struct spv_operand_desc_t {
38   const char* name;
39   const uint32_t value;
40   const libspirv::CapabilitySet capabilities;
41   // A set of extensions that enable this feature. If empty then this operand
42   // value is always enabled, i.e. it's in core. The assembler, binary parser,
43   // and disassembler ignore this rule, so you can freely process invalid
44   // modules.
45   const libspirv::ExtensionSet extensions;
46   const spv_operand_type_t operandTypes[16];  // TODO: Smaller/larger?
47 } spv_operand_desc_t;
48 
49 typedef struct spv_operand_desc_group_t {
50   const spv_operand_type_t type;
51   const uint32_t count;
52   const spv_operand_desc_t* entries;
53 } spv_operand_desc_group_t;
54 
55 typedef struct spv_ext_inst_desc_t {
56   const char* name;
57   const uint32_t ext_inst;
58   const libspirv::CapabilitySet capabilities;
59   const spv_operand_type_t operandTypes[16];  // TODO: Smaller/larger?
60 } spv_ext_inst_desc_t;
61 
62 typedef struct spv_ext_inst_group_t {
63   const spv_ext_inst_type_t type;
64   const uint32_t count;
65   const spv_ext_inst_desc_t* entries;
66 } spv_ext_inst_group_t;
67 
68 typedef struct spv_opcode_table_t {
69   const uint32_t count;
70   const spv_opcode_desc_t* entries;
71 } spv_opcode_table_t;
72 
73 typedef struct spv_operand_table_t {
74   const uint32_t count;
75   const spv_operand_desc_group_t* types;
76 } spv_operand_table_t;
77 
78 typedef struct spv_ext_inst_table_t {
79   const uint32_t count;
80   const spv_ext_inst_group_t* groups;
81 } spv_ext_inst_table_t;
82 
83 typedef const spv_opcode_desc_t* spv_opcode_desc;
84 typedef const spv_operand_desc_t* spv_operand_desc;
85 typedef const spv_ext_inst_desc_t* spv_ext_inst_desc;
86 
87 typedef const spv_opcode_table_t* spv_opcode_table;
88 typedef const spv_operand_table_t* spv_operand_table;
89 typedef const spv_ext_inst_table_t* spv_ext_inst_table;
90 
91 struct spv_context_t {
92   const spv_target_env target_env;
93   const spv_opcode_table opcode_table;
94   const spv_operand_table operand_table;
95   const spv_ext_inst_table ext_inst_table;
96   spvtools::MessageConsumer consumer;
97 };
98 
99 // Sets the message consumer to |consumer| in the given |context|. The original
100 // message consumer will be overwritten.
101 void SetContextMessageConsumer(spv_context context,
102                                spvtools::MessageConsumer consumer);
103 
104 // Populates *table with entries for env.
105 spv_result_t spvOpcodeTableGet(spv_opcode_table* table, spv_target_env env);
106 
107 // Populates *table with entries for env.
108 spv_result_t spvOperandTableGet(spv_operand_table* table, spv_target_env env);
109 
110 // Populates *table with entries for env.
111 spv_result_t spvExtInstTableGet(spv_ext_inst_table* table, spv_target_env env);
112 
113 #endif  // LIBSPIRV_TABLE_H_
114