1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HCS_COMPILER_LOG_H 10 #define HCS_COMPILER_LOG_H 11 12 #include <stdio.h> 13 #include "hcs_types.h" 14 15 #ifdef DEBUG 16 #define HCS_DEBUG(fmt, args...) fprintf(stdout, fmt"\n", ##args) 17 #else 18 #define HCS_DEBUG(fmt, args...) do {} while (0) 19 #endif 20 21 #ifdef OS_LINUX 22 #define ERROR_COLOR_PREFIX "\033[31m" 23 #define ERROR_COLOR_END "\033[0m" 24 #else 25 #define ERROR_COLOR_PREFIX 26 #define ERROR_COLOR_END 27 #endif 28 29 #define HCS_LOG_PRINT(fmt, args...) fprintf(stdout, ERROR_COLOR_PREFIX fmt ERROR_COLOR_END"\n", ##args) 30 31 #define HCS_PRINT(fmt, args...) fprintf(stdout, fmt, ##args) 32 33 #define HCS_INFO(fmt, args...) fprintf(stdout, fmt"\n", ##args) 34 35 #define HCS_ERROR(fmt, args...) HCS_LOG_PRINT("Error: " fmt, ##args) 36 37 #define HCS_WARNING(fmt, args...) HCS_LOG_PRINT("Warning: " fmt, ##args) 38 39 #define HCS_OBJECT_PR(prefix, object, fmt, args...) \ 40 do { \ 41 HCS_LOG_PRINT(prefix": %s:%u\n\t" fmt"\n", \ 42 object ? ((ParserObjectBase*)object)->src : "unknown", \ 43 object ? ((ParserObjectBase*)object)->lineno : 0, \ 44 ##args); \ 45 } while (0) 46 47 #define HCS_OBJECT_ERROR(object, fmt, args...) HCS_OBJECT_PR("Error", object, fmt, ##args) 48 49 #define HCS_OBJECT_WARNING(object, fmt, args...) HCS_OBJECT_PR("Warning", object, fmt, ##args) 50 51 #define PRINTF_CHECK_AND_RETURN(printRes) \ 52 do { \ 53 if ((printRes) < 0) { \ 54 HCS_ERROR("Error:%s(%d), sprintf_s failed", \ 55 __FUNCTION__, __LINE__); \ 56 return EOUTPUT; \ 57 } \ 58 } while (0) 59 60 #define OUTPUT_CHECK_AND_RETURN(printRes) \ 61 do { \ 62 if ((printRes) < 0) { \ 63 HCS_ERROR("Error:%s(%d), output write failed", \ 64 __FUNCTION__, __LINE__); \ 65 return EOUTPUT; \ 66 } \ 67 } while (0) 68 69 70 #endif // HCS_COMPILER_LOG_H 71