chore(phase1): translate 流程加 printf 断点,定位 stdint.vp 访问违规崩溃点
stdint.vp 翻译中崩溃(退出码 -1073741815=0xC0000005 访问违规), 发生在 translate 内部 printf.fmt 创建后。在 translate 声明完成/ main 检查/模块级各步骤(import、容器可见性、CTypedef 扫描、vpi 注入、 变量预注册、前向声明、translate_children)加断点,崩溃前最后打印的 步骤即为崩点。
This commit is contained in:
1 parent
0cb0a12810
commit
407f047411
1 file changed
+10
@@ -380,6 +380,7 @@ class Translator:
|
||||
if malloc_func is not None:
|
||||
i64_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Int64(pool)
|
||||
llvmlite.add_param(pool, malloc_func, i64_ty, "size")
|
||||
stdio.printf("[DIAG] translate: 声明完成\n")
|
||||
|
||||
# 检查用户是否定义了 main 函数
|
||||
has_user_main: int = 0
|
||||
@@ -394,6 +395,7 @@ class Translator:
|
||||
if string.strcmp(fd.name, "main") == 0:
|
||||
has_user_main = 1
|
||||
break
|
||||
stdio.printf("[DIAG] translate: main 检查完成(has_user_main=%d)\n", has_user_main)
|
||||
|
||||
if self._declare_only != 0:
|
||||
# Phase 1a-pre(2=import扫描) / Phase 1a(1=struct注册): 只处理模块级,不创建 main 函数和 builder
|
||||
@@ -428,6 +430,7 @@ class Translator:
|
||||
"""委托 HandlesMain.translate_children() 翻译模块级语句(trans 单参)"""
|
||||
# 全量翻译模式下,先处理导入语句,再创建前向声明,解决前向引用问题
|
||||
if self._declare_only == 0:
|
||||
stdio.printf("[DIAG] 模块级: 开始\n")
|
||||
# 预处理导入语句,确保 _imported_modules 和 _from_imports 已填充
|
||||
# (前向声明需要解析类型注解,如 t.CArray[str] 依赖 t 模块已导入)
|
||||
# 记录最后处理的 import 行号,供 vpi 注入错误上下文帧定位
|
||||
@@ -447,6 +450,7 @@ class Translator:
|
||||
cur_imp_lineno = child.lineno
|
||||
self.ImportsH.HandleImportFromModule(child)
|
||||
self.ImportsH.HandleImportFromNames(child)
|
||||
stdio.printf("[DIAG] 模块级: import 处理完成\n")
|
||||
# 对齐 TPC _inject_auto_imports:检测源文件对 list/dict 容器的使用
|
||||
# (裸名注解 d: dict / 构造 dict(...) / 下标 list[T]),自动把容器
|
||||
# 类标记为可见结构体。背景:_list.vp/_dict.vp 定义内建容器类且已由
|
||||
@@ -455,9 +459,11 @@ class Translator:
|
||||
# `d: dict` 注解 resolve_annotation_type 时 is_struct_visible=0
|
||||
# 解析失败(DictTest 的 "变量类型注解解析失败")。
|
||||
self._inject_auto_container_visibility(pool, tree)
|
||||
stdio.printf("[DIAG] 模块级: 容器可见性完成\n")
|
||||
# 扫描当前模块的 CTypedef 声明(NAME: t.CTypedef = Type),
|
||||
# 注册到动态 CTypedef 表,供 resolve_annotation_type 查询
|
||||
HandlesType.ScanCTypedefDeclarations(pool, tree)
|
||||
stdio.printf("[DIAG] 模块级: CTypedef 扫描完成\n")
|
||||
# 跨模块 .vpi 注入:加载依赖模块的 .vpi 文件,
|
||||
# 将函数 declare 声明注入到当前模块,解决跨模块函数调用找不到函数的问题
|
||||
# 严格保证 declare_only == 0 时才注入(避免 Phase A-pre-inc 死锁)
|
||||
@@ -469,6 +475,7 @@ class Translator:
|
||||
pool, mod, self._imported_modules, self._from_imports,
|
||||
HandlesType.get_temp_dir(), self)
|
||||
HandlesType.pop_trace()
|
||||
stdio.printf("[DIAG] 模块级: vpi 注入完成\n")
|
||||
# 预注册模块级变量(AnnAssign/Assign)到 SymTab
|
||||
# 解决时序问题:class Logger 的 __init__ 引用 _mbuddy 时,
|
||||
# _mbuddy 的 AnnAssign 在 AST 中位于 class Logger 之后,
|
||||
@@ -484,9 +491,12 @@ class Translator:
|
||||
kd_mv: int = child.kind()
|
||||
if kd_mv == ast.ASTKind.AnnAssign or kd_mv == ast.ASTKind.Assign:
|
||||
HandlesMain.handle_module_level_var(self, child)
|
||||
stdio.printf("[DIAG] 模块级: 变量预注册完成\n")
|
||||
# 创建前向声明
|
||||
HandlesFunctions.forward_declare_functions(self, tree)
|
||||
stdio.printf("[DIAG] 模块级: 前向声明完成\n")
|
||||
added: int = HandlesMain.translate_children(self, tree)
|
||||
stdio.printf("[DIAG] 模块级: translate_children 完成\n")
|
||||
|
||||
# ============================================================
|
||||
# 容器模块自动可见性注入(对齐 TPC _inject_auto_imports)
|
||||
|
||||
Reference in new issue
Block a user