fuzzer_util.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. void ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit);
  19. namespace Internal {
  20. // Returns a full path for a file under bazel runfiles.
  21. // Exposed for testing.
  22. auto GetRunfilesFile(const std::string& file) -> ErrorOr<std::string>;
  23. } // namespace Internal
  24. } // namespace Carbon
  25. #endif // CARBON_EXPLORER_FUZZING_FUZZER_UTIL_H_