instruction.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_INSTRUCTION_H_
  15. #define SOURCE_INSTRUCTION_H_
  16. #include <cstdint>
  17. #include <vector>
  18. #include "source/latest_version_spirv_header.h"
  19. #include "spirv-tools/libspirv.h"
  20. // Describes an instruction.
  21. struct spv_instruction_t {
  22. // Normally, both opcode and extInstType contain valid data.
  23. // However, when the assembler parses !<number> as the first word in
  24. // an instruction and opcode and extInstType are invalid.
  25. SpvOp opcode;
  26. spv_ext_inst_type_t extInstType;
  27. // The Id of the result type, if this instruction has one. Zero otherwise.
  28. uint32_t resultTypeId;
  29. // The instruction, as a sequence of 32-bit words.
  30. // For a regular instruction the opcode and word count are combined
  31. // in words[0], as described in the SPIR-V spec.
  32. // Otherwise, the first token was !<number>, and that number appears
  33. // in words[0]. Subsequent elements are the result of parsing
  34. // tokens in the alternate parsing mode as described in syntax.md.
  35. std::vector<uint32_t> words;
  36. };
  37. // Appends a word to an instruction, without checking for overflow.
  38. inline void spvInstructionAddWord(spv_instruction_t* inst, uint32_t value) {
  39. inst->words.push_back(value);
  40. }
  41. #endif // SOURCE_INSTRUCTION_H_