transformation.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2019 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.h"
  15. #include <cassert>
  16. #include "source/util/make_unique.h"
  17. #include "transformation_add_constant_boolean.h"
  18. #include "transformation_add_constant_scalar.h"
  19. #include "transformation_add_dead_break.h"
  20. #include "transformation_add_dead_continue.h"
  21. #include "transformation_add_type_boolean.h"
  22. #include "transformation_add_type_float.h"
  23. #include "transformation_add_type_int.h"
  24. #include "transformation_add_type_pointer.h"
  25. #include "transformation_move_block_down.h"
  26. #include "transformation_replace_boolean_constant_with_constant_binary.h"
  27. #include "transformation_replace_constant_with_uniform.h"
  28. #include "transformation_split_block.h"
  29. namespace spvtools {
  30. namespace fuzz {
  31. Transformation::~Transformation() = default;
  32. std::unique_ptr<Transformation> Transformation::FromMessage(
  33. const protobufs::Transformation& message) {
  34. switch (message.transformation_case()) {
  35. case protobufs::Transformation::TransformationCase::kAddConstantBoolean:
  36. return MakeUnique<TransformationAddConstantBoolean>(
  37. message.add_constant_boolean());
  38. case protobufs::Transformation::TransformationCase::kAddConstantScalar:
  39. return MakeUnique<TransformationAddConstantScalar>(
  40. message.add_constant_scalar());
  41. case protobufs::Transformation::TransformationCase::kAddDeadBreak:
  42. return MakeUnique<TransformationAddDeadBreak>(message.add_dead_break());
  43. case protobufs::Transformation::TransformationCase::kAddDeadContinue:
  44. return MakeUnique<TransformationAddDeadContinue>(
  45. message.add_dead_continue());
  46. case protobufs::Transformation::TransformationCase::kAddTypeBoolean:
  47. return MakeUnique<TransformationAddTypeBoolean>(
  48. message.add_type_boolean());
  49. case protobufs::Transformation::TransformationCase::kAddTypeFloat:
  50. return MakeUnique<TransformationAddTypeFloat>(message.add_type_float());
  51. case protobufs::Transformation::TransformationCase::kAddTypeInt:
  52. return MakeUnique<TransformationAddTypeInt>(message.add_type_int());
  53. case protobufs::Transformation::TransformationCase::kAddTypePointer:
  54. return MakeUnique<TransformationAddTypePointer>(
  55. message.add_type_pointer());
  56. case protobufs::Transformation::TransformationCase::kMoveBlockDown:
  57. return MakeUnique<TransformationMoveBlockDown>(message.move_block_down());
  58. case protobufs::Transformation::TransformationCase::
  59. kReplaceBooleanConstantWithConstantBinary:
  60. return MakeUnique<TransformationReplaceBooleanConstantWithConstantBinary>(
  61. message.replace_boolean_constant_with_constant_binary());
  62. case protobufs::Transformation::TransformationCase::
  63. kReplaceConstantWithUniform:
  64. return MakeUnique<TransformationReplaceConstantWithUniform>(
  65. message.replace_constant_with_uniform());
  66. case protobufs::Transformation::TransformationCase::kSplitBlock:
  67. return MakeUnique<TransformationSplitBlock>(message.split_block());
  68. default:
  69. assert(message.transformation_case() ==
  70. protobufs::Transformation::TRANSFORMATION_NOT_SET &&
  71. "Unhandled transformation type.");
  72. assert(false && "An unset transformation was encountered.");
  73. return nullptr;
  74. }
  75. }
  76. } // namespace fuzz
  77. } // namespace spvtools