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:
zzy
2026-06-05 13:07:41 +08:00
parent 0acea43e4e
commit 88846d7479
70 changed files with 1497 additions and 469 deletions

View File

@@ -0,0 +1,54 @@
#include <scc_log.h>
int scc_log_handler(logger_t *module, log_level_t level, const char *file,
int line, int col, const char *fmt, ...) {
/* clang-format off */
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 offset =
scc_snprintf(module->buf, sizeof(module->buf), "%s[%s] %s - %s:%d:%d%s",
color_code ? color_code : "", level_str, module->name,
file, line, col, color_code ? ANSI_NONE : "");
va_list args;
va_start(args, fmt);
scc_vsnprintf(module->buf + offset, sizeof(module->buf) - offset, fmt,
args);
va_end(args);
log_puts(buf);
if (level == LOG_LEVEL_FATAL) {
log_abort();
}
return 0;
}
logger_t __scc_pos_log = {
.name = "pos_log",
.user_handler = scc_log_handler,
.level = LOG_LEVEL_ALL,
};