尝试进行 Qt 测试,增加了 AI 人机调试工具 _console,以及 TransPyV 进行修正

This commit is contained in:
2026-07-21 14:41:22 +08:00
parent a277ded8d4
commit 135aa05485
311 changed files with 7084 additions and 2131 deletions

View File

@@ -44,78 +44,47 @@ SRC_BUF_SIZE: t.CDefine = 1048576
def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
log: VLogger.Logger | t.CPtr) -> int:
"""Phase1: 扫描 includes 目录,按需翻译并生成 stub"""
stdio.printf("[P1 ENTER] mb=%p inc=%p temp=%p log=%p\n", mb, includes_dir, temp_dir, log)
stdio.fflush(0)
if includes_dir is None or temp_dir is None:
stdio.printf("[Phase1] includes_dir 或 temp_dir 为空,跳过\n")
return 1
stdio.printf("[P1] before log.banner\n")
stdio.fflush(0)
if log is not None:
log.banner("Phase1: 扫描 includes按需翻译")
stdio.printf("[P1] after log.banner\n")
stdio.fflush(0)
# 扫描 includes 目录
stdio.printf("[P1] before scan_includes: mb=%p inc=%s\n", mb, includes_dir)
stdio.fflush(0)
result: IncludesScanner.ScanResult | t.CPtr = IncludesScanner.scan_includes(mb, includes_dir)
stdio.printf("[P1] after scan_includes: result=%p\n", result)
stdio.fflush(0)
if result is None:
stdio.printf("[Phase1] 扫描失败\n")
return 1
stdio.printf("[P1] result.Count=%d\n", result.Count)
stdio.fflush(0)
stdio.printf("[Phase1] 共 %d 个文件\n", result.Count)
# 读取 _sha1_map.txt 获取需要的 includes SHA1 集合
# 优先使用 Projectrans.py 生成的 _sha1_map.txt含依赖分析只包含需要的 includes
# 若不存在,则从扫描结果生成(包含所有 includes可能导致结构体表溢出
sha1_set: str = stdlib.malloc(StubMerger.MAX_INCLUDES_SHA1 * 17)
stdio.printf("[P1] sha1_set=%p\n", sha1_set)
stdio.fflush(0)
if sha1_set is None:
stdio.printf("[Phase1] sha1_set 分配失败\n")
return 1
string.memset(sha1_set, 0, StubMerger.MAX_INCLUDES_SHA1 * 17)
stdio.printf("[P1] before _load_includes_sha1_set\n")
stdio.fflush(0)
set_count: int = StubMerger._load_includes_sha1_set(mb, temp_dir, sha1_set)
stdio.printf("[P1] set_count=%d\n", set_count)
stdio.fflush(0)
if set_count <= 0:
stdio.printf("[Phase1] _sha1_map.txt 不存在或为空,从扫描结果生成\n")
stdio.fflush(0)
stdio.printf("[P1] before WriteIncludesSha1Map\n")
stdio.fflush(0)
StubMerger.WriteIncludesSha1Map(mb, temp_dir, result, None, 0)
stdio.printf("[P1] after WriteIncludesSha1Map, before _load_includes_sha1_set\n")
stdio.fflush(0)
set_count = StubMerger._load_includes_sha1_set(mb, temp_dir, sha1_set)
stdio.printf("[P1] set_count2=%d\n", set_count)
stdio.fflush(0)
if set_count < 0:
stdio.printf("[Phase1] 无法加载 _sha1_map.txt跳过 Phase1\n")
return 1
stdio.printf("[Phase1] includes SHA1 集合: %d\n", set_count)
stdio.fflush(0)
# 构建模块 SHA1 映射(供跨模块函数调用名混淆使用)
td_len_p1map: t.CSizeT = string.strlen(temp_dir)
p1_sha1_arr: bytes = stdlib.malloc(StubMerger.MAX_INCLUDES * 17)
p1_mod_arr: bytes = stdlib.malloc(StubMerger.MAX_INCLUDES * 64)
p1_inc_count: int = 0
stdio.printf("[P1] before _BuildIncludesSha1Map\n")
stdio.fflush(0)
if p1_sha1_arr is not None and p1_mod_arr is not None:
p1_inc_count = StubMerger._BuildIncludesSha1Map(temp_dir, td_len_p1map, p1_sha1_arr, p1_mod_arr)
stdio.printf("[P1] after _BuildIncludesSha1Map: inc=%d\n", p1_inc_count)
stdio.fflush(0)
stdio.printf("[P1] before set_module_sha1_map\n")
stdio.fflush(0)
HandlesExprCall.set_module_sha1_map(p1_sha1_arr, p1_mod_arr, p1_inc_count)
stdio.printf("[P1] after set_module_sha1_map\n")
stdio.fflush(0)
# 初始化 AST 表(只需一次)
ast._init_tables(mb)