instruction.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "source/val/instruction.h"
  15. #include <utility>
  16. namespace spvtools {
  17. namespace val {
  18. Instruction::Instruction(const spv_parsed_instruction_t* inst)
  19. : words_(inst->words, inst->words + inst->num_words),
  20. operands_(inst->operands, inst->operands + inst->num_operands),
  21. inst_({words_.data(), inst->num_words, inst->opcode, inst->ext_inst_type,
  22. inst->type_id, inst->result_id, operands_.data(),
  23. inst->num_operands}) {}
  24. void Instruction::RegisterUse(const Instruction* inst, uint32_t index) {
  25. uses_.push_back(std::make_pair(inst, index));
  26. }
  27. bool operator<(const Instruction& lhs, const Instruction& rhs) {
  28. return lhs.id() < rhs.id();
  29. }
  30. bool operator<(const Instruction& lhs, uint32_t rhs) { return lhs.id() < rhs; }
  31. bool operator==(const Instruction& lhs, const Instruction& rhs) {
  32. return lhs.id() == rhs.id();
  33. }
  34. bool operator==(const Instruction& lhs, uint32_t rhs) {
  35. return lhs.id() == rhs;
  36. }
  37. } // namespace val
  38. } // namespace spvtools