summaryrefslogtreecommitdiffstats
path: root/omni/log.h
blob: f3e865b641e0d49937db8ae8ada224fcfef46bf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef OMNI_ASSERT_H
#define OMNI_ASSERT_H

#include <cstdio>
#include <cstdlib>

#include "stdint.h"

template <typename... Args>
[[noreturn]] void panic_impl(const char* file, u32 line, const char* fmt,
                             Args arguments) {
  fprintf(stderr, "PANIC at %s:%d: ", file, line);
  fprintf(stderr, fmt, args...);
  fputs("\n", stderr);
  abort();
}

#define panic(...) panic_impl(__FILE__, __LINE__, __VA_ARGS__)

#ifndef NDEBUG
#  define assert(cond)                                   \
    do {                                                 \
      if (!(cond)) panic("assertion failed: %s", #cond); \
    } while (0);
#else
#  define assert(cond) unused(cond)
#endif

#endif