stage2 更多底层函数 stage1 layout正确使用 内置函数重新编写

This commit is contained in:
zzy committed 2026-09-17 22:03:23 +08:00
1 parent fb0ff9b663
commit 4141e7d574
15 files changed
+2588 -122

No files matched your search

+20 -4
View File
@@ -182,6 +182,8 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
spl_attr_t attr;
spl_lang_type_t lang_type;
spl_layout_target_t layout_target;
spl_layout_t layout;
spl_scope_t scope;
spl_sema_t sema;
spl_ast2ir_t a2ir;
@@ -189,7 +191,7 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
spl_ir2vm_t ir2vm;
spl_ast_ptr_vec_t all_asts;
int attr_ok = 0, lang_type_ok = 0, scope_ok = 0;
int attr_ok = 0, lang_type_ok = 0, layout_ok = 0, scope_ok = 0;
int sema_ok = 0, a2ir_ok = 0, irb_ok = 0, ir2vm_ok = 0;
spl_diag_set_stage(&diag, SPL_STAGE_PARSE);
@@ -212,10 +214,19 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
attr_ok = 1;
spl_lang_type_init(&lang_type);
lang_type_ok = 1;
/* 目标描述符:剥离目标机器细节,layout 是 size/align/offset 的唯一来源。 */
memset(&layout_target, 0, sizeof layout_target);
layout_target.endian = SPL_LITTLE_ENDIAN;
layout_target.ptr_size = sizeof(void *);
layout_target.ptr_align = sizeof(void *);
spl_layout_init(&layout, &layout_target);
layout_ok = 1;
spl_scope_init(&scope);
scope_ok = 1;
spl_sema_init(&sema, &drv.main_ast, &lang_type, &scope, &attr);
spl_sema_init(&sema, &drv.main_ast, &lang_type, &layout, &scope, &attr);
sema_ok = 1;
spl_module_loader_t loader = {.load = driver_load, .user = &drv};
sema.loader = &loader;
@@ -242,7 +253,7 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
spl_ir_builder_init(&ir_builder);
irb_ok = 1;
spl_ast2ir_init(&a2ir, &ir_builder, &sema);
spl_ast2ir_init(&a2ir, &ir_builder, &layout, &sema);
a2ir_ok = 1;
spl_diag_set_stage(&diag, SPL_STAGE_AST2IR);
a2ir.diag = &diag;
@@ -257,7 +268,10 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
goto cleanup;
}
spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, &lang_type.ir, &attr);
/* 类型已全部就绪:解析 layout,供 ir2vm 的 size/align/offset 使用。 */
spl_layout_resolve(&layout, &lang_type.ir);
spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, &lang_type.ir, &layout, &attr);
ir2vm_ok = 1;
spl_diag_set_stage(&diag, SPL_STAGE_IR2VM);
ir2vm.diag = &diag;
@@ -285,6 +299,8 @@ cleanup:
spl_sema_drop(&sema);
if (scope_ok)
spl_scope_drop(&scope);
if (layout_ok)
spl_layout_drop(&layout);
if (lang_type_ok)
spl_lang_type_drop(&lang_type);
if (attr_ok)