feat(cbuild): 更新项目配置以支持HIR中间表示

- 统一包名格式化,添加空格对齐
- 将依赖项从ir和lir重命名为hir,移除lir注释
- 为ast2ir模块添加正确的包名称"scc_ast2ir"
- 更新依赖引用路径指向新的HIR库结构
- 移除注释掉的ir2mcode和sccf2target依赖项

refactor(ast2ir): 迁移到HIR中间表示替换IR表示

- 更新头文件包含,使用hir_builder.h替代ir_builder.h
- 修改上下文结构体,将scc_ir_builder_t替换为scc_hir_builder_t
- 更新函数签名,将参数类型从scc_ir_*转换为scc_hir_*
- 调整返回值类型,将scc_ir_value_ref_t和scc_ir_type_ref_t
  分别替换为scc_hir_value_ref_t和scc_hir_type_ref_t
- 重新排列头文件包含顺序以满足依赖关系
This commit is contained in:
zzy
2026-04-21 14:05:21 +08:00
parent e5bbffe170
commit 0fbfb36262
49 changed files with 2555 additions and 3989 deletions

9
runtime/ap/cbuild.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "ap"
version = "0.1.0"
authors = []
description = ""
# dependencies = []
# features = {}
# default_features = []

92
runtime/ap/include/ap.h Normal file
View File

@@ -0,0 +1,92 @@
#ifndef __SCC_AP_H__
#define __SCC_AP_H__
/**
* @brief Arbitrary Precision Library
*
*/
#ifdef __AP_SCC__
#include <scc_core.h>
#define SCC_AP_DIGIT u64
#define SCC_AP_PANIC Panic
#define SCC_AP_ASSERT Assert
#define SCC_AP_MALLOC scc_malloc
#define SCC_AP_REALLOC scc_realloc
#define SCC_AP_FREE scc_free
#else
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define SCC_AP_DIGIT uint64_t
#define SCC_AP_PANIC(...) \
do { \
fprintf(stderr, __VA_ARGS__); \
abort(); \
} while (0)
#define SCC_AP_ASSERT assert
#define SCC_AP_MALLOC malloc
#define SCC_AP_REALLOC realloc
#define SCC_AP_FREE free
#endif
#ifndef SCC_AP_DIGIT
#error "SCC_AP_DIGIT is not defined"
#endif
#define SCC_AP_DIGIT_BITS (sizeof(SCC_AP_DIGIT))
#ifndef nullptr
#define nullptr ((void *)0)
#endif
typedef SCC_AP_DIGIT scc_ap_digit;
typedef struct {
int capacity; // maybe power of 2 (-1 means using digit)
int len; // data length (sign with in)
union {
scc_ap_digit *array;
scc_ap_digit digit;
} data;
} scc_ap_t;
static inline void scc_ap_init(scc_ap_t *ap) {
ap->len = 0;
ap->capacity = -1;
ap->len = 1;
ap->data.digit = 0;
}
static inline void scc_ap_set_int(scc_ap_t *ap, int val) {
if (val < 0) {
ap->len = -1;
} else {
ap->len = 1;
}
SCC_AP_ASSERT(sizeof(scc_ap_digit) >= sizeof(int));
ap->capacity = -1;
ap->data.digit = val;
}
void scc_ap_drop(scc_ap_t *ap);
void scc_ap_with_bits(scc_ap_t *ap, int bits);
void scc_ap_from_string(scc_ap_t *ap, const char *str, int len, int base);
void scc_ap_set_digit(scc_ap_t *ap, scc_ap_digit digit);
void scc_ap_add(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b);
void scc_ap_sub(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b);
void scc_ap_mul(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b);
void scc_ap_div(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b);
void scc_ap_mod(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b);
/**
* @brief equal
*
* @param a
* @param b
* @return int
*/
int scc_ap_eql(const scc_ap_t *a, const scc_ap_t *b);
typedef void (*ap_dump_fn)(const char ch, void *user_data);
int scc_ap_dump(scc_ap_t *ap, ap_dump_fn dump_fn, void *user_data);
#endif /* __SCC_AP_H__ */

48
runtime/ap/src/ap.c Normal file
View File

@@ -0,0 +1,48 @@
#include <ap.h>
static void *scc_ap_alloc(size_t size) {
void *p = SCC_AP_MALLOC(size);
SCC_AP_ASSERT(p != NULL);
return p;
}
/* 重新分配内存 */
static void *scc_ap_realloc_data(void *old, size_t new_size) {
void *p = SCC_AP_REALLOC(old, new_size);
SCC_AP_ASSERT(p != NULL);
return p;
}
void scc_ap_drop(scc_ap_t *ap) {
SCC_AP_ASSERT(ap);
// SCC_AP_FREE(ap->data);
scc_ap_init(ap);
}
void scc_ap_with_bits(scc_ap_t *ap, int bits) {}
void scc_ap_from_string(scc_ap_t *ap, const char *str, int len, int base) {
SCC_AP_ASSERT(base == 10);
SCC_AP_ASSERT(ap && str);
if (len == 0) {
scc_ap_set_int(ap, 0);
}
// FIXME
int int_lit = 0;
for (int i = 0; i < len; i += 1) {
int_lit = int_lit * 10 + (str[i] - '0');
}
scc_ap_set_int(ap, int_lit);
}
void scc_ap_set_digit(scc_ap_t *ap, scc_ap_digit digit) {}
void scc_ap_add_impl(scc_ap_t *to, const scc_ap_t *from_a,
const scc_ap_t *from_b) {}
void scc_ap_add(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b) {}
void scc_ap_sub(scc_ap_t *to, const scc_ap_t *from_a, const scc_ap_t *from_b) {}
typedef void (*ap_dump_fn)(const char ch, void *user_data);
int scc_ap_dump(scc_ap_t *ap, ap_dump_fn dump_fn, void *user_data) { return 0; }

5
runtime/ap/src/lib.c Normal file
View File

@@ -0,0 +1,5 @@
#include <stdio.h>
void hello_from_lib() {
printf("Hello from library!\n");
}

View File

@@ -0,0 +1,16 @@
#ifndef __SCC_UTILS_AP_H__
#define __SCC_UTILS_AP_H__
#include <scc_core.h>
#define __AP_SCC__
#include <ap.h>
static inline void scc_ap_from_str(scc_ap_t *ap, scc_str_t *str, int base) {
scc_ap_from_string(ap, scc_vec_unsafe_get_data(*str), scc_vec_size(*str),
base);
}
static inline void scc_ap_from_cstr(scc_ap_t *ap, const char *str, int base) {
scc_ap_from_string(ap, str, scc_strlen(str), base);
}
#endif /* __SCC_UTILS_AP_H__ */