refactor(log): 统一日志系统并添加链接器实现
- 为所有模块添加统一的 scc_*_log.h 日志头文件,删除旧的 lexer_log.h/c - 将运行时日志从 scc_utils 迁移到 scc_core 目录,统一日志管理 - 在解析器表达式/语句/类型解析中添加 LOG_TRACE 调试日志 - 实现 SCCF 链接器 (sccf_linker) 支持多目标文件链接 - 重构 CLI 主程序 (main.c/config.c),新增 cmd_log.h 调试支持 - 优化 x86 指令编码操作数对齐检查 - 修复预处理器的指令处理和宏展开逻辑
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#ifndef __SCC_POS_LOG_H__
|
||||
#define __SCC_POS_LOG_H__
|
||||
|
||||
#include "scc_pos.h"
|
||||
#include <scc_core.h>
|
||||
|
||||
extern logger_t __scc_pos_log;
|
||||
|
||||
#define SCC_POS_LOG(level, pos, fmt, ...) \
|
||||
do { \
|
||||
char _full_msg[LOGGER_MAX_BUF_SIZE]; \
|
||||
int _n = scc_snprintf(_full_msg, sizeof(_full_msg), \
|
||||
scc_pos_pnt_fmt ": ", scc_pos_pnt_val(pos)); \
|
||||
scc_snprintf(_full_msg + _n, sizeof(_full_msg) - _n, fmt, \
|
||||
##__VA_ARGS__); \
|
||||
__scc_pos_log.handler(&__scc_pos_log, level, nullptr, 0, nullptr, \
|
||||
"%s", _full_msg); \
|
||||
} while (0)
|
||||
|
||||
#define SCC_DEBUG(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_DEBUG, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_INFO(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_INFO, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_WARN(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_WARN, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_ERROR(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_ERROR, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_FATAL(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_FATAL, pos, fmt, ##__VA_ARGS__)
|
||||
|
||||
#endif /* __SCC_POS_LOG_H__ */
|
||||
@@ -45,7 +45,8 @@ void scc_hashtable_usize_init(scc_hashtable_t *ht) {
|
||||
}
|
||||
|
||||
static usize next_power_of_two(usize n) {
|
||||
if (n == 0) return 32;
|
||||
if (n == 0)
|
||||
return 32;
|
||||
n--;
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
@@ -56,8 +57,8 @@ static usize next_power_of_two(usize n) {
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
static scc_hashtable_entry_t *find_entry(scc_hashtable_t *ht, const void *key,
|
||||
u32 hash) {
|
||||
static scc_hashtable_entry_t *find_entry(const scc_hashtable_t *ht,
|
||||
const void *key, u32 hash) {
|
||||
if (ht->entries.cap == 0)
|
||||
return nullptr;
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#include <scc_pos_log.h>
|
||||
|
||||
static int pos_log_handler(logger_t *module, log_level_t level,
|
||||
const char *file, int line, const char *func,
|
||||
const char *fmt, ...) {
|
||||
|
||||
/* clang-format off */
|
||||
(void) module, (void)file, (void)line, (void)func; // 不再使用
|
||||
|
||||
const char *level_str = nullptr;
|
||||
switch (level) {
|
||||
case LOG_LEVEL_DEBUG: level_str = "DEBUG"; break;
|
||||
case LOG_LEVEL_INFO: level_str = "INFO "; break;
|
||||
case LOG_LEVEL_WARN: level_str = "WARN "; break;
|
||||
case LOG_LEVEL_ERROR: level_str = "ERROR"; break;
|
||||
case LOG_LEVEL_FATAL: level_str = "FATAL"; break;
|
||||
case LOG_LEVEL_TRACE: level_str = "TRACE"; break;
|
||||
default: level_str = "NOTSET"; break;
|
||||
}
|
||||
/// @note: 定义 __LOG_NO_COLOR__ 会取消颜色输出
|
||||
#ifndef __LOG_NO_COLOR__
|
||||
const char *color_code;
|
||||
switch (level) {
|
||||
case LOG_LEVEL_DEBUG: color_code = ANSI_FG_CYAN; break;
|
||||
case LOG_LEVEL_INFO: color_code = ANSI_FG_GREEN; break;
|
||||
case LOG_LEVEL_TRACE: color_code = ANSI_FG_BLUE; break;
|
||||
case LOG_LEVEL_WARN: color_code = ANSI_FG_YELLOW; break;
|
||||
case LOG_LEVEL_ERROR: color_code = ANSI_FG_RED; break;
|
||||
case LOG_LEVEL_FATAL: color_code = ANSI_FG_RED ANSI_UNDERLINED; break;
|
||||
default: color_code = ANSI_NONE;
|
||||
}
|
||||
#endif
|
||||
/* clang-format on */
|
||||
char buf[LOGGER_MAX_BUF_SIZE];
|
||||
int off = scc_snprintf(buf, sizeof(buf), "%s[%s]%s ",
|
||||
color_code ? color_code : "", level_str,
|
||||
color_code ? ANSI_NONE : "");
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
scc_vsnprintf(buf + off, sizeof(buf) - off, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
log_puts(buf);
|
||||
log_puts("\n");
|
||||
|
||||
if (level == LOG_LEVEL_FATAL) {
|
||||
log_abort();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
logger_t __scc_pos_log = {
|
||||
.name = "pos_log",
|
||||
.handler = pos_log_handler,
|
||||
.level = LOG_LEVEL_ALL,
|
||||
};
|
||||
Reference in New Issue
Block a user