fix(codegen): 新规范迁移暴露的 4 类解析/代码生成缺陷
1) HandlesExpr._HandleConstantLlvm 引号判定用 AST lineno 直查磁盘行,漏了 _inject_auto_imports 注入行的偏移 N,取到错行;改用 _DiskLineno 还原,并把 col_offset(UTF-8 字节偏移)转字符偏移后再切片。2) Phase2Translator 新增 _DedupComdatDecls:_dso.ll 由各依赖片段拼接,每片段各带同名 comdat 声明,llc 报 redefinition of comdat;在 _AddWeakComdat 入口与两处落盘点去重。3) LLVMTypeMapper._resolve_name 补存储类/类型限定符标记分支(CExport/CExtern/CConst… 返回空串,由 _resolve_bitor 取另一侧真实类型),与 _resolve_attribute 同口径。4) 短别名(int/int64/sizet/char…)在 typedef 右值与类型转换调用处解析不到:SymbolTypeResolver._resolve_typedef_from_value 与 LLVMTypeMapper.resolve_typedef_value_type 的 ast.Name 分支补 builtins typedef / BuiltinTypeMap 兜底(BaseType 可能是 CType 实例,须取 type(x).__name__),HandlesExprCall 的类型转换求值补 _lookup_builtins_typedef 回退并保留双参数 CPtr 指针包装。验证:TransPyV 自举 includes 52/52 + App 76/76 全通过;TPV 顺序回归 77/77。
This commit is contained in:
1 parent
65f0e87193
commit
07ba7a4fe5
5 files changed
+141
-11
No files matched your search
@@ -723,13 +723,35 @@ class ExprCallHandle(BaseHandle):
|
||||
# 因此改走权威 typedef 值:'t.CUInt64T' → CTypeRegistry.NameToLLVM
|
||||
# → 'i64'(与 DeclarationGenerator 的 stub 兜底同机制)。
|
||||
_bv_td: str | None = _TAR_TD.builtins_typedef_value(FuncName)
|
||||
_lls_td: str | None = None
|
||||
if _bv_td:
|
||||
_nm_td: str = _bv_td[2:] if _bv_td.startswith('t.') else _bv_td
|
||||
from lib.includes.t import CTypeRegistry as _CR_TD
|
||||
_lls_td: str | None = _CR_TD.NameToLLVM(_nm_td)
|
||||
if _lls_td:
|
||||
_tg_td: ir.Type = Gen._ctype_to_llvm(_lls_td)
|
||||
if isinstance(_tg_td, (ir.IntType, ir.FloatType, ir.DoubleType, ir.PointerType)):
|
||||
_lls_td = _CR_TD.NameToLLVM(_nm_td)
|
||||
if not _lls_td:
|
||||
# 声明值本身也是短别名(新语法:`typedef short = int16`、
|
||||
# `typedef longlong = int64`)⇒ 单步 NameToLLVM(不认短别名)
|
||||
# 落空。改走权威链式解析(builtins.vp 声明 → 逐级展开到 t.C*),
|
||||
# 与注解位置 LLVMTypeMapper._resolve_name 同一来源。
|
||||
_td_info = _TAR_TD._lookup_builtins_typedef(FuncName, self.Trans.SymbolTable)
|
||||
if _td_info is not None and _td_info.BaseType:
|
||||
_tg_td2: ir.Type = Gen._ctype_to_llvm(_td_info)
|
||||
if isinstance(_tg_td2, (ir.IntType, ir.FloatType, ir.DoubleType, ir.PointerType)):
|
||||
if len(Node.args) >= 2:
|
||||
_p2b: ast.AST = Node.args[1]
|
||||
_p2b_cptr: bool = (
|
||||
(isinstance(_p2b, ast.Attribute) and _p2b.attr == 'CPtr'
|
||||
and isinstance(_p2b.value, ast.Name) and _p2b.value.id in ('t', 'c')) or
|
||||
(isinstance(_p2b, ast.Name) and _p2b.id == 'CPtr')
|
||||
)
|
||||
if _p2b_cptr:
|
||||
if isinstance(_tg_td2, ir.PointerType):
|
||||
return self._emit_rawptr_cast(Node, Gen, _tg_td2)
|
||||
return self._emit_rawptr_cast(Node, Gen, ir.PointerType(_tg_td2))
|
||||
return self._emit_rawptr_cast(Node, Gen, _tg_td2)
|
||||
if _lls_td:
|
||||
_tg_td: ir.Type = Gen._ctype_to_llvm(_lls_td)
|
||||
if isinstance(_tg_td, (ir.IntType, ir.FloatType, ir.DoubleType, ir.PointerType)):
|
||||
# 双参数形式 uint8(s, t.CPtr) / int64(v, CPtr):第二参是
|
||||
# CPtr 标记 → 指针包装(等价旧写法 t.CUInt8T(s, t.CPtr),
|
||||
# 对齐 Attribute 形式 t.CXXX(v, t.CPtr) 的 IsPtr_cast 语义)。
|
||||
|
||||
Reference in new issue
Block a user