table.h 4.8 KB

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