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 #ifndef MIR_DEBUG_LEVEL 39 #define MIR_DEBUG_LEVEL 0 40 #endif // MIR_DEBUG_LEVEL 41 // assertion 42 #if !MIR_FEATURE_FULL 43 #define MIR_ASSERT(...) \ 44 do { \ 45 } while (0) 46 #define MIR_PRINTF(...) \ 47 do { \ 48 } while (0) 49 #define MIR_INFO(...) \ 50 do { \ 51 } while (0) 52 #define MIR_ERROR(...) \ 53 do { \ 54 } while (0) 55 #define MIR_WARNING(...) \ 56 do { \ 57 } while (0) 58 #define MIR_CAST_TO(var, totype) ((totype)(var)) 59 #include <stdlib.h> 60 #if DEBUG // default no debug 61 #include <stdio.h> 62 #define MIR_FATAL(...) \ 63 do { \ 64 printf("FATAL ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 65 printf(__VA_ARGS__); \ 66 exit(1); \ 67 } while (0) 68 #else 69 #define MIR_FATAL(...) \ 70 do { \ 71 exit(1); \ 72 } while (0) 73 #endif // DEBUG 74 #else // MIR_FEATURE_FULL 75 #include <cassert> 76 #include <cstdio> 77 #include <cstdlib> 78 79 namespace maple { 80 #define MIR_ASSERT(...) assert(__VA_ARGS__) 81 82 #ifndef IS_RELEASE_VERSION 83 #define MIR_FATAL(...) \ 84 do { \ 85 fprintf(stderr, "FATAL ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 86 fprintf(stderr, __VA_ARGS__); \ 87 exit(EXIT_FAILURE); \ 88 } while (0) 89 #define MIR_ERROR(...) \ 90 do { \ 91 fprintf(stderr, "ERROR: (%s:%d) ", __FILE_NAME__, __LINE__); \ 92 fprintf(stderr, __VA_ARGS__); \ 93 } while (0) 94 #define MIR_WARNING(...) \ 95 do { \ 96 fprintf(stderr, "WARNING: (%s:%d) ", __FILE_NAME__, __LINE__); \ 97 fprintf(stderr, __VA_ARGS__); \ 98 } while (0) 99 #else 100 #define MIR_FATAL(...) \ 101 do { \ 102 fprintf(stderr, __VA_ARGS__); \ 103 exit(EXIT_FAILURE); \ 104 } while (0) 105 #define MIR_ERROR(...) \ 106 do { \ 107 fprintf(stderr, __VA_ARGS__); \ 108 } while (0) 109 #define MIR_WARNING(...) \ 110 do { \ 111 fprintf(stderr, __VA_ARGS__); \ 112 } while (0) 113 #endif // IS_RELEASE_VERSION 114 115 #define MIR_PRINTF(...) printf(__VA_ARGS__) 116 #define MIR_INFO(...) printf(__VA_ARGS__) 117 #define MIR_CAST_TO(var, totype) static_cast<totype>(var) 118 #endif // !MIR_FEATURE_FULL 119 #if MIR_DEBUG 120 #else 121 #endif // MIR_DEBUG 122 123 // MIR specific configurations. 124 // Note: fix size definition cannot handle arbitary long MIR lines, such 125 // as those array initialization lines. 126 constexpr int kMirMaxLineSize = 3072; // a max of 3K characters per line initially 127 // LIBRARY API availability 128 #if MIR_FEATURE_FULL 129 #define HAVE_STRTOD 1 // strtod 130 #define HAVE_MALLOC 1 // malloc/free 131 #else // compact VM 132 #define HAVE_STRTOD 1 // strtod in current libc 133 #define HAVE_MALLOC 0 // no malloc/free in current libc 134 #endif // MIR_FEATURE_FULL 135 136 #ifndef ALWAYS_INLINE 137 #define ALWAYS_INLINE __attribute__((always_inline)) 138 #endif 139 } // namespace maple 140 #endif // MAPLE_IR_INCLUDE_MIR_CONFIG_H 141