o
    ۾i                     @   s   d Z ddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ dd Zdd	 Zd
d ZG dd deZG dd deZe ZdS )zD
Register external C functions necessary for Numba code generation.
    N)ir)utils
intrinsics)
_helperlibc                 C   s   t | st | | dS dS )z1Add missing symbol into LLVM internal symtab
    N)lladdress_of_symbol
add_symbol)symboladdr r   H/home/ubuntu/.local/lib/python3.10/site-packages/numba/core/externals.py_add_missing_symbol   s   
r   c                 C   s,   ddl m}m}m} t|j| }|||jS )zr
    Under Windows, look up a symbol inside the C runtime
    and return the raw pointer value as an integer.
    r   )cdllcastc_void_p)ctypesr   r   r   getattrmsvcrtvalue)r	   r   r   r   fr   r   r   _get_msvcrt_symbol   s   r   c              
   C   s@  |   }|d}|d}td}td}t|d}t|d}t|d}t|||g}	tj||	dd}
|
j\}}|
	 }t
|}|||}|||}|||||}|||||}|||||||}|||}|||}|||||||||}|||||}|||}|||}|||}|||||||||}|||||}|||||}|||||||||}|||||}|||||}|||}|||||||}|| || |  |S )zo
    Compile the multi3() helper function used by LLVM
    for 128-bit multiplication on 32-bit platforms.
    multi3@      l        )name)codegencreate_librarycreate_ir_moduler   IntTypeConstantFunctionTypeFunctionargsappend_basic_block	IRBuildertruncashrmuland_lshraddshlzextretadd_ir_modulefinalize)contextr   libraryir_modi64i128
lower_mask_32_64fn_typefnabbbbuilderalblahbhrltrhrr   r   r   compile_multi3   sV   










rG   c                   @      e Zd ZdZdd ZdS )
_InstallerFc                 C   s   | j s| | d| _ dS dS )z
        Install the functions into LLVM.  This only needs to be done once,
        as the mappings are persistent during the process lifetime.
        TN)
_installed_do_install)selfr1   r   r   r   installl   s   

z_Installer.installN)__name__
__module____qualname__rJ   rM   r   r   r   r   rI   h   s    rI   c                   @   rH   )_ExternalMathFunctionszd
    Map the math functions from the C runtime library into the LLVM
    execution environment.
    c                 C   s   t jdk}tj}tjdr|rtd}td| ntjdr0|r0td|d  td|d	  |rFt	|| _
| j
d
}|sAJ td| tjD ]
}t|||  qId S )Nr   win32_ftol_ftol2linux__fixunsdfdifptoui__fixunssfdifptouifr   __multi3)r   MACHINE_BITSr   	c_helperssysplatform
startswithr   r   rG   _multi3_libget_pointer_to_functionr   	INTR_MATHr   r   )rL   r1   is32bitr\   ftolptrfnamer   r   r   rK   |   s    



z"_ExternalMathFunctions._do_installN)rN   rO   rP   __doc__rK   r   r   r   r   rQ   v   s    rQ   )rg   r]   llvmliter   llvmlite.bindingbindingr   
numba.corer   r   numbar   r   r   rG   objectrI   rQ   c_math_functionsr   r   r   r   <module>   s    
I
%