Compare commits

...

3 Commits

9 changed files with 32 additions and 21 deletions

View File

@ -1,4 +1,5 @@
#include "arch/Serial.h"
#include "arch/CPU.h"
#include <Format.h>
namespace Serial
@ -33,4 +34,16 @@ namespace Serial
va_end(ap);
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();
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <FormatAttribute.h>
#include <Attributes.h>
#include <Types.h>
template <typename T> class Result;

6
luna/Attributes.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#define _weak __attribute__((weak))
#define _format(n, m) __attribute__((format(printf, n, m)))
#define _align(x) __attribute__((aligned(x)))
#define _noreturn __attribute__((noreturn))

View File

@ -6,6 +6,7 @@ set(FREESTANDING_SOURCES
set(SOURCES
${FREESTANDING_SOURCES}
Check.cpp
)
add_library(luna-freestanding ${FREESTANDING_SOURCES})

6
luna/Check.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <Attributes.h>
_weak _noreturn bool __check_failed(const char*, const char*, const char*, const char*)
{
__builtin_trap();
}

View File

@ -1,22 +1,9 @@
#pragma once
#ifdef IN_MOON
#include "arch/Serial.h"
#include <Attributes.h>
[[noreturn]] inline bool __check_failed(const char* string)
{
Serial::print("CHECK FAILED: ");
Serial::println(string);
for (;;)
;
}
#else
[[noreturn]] inline bool __check_failed(const char*)
{
__builtin_trap();
}
#endif
extern _noreturn bool __check_failed(const char* file, const char* line, const char* func, const char* expr);
#define STRINGIZE(x) #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)

View File

@ -1,3 +1,4 @@
#include <CType.h>
#include <Format.h>
#include <NumberParsing.h>

View File

@ -1,6 +1,5 @@
#pragma once
#include <CType.h>
#include <FormatAttribute.h>
#include <Attributes.h>
#include <Result.h>
#include <stdarg.h>

View File

@ -1,2 +0,0 @@
#pragma once
#define _format(n, m) __attribute__((format(printf, n, m)))