1 // Copyright 2019 The Marl Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef marl_debug_h 16 #define marl_debug_h 17 18 #include "export.h" 19 20 #if !defined(MARL_DEBUG_ENABLED) 21 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 22 #define MARL_DEBUG_ENABLED 1 23 #else 24 #define MARL_DEBUG_ENABLED 0 25 #endif 26 #endif 27 28 namespace marl { 29 30 MARL_EXPORT 31 void fatal(const char* msg, ...); 32 33 MARL_EXPORT 34 void warn(const char* msg, ...); 35 36 MARL_EXPORT 37 void assert_has_bound_scheduler(const char* feature); 38 39 #if MARL_DEBUG_ENABLED 40 #define MARL_FATAL(msg, ...) marl::fatal(msg "\n", ##__VA_ARGS__); 41 #define MARL_ASSERT(cond, msg, ...) \ 42 do { \ 43 if (!(cond)) { \ 44 MARL_FATAL("ASSERT: " msg, ##__VA_ARGS__); \ 45 } \ 46 } while (false); 47 #define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature) \ 48 assert_has_bound_scheduler(feature); 49 #define MARL_UNREACHABLE() MARL_FATAL("UNREACHABLE"); 50 #define MARL_WARN(msg, ...) marl::warn("WARNING: " msg "\n", ##__VA_ARGS__); 51 #else 52 #define MARL_FATAL(msg, ...) 53 #define MARL_ASSERT(cond, msg, ...) 54 #define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature) 55 #define MARL_UNREACHABLE() 56 #define MARL_WARN(msg, ...) 57 #endif 58 59 } // namespace marl 60 61 #endif // marl_debug_h 62