fuzzer_util.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_EXPLORER_FUZZING_FUZZER_UTIL_H_
  5. #define CARBON_EXPLORER_FUZZING_FUZZER_UTIL_H_
  6. #include "common/error.h"
  7. #include "common/fuzzing/carbon.pb.h"
  8. namespace Carbon {
  9. // Parses text proto with a Carbon message, optionally ignoring unknown fields.
  10. auto ParseCarbonTextProto(const std::string& contents,
  11. bool allow_unknown = true)
  12. -> ErrorOr<Fuzzing::Carbon>;
  13. // Converts `compilation_unit` to Carbon. Adds an default `Main()`
  14. // definition if one is not present in the proto.
  15. auto ProtoToCarbonWithMain(const Fuzzing::CompilationUnit& compilation_unit)
  16. -> std::string;
  17. // Parses and executes a fuzzer-generated program.
  18. // Returns program result if execution was successful.
  19. auto ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit)
  20. -> ErrorOr<int>;
  21. namespace Internal {
  22. // Returns a full path for a file under bazel runfiles.
  23. // Exposed for testing.
  24. auto GetRunfilesFile(const std::string& file) -> ErrorOr<std::string>;
  25. } // namespace Internal
  26. } // namespace Carbon
  27. #endif // CARBON_EXPLORER_FUZZING_FUZZER_UTIL_H_