fix(handles): 删除 [CD] lookup: 调试输出及无用 _is_cd_key 逻辑
删除 _HandleNameLlvm 中 4 处 [CD] lookup 调试打印(干扰编译日志)、 随之失效的 _is_cd_key 计算、以及仅用于打印的 SymbolTable.lookup 死代码。
This commit is contained in:
1 parent
3b5f2af838
commit
bd0e541b74
1 file changed
-17
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user