错拼 rowptr 改为 rawptr
This commit is contained in:
1 parent
7cba4cbc95
commit
9a191daa8d
70 files changed
+585
-585
No files matched your search
@@ -34,7 +34,7 @@ import lib.Stub.StubMerger.StubMergerCollect as StubMergerCollect
|
||||
# ============================================================
|
||||
|
||||
# 全局 mbuddy 指针
|
||||
_mbuddy: rowptr[memhub.MemBuddy]
|
||||
_mbuddy: rawptr[memhub.MemBuddy]
|
||||
|
||||
# ASan 模式(--asan):对 .ll 先 opt -passes=asan 插桩;ASan 运行库由
|
||||
# project.vpj 的 linker.static_libs / dynamic_libs 显式声明(TPV 不注入)
|
||||
@@ -61,7 +61,7 @@ PYI_BUF_SIZE: sizet = 262144
|
||||
# Args: mb 内存池;file_path 源文件路径;sha1_val 文件内容的 SHA1 前16字符(用于函数名混淆);current_package 当前文件所属包名(用于解析相对导入),None 表示顶级模块;declare_only 0=全量翻译(默认),1=仅注册 struct/enum/union(不翻译方法体);temp_dir temp 目录路径(非 None 时在翻译前生成 .vpi 存根文件)
|
||||
# Returns: Translator 对象(None 失败)
|
||||
# ============================================================
|
||||
def TranslateFileGetTrans(mb: rowptr[memhub.MemBuddy], file_path: str,
|
||||
def TranslateFileGetTrans(mb: rawptr[memhub.MemBuddy], file_path: str,
|
||||
sha1_val: str,
|
||||
current_package: str = None,
|
||||
declare_only: int = 0,
|
||||
@@ -73,7 +73,7 @@ def TranslateFileGetTrans(mb: rowptr[memhub.MemBuddy], file_path: str,
|
||||
temp_dir: temp 目录路径(非 None 时在翻译前生成 .vpi 存根文件)
|
||||
"""
|
||||
if file_path is None: return None
|
||||
f: rowptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
f: rawptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
if f.closed: return None
|
||||
# read_all 的容量参数含终止符(最多读 cap-1 字节), 文件更长会被**静默截断**;
|
||||
# 这里先按文件大小拒绝, 否则拿截断后的源码去 parse 只会得到莫名其妙的语法错误
|
||||
@@ -121,7 +121,7 @@ def TranslateFileGetTrans(mb: rowptr[memhub.MemBuddy], file_path: str,
|
||||
td_len_vpi: sizet = len(temp_dir)
|
||||
pyi_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_vpi, sha1_val, "vpi")
|
||||
if pyi_path is not None:
|
||||
pf: rowptr[fileio.File] = fileio.File(pyi_path, fileio.MODE.W)
|
||||
pf: rawptr[fileio.File] = fileio.File(pyi_path, fileio.MODE.W)
|
||||
if not pf.closed:
|
||||
pf.write(pyi_buf, pyi_pos)
|
||||
pf.close()
|
||||
@@ -135,7 +135,7 @@ def TranslateFileGetTrans(mb: rowptr[memhub.MemBuddy], file_path: str,
|
||||
tr._declare_only = declare_only
|
||||
# P2: 复用全局 gen 单例(App/main.vp 创建;HandlesType 等旧模块函数经
|
||||
# 延迟 import 委托到 gen 方法)。单例未注册时兜底创建(防御直接调用路径)。
|
||||
gen: rowptr[GenGenerator.Generator] = GenGenerator._g_gen
|
||||
gen: rawptr[GenGenerator.Generator] = GenGenerator._g_gen
|
||||
if gen is None:
|
||||
gen = mb.alloc(GenGenerator.Generator.__sizeof__())
|
||||
if gen is None:
|
||||
@@ -282,7 +282,7 @@ def write_ir_to_file(ir_buf: bytes, ir_len: sizet, output_dir: str, module_name:
|
||||
if path is None: return 1
|
||||
|
||||
# 打开文件写入
|
||||
f: rowptr[fileio.File] = fileio.File(path, fileio.MODE.W)
|
||||
f: rawptr[fileio.File] = fileio.File(path, fileio.MODE.W)
|
||||
if f.closed: return 1
|
||||
|
||||
written: int64 = f.write(ir_buf, ir_len)
|
||||
@@ -467,7 +467,7 @@ def _phase2_write_cmd(cmd: str) -> None:
|
||||
global _phase2_bat_init
|
||||
if _phase2_cmd_path is None or cmd is None:
|
||||
return
|
||||
f: rowptr[fileio.File] = fileio.File(_phase2_cmd_path, fileio.MODE.A)
|
||||
f: rawptr[fileio.File] = fileio.File(_phase2_cmd_path, fileio.MODE.A)
|
||||
if f.closed:
|
||||
VLogger.error("phase2command: bat 打开失败", "phase2cmd")
|
||||
return
|
||||
|
||||
@@ -146,7 +146,7 @@ def _RewriteDepsTxt(temp_dir: str, sha1: str, deps_str: str) -> None:
|
||||
dpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "deps.txt")
|
||||
if dpath is None:
|
||||
return
|
||||
df: rowptr[fileio.File] = fileio.File(dpath, fileio.MODE.W)
|
||||
df: rawptr[fileio.File] = fileio.File(dpath, fileio.MODE.W)
|
||||
if not df.closed:
|
||||
dl: sizet = string.strlen(deps_str)
|
||||
if dl > 0:
|
||||
@@ -234,7 +234,7 @@ def _BreakContainerCyclesInDeps(temp_dir: str) -> int:
|
||||
# Args: mb 内存池;includes_dir includes 根目录(仅用于失败诊断,路径以 store 为准)
|
||||
# Returns: ScanResult 指针(stdlib 分配,调用方负责释放);失败返回 None
|
||||
# ============================================================
|
||||
def _BuildReachableResult(mb: rowptr[memhub.MemBuddy],
|
||||
def _BuildReachableResult(mb: rawptr[memhub.MemBuddy],
|
||||
includes_dir: str) -> IncludesScanner.ScanResult | t.CPtr:
|
||||
"""从 Sha1Store(仅可达 includes + App)构建可达 FileEntry 列表"""
|
||||
if mb is None:
|
||||
@@ -318,7 +318,7 @@ def _BuildReachableResult(mb: rowptr[memhub.MemBuddy],
|
||||
# Args: mb 内存池;includes_dir includes 目录路径;temp_dir 临时目录(保存 stub);log 日志器
|
||||
# Returns: 0 成功,非 0 失败
|
||||
# ============================================================
|
||||
def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
def RunPhase1(mb: rawptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
log: VLogger.Logger | t.CPtr) -> int:
|
||||
"""Phase1: 扫描 includes 目录,按需翻译并生成 stub"""
|
||||
if includes_dir is None or temp_dir is None:
|
||||
@@ -581,7 +581,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
|
||||
# 读取文件内容
|
||||
file_path_r: str = entry_r.Path
|
||||
f_r: rowptr[fileio.File] = fileio.File(file_path_r, fileio.MODE.R)
|
||||
f_r: rawptr[fileio.File] = fileio.File(file_path_r, fileio.MODE.R)
|
||||
if f_r.closed:
|
||||
p1a_fl += 1
|
||||
continue
|
||||
@@ -733,7 +733,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {entry_pv.Path} | vpi 路径生成失败", "Phase1")
|
||||
continue
|
||||
vf_pv: rowptr[fileio.File] = fileio.File(vpi_path_pv, fileio.MODE.R)
|
||||
vf_pv: rawptr[fileio.File] = fileio.File(vpi_path_pv, fileio.MODE.R)
|
||||
if not vf_pv.closed:
|
||||
vf_pv.close()
|
||||
stdlib.free(vpi_path_pv)
|
||||
@@ -741,7 +741,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
stdlib.free(vpi_path_pv)
|
||||
# 读取文件、解析 AST、生成 vpi
|
||||
file_path_pv: str = entry_pv.Path
|
||||
f_pv: rowptr[fileio.File] = fileio.File(file_path_pv, fileio.MODE.R)
|
||||
f_pv: rawptr[fileio.File] = fileio.File(file_path_pv, fileio.MODE.R)
|
||||
if f_pv.closed:
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | 无法打开源文件", "Phase1")
|
||||
@@ -790,7 +790,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
if pyi_pos_pv > 0:
|
||||
pyi_path_pv: str = StubMergerCollect._sliced_path(temp_dir, dir_len_pv, sha1_pv, "vpi")
|
||||
if pyi_path_pv is not None:
|
||||
pf_pv: rowptr[fileio.File] = fileio.File(pyi_path_pv, fileio.MODE.W)
|
||||
pf_pv: rawptr[fileio.File] = fileio.File(pyi_path_pv, fileio.MODE.W)
|
||||
if not pf_pv.closed:
|
||||
pf_pv.write(pyi_buf_pv, pyi_pos_pv)
|
||||
pf_pv.close()
|
||||
@@ -876,7 +876,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
force_translate: int = 0
|
||||
vpi_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "vpi")
|
||||
if vpi_path_1b is not None:
|
||||
vf_1b: rowptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
vf_1b: rawptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
if not vf_1b.closed:
|
||||
vbuf_1b: bytes = stdlib.malloc(1048576)
|
||||
if vbuf_1b is not None:
|
||||
@@ -910,13 +910,13 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
VLogger.info(f"含 class 定义,强制翻译: {rp}(sha1={sha1})", "Phase1")
|
||||
else:
|
||||
# 检查 stub 是否已存在(按需翻译:跳过已存在的)
|
||||
sf: rowptr[fileio.File] = fileio.File(stub_path, fileio.MODE.R)
|
||||
sf: rawptr[fileio.File] = fileio.File(stub_path, fileio.MODE.R)
|
||||
if not sf.closed:
|
||||
sf.close()
|
||||
# 检查 text.ll 是否也存在(虚表扫描需要 text.ll)
|
||||
text_path: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "text.ll")
|
||||
if text_path is not None:
|
||||
tf: rowptr[fileio.File] = fileio.File(text_path, fileio.MODE.R)
|
||||
tf: rawptr[fileio.File] = fileio.File(text_path, fileio.MODE.R)
|
||||
if not tf.closed:
|
||||
tf.close()
|
||||
stdlib.free(text_path)
|
||||
@@ -938,7 +938,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
|
||||
# 读取文件内容
|
||||
file_path: str = entry.Path
|
||||
f: rowptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
f: rawptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
if f is None:
|
||||
VLogger.error(f"无法打开(f=None): {file_path}", "Phase1")
|
||||
failed += 1
|
||||
@@ -998,7 +998,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
# (消除 1b-pre 与 1b 对同一文件的重复 _GeneratePyiFromAst 工作)
|
||||
vpi_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "vpi")
|
||||
if vpi_path_1b is not None:
|
||||
vf_1b: rowptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
vf_1b: rawptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
vpi_exists_1b: int = 0
|
||||
if not vf_1b.closed:
|
||||
vf_1b.close()
|
||||
@@ -1009,7 +1009,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
pyi_pos: sizet = StubConverter._GeneratePyiFromAst(
|
||||
mb, tree, entry.RelPath, pyi_buf, Phase1.PYI_BUF_SIZE)
|
||||
if pyi_pos > 0:
|
||||
pf_1b: rowptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.W)
|
||||
pf_1b: rawptr[fileio.File] = fileio.File(vpi_path_1b, fileio.MODE.W)
|
||||
if not pf_1b.closed:
|
||||
pf_1b.write(pyi_buf, pyi_pos)
|
||||
pf_1b.close()
|
||||
@@ -1082,7 +1082,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
dir_len_p1: sizet = string.strlen(temp_dir)
|
||||
stub_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "stub.ll")
|
||||
if stub_path_p1 is not None:
|
||||
sf_p1: rowptr[fileio.File] = fileio.File(stub_path_p1, fileio.MODE.W)
|
||||
sf_p1: rawptr[fileio.File] = fileio.File(stub_path_p1, fileio.MODE.W)
|
||||
if not sf_p1.closed:
|
||||
sf_p1.write(stub_buf, stub_len)
|
||||
sf_p1.close()
|
||||
@@ -1105,7 +1105,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
# save text.ll
|
||||
text_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "text.ll")
|
||||
if text_path_p1 is not None:
|
||||
tf_p1: rowptr[fileio.File] = fileio.File(text_path_p1, fileio.MODE.W)
|
||||
tf_p1: rawptr[fileio.File] = fileio.File(text_path_p1, fileio.MODE.W)
|
||||
if not tf_p1.closed:
|
||||
tf_p1.write(text_buf, text_len)
|
||||
tf_p1.close()
|
||||
@@ -1119,7 +1119,7 @@ def RunPhase1(mb: rowptr[memhub.MemBuddy], includes_dir: str, temp_dir: str,
|
||||
# save dependencies(_imported_modules) for Phase B
|
||||
deps_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "deps.txt")
|
||||
if deps_path_p1 is not None:
|
||||
df_p1: rowptr[fileio.File] = fileio.File(deps_path_p1, fileio.MODE.W)
|
||||
df_p1: rawptr[fileio.File] = fileio.File(deps_path_p1, fileio.MODE.W)
|
||||
if not df_p1.closed:
|
||||
if tr._imported_modules is not None:
|
||||
dl: sizet = string.strlen(tr._imported_modules)
|
||||
|
||||
@@ -53,7 +53,7 @@ import lib.core.Gen.GenApi as GenApi
|
||||
# parent_names_buf 父类名扁平数组(每个 Phase1.CLASS_NAME_LEN 字节,无父类填 '\0');def_sha1s_buf 定义 SHA1 扁平数组(每个 Phase1.SHA1_LEN 字节)
|
||||
# Returns: 收集到的类数量,-1 失败
|
||||
# ============================================================
|
||||
def _ScanClassInheritance(mb: rowptr[memhub.MemBuddy],
|
||||
def _ScanClassInheritance(mb: rawptr[memhub.MemBuddy],
|
||||
result: IncludesScanner.ScanResult | t.CPtr,
|
||||
reachable_set: str, reachable_count: int,
|
||||
use_reachable: int,
|
||||
@@ -97,7 +97,7 @@ def _ScanClassInheritance(mb: rowptr[memhub.MemBuddy],
|
||||
|
||||
# 读取文件
|
||||
file_path: str = entry.Path
|
||||
f: rowptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
f: rawptr[fileio.File] = fileio.File(file_path, fileio.MODE.R)
|
||||
if f.closed:
|
||||
continue
|
||||
|
||||
@@ -252,12 +252,12 @@ def _BufHasGenericClassMarker(buf: bytes, blen: sizet) -> int:
|
||||
# _find_generic_template 遍历悬空内存 strcmp 崩溃。本函数先文本扫描(_BufHasGenericClassMarker,不 parse)筛选出含泛型类的文件,
|
||||
# 仅对命中文件用**永久池(perm_pool)**解析(模板节点与表直接进 perm_pool,跨 mark 永久存活、不占主 pool);重复注册由 _register_generic_template 内部查重跳过。
|
||||
# ============================================================
|
||||
def _PreRegisterAllGenericTemplates(mb: rowptr[memhub.MemBuddy],
|
||||
def _PreRegisterAllGenericTemplates(mb: rawptr[memhub.MemBuddy],
|
||||
result: IncludesScanner.ScanResult | t.CPtr) -> int:
|
||||
"""预注册全部 includes 文件的泛型类模板,返回处理到的泛型类数量"""
|
||||
if result is None or mb is None:
|
||||
return 0
|
||||
perm: rowptr[memhub.MemBuddy] = CompilerFactory.factory.PermPool
|
||||
perm: rawptr[memhub.MemBuddy] = CompilerFactory.factory.PermPool
|
||||
if perm is None:
|
||||
return 0
|
||||
p1e_size: sizet = IncludesScanner.FileEntry.__sizeof__()
|
||||
@@ -270,7 +270,7 @@ def _PreRegisterAllGenericTemplates(mb: rowptr[memhub.MemBuddy],
|
||||
continue
|
||||
# 读取文件
|
||||
file_path_pg: str = entry_pg.Path
|
||||
f_pg: rowptr[fileio.File] = fileio.File(file_path_pg, fileio.MODE.R)
|
||||
f_pg: rawptr[fileio.File] = fileio.File(file_path_pg, fileio.MODE.R)
|
||||
if f_pg.closed:
|
||||
continue
|
||||
# read_all 的容量参数含终止符(最多读 cap-1 字节), 文件更长会被静默截断
|
||||
|
||||
@@ -45,7 +45,7 @@ import lib.Phase.Phase1 as Phase1
|
||||
# class_count 类数量;out_order 输出拓扑顺序的文件索引数组(调用者分配,int 数组);out_count 输出文件数量
|
||||
# Returns: 0 成功,-1 失败
|
||||
# ============================================================
|
||||
def _TopoSortFiles(mb: rowptr[memhub.MemBuddy],
|
||||
def _TopoSortFiles(mb: rawptr[memhub.MemBuddy],
|
||||
result: IncludesScanner.ScanResult | t.CPtr,
|
||||
reachable_set: str, reachable_count: int,
|
||||
use_reachable: int,
|
||||
|
||||
@@ -3,7 +3,7 @@ from stdint import *
|
||||
import memhub
|
||||
|
||||
# 全局 mbuddy 指针
|
||||
_mbuddy: rowptr[memhub.MemBuddy]
|
||||
_mbuddy: rawptr[memhub.MemBuddy]
|
||||
|
||||
# 源代码缓冲区大小(1MB)
|
||||
SRC_BUF_SIZE: t.CDefine = 1048576
|
||||
|
||||
@@ -30,7 +30,7 @@ import lib.Stub.StubMerger.StubMergerTopo as StubMergerTopo
|
||||
import lib.Stub.StubGen.Converter as StubConverter
|
||||
|
||||
# 全局 mbuddy 指针
|
||||
_mbuddy: rowptr[memhub.MemBuddy]
|
||||
_mbuddy: rawptr[memhub.MemBuddy]
|
||||
|
||||
# 源代码缓冲区大小(1MB)
|
||||
SRC_BUF_SIZE: t.CDefine = 1048576
|
||||
@@ -50,7 +50,7 @@ class SrcFileEntry:
|
||||
# Args: mb 内存池;dir_path 当前扫描目录;entries SrcFileEntry 数组;entry_size 单个条目大小(SrcFileEntry.__sizeof__());file_count 当前已收集的文件数;max_files 最大文件数
|
||||
# Returns: 新的 file_count
|
||||
# ============================================================
|
||||
def _ScanDirForPyFiles(mb: rowptr[memhub.MemBuddy],
|
||||
def _ScanDirForPyFiles(mb: rawptr[memhub.MemBuddy],
|
||||
dir_path: str,
|
||||
entries: SrcFileEntry | t.CPtr,
|
||||
entry_size: sizet,
|
||||
@@ -156,7 +156,7 @@ def _ScanDirForPyFiles(mb: rowptr[memhub.MemBuddy],
|
||||
# Kernel/intr/isr.s 定义 isr0/syscall_entry/_per_cpu 等符号)。
|
||||
# TPV 不对 .s 翻译,直接用 llvm-mc 汇编为 .obj 参与链接。
|
||||
# ============================================================
|
||||
def _ScanDirForAsmFiles(mb: rowptr[memhub.MemBuddy],
|
||||
def _ScanDirForAsmFiles(mb: rawptr[memhub.MemBuddy],
|
||||
dir_path: str,
|
||||
entries: SrcFileEntry | t.CPtr,
|
||||
entry_size: sizet,
|
||||
@@ -256,7 +256,7 @@ def _ScanDirForAsmFiles(mb: rowptr[memhub.MemBuddy],
|
||||
# 才首次注册,reset_to(mark2) 会回收表与节点 → 后续查重/特化遍历悬空内存崩溃;App 文件数量少,mark2 前预注册的 AST 驻留内存可忽略。
|
||||
# 重复注册由 _register_generic_template 查重跳过。
|
||||
# ============================================================
|
||||
def _PreRegisterAppGenericTemplates(mb: rowptr[memhub.MemBuddy],
|
||||
def _PreRegisterAppGenericTemplates(mb: rawptr[memhub.MemBuddy],
|
||||
entries: SrcFileEntry | t.CPtr,
|
||||
file_count: int,
|
||||
entry_size: sizet) -> int:
|
||||
@@ -270,7 +270,7 @@ def _PreRegisterAppGenericTemplates(mb: rowptr[memhub.MemBuddy],
|
||||
if ent_pa is None or ent_pa.Path is None or ent_pa.Sha1 is None:
|
||||
continue
|
||||
# 读取文件
|
||||
f_pa: rowptr[fileio.File] = fileio.File(ent_pa.Path, fileio.MODE.R)
|
||||
f_pa: rawptr[fileio.File] = fileio.File(ent_pa.Path, fileio.MODE.R)
|
||||
if f_pa.closed:
|
||||
continue
|
||||
# read_all 的容量参数含终止符(最多读 cap-1 字节), 文件更长会被静默截断
|
||||
@@ -290,7 +290,7 @@ def _PreRegisterAppGenericTemplates(mb: rowptr[memhub.MemBuddy],
|
||||
if bytes_read_pa < SRC_BUF_SIZE:
|
||||
src_buf_pa[bytes_read_pa] = 0
|
||||
# 解析 AST(只解析,不完整翻译;用永久池使模板节点跨 mark2 reset 存活)
|
||||
perm_pa: rowptr[memhub.MemBuddy] = CompilerFactory.factory.PermPool
|
||||
perm_pa: rawptr[memhub.MemBuddy] = CompilerFactory.factory.PermPool
|
||||
if perm_pa is None:
|
||||
perm_pa = mb
|
||||
lx_pa: ast.Lexer | t.CPtr = ast.new_lexer(perm_pa)
|
||||
@@ -450,7 +450,7 @@ def _PhaseATextLLExists(temp_dir: str, td_len: sizet, sha1: str) -> int:
|
||||
tpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "text.ll")
|
||||
if tpath is None:
|
||||
return 0
|
||||
tf: rowptr[fileio.File] = fileio.File(tpath, fileio.MODE.R)
|
||||
tf: rawptr[fileio.File] = fileio.File(tpath, fileio.MODE.R)
|
||||
exists: int = 0
|
||||
if not tf.closed:
|
||||
tf.close()
|
||||
@@ -479,7 +479,7 @@ def _PhaseADumpNode(temp_dir: str, td_len: sizet, sha1: str,
|
||||
# 回退:读取 {temp_dir}/{前缀}/{sha1}.deps.txt(Phase1 已为 includes 写盘)
|
||||
dpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "deps.txt")
|
||||
if dpath is not None:
|
||||
df: rowptr[fileio.File] = fileio.File(dpath, fileio.MODE.R)
|
||||
df: rawptr[fileio.File] = fileio.File(dpath, fileio.MODE.R)
|
||||
if not df.closed:
|
||||
deps = stdlib.malloc(PA_DEPS_MAX_STR)
|
||||
if deps is not None:
|
||||
@@ -608,7 +608,7 @@ def _PhaseADumpFailGraph(temp_dir: str, td_len: sizet, path: str, sha1: str) ->
|
||||
stdio.fflush(None)
|
||||
|
||||
|
||||
def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
def RunMultiFileProject(mb: rawptr[memhub.MemBuddy],
|
||||
source_dir: str, temp_dir: str, output_dir: str,
|
||||
cc_cmd: str, cc_flags: str,
|
||||
linker_cmd: str, linker_flags: str, linker_output: str,
|
||||
@@ -699,7 +699,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
map_path_am: bytes = stdlib.malloc(td_len_am + 32)
|
||||
if map_path_am is not None:
|
||||
viperlib.snprintf(map_path_am, td_len_am + 32, "%s/_sha1_map.txt", temp_dir)
|
||||
mf: rowptr[fileio.File] = fileio.File(map_path_am, fileio.MODE.A)
|
||||
mf: rawptr[fileio.File] = fileio.File(map_path_am, fileio.MODE.A)
|
||||
line_am: bytes = stdlib.malloc(512)
|
||||
# 先遍历一次填充内存存储器(不依赖文件 I/O),再写入 _sha1_map.txt
|
||||
app_filled: int = 0
|
||||
@@ -758,7 +758,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | vpi 路径生成失败", "PhaseA")
|
||||
continue
|
||||
vf_vp2: rowptr[fileio.File] = fileio.File(vpi_path_vp2, fileio.MODE.R)
|
||||
vf_vp2: rawptr[fileio.File] = fileio.File(vpi_path_vp2, fileio.MODE.R)
|
||||
if not vf_vp2.closed:
|
||||
vf_vp2.close()
|
||||
stdlib.free(vpi_path_vp2)
|
||||
@@ -766,7 +766,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
stdlib.free(vpi_path_vp2)
|
||||
# 读取源文件 → 解析 AST → 生成 vpi
|
||||
# (rel_path 传 None:与 TranslateFileGetTrans 后续覆盖写的内容一致)
|
||||
f_vp2: rowptr[fileio.File] = fileio.File(ent_vp2.Path, fileio.MODE.R)
|
||||
f_vp2: rawptr[fileio.File] = fileio.File(ent_vp2.Path, fileio.MODE.R)
|
||||
if f_vp2.closed:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | 无法打开源文件", "PhaseA")
|
||||
@@ -816,7 +816,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
if pyi_pos_vp2 > 0:
|
||||
pyi_path_vp2: str = StubMergerCollect._sliced_path(temp_dir, td_len_vpa, ent_vp2.Sha1, "vpi")
|
||||
if pyi_path_vp2 is not None:
|
||||
pf_vp2: rowptr[fileio.File] = fileio.File(pyi_path_vp2, fileio.MODE.W)
|
||||
pf_vp2: rawptr[fileio.File] = fileio.File(pyi_path_vp2, fileio.MODE.W)
|
||||
if not pf_vp2.closed:
|
||||
pf_vp2.write(pyi_buf_vp2, pyi_pos_vp2)
|
||||
pf_vp2.close()
|
||||
@@ -1052,7 +1052,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
# save stub.ll (切片路径: temp_dir/{sha1前缀}/{sha1}.stub.ll)
|
||||
stub_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "stub.ll")
|
||||
if stub_path_a is not None:
|
||||
sf_a: rowptr[fileio.File] = fileio.File(stub_path_a, fileio.MODE.W)
|
||||
sf_a: rawptr[fileio.File] = fileio.File(stub_path_a, fileio.MODE.W)
|
||||
if not sf_a.closed:
|
||||
sf_a.write(stub_buf_a, stub_len_a)
|
||||
sf_a.close()
|
||||
@@ -1069,7 +1069,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
# save text.ll (切片路径)
|
||||
text_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "text.ll")
|
||||
if text_path_a is not None:
|
||||
tf_a: rowptr[fileio.File] = fileio.File(text_path_a, fileio.MODE.W)
|
||||
tf_a: rawptr[fileio.File] = fileio.File(text_path_a, fileio.MODE.W)
|
||||
if not tf_a.closed:
|
||||
tf_a.write(text_buf_a, text_len_a)
|
||||
tf_a.close()
|
||||
@@ -1079,7 +1079,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
# save dependencies (_imported_modules) for Phase B (切片路径)
|
||||
deps_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "deps.txt")
|
||||
if deps_path_a is not None:
|
||||
df_a: rowptr[fileio.File] = fileio.File(deps_path_a, fileio.MODE.W)
|
||||
df_a: rawptr[fileio.File] = fileio.File(deps_path_a, fileio.MODE.W)
|
||||
if not df_a.closed:
|
||||
if tr_a._imported_modules is not None:
|
||||
dl_a: sizet = string.strlen(tr_a._imported_modules)
|
||||
@@ -1429,7 +1429,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
is_decl_mi: int = -1
|
||||
tpath_mi: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "text.ll")
|
||||
if tpath_mi is not None:
|
||||
tf_mi: rowptr[fileio.File] = fileio.File(tpath_mi, fileio.MODE.R)
|
||||
tf_mi: rawptr[fileio.File] = fileio.File(tpath_mi, fileio.MODE.R)
|
||||
if not tf_mi.closed:
|
||||
is_decl_mi = 1
|
||||
tbuf_mi: bytes = stdlib.malloc(StubMerger.STUB_READ_BUF_SIZE)
|
||||
@@ -1495,7 +1495,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
inc_stub_len: sizet = string.strlen(inc_stub_buf)
|
||||
inc_stub_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "stub.ll")
|
||||
if inc_stub_path is not None:
|
||||
isf: rowptr[fileio.File] = fileio.File(inc_stub_path, fileio.MODE.W)
|
||||
isf: rawptr[fileio.File] = fileio.File(inc_stub_path, fileio.MODE.W)
|
||||
if not isf.closed:
|
||||
isf.write(inc_stub_buf, inc_stub_len)
|
||||
isf.close()
|
||||
@@ -1508,7 +1508,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
inc_text_len: sizet = string.strlen(inc_text_buf)
|
||||
inc_text_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "text.ll")
|
||||
if inc_text_path is not None:
|
||||
itf: rowptr[fileio.File] = fileio.File(inc_text_path, fileio.MODE.W)
|
||||
itf: rawptr[fileio.File] = fileio.File(inc_text_path, fileio.MODE.W)
|
||||
if not itf.closed:
|
||||
itf.write(inc_text_buf, inc_text_len)
|
||||
itf.close()
|
||||
@@ -1527,13 +1527,13 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
diag_stub_ex: int = 0
|
||||
diag_text_ex: int = 0
|
||||
if diag_stub is not None:
|
||||
df_diag_s: rowptr[fileio.File] = fileio.File(diag_stub, fileio.MODE.R)
|
||||
df_diag_s: rawptr[fileio.File] = fileio.File(diag_stub, fileio.MODE.R)
|
||||
if not df_diag_s.closed:
|
||||
diag_stub_ex = 1
|
||||
df_diag_s.close()
|
||||
stdlib.free(diag_stub)
|
||||
if diag_text is not None:
|
||||
df_diag_t: rowptr[fileio.File] = fileio.File(diag_text, fileio.MODE.R)
|
||||
df_diag_t: rawptr[fileio.File] = fileio.File(diag_text, fileio.MODE.R)
|
||||
if not df_diag_t.closed:
|
||||
diag_text_ex = 1
|
||||
df_diag_t.close()
|
||||
@@ -1663,7 +1663,7 @@ def RunMultiFileProject(mb: rowptr[memhub.MemBuddy],
|
||||
obj_path_pc: str = StubMergerCollect._sliced_path(includes_binary_dir, ibd_len_pc, rsha1_pc, "obj")
|
||||
if obj_path_pc is not None:
|
||||
# 检查 .obj 文件是否存在
|
||||
cf_pc: rowptr[fileio.File] = fileio.File(obj_path_pc, fileio.MODE.R)
|
||||
cf_pc: rawptr[fileio.File] = fileio.File(obj_path_pc, fileio.MODE.R)
|
||||
if not cf_pc.closed:
|
||||
cf_pc.close()
|
||||
# .obj 存在,追加到 final_obj_paths
|
||||
|
||||
Reference in new issue
Block a user