pretty_stack_trace_function.h 879 B

12345678910111213141516171819202122232425262728
  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_TOOLCHAIN_BASE_PRETTY_STACK_TRACE_FUNCTION_H_
  5. #define CARBON_TOOLCHAIN_BASE_PRETTY_STACK_TRACE_FUNCTION_H_
  6. #include <functional>
  7. #include "llvm/Support/PrettyStackTrace.h"
  8. namespace Carbon {
  9. class PrettyStackTraceFunction : public llvm::PrettyStackTraceEntry {
  10. public:
  11. explicit PrettyStackTraceFunction(std::function<void(llvm::raw_ostream&)> fn)
  12. : fn_(std::move(fn)) {}
  13. ~PrettyStackTraceFunction() override = default;
  14. auto print(llvm::raw_ostream& output) const -> void override { fn_(output); }
  15. private:
  16. const std::function<void(llvm::raw_ostream&)> fn_;
  17. };
  18. } // namespace Carbon
  19. #endif // CARBON_TOOLCHAIN_BASE_PRETTY_STACK_TRACE_FUNCTION_H_