diff options
-rw-r--r-- | asl/BUILD.bazel | 17 | ||||
-rw-r--r-- | asl/base/BUILD.bazel | 7 | ||||
-rw-r--r-- | asl/base/assert.hpp | 20 | ||||
-rw-r--r-- | asl/base/bit.hpp | 4 | ||||
-rw-r--r-- | asl/base/config.hpp | 10 | ||||
-rw-r--r-- | asl/logging/logging.hpp | 29 | ||||
-rw-r--r-- | asl/types/span.hpp | 2 |
7 files changed, 71 insertions, 18 deletions
diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel new file mode 100644 index 0000000..aa76d47 --- /dev/null +++ b/asl/BUILD.bazel @@ -0,0 +1,17 @@ +# Copyright 2025 Steven Le Rouzic +# +# SPDX-License-Identifier: BSD-3-Clause + +config_setting( + name = "debug", + values = { + "compilation_mode": "dbg", + }, +) + +config_setting( + name = "optimized", + values = { + "compilation_mode": "opt", + }, +) diff --git a/asl/base/BUILD.bazel b/asl/base/BUILD.bazel index 7870ad9..6c90f06 100644 --- a/asl/base/BUILD.bazel +++ b/asl/base/BUILD.bazel @@ -24,6 +24,13 @@ cc_library( srcs = [ "assert.cpp", ], + defines = select({ + "//asl:debug": ["ASL_DEBUG=1"], + "//conditions:default": ["ASL_DEBUG=0"], + }) + select({ + "//asl:optimized": ["ASL_OPTIMIZED=1"], + "//conditions:default": ["ASL_OPTIMIZED=0"], + }), visibility = ["//visibility:public"], ) diff --git a/asl/base/assert.hpp b/asl/base/assert.hpp index 5aeb161..a899564 100644 --- a/asl/base/assert.hpp +++ b/asl/base/assert.hpp @@ -24,15 +24,17 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l #define ASL_DEBUG_BREAK() __builtin_debugtrap() #endif -// @Todo Configure asserts at build time - -#define ASL_ASSERT(...) \ - if (__VA_ARGS__) {} \ - else \ - { \ - ::asl::report_assert_failure(#__VA_ARGS__); \ - ASL_DEBUG_BREAK(); \ - } +#if !ASL_OPTIMIZED + #define ASL_ASSERT(...) \ + if (__VA_ARGS__) {} \ + else \ + { \ + ::asl::report_assert_failure(#__VA_ARGS__); \ + ASL_DEBUG_BREAK(); \ + } +#else + #define ASL_ASSERT(...) +#endif #define ASL_ASSERT_RELEASE(...) \ if (__VA_ARGS__) {} \ diff --git a/asl/base/bit.hpp b/asl/base/bit.hpp index 5056383..824005c 100644 --- a/asl/base/bit.hpp +++ b/asl/base/bit.hpp @@ -114,7 +114,7 @@ constexpr T rotl(T v, int s) // NOLINT(*-no-recursion) { static constexpr int N = sizeof(decltype(v)) * 8; s = s % N; - return (s >= 0) ? (v << s) | (v >> (N - s)) : rotr(v, -s); + return (s >= 0) ? (v << s) | (v >> ((N - s) % N)) : rotr(v, -s); } template<is_unsigned_integer T> @@ -122,7 +122,7 @@ constexpr T rotr(T v, int s) // NOLINT(*-no-recursion) { static constexpr int N = sizeof(decltype(v)) * 8; s = s % N; - return (s >= 0) ? (v >> s) | (v << (N - s)) : rotl(v, -s); + return (s >= 0) ? (v >> s) | (v << ((N - s) % N)) : rotl(v, -s); } constexpr uint16_t byteswap(uint16_t v) diff --git a/asl/base/config.hpp b/asl/base/config.hpp index f5756c3..e4e6e5d 100644 --- a/asl/base/config.hpp +++ b/asl/base/config.hpp @@ -22,5 +22,15 @@ #error Unknown compiler #endif +// ASL_DEBUG=1 for slow builds, with extra validation logic and such. +#if !defined(ASL_DEBUG) + #error ASL_DEBUG should be defined to 0 or 1 +#endif + +// ASL_OPTIMIZED=1 for fast builds, with minimal validation logic. +#if !defined(ASL_OPTIMIZED) + #error ASL_OPTIMIZED should be defined to 0 or 1 +#endif + // NOLINTEND(*-macro-to-enum) diff --git a/asl/logging/logging.hpp b/asl/logging/logging.hpp index 9774927..6b8192b 100644 --- a/asl/logging/logging.hpp +++ b/asl/logging/logging.hpp @@ -87,9 +87,26 @@ void log(level l, const source_location& sl, string_view fmt, const Args&... arg } // namespace asl::log -// @Todo Compile-time configuration of logging - -#define ASL_LOG_DEBUG(...) ::asl::log::log(::asl::log::kDebug, ::asl::source_location{}, __VA_ARGS__) -#define ASL_LOG_INFO(...) ::asl::log::log(::asl::log::kInfo, ::asl::source_location{}, __VA_ARGS__) -#define ASL_LOG_WARNING(...) ::asl::log::log(::asl::log::kWarning, ::asl::source_location{}, __VA_ARGS__) -#define ASL_LOG_ERROR(...) ::asl::log::log(::asl::log::kError, ::asl::source_location{}, __VA_ARGS__) +#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 4 + #define ASL_LOG_DEBUG(...) ::asl::log::log(::asl::log::kDebug, ::asl::source_location{}, __VA_ARGS__) +#else + #define ASL_LOG_DEBUG(...) +#endif + +#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 3 + #define ASL_LOG_INFO(...) ::asl::log::log(::asl::log::kInfo, ::asl::source_location{}, __VA_ARGS__) +#else + #define ASL_LOG_DEBUG(...) +#endif + +#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 2 + #define ASL_LOG_WARNING(...) ::asl::log::log(::asl::log::kWarning, ::asl::source_location{}, __VA_ARGS__) +#else + #define ASL_LOG_DEBUG(...) +#endif + +#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 1 + #define ASL_LOG_ERROR(...) ::asl::log::log(::asl::log::kError, ::asl::source_location{}, __VA_ARGS__) +#else + #define ASL_LOG_DEBUG(...) +#endif diff --git a/asl/types/span.hpp b/asl/types/span.hpp index af33ece..1ebef10 100644 --- a/asl/types/span.hpp +++ b/asl/types/span.hpp @@ -68,7 +68,7 @@ public: , m_size{size} {} - constexpr explicit span(T* data, isize_t size) + constexpr explicit span(T* data, [[maybe_unused]] isize_t size) requires (!kIsDynamic) : m_data{data} { |