refactor(gen): R12/R13 同步——下标 while 循环改 for range、去 c.Set
与 includes 同步执行两批源改写:R12 把「i: int = 0 与 while i < N: … i += 1」形式的计数循环改写为「for i in range(N):」;R13 把 c.Set(*p, v) 迁移为 *p = v、c.Set(a, b) 迁移为 a = b(c.Set 是正在退化的路径)。 验证:bootstrap 三重重编 SUCCESS(无 vast_c 解析回退);全量 77/77 顺序回归通过(WebTest 首轮网络超时,单独重跑通过)。
This commit is contained in:
1 parent
a7b8118ce8
commit
fb53f88893
25 files changed
+133
-345
No files matched your search
@@ -940,12 +940,10 @@ def link_objs_to_exe(obj_paths: str, obj_paths_len: sizet, linker_cmd: str, link
|
||||
dt2len: sizet = dj - ds2
|
||||
if dt2len == dtlen:
|
||||
deq: int = 1
|
||||
dk: sizet = 0
|
||||
while dk < dtlen:
|
||||
for dk in range(dtlen):
|
||||
if dedup[ds2 + dk] != obj_paths[dstart + dk]:
|
||||
deq = 0
|
||||
break
|
||||
dk += 1
|
||||
if deq != 0:
|
||||
ddup = 1
|
||||
break
|
||||
@@ -1304,18 +1302,14 @@ def _tb_quoted_after(mb: memhub.MemBuddy*, s: str, key: str) -> str:
|
||||
|
||||
|
||||
def _tb_dir_lookup(dirs: bytes, count: int, idx: int) -> str:
|
||||
i: int = 0
|
||||
while i < count:
|
||||
for i in range(count):
|
||||
if int(_tb_rd_u32(dirs, sizet(i) * TB_DIR_SIZE)) == idx: return rawptr(_tb_rd_u64(dirs, sizet(i) * TB_DIR_SIZE + 8))
|
||||
i += 1
|
||||
return None
|
||||
|
||||
|
||||
def _tb_file_rec(files: bytes, count: int, idx: int) -> int:
|
||||
i: int = 0
|
||||
while i < count:
|
||||
for i in range(count):
|
||||
if int(_tb_rd_u32(files, sizet(i) * TB_FILE_SIZE)) == idx: return i
|
||||
i += 1
|
||||
return -1
|
||||
|
||||
|
||||
@@ -1407,11 +1401,9 @@ def _tb_func_name_for(fbuf: bytes, fcount: int, rva: uint64) -> str:
|
||||
def _tb_intern(p: TbPool*, s: str) -> uint64:
|
||||
"""Intern s into the pool (linear scan; keeps offset 0 as the empty sentinel)."""
|
||||
if p is None or s is None: return 0
|
||||
k: int = 0
|
||||
while k < p.OffCount:
|
||||
for k in range(p.OffCount):
|
||||
o: uint64 = _tb_rd_u64(p.Offs, sizet(k) * 8)
|
||||
if string.strcmp(p.Pool + sizet(o), s) == 0: return o
|
||||
k += 1
|
||||
off: uint64 = uint64(p.PoolLen)
|
||||
n: sizet = string.strlen(s)
|
||||
string.memcpy(p.Pool + sizet(off), s, n)
|
||||
@@ -1456,8 +1448,7 @@ def _tb_read_pe_layout(mb: memhub.MemBuddy*, exe_path: str) -> TbPeLayout*:
|
||||
min_rva: uint64 = 0xFFFFFFFF
|
||||
found_text: int = 0
|
||||
have_sec: int = 0
|
||||
si: uint64 = 0
|
||||
while si < nsec:
|
||||
for si in range(nsec):
|
||||
base: sizet = sec_off + sizet(si) * 40
|
||||
if uint64(base) + 40 > uint64(got): break
|
||||
va: uint64 = uint64(_tb_rd_u32(head, base + 12))
|
||||
@@ -1466,7 +1457,6 @@ def _tb_read_pe_layout(mb: memhub.MemBuddy*, exe_path: str) -> TbPeLayout*:
|
||||
if _tb_cc(head, base) == 46 and _tb_cc(head, base + 1) == 116 and _tb_cc(head, base + 2) == 101 and _tb_cc(head, base + 3) == 120 and _tb_cc(head, base + 4) == 116:
|
||||
text_rva = va
|
||||
found_text = 1
|
||||
si += 1
|
||||
if found_text == 0 and have_sec != 0 and min_rva != 0xFFFFFFFF: text_rva = min_rva
|
||||
lay.ImageBase = img_base
|
||||
lay.SizeOfImage = size_img
|
||||
@@ -1752,8 +1742,7 @@ def _tb_grp_get(grp: bytes, cap: int, caller: str, callee: str, do_insert: int)
|
||||
if grp is None or cap <= 0 or caller is None or callee is None: return -1
|
||||
mask: uint64 = uint64(cap - 1)
|
||||
hv: uint64 = (_tb_strhash(caller) * 0x100000001B3 + _tb_strhash(callee)) & mask
|
||||
i: int = 0
|
||||
while i < cap:
|
||||
for i in range(cap):
|
||||
slot: int = int((hv + uint64(i)) & mask)
|
||||
off: sizet = sizet(slot) * TB_GRP_SIZE
|
||||
if uint64(_tb_rd_u32(grp, off + TB_GRP_OFF_USED)) == 0:
|
||||
@@ -1768,7 +1757,6 @@ def _tb_grp_get(grp: bytes, cap: int, caller: str, callee: str, do_insert: int)
|
||||
sc: str = rawptr(_tb_rd_u64(grp, off + TB_GRP_OFF_CALLER))
|
||||
sk: str = rawptr(_tb_rd_u64(grp, off + TB_GRP_OFF_CALLEE))
|
||||
if sc is not None and sk is not None and string.strcmp(sc, caller) == 0 and string.strcmp(sk, callee) == 0: return slot
|
||||
i += 1
|
||||
return -1
|
||||
|
||||
|
||||
@@ -1910,13 +1898,11 @@ def _tb_parse_vpcall_file(mb: memhub.MemBuddy*, path: str, cp: TbCallParse*) ->
|
||||
|
||||
def _tb_load_vpcalls(mb: memhub.MemBuddy*, cp: TbCallParse*) -> int:
|
||||
if _tb_vpcall_buf is None or _tb_vpcall_n <= 0: return 0
|
||||
k: int = 0
|
||||
while k < _tb_vpcall_n:
|
||||
for k in range(_tb_vpcall_n):
|
||||
slot: str* = (str*)(uint64(_tb_vpcall_buf) + sizet(k) * 8)
|
||||
path: str = slot[0]
|
||||
if path is not None:
|
||||
if _tb_parse_vpcall_file(mb, path, cp) != 0: return 1
|
||||
k += 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1929,8 +1915,7 @@ def _tb_build_groups(mb: memhub.MemBuddy*, cp: TbCallParse*) -> int:
|
||||
VLogger.error("--traceback: 调用点分组表分配失败,终止编译", "TRACEBACK")
|
||||
return 1
|
||||
string.memset(cp.Grp, 0, sizet(cp.GrpCap) * TB_GRP_SIZE)
|
||||
i: int = 0
|
||||
while i < cp.CrN:
|
||||
for i in range(cp.CrN):
|
||||
off: sizet = sizet(i) * TB_CR_SIZE
|
||||
caller: str = rawptr(_tb_rd_u64(cp.Cr, off + TB_CR_OFF_CALLER))
|
||||
callee: str = rawptr(_tb_rd_u64(cp.Cr, off + TB_CR_OFF_CALLEE))
|
||||
@@ -1948,7 +1933,6 @@ def _tb_build_groups(mb: memhub.MemBuddy*, cp: TbCallParse*) -> int:
|
||||
_tb_wr_u32(cp.Cr, toff + TB_CR_OFF_NEXT, uint64(i))
|
||||
_tb_wr_u32(cp.Cr, off + TB_CR_OFF_NEXT, uint64(TB_IDX_NONE))
|
||||
_tb_wr_u32(cp.Grp, goff + TB_GRP_OFF_TAIL, uint64(i))
|
||||
i += 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1972,15 +1956,13 @@ def _tb_emit_call_row(mb: memhub.MemBuddy*, d: TbDump*, cp: TbCallParse*, img_lo
|
||||
def _tb_emit_entry_row(mb: memhub.MemBuddy*, d: TbDump*, cp: TbCallParse*, img_lo: uint64, addr: uint64, sym: str) -> int:
|
||||
"""Emit a fallback function-entry row for an objdump label sym (file/line from the F record)."""
|
||||
if sym is None or cp.Fr is None or cp.FrN <= 0 or addr < img_lo: return 0
|
||||
i: int = 0
|
||||
while i < cp.FrN:
|
||||
for i in range(cp.FrN):
|
||||
off: sizet = sizet(i) * TB_FR_SIZE
|
||||
s: str = rawptr(_tb_rd_u64(cp.Fr, off + TB_FR_OFF_SYM))
|
||||
if s is not None and string.strcmp(s, sym) == 0:
|
||||
file: str = rawptr(_tb_rd_u64(cp.Fr, off + TB_FR_OFF_FILE))
|
||||
dl: int = int(_tb_rd_u32(cp.Fr, off + TB_FR_OFF_DEFLINE))
|
||||
return _tb_emit_row(mb, d, addr, file, dl, sym)
|
||||
i += 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -2298,8 +2280,7 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
if ro is None:
|
||||
VLogger.error("--traceback: 记录偏移缓冲分配失败,终止编译", "TRACEBACK")
|
||||
return 1
|
||||
i = 0
|
||||
while i < uniq:
|
||||
for i in range(uniq):
|
||||
pth2: str = rawptr(_tb_rd_u64(d.RowBuf, sizet(i) * TB_ROW_SIZE + TB_ROW_OFF_FILE))
|
||||
foff: uint64 = _tb_intern(p, pth2)
|
||||
noff: uint64 = 0
|
||||
@@ -2311,7 +2292,6 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
if nm2 is not None: noff = _tb_intern(p, nm2)
|
||||
_tb_wr_u32(ro, sizet(i) * 8, foff)
|
||||
_tb_wr_u32(ro, sizet(i) * 8 + 4, noff)
|
||||
i += 1
|
||||
|
||||
# ---- 5) self-checks (mirror the runtime LoadMapFile validation) ----
|
||||
prev_rva: uint64 = 0
|
||||
@@ -2335,13 +2315,11 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
return 1
|
||||
# file_off must be >= 1: offset 0 is the empty-string sentinel and the runtime
|
||||
# rejects a whole map whose record file_off is 0.
|
||||
ci = 0
|
||||
while ci < uniq:
|
||||
for ci in range(uniq):
|
||||
fo: uint64 = uint64(_tb_rd_u32(ro, sizet(ci) * 8))
|
||||
if fo == 0:
|
||||
VLogger.error("--traceback 自检失败:存在 file_off==0 的记录(空路径,运行期会拒绝该旁文件),终止编译", "TRACEBACK")
|
||||
return 1
|
||||
ci += 1
|
||||
|
||||
# ---- 6) serialise and write <exe>.stackmap ----
|
||||
total: sizet = 20 + sizet(uniq) * 20 + sizet(p.PoolLen)
|
||||
@@ -2357,8 +2335,7 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
_tb_wr_u32(out, 8, uint64(uniq))
|
||||
_tb_wr_u32(out, 12, uint64(p.OffCount))
|
||||
_tb_wr_u32(out, 16, uint64(p.PoolLen))
|
||||
ri2: int = 0
|
||||
while ri2 < uniq:
|
||||
for ri2 in range(uniq):
|
||||
roff2: sizet = 20 + sizet(ri2) * 20
|
||||
rv3: uint64 = _tb_rd_u64(d.RowBuf, sizet(ri2) * TB_ROW_SIZE)
|
||||
ln3: uint64 = uint64(_tb_rd_u32(d.RowBuf, sizet(ri2) * TB_ROW_SIZE + TB_ROW_OFF_LINE))
|
||||
@@ -2366,7 +2343,6 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
_tb_wr_u32(out, roff2 + 8, uint64(_tb_rd_u32(ro, sizet(ri2) * 8)))
|
||||
_tb_wr_u32(out, roff2 + 12, ln3)
|
||||
_tb_wr_u32(out, roff2 + 16, uint64(_tb_rd_u32(ro, sizet(ri2) * 8 + 4)))
|
||||
ri2 += 1
|
||||
string.memcpy(out + 20 + sizet(uniq) * 20, p.Pool, sizet(p.PoolLen))
|
||||
|
||||
map_len: sizet = string.strlen(exe_path) + 16
|
||||
|
||||
Reference in new issue
Block a user