reflect.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2016 Google 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_OPT_REFLECT_H_
  15. #define SOURCE_OPT_REFLECT_H_
  16. #include "source/latest_version_spirv_header.h"
  17. namespace spvtools {
  18. namespace opt {
  19. // Note that as SPIR-V evolves over time, new opcodes may appear. So the
  20. // following functions tend to be outdated and should be updated when SPIR-V
  21. // version bumps.
  22. inline bool IsDebug1Inst(spv::Op opcode) {
  23. return (opcode >= spv::Op::OpSourceContinued &&
  24. opcode <= spv::Op::OpSourceExtension) ||
  25. opcode == spv::Op::OpString;
  26. }
  27. inline bool IsDebug2Inst(spv::Op opcode) {
  28. return opcode == spv::Op::OpName || opcode == spv::Op::OpMemberName;
  29. }
  30. inline bool IsDebug3Inst(spv::Op opcode) {
  31. return opcode == spv::Op::OpModuleProcessed;
  32. }
  33. inline bool IsOpLineInst(spv::Op opcode) {
  34. return opcode == spv::Op::OpLine || opcode == spv::Op::OpNoLine;
  35. }
  36. inline bool IsAnnotationInst(spv::Op opcode) {
  37. return (opcode >= spv::Op::OpDecorate &&
  38. opcode <= spv::Op::OpGroupMemberDecorate) ||
  39. opcode == spv::Op::OpDecorateId ||
  40. opcode == spv::Op::OpDecorateStringGOOGLE ||
  41. opcode == spv::Op::OpMemberDecorateStringGOOGLE;
  42. }
  43. inline bool IsTypeInst(spv::Op opcode) {
  44. return spvOpcodeGeneratesType(opcode) ||
  45. opcode == spv::Op::OpTypeForwardPointer;
  46. }
  47. inline bool IsConstantInst(spv::Op opcode) {
  48. return spvOpcodeIsConstant(opcode);
  49. }
  50. inline bool IsSpecConstantInst(spv::Op opcode) {
  51. return spvOpcodeIsSpecConstant(opcode);
  52. }
  53. } // namespace opt
  54. } // namespace spvtools
  55. #endif // SOURCE_OPT_REFLECT_H_