1 // Copyright (c) 2020 Vasyl Teliman
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_FUZZER_PASS_ADD_PARAMETERS_H_
16 #define SOURCE_FUZZ_FUZZER_PASS_ADD_PARAMETERS_H_
17 
18 #include <vector>
19 
20 #include "source/fuzz/fuzzer_pass.h"
21 
22 namespace spvtools {
23 namespace fuzz {
24 
25 // Randomly decides for each non-entry-point function in the module whether to
26 // add new parameters to it. If so, randomly determines the number of parameters
27 // to add, their type and creates constants used to initialize them.
28 class FuzzerPassAddParameters : public FuzzerPass {
29  public:
30   FuzzerPassAddParameters(opt::IRContext* ir_context,
31                           TransformationContext* transformation_context,
32                           FuzzerContext* fuzzer_context,
33                           protobufs::TransformationSequence* transformations);
34 
35   ~FuzzerPassAddParameters() override;
36 
37   void Apply() override;
38 
39  private:
40   // Returns number of parameters of |function|.
41   uint32_t GetNumberOfParameters(const opt::Function& function) const;
42 };
43 
44 }  // namespace fuzz
45 }  // namespace spvtools
46 
47 #endif  // SOURCE_FUZZ_FUZZER_PASS_ADD_PARAMETERS_H_
48