| 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_TRANSFORMATION_CONTEXT_H_ |
| 16 |
#define SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_ |
| 17 |
|
| 18 |
#include <memory> |
| 19 |
|
| 20 |
#include "source/fuzz/fact_manager/fact_manager.h" |
| 21 |
#include "source/fuzz/overflow_id_source.h" |
| 22 |
#include "spirv-tools/libspirv.hpp" |
| 23 |
|
| 24 |
namespace spvtools { |
| 25 |
namespace fuzz { |
| 26 |
|
| 27 |
// Encapsulates all information that is required to inform how to apply a |
| 28 |
// transformation to a module. |
| 29 |
class TransformationContext { |
| 30 |
public: |
| 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); |
| 36 |
|
| 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); |
| 42 |
|
| 43 |
~TransformationContext(); |
| 44 |
|
| 45 |
FactManager* GetFactManager() { return fact_manager_.get(); } |
| 46 |
|
| 47 |
const FactManager* GetFactManager() const { return fact_manager_.get(); } |
| 48 |
|
| 49 |
OverflowIdSource* GetOverflowIdSource() { return overflow_id_source_.get(); } |
| 50 |
|
| 51 |
const OverflowIdSource* GetOverflowIdSource() const { |
| 52 |
return overflow_id_source_.get(); |
| 53 |
} |
| 54 |
|
| 55 |
spv_validator_options GetValidatorOptions() const { |
| 56 |
return validator_options_; |
| 57 |
} |
| 58 |
|
| 59 |
private: |
| 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_; |
| 63 |
|
| 64 |
// Options to control validation when deciding whether transformations can be |
| 65 |
// applied. |
| 66 |
spv_validator_options validator_options_; |
| 67 |
|
| 68 |
std::unique_ptr<OverflowIdSource> overflow_id_source_; |
| 69 |
}; |
| 70 |
|
| 71 |
} // namespace fuzz |
| 72 |
} // namespace spvtools |
| 73 |
|
| 74 |
#endif // SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_ |