7#include <llvm/Support/Casting.h>
8#include <llvm/Support/FileSystem.h>
9#include <llvm/Support/raw_ostream.h>
24using namespace std::literals::string_literals;
25using namespace std::literals::string_view_literals;
26namespace fs = std::filesystem;
31using std::string_view;
32using std::stringstream;
44template <
typename... Ts>
47 template <
typename...
Vs>
struct Visitor :
Vs... {
48 using Vs::operator()...;
50 template <
typename...
Vs> Visitor(
Vs...) -> Visitor<
Vs...>;
53 using std::variant<Ts...>::variant;
55 template <
typename... Us>
auto visit(Us... us) ->
decltype(
auto) {
return std::visit(Visitor<Us...>{us...}, *
this); }
56 template <
typename... Us> [[nodiscard]]
auto visit(Us... us)
const ->
decltype(
auto) {
57 return std::visit(Visitor<Us...>{us...}, *
this);
64 t.visit([](
auto&&) {})
68#if __has_feature(nullability)
69template <
typename T>
using nullable = T _Nullable;
70template <
typename T>
using nonnull = T _Nonnull;
78#define YUME_ASSERT(...) ((void)0);
81#define YUME_ASSERT(assertion, message) (static_cast<bool>(assertion) ? ((void)0) : yume_assert_failure(message))
86 llvm::errs() <<
"*** assertion failed: " <<
at(location) <<
" " << log_msg <<
'\n';
92 std::error_code error_code;
94 std::make_unique<llvm::raw_fd_ostream>(filename, error_code, llvm::sys::fs::CreationDisposition::CD_CreateAlways);
97 llvm::errs() <<
"Could not open file: " << error_code.message() <<
"\n";
112template <
typename T>
static void hash_combine(uint64_t& seed,
const T& v) {
113 static constexpr auto PHI_FRAC = std::numbers::phi_v<long double> - 1;
114 static constexpr auto ALL_BITS = std::numeric_limits<std::size_t>::max();
115 static constexpr auto FLOATING_HASH_CONST = PHI_FRAC * ALL_BITS;
116 static constexpr auto HASH_CONST =
static_cast<std::size_t
>(FLOATING_HASH_CONST);
117 static constexpr auto TWIST_LEFT = 6;
118 static constexpr auto TWIST_RIGHT = 2;
121 seed ^= hasher(v) + HASH_CONST + (seed << TWIST_LEFT) + (seed >> TWIST_RIGHT);
auto at(const source_location location=source_location::current()) -> std::string
auto open_file(nonnull< const char * > filename) -> unique_ptr< llvm::raw_pwrite_stream >
Opens a writeable stream to a file with the given filename relative to the current working directory.
void yume_assert_failure(const std::string_view log_msg={}, const source_location location=source_location::current()) noexcept
static void hash_combine(uint64_t &seed, const T &v)
constexpr StringLiteral(const char(&str)[N])
auto operator<=>(const StringLiteral &) const =default
static constexpr auto current()
auto visit(Us... us) const -> decltype(auto)
auto visit(Us... us) -> decltype(auto)