1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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 16 // configuration definition for code in maple_ir namespace 17 #ifndef MAPLE_IR_INCLUDE_MIR_CONFIG_H 18 #define MAPLE_IR_INCLUDE_MIR_CONFIG_H 19 20 // MIR_FEATURE_FULL = 1 : for host/server size building, by default. 21 // MIR_FEATURE_FULL = 0 : for resource-constrained devices. optimized for memory size 22 #if !defined(MIR_FEATURE_FULL) 23 #define MIR_FEATURE_FULL 1 // default to full feature building, for debugging 24 #endif // MIR_FEATURE_FULL define 25 26 // MIR_DEBUG = 0 : for release building. 27 // MIR_DEBUG = 1 : for debug building. 28 #ifndef MIR_DEBUG 29 #define MIR_DEBUG 0 // currently default to none. turn it on explicitly 30 #endif // MIR_DEBUG 31 32 // MIR_DEBUG_LEVEL = 0: no debuging information at all. 33 // 1: with error information. 34 // 2: with severe warning information 35 // 3: with normal warning information 36 // 4: with normal information 37 // 5: with everything 38 // 39 #ifndef MIR_DEBUG_LEVEL 40 #define MIR_DEBUG_LEVEL 0 41 #endif // MIR_DEBUG_LEVEL 42 // assertion 43 #if !MIR_FEATURE_FULL 44 #define MIR_ASSERT(...) \ 45 do { \ 46 } while (0) 47 #define MIR_PRINTF(...) \ 48 do { \ 49 } while (0) 50 #define MIR_INFO(...) \ 51 do { \ 52 } while (0) 53 #define MIR_ERROR(...) \ 54 do { \ 55 } while (0) 56 #define MIR_WARNING(...) \ 57 do { \ 58 } while (0) 59 #define MIR_CAST_TO(var, totype) ((totype)(var)) 60 #include <stdlib.h> 61 #if DEBUG // default no debug 62 #include <stdio.h> 63 #define MIR_FATAL(...) \ 64 do { \ 65 printf("FATAL ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 66 printf(__VA_ARGS__); \ 67 exit(1); \ 68 } while (0) 69 #else 70 #define MIR_FATAL(...) \ 71 do { \ 72 exit(1); \ 73 } while (0) 74 #endif // DEBUG 75 #else // MIR_FEATURE_FULL 76 #include <cassert> 77 #include <cstdio> 78 #include <cstdlib> 79 80 namespace maple { 81 #define MIR_ASSERT(...) assert(__VA_ARGS__) 82 83 #ifndef IS_RELEASE_VERSION 84 #define MIR_FATAL(...) \ 85 do { \ 86 fprintf(stderr, "FATAL ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 87 fprintf(stderr, __VA_ARGS__); \ 88 exit(EXIT_FAILURE); \ 89 } while (0) 90 #define MIR_ERROR(...) \ 91 do { \ 92 fprintf(stderr, "ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 93 fprintf(stderr, __VA_ARGS__); \ 94 } while (0) 95 #define MIR_WARNING(...) \ 96 do { \ 97 fprintf(stderr, "WARNING: (%s:%d) ", __FILE_NAME__, __LINE__); \ 98 fprintf(stderr, __VA_ARGS__); \ 99 } while (0) 100 #else 101 #define MIR_FATAL(...) \ 102 do { \ 103 fprintf(stderr, __VA_ARGS__); \ 104 exit(EXIT_FAILURE); \ 105 } while (0) 106 #define MIR_ERROR(...) \ 107 do { \ 108 fprintf(stderr, __VA_ARGS__); \ 109 } while (0) 110 #define MIR_WARNING(...) \ 111 do { \ 112 fprintf(stderr, __VA_ARGS__); \ 113 } while (0) 114 #endif // IS_RELEASE_VERSION 115 116 #define MIR_PRINTF(...) printf(__VA_ARGS__) 117 #define MIR_INFO(...) printf(__VA_ARGS__) 118 #define MIR_CAST_TO(var, totype) static_cast<totype>(var) 119 #endif // !MIR_FEATURE_FULL 120 #if MIR_DEBUG 121 #else 122 #endif // MIR_DEBUG 123 124 // MIR specific configurations. 125 // Note: fix size definition cannot handle arbitary long MIR lines, such 126 // as those array initialization lines. 127 constexpr int kMirMaxLineSize = 3072; // a max of 3K characters per line initially 128 // LIBRARY API availability 129 #if MIR_FEATURE_FULL 130 #define HAVE_STRTOD 1 // strtod 131 #define HAVE_MALLOC 1 // malloc/free 132 #else // compact VM 133 #define HAVE_STRTOD 1 // strtod in current libc 134 #define HAVE_MALLOC 0 // no malloc/free in current libc 135 #endif // MIR_FEATURE_FULL 136 137 #ifndef ALWAYS_INLINE 138 #define ALWAYS_INLINE __attribute__((always_inline)) 139 #endif 140 } // namespace maple 141 #endif // MAPLE_IR_INCLUDE_MIR_CONFIG_H 142