1 /* 2 * Copyright 2019 WebAssembly Community Group participants 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 // Implements BYN_DEBUG macro similar to llvm's include/llvm/Support/Debug.h, 18 // which can include any code, and in addition and printf-file BYN_TRACE. 19 // 20 // To use these macros you must define DEBUG_TYPE to a C string within your 21 // source code which then acts as the name of a channel which can be 22 // individually enabled via --debug=<chan>. Specifying --debug without any 23 // argument enables all channels. 24 25 #ifndef wasm_support_debug_h 26 #define wasm_support_debug_h 27 28 #ifndef NDEBUG 29 30 namespace wasm { 31 bool isDebugEnabled(const char* type); 32 void setDebugEnabled(const char* types); 33 } // namespace wasm 34 35 #define BYN_DEBUG_WITH_TYPE(TYPE, X) \ 36 do { \ 37 if (::wasm::isDebugEnabled(TYPE)) { \ 38 X; \ 39 } \ 40 } while (false) 41 42 #define BYN_TRACE_WITH_TYPE(TYPE, MSG) \ 43 BYN_DEBUG_WITH_TYPE(TYPE, std::cerr << MSG); 44 45 #else 46 47 // We have an option to build with assertions disabled 48 // BYN_ASSERTIONS_ENABLED=OFF, but we currently don't recommend using and we 49 // don't test with it. 50 #error "binaryen is currently designed to be built with assertions enabled." 51 #error "remove these #errors if you want to build without them anyway." 52 53 #define BYN_DEBUG_WITH_TYPE(...) \ 54 do { \ 55 } while (false) 56 #define BYN_TRACE_WITH_TYPE(...) \ 57 do { \ 58 } while (false) 59 #define isDebugEnabled(type) (false) 60 #define setDebugEnabled(types) 61 62 #endif 63 64 #define BYN_DEBUG(X) BYN_DEBUG_WITH_TYPE(DEBUG_TYPE, X) 65 #define BYN_TRACE(MSG) BYN_TRACE_WITH_TYPE(DEBUG_TYPE, MSG) 66 67 #endif // wasm_support_debug_h 68