transformation_context.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "source/fuzz/transformation_context.h"
  15. #include <cassert>
  16. #include "source/util/make_unique.h"
  17. namespace spvtools {
  18. namespace fuzz {
  19. namespace {
  20. // An overflow id source that should never be used: its methods assert false.
  21. // This is the right id source for use during fuzzing, when overflow ids should
  22. // never be required.
  23. class NullOverflowIdSource : public OverflowIdSource {
  24. bool HasOverflowIds() const override {
  25. assert(false && "Bad attempt to query whether overflow ids are available.");
  26. return false;
  27. }
  28. uint32_t GetNextOverflowId() override {
  29. assert(false && "Bad attempt to request an overflow id.");
  30. return 0;
  31. }
  32. const std::unordered_set<uint32_t>& GetIssuedOverflowIds() const override {
  33. assert(false && "Operation not supported.");
  34. return placeholder_;
  35. }
  36. private:
  37. std::unordered_set<uint32_t> placeholder_;
  38. };
  39. } // namespace
  40. TransformationContext::TransformationContext(
  41. std::unique_ptr<FactManager> fact_manager,
  42. spv_validator_options validator_options)
  43. : fact_manager_(std::move(fact_manager)),
  44. validator_options_(validator_options),
  45. overflow_id_source_(MakeUnique<NullOverflowIdSource>()) {}
  46. TransformationContext::TransformationContext(
  47. std::unique_ptr<FactManager> fact_manager,
  48. spv_validator_options validator_options,
  49. std::unique_ptr<OverflowIdSource> overflow_id_source)
  50. : fact_manager_(std::move(fact_manager)),
  51. validator_options_(validator_options),
  52. overflow_id_source_(std::move(overflow_id_source)) {}
  53. TransformationContext::~TransformationContext() = default;
  54. } // namespace fuzz
  55. } // namespace spvtools