feat(ast): 添加汇编器模块并改进AST定义和IR转换
- 在README.md中添加asm汇编器模块说明 - 更新ast_def.h中的枚举注释,添加sema相关信息以明确语义分析作用域 - 重命名函数参数param_types为params,使命名更清晰 - 移除call表达式中的_target字段,简化结构 - 为member、identifier等字段添加///< fill by sema注释说明填充时机 - 为jump语句添加_target字段用于语义分析 - 更新所有AST初始化函数,接受位置信息参数以改进错误定位 - 修复alignof表达式的类型应为ALIGN_OF而非SIZE_OF的问题 - 重构ast2ir.h,引入scc_ast2ir_ctx_t上下文结构体统一管理转换状态 - 添加符号表、节点到IR映射等必要的转换上下文信息
This commit is contained in:
@@ -10,33 +10,21 @@ typedef struct {
|
||||
scc_pe_buffer_t data; ///< 具体数据
|
||||
scc_hashtable_t str_map; ///< 符号名称映射到data的idx
|
||||
u32 section_offset; ///< 在idata中的偏移
|
||||
} scc_winpe_hnt_builder_t;
|
||||
|
||||
typedef struct {
|
||||
u32 offset; ///< 相对代码段的偏移地址
|
||||
i32 addend; ///< 可选的偏移量的附加值 可选默认为0
|
||||
u8 size; ///< 引用的地址的大小
|
||||
const char *library_name; ///< 库名称 eg. "Kernel32.dll"
|
||||
const char *symbol_name; ///< 导入dll的符号名称 eg. "CreateFileW"
|
||||
u16 ordinal; ///< 符号的序号 eg. 可选
|
||||
} scc_winpe_extern_t;
|
||||
typedef SCC_VEC(scc_winpe_extern_t) scc_winpe_extern_vec_t;
|
||||
} scc_pe_hnt_builder_t;
|
||||
|
||||
typedef SCC_VEC(const char *) scc_winpe_name_vec_t;
|
||||
typedef struct {
|
||||
const char *name;
|
||||
scc_winpe_name_vec_t symbol_names;
|
||||
} scc_winpe_idata_lib_t;
|
||||
typedef SCC_VEC(scc_winpe_idata_lib_t) scc_winpe_idata_lib_vec_t;
|
||||
typedef SCC_VEC(scc_winpe_idata_lib_t) scc_pe_idata_lib_vec_t;
|
||||
typedef struct {
|
||||
scc_pe_buffer_t buffer; ///< 导入表数据
|
||||
scc_winpe_extern_vec_t externs;
|
||||
scc_hashtable_t externs_set;
|
||||
|
||||
scc_winpe_hnt_builder_t hnt_builder;
|
||||
scc_pe_hnt_builder_t hnt_builder;
|
||||
scc_hashtable_t iat_map; ///< 符号名称映射到idata的虚拟镜像地址
|
||||
scc_winpe_idata_lib_vec_t idata_libs;
|
||||
} scc_winpe_idata_builder_t;
|
||||
scc_pe_idata_lib_vec_t idata_libs;
|
||||
} scc_pe_idata_builder_t;
|
||||
|
||||
/**
|
||||
* @brief PE格式导入表构建器初始化
|
||||
@@ -45,8 +33,8 @@ typedef struct {
|
||||
* @param builder
|
||||
* @param idata_libs
|
||||
*/
|
||||
void scc_pe_idata_builder_init(scc_winpe_idata_builder_t *builder,
|
||||
scc_winpe_idata_lib_vec_t *idata_libs);
|
||||
void scc_pe_idata_builder_init(scc_pe_idata_builder_t *builder,
|
||||
scc_pe_idata_lib_vec_t *idata_libs);
|
||||
|
||||
/**
|
||||
* @brief 获取导入表占据的大小
|
||||
@@ -55,7 +43,7 @@ void scc_pe_idata_builder_init(scc_winpe_idata_builder_t *builder,
|
||||
* @param builder
|
||||
* @return u32
|
||||
*/
|
||||
u32 scc_pe_reserve_idata(scc_winpe_idata_builder_t *builder);
|
||||
u32 scc_pe_reserve_idata(scc_pe_idata_builder_t *builder);
|
||||
|
||||
/**
|
||||
* @brief 构造导入表
|
||||
@@ -64,13 +52,12 @@ u32 scc_pe_reserve_idata(scc_winpe_idata_builder_t *builder);
|
||||
* @param builder
|
||||
* @param idata_range
|
||||
*/
|
||||
scc_pe_buffer_t scc_pe_construct_idata(scc_winpe_idata_builder_t *builder,
|
||||
scc_pe_buffer_t scc_pe_construct_idata(scc_pe_idata_builder_t *builder,
|
||||
scc_pe_section_range *idata_range);
|
||||
|
||||
// RVA Relative Virtual Address
|
||||
static inline u64
|
||||
scc_pe_idata_get_symbol_rva(scc_winpe_idata_builder_t *builder,
|
||||
const char *symbol_name) {
|
||||
static inline u64 scc_pe_idata_get_symbol_rva(scc_pe_idata_builder_t *builder,
|
||||
const char *symbol_name) {
|
||||
return (u64)scc_hashtable_get(&builder->iat_map, symbol_name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user