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,26 @@
#ifndef __SCC_IR2MCODE_LOG_H__
#define __SCC_IR2MCODE_LOG_H__
typedef struct logger logger_t;
extern logger_t __scc_ir2mcode_log;
extern logger_t __scc_ir2mcode_user;
#define SCC_LOG_HANDLER &__scc_ir2mcode_user
#define LOG_DEFAULT_HANDLER &__scc_ir2mcode_log
#include <scc_log.h>
#ifdef __SCC_IR2MCODE_LOG_IMPL__
logger_t __scc_ir2mcode_log = {
.name = "ir2mcode",
.level = LOG_LEVEL_ALL,
.handler = log_default_handler,
};
logger_t __scc_ir2mcode_user = {
.name = "ir2mcode",
.level = LOG_LEVEL_ALL,
.user_handler = scc_log_handler,
};
#endif
#endif

View File

@@ -1,3 +1,6 @@
#define __SCC_IR2MCODE_LOG_IMPL__
#include <scc_ir2mcode_log.h>
#include <scc_ir2mcode.h>
#include <scc_mcode.h>
#include <scc_mir_module.h>
@@ -117,10 +120,13 @@ void scc_ir2mcode_patch(scc_mcode_t *mcode, scc_reloc_t *reloc, i64 value) {
void scc_ir2mcode(scc_mcode_t *mcode, scc_reloc_vec_t *relocs,
const scc_mir_module_t *mir_module) {
Assert(mir_module != nullptr && mcode != nullptr);
LOG_INFO("MIR -> machine code (%zu funcs)",
scc_vec_size(mir_module->cfg_module.funcs));
scc_vec_foreach(mir_module->cfg_module.funcs, i) {
if (i == 0)
continue;
scc_mir_func_t *func = &scc_vec_at(mir_module->cfg_module.funcs, i);
LOG_DEBUG(" func[%zu]: %s", (size_t)i, func->name ? func->name : "?");
scc_vec_foreach(func->bblocks, i) {
scc_cfg_bblock_id_t id = scc_vec_at(func->bblocks, i);
const scc_cfg_bblock_t *bb =

View File

@@ -1,3 +1,5 @@
#include <scc_ir2mcode_log.h>
#include <scc_ir2sccf.h>
static inline void scc_ir_sym_to_sccf_sym(const scc_cfg_symbol_t *symbol,
@@ -47,6 +49,8 @@ static inline void scc_ir_symbol_to_sect_data(const scc_cfg_symbol_t *symbol,
static void emit_mir_module(sccf_builder_t *builder, scc_mcode_t *mcode,
scc_mir_module_t *mir_module) {
LOG_DEBUG("emit MIR to SCCF (%zu funcs)",
scc_vec_size(mir_module->cfg_module.funcs));
scc_hashtable_t bblock_offset;
@@ -54,6 +58,8 @@ static void emit_mir_module(sccf_builder_t *builder, scc_mcode_t *mcode,
if (i == 0)
continue;
scc_mir_func_t *func = &scc_vec_at(mir_module->cfg_module.funcs, i);
LOG_DEBUG(" emit func[%zu] '%s'", (size_t)i,
func->name ? func->name : "?");
sccf_sym_t *sym = sccf_builder_get_symbol_unsafe(builder, func->name);
Assert(sym != nullptr);
@@ -111,8 +117,9 @@ static void emit_mir_module(sccf_builder_t *builder, scc_mcode_t *mcode,
}
void scc_ir2sccf(sccf_builder_t *builder, scc_mir_module_t *mir_module) {
// mir_module->symbol_metas
// mir_module->cfg_module.funcs
LOG_INFO("MIR -> SCCF conversion (%zu symbols, %zu funcs)",
scc_vec_size(mir_module->cfg_module.symbols),
scc_vec_size(mir_module->cfg_module.funcs));
sccf_builder_init(builder);
sccf_sect_data_t sect_data;
scc_vec_init(sect_data);