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:
26
libs/ir/mir/include/scc_mir_log.h
Normal file
26
libs/ir/mir/include/scc_mir_log.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __SCC_MIR_LOG_H__
|
||||
#define __SCC_MIR_LOG_H__
|
||||
|
||||
typedef struct logger logger_t;
|
||||
extern logger_t __scc_mir_log;
|
||||
extern logger_t __scc_mir_user;
|
||||
|
||||
#define SCC_LOG_HANDLER &__scc_mir_user
|
||||
#define LOG_DEFAULT_HANDLER &__scc_mir_log
|
||||
#include <scc_log.h>
|
||||
|
||||
#ifdef __SCC_MIR_LOG_IMPL__
|
||||
logger_t __scc_mir_log = {
|
||||
.name = "mir",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.handler = log_default_handler,
|
||||
};
|
||||
|
||||
logger_t __scc_mir_user = {
|
||||
.name = "mir",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.user_handler = scc_log_handler,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <scc_mir_log.h>
|
||||
|
||||
#include <arch/scc_x86_mir.h>
|
||||
|
||||
static inline scc_x86_iform_t
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#include <scc_mir_log.h>
|
||||
|
||||
#include <arch/scc_x86_isel.h>
|
||||
#include <scc_lir2mir.h>
|
||||
#include <scc_mir_module.h>
|
||||
#include <target/scc_win64.h>
|
||||
|
||||
void scc_lir2mir(scc_mir_module_t *mir_module,
|
||||
const scc_lir_module_t *lir_module) {
|
||||
LOG_INFO("LIR -> MIR conversion (%zu funcs)",
|
||||
scc_vec_size(lir_module->cfg_module.funcs));
|
||||
// Move
|
||||
mir_module->cfg_module = lir_module->cfg_module;
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#define __SCC_MIR_LOG_IMPL__
|
||||
#include <scc_mir_log.h>
|
||||
|
||||
#include <scc_mir.h>
|
||||
|
||||
void scc_mir_func_meta_init(scc_mir_func_meta_t *func_meta) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <scc_mir_log.h>
|
||||
|
||||
#include <arch/scc_x86_mir.h>
|
||||
#include <arch/scc_x86_reg_alloc.h>
|
||||
#include <target/scc_win64.h>
|
||||
@@ -11,17 +13,23 @@
|
||||
|
||||
void scc_frame_layout(scc_frame_layout_t *ctx, scc_mir_module_t *module) {
|
||||
Assert(ctx && ctx->impl_fn && module);
|
||||
LOG_DEBUG(" frame layout for %zu funcs",
|
||||
scc_vec_size(module->cfg_module.funcs));
|
||||
scc_vec_foreach(module->cfg_module.funcs, i) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
scc_mir_func_t *func = &scc_vec_at(module->cfg_module.funcs, i);
|
||||
ctx->offset = SCC_MIR_FUNC_META(func)->frame_size;
|
||||
LOG_TRACE(" func[%zu] frame_size=%zu", (size_t)i,
|
||||
(size_t)ctx->offset);
|
||||
ctx->impl_fn(ctx, module, func);
|
||||
}
|
||||
}
|
||||
|
||||
void scc_prolog_epilog(scc_prolog_epilog_t *ctx, scc_mir_module_t *module) {
|
||||
Assert(ctx && ctx->epilog && ctx->prolog && module);
|
||||
LOG_DEBUG(" prolog/epilog for %zu funcs",
|
||||
scc_vec_size(module->cfg_module.funcs));
|
||||
scc_vec_foreach(module->cfg_module.funcs, i) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
@@ -58,29 +66,38 @@ void scc_prolog_epilog(scc_prolog_epilog_t *ctx, scc_mir_module_t *module) {
|
||||
}
|
||||
|
||||
void scc_mir_pass(scc_mir_module_t *mir_module, scc_mir_pass_stage_t stage) {
|
||||
LOG_INFO("running MIR passes (stage=%d, %zu funcs)", (int)stage,
|
||||
scc_vec_size(mir_module->cfg_module.funcs));
|
||||
|
||||
LOG_DEBUG(" pass 1/3: register allocation");
|
||||
scc_reg_alloc_ctx_t reg_alloc_ctx = {.func = nullptr, .ops = {0}};
|
||||
scc_reg_alloc_fill_arch_x86(®_alloc_ctx.ops);
|
||||
scc_win_pc_x64_reg_alloc_fill(®_alloc_ctx.ops);
|
||||
|
||||
scc_reg_alloc(®_alloc_ctx, mir_module);
|
||||
if (stage == SCC_MIR_STAGE_REGALLOC) {
|
||||
LOG_DEBUG(" stop after regalloc");
|
||||
return;
|
||||
}
|
||||
|
||||
void scc_x86_peephole_optimize(scc_mir_module_t * module);
|
||||
// scc_x86_peephole_optimize(mir_module);
|
||||
|
||||
LOG_DEBUG(" pass 2/3: frame layout");
|
||||
scc_frame_layout_t frame_layout_ctx = {0};
|
||||
scc_win_pc_x64_frame_layout_init(&frame_layout_ctx);
|
||||
scc_frame_layout(&frame_layout_ctx, mir_module);
|
||||
if (stage == SCC_MIR_STAGE_FRAME_LAYOUT) {
|
||||
LOG_DEBUG(" stop after frame layout");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DEBUG(" pass 3/3: prolog/epilog");
|
||||
scc_prolog_epilog_t prolog_epilog_ctx = {0};
|
||||
scc_win_pc_x64_prolog_epilog_init(&prolog_epilog_ctx);
|
||||
scc_prolog_epilog(&prolog_epilog_ctx, mir_module);
|
||||
if (stage == SCC_MIR_STAGE_PROLOGUE_EPILOGUE) {
|
||||
LOG_DEBUG(" stop after prolog/epilog");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user