Move __check_failed out of line so anyone can implement it
This commit is contained in:
parent
2b9bdf560e
commit
8cae20a82c
@ -1,4 +1,5 @@
|
|||||||
#include "arch/Serial.h"
|
#include "arch/Serial.h"
|
||||||
|
#include "arch/CPU.h"
|
||||||
#include <Format.h>
|
#include <Format.h>
|
||||||
|
|
||||||
namespace Serial
|
namespace Serial
|
||||||
@ -33,4 +34,16 @@ namespace Serial
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool g_check_already_failed = false;
|
||||||
|
|
||||||
|
_noreturn bool __check_failed(const char* file, const char* line, const char* func, const char* expr)
|
||||||
|
{
|
||||||
|
if (!g_check_already_failed)
|
||||||
|
{ // Avoid endlessly failing when trying to report a failed check.
|
||||||
|
g_check_already_failed = true;
|
||||||
|
Serial::printf("ERROR: Check failed at %s:%s, in %s: %s\n", file, line, func, expr);
|
||||||
|
}
|
||||||
|
CPU::efficient_halt();
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ set(FREESTANDING_SOURCES
|
|||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
${FREESTANDING_SOURCES}
|
${FREESTANDING_SOURCES}
|
||||||
|
Check.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(luna-freestanding ${FREESTANDING_SOURCES})
|
add_library(luna-freestanding ${FREESTANDING_SOURCES})
|
||||||
|
6
luna/Check.cpp
Normal file
6
luna/Check.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <Attributes.h>
|
||||||
|
|
||||||
|
_weak _noreturn bool __check_failed(const char*, const char*, const char*, const char*)
|
||||||
|
{
|
||||||
|
__builtin_trap();
|
||||||
|
}
|
19
luna/Check.h
19
luna/Check.h
@ -1,22 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef IN_MOON
|
#include <Attributes.h>
|
||||||
#include "arch/Serial.h"
|
|
||||||
|
|
||||||
[[noreturn]] inline bool __check_failed(const char* string)
|
extern _noreturn bool __check_failed(const char* file, const char* line, const char* func, const char* expr);
|
||||||
{
|
|
||||||
Serial::print("CHECK FAILED: ");
|
|
||||||
Serial::println(string);
|
|
||||||
for (;;)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
[[noreturn]] inline bool __check_failed(const char*)
|
|
||||||
{
|
|
||||||
__builtin_trap();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define STRINGIZE(x) #x
|
#define STRINGIZE(x) #x
|
||||||
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
||||||
|
|
||||||
#define check(expr) (expr) || __check_failed("at " __FILE__ ":" STRINGIZE_VALUE_OF(__LINE__) ": " #expr)
|
#define check(expr) (expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr)
|
||||||
|
Loading…
Reference in New Issue
Block a user