38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""计算 Generator struct 中元素 105/106/107/108 的字节偏移,验证 this_adjust=776 一致性"""
|
|
import re
|
|
|
|
p = r'd:\Users\TermiNexus\Desktop\TransPyC\TransPyV\output\0bef502adb69f851.ll'
|
|
for line in open(p, encoding='utf-8', errors='replace'):
|
|
if '"e1ea7eaf63a9c3d1.Generator" = type' in line:
|
|
s = line.strip()
|
|
start = s.index('{')
|
|
end = s.rindex('}')
|
|
body = s[start + 1:end].strip()
|
|
# 顶层按逗号分割(元素不含嵌套花括号)
|
|
elems = [e.strip() for e in body.split(',')]
|
|
print('elements count:', len(elems))
|
|
|
|
def size_align(t):
|
|
t = t.strip()
|
|
if t.endswith('*') or t == 'i64' or t == 'double':
|
|
return (8, 8)
|
|
if t == 'i32' or t.startswith('float'):
|
|
return (4, 4)
|
|
if t == 'i16':
|
|
return (2, 2)
|
|
if t == 'i1' or t == 'i8':
|
|
return (1, 1)
|
|
return (8, 8)
|
|
|
|
off = 0
|
|
for i, e in enumerate(elems):
|
|
sz, al = size_align(e)
|
|
if al > 1:
|
|
off = ((off + al - 1) // al) * al
|
|
if i in (104, 105, 106, 107, 108, 109):
|
|
print(f' idx={i} type={e[:60]} byte_offset={off}')
|
|
off += sz
|
|
print('approx total:', off)
|
|
break
|