From f32235274b349c26ef419795e3448874704e3592 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sun, 18 Oct 2026 21:45:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(expr):=20=E5=88=A0=E9=99=A4=E8=A3=B8?= =?UTF-8?q?=E5=90=8D=20Set=20=E8=AF=AD=E6=B3=95=E7=B3=96=E5=8F=8A=20=5FHan?= =?UTF-8?q?dleCSetLlvm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set 原本对应已退役的 c.Set;裸名 Set 与用户类 ast.Set 冲突,直接删除,Set(...) 走正常类构造。 --- lib/core/Handles/HandlesExprCall.py | 4 +- lib/core/Handles/HandlesSpecialCall.py | 62 -------------------------- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/lib/core/Handles/HandlesExprCall.py b/lib/core/Handles/HandlesExprCall.py index 24eae90..9eec122 100644 --- a/lib/core/Handles/HandlesExprCall.py +++ b/lib/core/Handles/HandlesExprCall.py @@ -531,15 +531,13 @@ class ExprCallHandle(BaseHandle): # irinp/irout 等价 LInp/LOut(仅作模板占位符,独立调用返回 0) if FuncName in ('irinp', 'irout'): return ir.Constant(ir.IntType(32), 0) - # 内建语法糖调用(裸名):Asm / Addr / Deref / DerefAs / Set / Load / + # 内建语法糖调用(裸名):Asm / Addr / Deref / DerefAs / Load / # PtrToInt / CError / AsmInp / AsmOut / LLVMIR / LInp / LOut / # CPragma / CUndef 不是普通函数,优先于符号查找。 if FuncName == 'Asm': return self.Trans.ExprAsmHandle._HandleAsmLlvm(Node) if FuncName == 'Addr': return self.Trans.CSpecialCallHandle._HandleCAddrLlvm(Node) - if FuncName == 'Set' and self.Trans.SymbolTable.lookup('Set') is None: - return self.Trans.CSpecialCallHandle._HandleCSetLlvm(Node) if FuncName == 'Load': return self.Trans.CSpecialCallHandle._HandleCLoadLlvm(Node) if FuncName == 'Deref': diff --git a/lib/core/Handles/HandlesSpecialCall.py b/lib/core/Handles/HandlesSpecialCall.py index 56e1db9..daa1b9f 100644 --- a/lib/core/Handles/HandlesSpecialCall.py +++ b/lib/core/Handles/HandlesSpecialCall.py @@ -89,68 +89,6 @@ class CSpecialCallHandle(BaseHandle): return Gen.builder.bitcast(ArgVal, ir.IntType(8).as_pointer(), name="addr_bitcast") return ir.Constant(ir.IntType(8).as_pointer(), None) - def _HandleCSetLlvm(self, Node: ast.Call) -> ir.Value: - Gen: LlvmGeneratorMixin = self.Trans.LlvmGen - if len(Node.args) >= 2: - target_arg: ast.expr = Node.args[0] - value_arg: ast.expr = Node.args[1] - target_ptr: ir.Value | None = None - if isinstance(target_arg, ast.Call) and isinstance(target_arg.func, ast.Name): - if target_arg.func.id == 'Deref' and target_arg.args: - deref_arg = target_arg.args[0] - if isinstance(deref_arg, ast.Name) and deref_arg.id in Gen.variables and Gen.variables[deref_arg.id] is not None: - target_ptr = Gen._load(Gen.variables[deref_arg.id], name="deref_load_ptr") - else: - inner_value = self.HandleExprLlvm(deref_arg) - if inner_value: - if isinstance(inner_value.type, ir.PointerType): - if isinstance(inner_value.type.pointee, ir.PointerType): - inner_value = Gen._load(inner_value, name="cast_deref") - target_ptr = inner_value - elif target_arg.func.id == 'Addr' and target_arg.args: - target_ptr = self.HandleExprLlvm(target_arg) - else: - type_attr = target_arg.func.id - resolved_cname = self.Trans.TSpecialCallHandle._ResolveTAttrToCName(type_attr) - if target_arg.args and resolved_cname is not None: - inner_val = self.HandleExprLlvm(target_arg.args[0]) - if inner_val and isinstance(inner_val.type, ir.PointerType): - target_llvm_type = Gen._basic_type_to_llvm(resolved_cname) - if target_llvm_type: - target_ptr = Gen.builder.bitcast(inner_val, ir.PointerType(target_llvm_type), name="tcast_ptr") - if not target_ptr: - if isinstance(target_arg, ast.Subscript): - target_ptr = self.Trans.ExprAttrHandle.HandleSubscriptPtrLlvm(target_arg) - else: - target_ptr = self.HandleExprLlvm(target_arg) - Val = self.HandleExprLlvm(value_arg) - if target_ptr and Val: - if isinstance(target_ptr.type, ir.PointerType): - ValToStore = Val - pointee = target_ptr.type.pointee - if isinstance(pointee, ir.PointerType) and isinstance(pointee.pointee, ir.IntType) and pointee.pointee.width == 8: - if isinstance(Val.type, ir.PointerType) and isinstance(Val.type.pointee, ir.IntType) and Val.type.pointee.width == 8: - ValToStore = Val - elif isinstance(Val.type, ir.IntType): - ValToStore = Gen.builder.inttoptr(Val, pointee, name="int_to_ptr_set") - elif isinstance(pointee, ir.IntType): - if isinstance(Val.type, ir.ArrayType) and isinstance(Val.type.element, ir.IntType) and Val.type.element.width == 8: - zero = ir.Constant(ir.IntType(32), 0) - value_ptr = Gen.builder.gep(Val, [zero, zero], name="value_ptr") - ValToStore = Gen._load(value_ptr, name="Load_value") - elif isinstance(Val.type, ir.PointerType) and isinstance(Val.type.pointee, ir.IntType) and Val.type.pointee.width == 8: - ValToStore = Gen._load(Val, name="Load_char_value") - if isinstance(ValToStore.type, ir.IntType) and isinstance(pointee, ir.IntType): - if ValToStore.type.width < pointee.width: - ValToStore = Gen.builder.zext(ValToStore, pointee, name="zext_set") - elif ValToStore.type.width > pointee.width: - ValToStore = Gen.builder.trunc(ValToStore, pointee, name="trunc_set") - elif Val.type != pointee: - if isinstance(pointee, ir.PointerType) and isinstance(Val.type, ir.PointerType): - ValToStore = Gen.builder.bitcast(Val, pointee, name="bitcast_set") - Gen._store(ValToStore, target_ptr) - return ir.Constant(ir.IntType(32), 1) - def EmitRawCopyLlvm(self, DstPtr: ir.Value, SrcPtr: ir.Value, Gen: LlvmGeneratorMixin, NamePrefix: str = "rawcopy") -> bool: """Emit `*dst = *src` as a raw byte copy (Load semantics); False if unusable.