Files
TransPyC/lib/core/Handles/HandlesSpecialCall.py
T
TermiNexus 2e80424d67 refactor(handles): 删除 CSpecialCallHandle/TSpecialCallHandle
EmitRawCopyLlvm 改为模块级函数;删除 c./t. 语法糖处理类及 BaseTranslator 实例化,全仓零引用。
2026-10-18 21:51:10 +08:00

29 lines
1.3 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
import llvmlite.ir as ir
if TYPE_CHECKING:
from lib.core.Translator.LlvmGenerator import LlvmGeneratorMixin
def EmitRawCopyLlvm(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.
The width comes from the destination pointee and the source pointer is
bitcast to it, so this reinterprets memory instead of converting values
(e.g. `*&bits = *&dbl` must keep the IEEE bits, not fptosi).
"""
if not isinstance(DstPtr.type, ir.PointerType) or not isinstance(SrcPtr.type, ir.PointerType):
return False
Pointee: ir.Type = DstPtr.type.pointee
if isinstance(Pointee, ir.VoidType):
return False
TargetPtrTy: ir.PointerType = ir.PointerType(Pointee)
SrcCast: ir.Value = SrcPtr if SrcPtr.type == TargetPtrTy else Gen.builder.bitcast(SrcPtr, TargetPtrTy, name=f"{NamePrefix}_src_cast")
Loaded: ir.Value | None = Gen._load(SrcCast, name=f"{NamePrefix}_loaded")
if Loaded is None:
return False
DstCast: ir.Value = DstPtr if DstPtr.type == TargetPtrTy else Gen.builder.bitcast(DstPtr, TargetPtrTy, name=f"{NamePrefix}_dst_cast")
Gen._store(Loaded, DstCast)
return True