1 // Copyright (c) 2020 Google LLC
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_
16 #define SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_
20 #include "source/fuzz/fact_manager/fact_manager.h"
21 #include "source/fuzz/overflow_id_source.h"
22 #include "spirv-tools/libspirv.hpp"
27 // Encapsulates all information that is required to inform how to apply a
28 // transformation to a module.
29 class TransformationContext
{
31 // Constructs a transformation context with a given fact manager and validator
32 // options. Overflow ids are not available from a transformation context
33 // constructed in this way.
34 TransformationContext(std::unique_ptr
<FactManager
>,
35 spv_validator_options validator_options
);
37 // Constructs a transformation context with a given fact manager, validator
38 // options and overflow id source.
39 TransformationContext(std::unique_ptr
<FactManager
>,
40 spv_validator_options validator_options
,
41 std::unique_ptr
<OverflowIdSource
> overflow_id_source
);
43 ~TransformationContext();
45 FactManager
* GetFactManager() { return fact_manager_
.get(); }
47 const FactManager
* GetFactManager() const { return fact_manager_
.get(); }
49 OverflowIdSource
* GetOverflowIdSource() { return overflow_id_source_
.get(); }
51 const OverflowIdSource
* GetOverflowIdSource() const {
52 return overflow_id_source_
.get();
55 spv_validator_options
GetValidatorOptions() const {
56 return validator_options_
;
60 // Manages facts that inform whether transformations can be applied, and that
61 // are produced by applying transformations.
62 std::unique_ptr
<FactManager
> fact_manager_
;
64 // Options to control validation when deciding whether transformations can be
66 spv_validator_options validator_options_
;
68 std::unique_ptr
<OverflowIdSource
> overflow_id_source_
;
72 } // namespace spvtools
74 #endif // SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_