1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 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 http://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 TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 16 #define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 17 18 // If we're on a platform without standard IO functions, fall back to a 19 // non-portable function. 20 #ifdef TF_LITE_MCU_DEBUG_LOG 21 22 #include "tensorflow/lite/experimental/micro/micro_error_reporter.h" 23 24 #define DEBUG_LOG(x) \ 25 do { \ 26 DebugLog(x); \ 27 } while (0) 28 InfiniteLoop()29inline void InfiniteLoop() { 30 DEBUG_LOG("HALTED\n"); 31 while (1) { 32 } 33 } 34 #define TFLITE_ASSERT_FALSE InfiniteLoop(); 35 #define TFLITE_ABORT InfiniteLoop(); 36 37 #else // TF_LITE_MCU_DEBUG_LOG 38 39 #include <cassert> 40 #include <cstdio> 41 #include <cstdlib> 42 43 #define DEBUG_LOG(x) \ 44 do { \ 45 fprintf(stderr, "%s", (x)); \ 46 } while (0) 47 48 #define TFLITE_ASSERT_FALSE assert(false) 49 #define TFLITE_ABORT abort() 50 51 #endif // TF_LITE_MCU_DEBUG_LOG 52 53 #define TF_LITE_FATAL(msg) \ 54 do { \ 55 DEBUG_LOG(msg); \ 56 DEBUG_LOG("\nFATAL\n"); \ 57 TFLITE_ABORT; \ 58 } while (0) 59 60 #define TF_LITE_ASSERT(x) \ 61 do { \ 62 if (!(x)) TF_LITE_FATAL(#x); \ 63 } while (0) 64 65 #define TF_LITE_ASSERT_EQ(x, y) \ 66 do { \ 67 if ((x) != (y)) TF_LITE_FATAL(#x " didn't equal " #y); \ 68 } while (0) 69 70 #endif // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 71