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 62 #include <stdio.h> 63 #define MIR_FATAL(...) \ 64 do { \ 65 printf("FATAL ERROR: (%s:%d) ", __FILE__, __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 #define MIR_FATAL(...) \ 83 do { \ 84 fprintf(stderr, "FATAL ERROR: (%s:%d) ", __FILE__, __LINE__); \ 85 fprintf(stderr, __VA_ARGS__); \ 86 exit(EXIT_FAILURE); \ 87 } while (0) 88 #define MIR_ERROR(...) \ 89 do { \ 90 fprintf(stderr, "ERROR: (%s:%d) ", __FILE__, __LINE__); \ 91 fprintf(stderr, __VA_ARGS__); \ 92 } while (0) 93 #define MIR_WARNING(...) \ 94 do { \ 95 fprintf(stderr, "WARNING: (%s:%d) ", __FILE__, __LINE__); \ 96 fprintf(stderr, __VA_ARGS__); \ 97 } while (0) 98 #define MIR_PRINTF(...) printf(__VA_ARGS__) 99 #define MIR_INFO(...) printf(__VA_ARGS__) 100 #define MIR_CAST_TO(var, totype) static_cast<totype>(var) 101 #endif // !MIR_FEATURE_FULL 102 #if MIR_DEBUG 103 #else 104 #endif // MIR_DEBUG 105 106 // MIR specific configurations. 107 // Note: fix size definition cannot handle arbitary long MIR lines, such 108 // as those array initialization lines. 109 constexpr int kMirMaxLineSize = 3072; // a max of 3K characters per line initially 110 // LIBRARY API availability 111 #if MIR_FEATURE_FULL 112 #define HAVE_STRTOD 1 // strtod 113 #define HAVE_MALLOC 1 // malloc/free 114 #else // compact VM 115 #define HAVE_STRTOD 1 // strtod in current libc 116 #define HAVE_MALLOC 0 // no malloc/free in current libc 117 #endif // MIR_FEATURE_FULL 118 } // namespace maple 119 #endif // MAPLE_IR_INCLUDE_MIR_CONFIG_H 120