transformation_context.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_TRANSFORMATION_CONTEXT_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_
  16. #include <memory>
  17. #include "source/fuzz/fact_manager/fact_manager.h"
  18. #include "source/fuzz/overflow_id_source.h"
  19. #include "spirv-tools/libspirv.hpp"
  20. namespace spvtools {
  21. namespace fuzz {
  22. // Encapsulates all information that is required to inform how to apply a
  23. // transformation to a module.
  24. class TransformationContext {
  25. public:
  26. // Constructs a transformation context with a given fact manager and validator
  27. // options. Overflow ids are not available from a transformation context
  28. // constructed in this way.
  29. TransformationContext(std::unique_ptr<FactManager>,
  30. spv_validator_options validator_options);
  31. // Constructs a transformation context with a given fact manager, validator
  32. // options and overflow id source.
  33. TransformationContext(std::unique_ptr<FactManager>,
  34. spv_validator_options validator_options,
  35. std::unique_ptr<OverflowIdSource> overflow_id_source);
  36. ~TransformationContext();
  37. FactManager* GetFactManager() { return fact_manager_.get(); }
  38. const FactManager* GetFactManager() const { return fact_manager_.get(); }
  39. OverflowIdSource* GetOverflowIdSource() { return overflow_id_source_.get(); }
  40. const OverflowIdSource* GetOverflowIdSource() const {
  41. return overflow_id_source_.get();
  42. }
  43. spv_validator_options GetValidatorOptions() const {
  44. return validator_options_;
  45. }
  46. private:
  47. // Manages facts that inform whether transformations can be applied, and that
  48. // are produced by applying transformations.
  49. std::unique_ptr<FactManager> fact_manager_;
  50. // Options to control validation when deciding whether transformations can be
  51. // applied.
  52. spv_validator_options validator_options_;
  53. std::unique_ptr<OverflowIdSource> overflow_id_source_;
  54. };
  55. } // namespace fuzz
  56. } // namespace spvtools
  57. #endif // SOURCE_FUZZ_TRANSFORMATION_CONTEXT_H_