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,48 +0,0 @@
|
||||
#ifndef __SCC_LEXER_LOG_H__
|
||||
#define __SCC_LEXER_LOG_H__
|
||||
|
||||
#include <scc_core.h>
|
||||
|
||||
#ifndef LEX_LOG_LEVEL
|
||||
#define LEX_LOG_LEVEL 4
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 1
|
||||
#define LEX_NOTSET(fmt, ...) MLOG_NOTSET(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_NOTSET(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 2
|
||||
#define LEX_DEBUG(fmt, ...) MLOG_DEBUG(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 3
|
||||
#define LEX_INFO(fmt, ...) MLOG_INFO(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_INFO(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 4
|
||||
#define LEX_WARN(fmt, ...) MLOG_WARN(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_WARN(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 5
|
||||
#define LEX_ERROR(fmt, ...) MLOG_ERROR(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_ERROR(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if LEX_LOG_LEVEL <= 6
|
||||
#define LEX_FATAL(fmt, ...) MLOG_FATAL(&__scc_lexer_log, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LEX_FATAL(fmt, ...)
|
||||
#endif
|
||||
|
||||
extern logger_t __scc_lexer_log;
|
||||
|
||||
#endif /* __SCC_LEXER_LOG_H__ */
|
||||
26
libs/lexer/include/scc_lexer_log.h
Normal file
26
libs/lexer/include/scc_lexer_log.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __SCC_LEXER_LOG_H__
|
||||
#define __SCC_LEXER_LOG_H__
|
||||
|
||||
typedef struct logger logger_t;
|
||||
extern logger_t __scc_lexer_log;
|
||||
extern logger_t __scc_lexer_user;
|
||||
|
||||
#define SCC_LOG_HANDLER &__scc_lexer_user
|
||||
#define LOG_DEFAULT_HANDLER &__scc_lexer_log
|
||||
#include <scc_log.h>
|
||||
|
||||
#ifdef __SCC_LEXER_LOG_IMPL__
|
||||
logger_t __scc_lexer_log = {
|
||||
.name = "lexer",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.handler = log_default_handler,
|
||||
};
|
||||
|
||||
logger_t __scc_lexer_user = {
|
||||
.name = "lexer",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.user_handler = scc_log_handler,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __SCC_LEXER_LOG_H__ */
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <lexer_log.h>
|
||||
#define __SCC_LEXER_LOG_IMPL__
|
||||
#include <scc_lexer_log.h>
|
||||
|
||||
#include <scc_lexer.h>
|
||||
|
||||
static const struct {
|
||||
@@ -153,7 +155,7 @@ void scc_lexer_get_token(scc_lexer_t *lexer, scc_lexer_tok_t *token) {
|
||||
while (1) {
|
||||
if (!next_char(lexer, &lex, &cur)) {
|
||||
// 文件结束,注释未闭合
|
||||
LOG_ERROR("Unterminated block comment");
|
||||
SCC_ERROR(start_loc, "unterminated block comment");
|
||||
break;
|
||||
}
|
||||
if (cur.character == '*' && peek_char(lexer, &next) &&
|
||||
@@ -234,7 +236,7 @@ void scc_lexer_get_token(scc_lexer_t *lexer, scc_lexer_tok_t *token) {
|
||||
next_char(lexer, &lex, &cur); // 开头的 '
|
||||
while (1) {
|
||||
if (!peek_char(lexer, &cur)) {
|
||||
LOG_ERROR("Unterminated character literal");
|
||||
SCC_ERROR(start_loc, "unterminated character literal");
|
||||
break;
|
||||
}
|
||||
if (cur.character == '\'') {
|
||||
@@ -257,7 +259,7 @@ void scc_lexer_get_token(scc_lexer_t *lexer, scc_lexer_tok_t *token) {
|
||||
next_char(lexer, &lex, &cur); // 开头的 "
|
||||
while (1) {
|
||||
if (!peek_char(lexer, &cur)) {
|
||||
LOG_ERROR("Unterminated string literal");
|
||||
SCC_ERROR(start_loc, "unterminated string literal");
|
||||
break;
|
||||
}
|
||||
if (cur.character == '"') {
|
||||
@@ -487,7 +489,7 @@ void scc_lexer_get_token(scc_lexer_t *lexer, scc_lexer_tok_t *token) {
|
||||
token->type = token->type; // 上面已设
|
||||
token->loc = start_loc;
|
||||
token->lexeme = lex; // 转移所有权
|
||||
LEX_DEBUG("get token `%s` (%s) at %s:%d:%d", scc_get_tok_name(token->type),
|
||||
LOG_DEBUG("get token `%s` (%s) at %s:%d:%d", scc_get_tok_name(token->type),
|
||||
scc_str_as_cstr(&token->lexeme), token->loc.name, token->loc.line,
|
||||
token->loc.col);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include <lexer_log.h>
|
||||
|
||||
logger_t __scc_lexer_log = {
|
||||
.name = "lexer",
|
||||
.level = LOG_LEVEL_ALL,
|
||||
.handler = log_default_handler,
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
#define LEX_LOG_LEVEL 1
|
||||
#include <lexer_log.h>
|
||||
#include <scc_lexer.h>
|
||||
#include <stdbool.h>
|
||||
@@ -24,12 +25,11 @@ int g_num_arr[3];
|
||||
int main(int argc, char *argv[]) {
|
||||
// int num = 0;
|
||||
if (argc == 3 && strcmp(argv[2], "--debug") == 0) {
|
||||
log_set_level(nullptr, LOG_LEVEL_ALL);
|
||||
log_set_level(&__scc_lexer_log, LOG_LEVEL_ALL);
|
||||
} else {
|
||||
// FIXME it is a hack lexer_logger
|
||||
log_set_level(&__scc_lexer_log, LOG_LEVEL_NOTSET);
|
||||
log_set_level(nullptr, LOG_LEVEL_INFO | LOG_LEVEL_WARN |
|
||||
LOG_LEVEL_ERROR | LOG_LEVEL_FATAL);
|
||||
log_set_level(&__scc_lexer_log,
|
||||
LOG_LEVEL_INFO | LOG_LEVEL_WARN | LOG_LEVEL_ERROR |
|
||||
LOG_LEVEL_FATAL);
|
||||
}
|
||||
|
||||
const char *file_name = __FILE__;
|
||||
@@ -57,7 +57,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_INFO("get token [%-8s] `%s` at %s:%d:%d",
|
||||
LEX_INFO("get token [%-8s] `%s` at %s:%d:%d",
|
||||
scc_get_tok_name(token.type), scc_str_as_cstr(&token.lexeme),
|
||||
token.loc.name, token.loc.line, token.loc.col);
|
||||
scc_str_drop(&token.lexeme);
|
||||
@@ -65,6 +65,6 @@ int main(int argc, char *argv[]) {
|
||||
scc_sstream_drop_ring(ref);
|
||||
scc_sstream_drop(&stream);
|
||||
|
||||
LOG_INFO("Lexer is Ok...");
|
||||
LEX_INFO("Lexer is Ok...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user