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