Files
scc/libs/ast2ir/include/scc_ast2ir.h
zzy cec96333e7 feat(ast2ir): 实现C11类型提升系统并重构HIR基本块管理
- 新增 scc_ast2ir_promote.c 实现整数提升(6.3.1.1)和寻常算术转换(6.3.1.8)
- 重构 HIR Builder: bblock → create_bblock + append_bblock,引入BBList链表管理
- AST2IR 全面集成类型提升:二元运算、赋值、函数调用参数、自增/自减操作符
- 变参函数支持:跳过 ... 假参数,实现默认参数提升(float→double等)
- 简化 HIR Dump 实现
- MIR: Win64 ABI改进、x86指令选择优化
- 新增 printf 测试用例
2026-05-24 15:46:22 +08:00

71 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __SCC_AST2IR_H__
#define __SCC_AST2IR_H__
#include <scc_ast.h>
#include <scc_hir_builder.h>
#include <scc_type_abi.h>
typedef struct {
scc_hir_builder_t builder;
scc_hashtable_t ast2ir_cache; ///< ast node to ir ref cache
scc_hashtable_t break_cache; ///< break cache
scc_hashtable_t continue_cache; ///< continue cache
scc_hashtable_t symtab; ///< symbol to ir_ref
scc_hashtable_t type_cache; ///< scc_ast_canon_type_t* -> scc_hir_type_ref_t
// scc_strpool_t strpool; ///< string pool
const scc_abi_type_calc_t *abi;
cbool hint_using_value; // 转换时尽可能使用value而不是alloc
scc_ast_ctx_t *ast_ctx;
} scc_ast2ir_ctx_t;
static inline scc_hir_module_t *scc_ast2ir_mir_module(scc_ast2ir_ctx_t *ctx) {
return &ctx->builder.cprog->module;
}
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_abi_type_calc_t *abi,
scc_ast_ctx_t *ast_ctx, scc_hir_cprog_t *cprog);
void scc_ast2ir_ctx_drop(scc_ast2ir_ctx_t *ctx);
void scc_ast2ir_run(scc_ast2ir_ctx_t *ctx,
const scc_ast_translation_unit_t *tu);
void scc_ast2ir_decl(scc_ast2ir_ctx_t *ctx, const scc_ast_decl_t *decl,
cbool is_global);
scc_hir_value_ref_t scc_ast2ir_expr(scc_ast2ir_ctx_t *ctx,
const scc_ast_expr_t *expr,
cbool is_lvalue);
void scc_ast2ir_stmt(scc_ast2ir_ctx_t *ctx, const scc_ast_stmt_t *stmt);
scc_hir_type_ref_t scc_ast2ir_type(scc_ast2ir_ctx_t *ctx,
const scc_ast_qual_type_t *ast_type);
// ====== 类型提升Type Promotion接口 ======
/**
* @brief 整数提升C11 6.3.1.1
* 对 _Bool、char、short 等秩低于 int 的类型提升为 int/unsigned int
* @param type_ref 原始类型引用
* @return 提升后的类型的引用,若无需提升则返回原始类型
*/
scc_hir_type_ref_t scc_ast2ir_integer_promotion(scc_ast2ir_ctx_t *ctx,
scc_hir_type_ref_t type_ref);
/**
* @brief 寻常算术转换C11 6.3.1.8
* 对二元算术操作的两个操作数类型找到公共类型
* @return 公共类型的引用
*/
scc_hir_type_ref_t scc_ast2ir_usual_arithmetic_conversion(
scc_ast2ir_ctx_t *ctx, scc_hir_type_ref_t t1_ref,
scc_hir_type_ref_t t2_ref);
/**
* @brief 插入类型转换指令
* 根据源类型和目标类型自动选择 SEXT/ZEXT/TRUNC/F2I/I2F/F2F
* @return 转换后的值引用
*/
scc_hir_value_ref_t scc_ast2ir_emit_conversion(scc_ast2ir_ctx_t *ctx,
scc_hir_value_ref_t value,
scc_hir_type_ref_t target_type);
#endif /* __SCC_AST2IR_H__ */