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/lir/include/scc_lir_log.h
Normal file
26
libs/ir/lir/include/scc_lir_log.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __SCC_LIR_LOG_H__
|
||||
#define __SCC_LIR_LOG_H__
|
||||
|
||||
typedef struct logger logger_t;
|
||||
extern logger_t __scc_lir_log;
|
||||
extern logger_t __scc_lir_user;
|
||||
|
||||
#define SCC_LOG_HANDLER &__scc_lir_user
|
||||
#define LOG_DEFAULT_HANDLER &__scc_lir_log
|
||||
#include <scc_log.h>
|
||||
|
||||
#ifdef __SCC_LIR_LOG_IMPL__
|
||||
logger_t __scc_lir_log = {
|
||||
.name = "lir",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.handler = log_default_handler,
|
||||
};
|
||||
|
||||
logger_t __scc_lir_user = {
|
||||
.name = "lir",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.user_handler = scc_log_handler,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
* @file scc_hir2lir.c
|
||||
* @brief 将高级 IR (scc_ir) 降级为低层 LIR (scc_lir)
|
||||
*/
|
||||
#include <scc_lir_log.h>
|
||||
|
||||
#include <scc_hashtable.h>
|
||||
#include <scc_hir2lir.h>
|
||||
@@ -323,6 +324,7 @@ static void translate_hir_value(ir2lir_ctx_t *ctx, scc_hir_value_t *value,
|
||||
if (scc_hashtable_get(&ctx->value_to_vreg, (void *)(uintptr_t)value_ref))
|
||||
return;
|
||||
|
||||
LOG_TRACE("translate val_ref=%zu tag=%d", (size_t)value_ref, value->tag);
|
||||
u8 size_bits = 0;
|
||||
scc_lir_ext_t ext = SCC_LIR_EXT_NONE;
|
||||
ir_type_to_lir_size_ext(ctx->hir_module, value->type, &size_bits, &ext);
|
||||
@@ -643,6 +645,9 @@ static void translate_hir_value(ir2lir_ctx_t *ctx, scc_hir_value_t *value,
|
||||
|
||||
static void translate_func(ir2lir_ctx_t *ctx, scc_hir_func_t *ir_func) {
|
||||
scc_hir_func_meta_t *func_meta = SCC_HIR_FUNC_META(ir_func);
|
||||
LOG_DEBUG("translate func '%s' (%zu bblocks)",
|
||||
ir_func->name ? ir_func->name : "?",
|
||||
scc_vec_size(ir_func->bblocks));
|
||||
|
||||
scc_lir_func_meta_t *lir_func_meta =
|
||||
scc_malloc(sizeof(scc_lir_func_meta_t));
|
||||
@@ -689,6 +694,8 @@ static void translate_func(ir2lir_ctx_t *ctx, scc_hir_func_t *ir_func) {
|
||||
}
|
||||
|
||||
void scc_hir2lir(scc_lir_module_t *module, scc_hir_cprog_t *cprog) {
|
||||
LOG_INFO("HIR -> LIR lowering start (%zu funcs)",
|
||||
scc_vec_size(cprog->func_defs));
|
||||
Assert(module != nullptr && cprog != nullptr);
|
||||
|
||||
// FIXME
|
||||
|
||||
2
libs/ir/lir/src/scc_lir.c
Normal file
2
libs/ir/lir/src/scc_lir.c
Normal file
@@ -0,0 +1,2 @@
|
||||
#define __SCC_LIR_LOG_IMPL__
|
||||
#include <scc_lir_log.h>
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <scc_lir_log.h>
|
||||
|
||||
#include <scc_lir_module.h>
|
||||
|
||||
void scc_lir_module_init(scc_lir_module_t *lir_module) {
|
||||
@@ -13,7 +15,8 @@ void scc_lir_module_drop(scc_lir_module_t *lir_module) {
|
||||
scc_lir_symbol_meta_t *meta = lir_module->symbol_metas.data[i];
|
||||
usize cfg_idx = i + 1; /* cfg_module.symbols[0] is null sentinel */
|
||||
if (cfg_idx < scc_vec_size(lir_module->cfg_module.symbols)) {
|
||||
scc_cfg_symbol_t *sym = &lir_module->cfg_module.symbols.data[cfg_idx];
|
||||
scc_cfg_symbol_t *sym =
|
||||
&lir_module->cfg_module.symbols.data[cfg_idx];
|
||||
if (sym->kind == SCC_CFG_SYMBOL_KIND_DATA && meta->data.init_data) {
|
||||
scc_free(meta->data.init_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user