- 在scc_ast2ir_ctx_t中添加ast_ctx字段用于访问AST上下文 - 修改scc_ast2ir_ctx_init函数签名以接收ast_ctx参数 - 修复enum类型的处理逻辑,使用正确的内置类型获取方式 - 修正for循环控制流中错误的跳转目标 - 移除未使用的parse_struct_union_layout函数 refactor(cfg): 优化模块接口的const正确性 - 将scc_cfg_module_unsafe_get_*系列函数的module参数标记为const - 提高接口的安全性和一致性 refactor(lir): 简化寄存器定义宏 - 移除未使用的SCC_LIR_PREG宏定义 - 简化头文件中的冗余声明 fix(hir2lir): 修复空指针常量的表示方式 - 修正NULL值的AP整数表示,正确初始化ap结构体字段 - 确保空指针在低级IR中被正确表示 refactor(mir): 重构函数元数据结构 - 为MIR函数元数据添加栈槽位和寄存器分配相关字段 - 定义新的栈槽位数据结构scc_mir_stack_slot_t - 添加函数元数据初始化函数scc_mir_func_meta_init refactor(x86): 改进后端代码生成 - 修正ret指令生成,使用近返回指令RET_NEAR - 修复伪alloca指令的形式转换问题 - 改进选择函数的const正确性 - 正确初始化函数元数据结构 style(config): 添加MIR阶段配置选项 - 为MIR各个处理阶段添加配置标志 - 包括寄存器分配、栈布局和前言后记生成的输出选项 fix(parser): 改进错误处理机制 - 修正语义分析上下文变量命名 - 添加解析错误码检查,及时返回错误状态
120 lines
4.3 KiB
C
120 lines
4.3 KiB
C
#ifndef __SCC_CFG_H__
|
|
#define __SCC_CFG_H__
|
|
|
|
#include <scc_core.h>
|
|
#include <scc_hashtable.h>
|
|
|
|
#define SCC_CFG_ID_nullptr (0)
|
|
typedef usize scc_cfg_id_t;
|
|
typedef scc_cfg_id_t scc_cfg_bblock_id_t;
|
|
typedef scc_cfg_id_t scc_cfg_func_id_t;
|
|
typedef scc_cfg_id_t scc_cfg_symbol_id_t;
|
|
|
|
typedef SCC_VEC(scc_cfg_bblock_id_t) scc_cfg_bblock_id_vec_t;
|
|
typedef SCC_VEC(void *) scc_cfg_value_vec_t;
|
|
typedef struct scc_cfg_module scc_cfg_module_t;
|
|
typedef struct scc_cfg_func scc_cfg_func_t;
|
|
typedef struct scc_cfg_bblock scc_cfg_bblock_t;
|
|
typedef struct scc_cfg_symbol scc_cfg_symbol_t;
|
|
|
|
struct scc_cfg_bblock {
|
|
scc_cfg_bblock_id_t id;
|
|
const char *name;
|
|
scc_cfg_bblock_id_vec_t preds; // 前驱
|
|
scc_cfg_bblock_id_vec_t succs; // 后继
|
|
scc_cfg_value_vec_t values; // using cast
|
|
void *meta;
|
|
};
|
|
|
|
struct scc_cfg_func {
|
|
const char *name;
|
|
|
|
scc_cfg_bblock_id_t next_bblock_id;
|
|
scc_cfg_bblock_id_vec_t bblocks;
|
|
scc_hashtable_t bblock_map; // id -> index
|
|
|
|
scc_cfg_bblock_id_t entry_bblock_id; // maybe it will always 0
|
|
void *meta;
|
|
};
|
|
|
|
typedef enum {
|
|
SCC_CFG_SYMBOL_KIND_FUNC,
|
|
SCC_CFG_SYMBOL_KIND_DATA,
|
|
SCC_CFG_SYMBOL_KIND_EXTERN,
|
|
} scc_cfg_symbol_kind_t;
|
|
|
|
typedef enum {
|
|
SCC_CFG_SYMBOL_LINK_GLOABL,
|
|
SCC_CFG_SYMBOL_LINK_LOCAL,
|
|
} scc_cfg_symbol_linkage_t;
|
|
|
|
struct scc_cfg_symbol {
|
|
const char *name;
|
|
scc_cfg_symbol_kind_t kind;
|
|
scc_cfg_symbol_linkage_t linkage;
|
|
void *meta;
|
|
};
|
|
|
|
typedef SCC_VEC(scc_cfg_bblock_t) scc_cfg_bblock_vec_t;
|
|
typedef SCC_VEC(scc_cfg_func_t) scc_cfg_func_vec_t;
|
|
typedef SCC_VEC(scc_cfg_symbol_t) scc_cfg_symbol_vec_t;
|
|
struct scc_cfg_module {
|
|
scc_cfg_bblock_vec_t bblocks;
|
|
scc_cfg_func_vec_t funcs; /* 所有函数定义(按添加顺序) */
|
|
scc_cfg_symbol_vec_t symbols; /* 全局符号表 */
|
|
scc_hashtable_t symbol_map; /* 名称 -> 索引 */
|
|
};
|
|
|
|
void scc_cfg_module_init(scc_cfg_module_t *module);
|
|
/**
|
|
* @brief
|
|
*
|
|
* @param module
|
|
* @warning 由于void*存在可能导致严重内存泄漏
|
|
*/
|
|
void scc_cfg_module_drop(scc_cfg_module_t *module);
|
|
scc_cfg_func_id_t scc_cfg_module_add_func(scc_cfg_module_t *module,
|
|
const scc_cfg_func_t *func);
|
|
scc_cfg_func_t *scc_cfg_module_unsafe_get_func(const scc_cfg_module_t *module,
|
|
scc_cfg_func_id_t id);
|
|
scc_cfg_bblock_id_t scc_cfg_module_add_bblock(scc_cfg_module_t *module,
|
|
const scc_cfg_bblock_t *bblock);
|
|
scc_cfg_bblock_t *
|
|
scc_cfg_module_unsafe_get_bblock(const scc_cfg_module_t *module,
|
|
scc_cfg_bblock_id_t id);
|
|
scc_cfg_symbol_id_t scc_cfg_module_add_symbol(scc_cfg_module_t *module,
|
|
const scc_cfg_symbol_t *symbol);
|
|
scc_cfg_symbol_t *
|
|
scc_cfg_module_unsafe_get_symbol(const scc_cfg_module_t *module,
|
|
scc_cfg_symbol_id_t id);
|
|
scc_cfg_symbol_id_t scc_cfg_module_lookup_symbol(const scc_cfg_module_t *module,
|
|
const char *name);
|
|
|
|
static inline const scc_cfg_symbol_t *
|
|
scc_cfg_module_unsafe_lookup_symbol(const scc_cfg_module_t *module,
|
|
const char *name) {
|
|
scc_cfg_id_t idx = scc_cfg_module_lookup_symbol(module, name);
|
|
if (idx == 0) {
|
|
Panic("Can't find symbol %s", name);
|
|
return nullptr;
|
|
}
|
|
return &scc_vec_at(module->symbols, idx);
|
|
}
|
|
|
|
// scc_cfg_bblock_id_t scc_cfg_func_add_bblock(scc_cfg_func_t *func,
|
|
// const scc_cfg_bblock_t *bblock);
|
|
// scc_cfg_bblock_t *scc_cfg_func_unsafe_get_bblock(scc_cfg_func_t *func,
|
|
// scc_cfg_bblock_id_t id);
|
|
// scc_cfg_bblock_t *scc_cfg_func_unsafe_entry_bblock(scc_cfg_func_t *func);
|
|
|
|
void scc_cfg_bblock_add_pred(scc_cfg_bblock_t *bb, scc_cfg_bblock_id_t pred_id);
|
|
void scc_cfg_bblock_remove_pred(scc_cfg_bblock_t *bb,
|
|
scc_cfg_bblock_id_t pred_id);
|
|
void scc_cfg_bblock_clear_pred(scc_cfg_bblock_t *bb);
|
|
void scc_cfg_bblock_add_succ(scc_cfg_bblock_t *bb, scc_cfg_bblock_id_t succ_id);
|
|
void scc_cfg_bblock_remove_succ(scc_cfg_bblock_t *bb,
|
|
scc_cfg_bblock_id_t succ_id);
|
|
void scc_cfg_bblock_clear_succs(scc_cfg_bblock_t *bb);
|
|
|
|
#endif /* __SCC_CFG_H__ */
|