counter_overflow_id_source.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2020 Google LLC
  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_FUZZ_COUNTER_OVERFLOW_ID_SOURCE_H_
  15. #define SOURCE_FUZZ_COUNTER_OVERFLOW_ID_SOURCE_H_
  16. #include "source/fuzz/overflow_id_source.h"
  17. namespace spvtools {
  18. namespace fuzz {
  19. // A source of overflow ids that uses a counter to provide successive ids from
  20. // a given starting value.
  21. class CounterOverflowIdSource : public OverflowIdSource {
  22. public:
  23. // |first_available_id| is the starting value for the counter.
  24. explicit CounterOverflowIdSource(uint32_t first_available_id);
  25. // Always returns true.
  26. bool HasOverflowIds() const override;
  27. // Returns the current counter value and increments the counter.
  28. // TODO(https://github.com/KhronosGroup/SPIRV-Tools/issues/2541) We should
  29. // account for the case where the maximum allowed id is reached.
  30. uint32_t GetNextOverflowId() override;
  31. const std::unordered_set<uint32_t>& GetIssuedOverflowIds() const override;
  32. private:
  33. uint32_t next_available_id_;
  34. std::unordered_set<uint32_t> issued_ids_;
  35. };
  36. } // namespace fuzz
  37. } // namespace spvtools
  38. #endif // SOURCE_FUZZ_OVERFLOW_ID_SOURCE_COUNTER_H_