From 3efe83f1ea4de82a9fffb86d651ba0031227a7d4 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 30 Sep 2026 14:55:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=96=E8=AF=91=E6=9C=9F=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E8=A7=A3=E6=9E=90):=20=E4=BF=AE=20StructGen=20?= =?UTF-8?q?=E7=BC=BA=20=5Fvlog=20=E5=AF=BC=E5=85=A5=E4=B8=8E=20HandlesImpo?= =?UTF-8?q?rts=20=E7=9A=84=20node/Node=20=E8=AF=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两处均为 a(编译器缺陷),且都被 HandlesImports.py:1055 的 `except Exception -> WARN 忽略异常` 吞掉,表现为模块声明静默退化 (本次现场:VpiReader.vp 阶段 WARN + 结构体声明路径中断)。非源码违规、 非机制漏豁免。 1) lib/core/LLVMCG/StructGen.py - `_generate_structs` 的「成员表含重名条目、body 已是权威布局」提示调用 `_vlog().warning(...)`,但本文件从未定义/导入 `_vlog` ⇒ NameError。 该分支一旦命中(astaux.ExceptHandler 一类),`_generate_structs` 整体中断。 - 补 `from lib.core.VLogger import get_logger as _vlog`,与同目录 FuncGen.py / TypeConvert.py 同口径。 2) lib/core/Handles/HandlesImports.py:1317 - `_EmitExternalGlobalDeclLlvm` 形参名为 `Node`,该 elif 分支误写成小写 `node` ⇒ 只要传入的是**非带注解**的跨模块全局量(`ast.Assign`)就恒抛 NameError, 分支整体不可达:外部全局变量从未声明 external,消费侧表现为 unknown global / 类型占位。 - 判据改回 `isinstance(Node, ast.Assign)`。 静态核验:对 TransPyC 全部 .py 做 symtable 未定义名扫描,结果 0 条; `python -m py_compile` 通过。 --- lib/core/Handles/HandlesImports.py | 2 +- lib/core/LLVMCG/StructGen.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/Handles/HandlesImports.py b/lib/core/Handles/HandlesImports.py index 61386d5..c84ec3b 100644 --- a/lib/core/Handles/HandlesImports.py +++ b/lib/core/Handles/HandlesImports.py @@ -1314,7 +1314,7 @@ class ImportHandle(BaseHandle): gv = ir.GlobalVariable(Gen.module, var_type, name=VarName) # 外部全局变量声明:只声明不定义(external linkage),避免多重定义 gv.linkage = 'external' - elif isinstance(node, ast.Assign) and Node.targets and isinstance(Node.targets[0], ast.Name): + elif isinstance(Node, ast.Assign) and Node.targets and isinstance(Node.targets[0], ast.Name): VarName = Node.targets[0].id if VarName.startswith('_'): return diff --git a/lib/core/LLVMCG/StructGen.py b/lib/core/LLVMCG/StructGen.py index ac5c88b..82bca9a 100644 --- a/lib/core/LLVMCG/StructGen.py +++ b/lib/core/LLVMCG/StructGen.py @@ -5,6 +5,7 @@ import vast as ast import llvmlite.ir as ir from llvmlite.ir.values import _Undefined from lib.includes import t as _t +from lib.core.VLogger import get_logger as _vlog # vtable 槽类型 `i8*` 的共享实例:llvmlite 的类型是不可变值语义(`_TypedPointerType` # 的 `__eq__` 按结构比较、打印结果只取决于结构),同一实例可在任意多少量复用。