transformation.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_copy_object.h"
  26. #include "transformation_move_block_down.h"
  27. #include "transformation_replace_boolean_constant_with_constant_binary.h"
  28. #include "transformation_replace_constant_with_uniform.h"
  29. #include "transformation_split_block.h"
  30. namespace spvtools {
  31. namespace fuzz {
  32. Transformation::~Transformation() = default;
  33. std::unique_ptr<Transformation> Transformation::FromMessage(
  34. const protobufs::Transformation& message) {
  35. switch (message.transformation_case()) {
  36. case protobufs::Transformation::TransformationCase::kAddConstantBoolean:
  37. return MakeUnique<TransformationAddConstantBoolean>(
  38. message.add_constant_boolean());
  39. case protobufs::Transformation::TransformationCase::kAddConstantScalar:
  40. return MakeUnique<TransformationAddConstantScalar>(
  41. message.add_constant_scalar());
  42. case protobufs::Transformation::TransformationCase::kAddDeadBreak:
  43. return MakeUnique<TransformationAddDeadBreak>(message.add_dead_break());
  44. case protobufs::Transformation::TransformationCase::kAddDeadContinue:
  45. return MakeUnique<TransformationAddDeadContinue>(
  46. message.add_dead_continue());
  47. case protobufs::Transformation::TransformationCase::kAddTypeBoolean:
  48. return MakeUnique<TransformationAddTypeBoolean>(
  49. message.add_type_boolean());
  50. case protobufs::Transformation::TransformationCase::kAddTypeFloat:
  51. return MakeUnique<TransformationAddTypeFloat>(message.add_type_float());
  52. case protobufs::Transformation::TransformationCase::kAddTypeInt:
  53. return MakeUnique<TransformationAddTypeInt>(message.add_type_int());
  54. case protobufs::Transformation::TransformationCase::kAddTypePointer:
  55. return MakeUnique<TransformationAddTypePointer>(
  56. message.add_type_pointer());
  57. case protobufs::Transformation::TransformationCase::kCopyObject:
  58. return MakeUnique<TransformationCopyObject>(message.copy_object());
  59. case protobufs::Transformation::TransformationCase::kMoveBlockDown:
  60. return MakeUnique<TransformationMoveBlockDown>(message.move_block_down());
  61. case protobufs::Transformation::TransformationCase::
  62. kReplaceBooleanConstantWithConstantBinary:
  63. return MakeUnique<TransformationReplaceBooleanConstantWithConstantBinary>(
  64. message.replace_boolean_constant_with_constant_binary());
  65. case protobufs::Transformation::TransformationCase::
  66. kReplaceConstantWithUniform:
  67. return MakeUnique<TransformationReplaceConstantWithUniform>(
  68. message.replace_constant_with_uniform());
  69. case protobufs::Transformation::TransformationCase::kSplitBlock:
  70. return MakeUnique<TransformationSplitBlock>(message.split_block());
  71. case protobufs::Transformation::TRANSFORMATION_NOT_SET:
  72. assert(false && "An unset transformation was encountered.");
  73. return nullptr;
  74. }
  75. assert(false && "Should be unreachable as all cases must be handled above.");
  76. return nullptr;
  77. }
  78. } // namespace fuzz
  79. } // namespace spvtools