修正了 TPC 的一些错误,包括 Test 维护后 TPV 无法重新编译或重编译后越界的部分问题

This commit is contained in:
2026-07-20 11:12:30 +08:00
parent ab73420b4f
commit a277ded8d4
476 changed files with 4000 additions and 3439 deletions

View File

@@ -245,17 +245,18 @@ def param_set_attrs(param: Param | t.CPtr, attrs: t.CChar | t.CPtr):
# ============================================================
# _ll_name_needs_quote - 检查 LLVM 标识符是否需要加引号
#
# LLVM IR 规范:标识符以数字开头或含特殊字符(如 '.')时必须
# 用双引号包围。SHA1 命名空间的函数名格式为 "sha1hex.funcname"
# (含 '.'),以 hex 字符开头(可能以数字开头),因此需要加引号
# 普通函数名(如 printf/malloc/main不含特殊字符不加引号。
# LLVM IR 规范:标识符合法字符集为 [-a-zA-Z$._][-a-zA-Z$._0-9]*
# 以数字开头或含非合法字符(如 '['、']'、' '、'@' 等)时必须用双引号包围。
# '.' 是合法字符,不需要加引号(如 @.str、@llvm.memcpy 都不加引号)
# SHA1 命名空间的函数名(如 "4dad2ba72ed7ba09.GSListNode[Param]")含 '['、']'
# 需要加引号;但纯 hex+点 的名字(如 "abc.def")不需要。
# ============================================================
def _ll_name_needs_quote(name: str) -> t.CInt:
"""检查 LLVM 标识符是否需要加引号(以数字开头或含 '.'
"""检查 LLVM 标识符是否需要加引号(以数字开头或含非合法字符
例外: LLVM 内联函数名(如 llvm.memcpy/llvm.memset'llvm.' 开头,
虽含 '.',但不能加引号——加引号后 LLVM 解析器不识别为内联函数,
导致 declare/call 签名不匹配Intrinsic called with incompatible signature
LLVM IR 合法字符a-z, A-Z, 0-9, -, $, ., _
首字符是数字时需要加引号LLVM 要求局部/全局标识符首字符非数字,除非加引号)。
含其他字符(如 '['']'、空格)时需要加引号
"""
if name is None:
return 0
@@ -263,13 +264,13 @@ def _ll_name_needs_quote(name: str) -> t.CInt:
if c0 >= '0' and c0 <= '9':
return 1
name_len: t.CSizeT = string.strlen(name)
# 豁免 llvm.* 前缀的内联函数名
if name_len >= 5:
if name[0] == 'l' and name[1] == 'l' and name[2] == 'v' and name[3] == 'm' and name[4] == '.':
return 0
i: t.CSizeT = 0
while i < name_len:
if name[i] == '.':
ch: t.CChar = name[i]
# 合法字符a-z, A-Z, 0-9, -, $, ., _
if not ((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z') or
(ch >= '0' and ch <= '9') or ch == '-' or ch == '$' or
ch == '.' or ch == '_'):
return 1
i += 1
return 0
@@ -329,8 +330,8 @@ def FunctionPrint(buf: t.CChar | t.CPtr, size: t.CSizeT,
ty_buf[0] = '\0'
TypePrint(ty_buf, 128, cur.Ty, pool)
_append_cstr(buf, size, ty_buf)
# declare 声明不打印参数名
if func.IsDeclared == 0 and cur.Name is not None:
# declare 和 define 都打印参数名(如果有)
if cur.Name is not None:
_append_cstr(buf, size, " ")
# LLVM IR 要求参数名以 % 开头
if cur.Name[0] != '%':