From bd0e541b7423c1ad26e8d5b1e85def6ffeabbdb7 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 17 Aug 2026 21:00:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(handles):=20=E5=88=A0=E9=99=A4=20[CD]=20loo?= =?UTF-8?q?kup:=20=E8=B0=83=E8=AF=95=E8=BE=93=E5=87=BA=E5=8F=8A=E6=97=A0?= =?UTF-8?q?=E7=94=A8=20=5Fis=5Fcd=5Fkey=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除 _HandleNameLlvm 中 4 处 [CD] lookup 调试打印(干扰编译日志)、 随之失效的 _is_cd_key 计算、以及仅用于打印的 SymbolTable.lookup 死代码。 --- lib/core/Handles/HandlesExpr.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/core/Handles/HandlesExpr.py b/lib/core/Handles/HandlesExpr.py index af12896..e6cb97b 100644 --- a/lib/core/Handles/HandlesExpr.py +++ b/lib/core/Handles/HandlesExpr.py @@ -328,9 +328,6 @@ class ExprHandle(BaseHandle): def _HandleNameLlvm(self, Node: ast.Name, VarType: ir.Type | str | None = None) -> ir.Value: Gen: LlvmCodeGenerator = self.Trans.LlvmGen VarName: str = Node.id - # [CD] 诊断:仅对关键常量输出(FOREGROUND_*, BACKGROUND_*, STD_*, *HANDLE*) - import sys as _sys - _is_cd_key: bool = isinstance(VarName, str) and (VarName.startswith('FOREGROUND_') or VarName.startswith('BACKGROUND_') or 'STD_' in VarName or 'HANDLE' in VarName) # 治本修复:不把 module.globals 的 initializer 注入 _define_constants。 # 原因:CDefine(t.CDefine 注解)在 AnnAssign/Assign 处理时已注册到 # _define_constants 且不创建 LLVM global(不在 module.globals); @@ -357,8 +354,6 @@ class ExprHandle(BaseHandle): _init: Any = _gvar.initializer if isinstance(_init, ir.Constant) and isinstance(_init.constant, (int, float, str)): val = _init.constant - if _is_cd_key: - print(f"[CD] lookup: '{VarName}' found in _define_constants val={val}", file=_sys.stderr, flush=True) if isinstance(val, int): # Use VarType hint if available to avoid unnecessary type mismatch if VarType is not None and isinstance(VarType, ir.IntType): @@ -379,14 +374,6 @@ class ExprHandle(BaseHandle): # 覆盖本模块同名全局变量(VpiReader.SHA1_LEN=16 被 Phase1.SHA1_LEN=17 覆盖)。 # 本模块 CDefine 已在步骤1(_define_constants)解析; # 跨模块 CDefine 通过 _RegisterFromImportAliases 显式导入注册到 _define_constants。 - if VarName not in define_constants: - try: - sym_info: Any = self.Trans.SymbolTable.lookup(VarName) - if _is_cd_key and sym_info and sym_info.IsDefine: - print(f"[CD] lookup: '{VarName}' skipped in SymbolTable (CDefine not cross-module)", file=_sys.stderr, flush=True) - except Exception as _e: - if _config_mode == "strict": - self.Trans.LogWarning(f"异常被忽略: {_e}") # 治本修复:如果符号表也没有,回退查询 _all_define_constants # _all_define_constants 由 Phase2Translator 从所有 .pyi 文件预提取, # 包含跨模块导入的 CDefine 常量(如 FOREGROUND_GREEN、STD_OUTPUT_HANDLE) @@ -394,8 +381,6 @@ class ExprHandle(BaseHandle): all_dc: dict[str, Any] = getattr(Gen, '_all_define_constants', None) or getattr(self.Trans, '_all_define_constants', None) or {} if VarName in all_dc: val: Any = all_dc[VarName] - if _is_cd_key: - print(f"[CD] lookup: '{VarName}' found in _all_define_constants val={val}", file=_sys.stderr, flush=True) if isinstance(val, int): if VarType is not None and isinstance(VarType, ir.IntType): return ir.Constant(VarType, val & ((1 << VarType.width) - 1)) @@ -406,8 +391,6 @@ class ExprHandle(BaseHandle): return ir.Constant(ir.DoubleType(), val) elif isinstance(val, str): return Gen._create_string_global(val) - elif _is_cd_key: - print(f"[CD] lookup: '{VarName}' NOT found in ANY CDefine table", file=_sys.stderr, flush=True) # 优先检查 variables(alloca),因为变量可能已被 += 等操作迁移到 variables if VarName in Gen.variables and Gen.variables[VarName] is not None: VarPtr: Any = Gen.variables[VarName]