pretty_stack_trace_function.h 995 B

12345678910111213141516171819202122232425262728293031
  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_COMMON_PRETTY_STACK_TRACE_FUNCTION_H_
  5. #define CARBON_COMMON_PRETTY_STACK_TRACE_FUNCTION_H_
  6. #include <functional>
  7. #include "llvm/Support/PrettyStackTrace.h"
  8. namespace Carbon {
  9. // Calls `fn` as part of LLVM's pretty stack trace support. Implementations
  10. // should typically have a terminating `\n`.
  11. class PrettyStackTraceFunction : public llvm::PrettyStackTraceEntry {
  12. public:
  13. explicit PrettyStackTraceFunction(
  14. std::function<auto(llvm::raw_ostream&)->void> fn)
  15. : fn_(std::move(fn)) {}
  16. ~PrettyStackTraceFunction() override = default;
  17. auto print(llvm::raw_ostream& output) const -> void override { fn_(output); }
  18. private:
  19. const std::function<auto(llvm::raw_ostream&)->void> fn_;
  20. };
  21. } // namespace Carbon
  22. #endif // CARBON_COMMON_PRETTY_STACK_TRACE_FUNCTION_H_