1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_LITE_MICRO_CODER_LOG_H_ 18 #define MINDSPORE_LITE_MICRO_CODER_LOG_H_ 19 20 #include "src/common/log_adapter.h" 21 #include "include/errorcode.h" 22 #include "nnacl/op_base.h" 23 24 #define MS_CHECK_PTR(ptr) \ 25 do { \ 26 if ((ptr) == nullptr) { \ 27 MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \ 28 return mindspore::lite::RET_ERROR; \ 29 } \ 30 } while (0) 31 32 #define MS_CHECK_PTR_WITH_EXE(ptr, FUNC) \ 33 do { \ 34 if ((ptr) == nullptr) { \ 35 MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \ 36 FUNC; \ 37 return mindspore::lite::RET_ERROR; \ 38 } \ 39 } while (0) 40 41 #define MS_CHECK_PTR_RET_NULL(ptr) \ 42 do { \ 43 if ((ptr) == nullptr) { \ 44 MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \ 45 return nullptr; \ 46 } \ 47 } while (0) 48 49 #define MS_CHECK_RET_CODE(code, msg) \ 50 do { \ 51 if ((code) != RET_OK) { \ 52 MS_LOG(ERROR) << msg; \ 53 return mindspore::lite::RET_ERROR; \ 54 } \ 55 } while (0) 56 57 #define MS_CHECK_RET_CODE_WITH_EXE(code, msg, FUNC) \ 58 do { \ 59 if ((code) != RET_OK) { \ 60 MS_LOG(ERROR) << msg; \ 61 FUNC; \ 62 return mindspore::lite::RET_ERROR; \ 63 } \ 64 } while (0) 65 66 #define MS_CHECK_RET_CODE_RET_NULL(code, msg) \ 67 do { \ 68 if ((code) != RET_OK) { \ 69 MS_LOG(ERROR) << msg; \ 70 return nullptr; \ 71 } \ 72 } while (0) 73 74 #define MS_CHECK_TRUE(code, msg) \ 75 do { \ 76 if (!(code)) { \ 77 MS_LOG(ERROR) << msg; \ 78 return mindspore::lite::RET_ERROR; \ 79 } \ 80 } while (0) 81 82 #define MS_CHECK_TRUE_WITH_EXE(code, msg, FUNC) \ 83 do { \ 84 if (!(code)) { \ 85 MS_LOG(ERROR) << msg; \ 86 FUNC; \ 87 return mindspore::lite::RET_ERROR; \ 88 } \ 89 } while (0) 90 91 #define MS_CHECK_TRUE_WITHOUT_RET(code, msg) \ 92 do { \ 93 if (!(code)) { \ 94 MS_LOG(ERROR) << msg; \ 95 return; \ 96 } \ 97 } while (0) 98 99 #define MS_CHECK_TRUE_RET_NULL(code, msg) \ 100 do { \ 101 if (!(code)) { \ 102 MS_LOG(ERROR) << msg; \ 103 return nullptr; \ 104 } \ 105 } while (0) 106 107 #define MS_CHECK_TRUE_RET_BOOL(code, msg) \ 108 do { \ 109 if (!(code)) { \ 110 MS_LOG(ERROR) << msg; \ 111 return false; \ 112 } \ 113 } while (0) 114 115 #endif // MINDSPORE_LITE_MICRO_CODER_LOG_H_ 116