U
    |eR0                     @   s4  d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d d	lmZ d dlZd d
lmZm Z m!Z! d dl"m#Z# G dd dej$Z%G dd dej$Z&G dd deZ'eddddddddddddddd d!d"d#Z(G d$d% d%e(eZ)dS )&    N)ir)_dynfunc)PyCallWrapper)BaseContext)	utilstypesconfigcgutilscallconvcodegen	externalsfastmathpass
intrinsics)TargetOptionsinclude_default_options)rtsys)global_compiler_lock)ParallelOptionsFastMathOptionsInlineOptions)ufunc_dbc                   @   s   e Zd ZdejfgZdS )ClosureBodyenvN__name__
__module____qualname__r   pyobject_fields r   r   K/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/cpu.pyr      s   r   c                   @   s    e Zd ZdejfdejfgZdS )EnvBodyglobalsconstsNr   r   r   r   r    r!      s   r!   c                       s   e Zd ZdZdZd- fdd	Zdd Zedd	 Zd
d Z	e
dd Zdd Zdd Ze
dd Zdd Zd.ddZdd Zdd Zdd Zdd  Zd!d" Zd/d#d$Zd%d& Zd'd( Zd)d* Zd+d, Z  ZS )0
CPUContextz0
    Changes BaseContext calling convention
    Tcpuc                    s   t  || d S N)super__init__)self	typingctxtarget	__class__r   r    r(   )   s    zCPUContext.__init__c                 C   s   | j |S r&   )_internal_codegenZ_create_empty_module)r)   namer   r   r    create_module-   s    zCPUContext.create_modulec                 C   s>   t jdk| _td| _t dkr.t	d t
j|  d S )N    z
numba.execZarmv7lzlibgcc_s.so.1)r   MACHINE_BITSis32bitr   ZJITCPUCodegenr.   platformmachinellload_library_permanentlyr   Zc_math_functionsinstallr)   r   r   r    init0   s
    
zCPUContext.initc           &      C   sr  t |  ddlm}m}m}m}m}m}m	}m
}m}	m}
m}m}m} ddlm} ddlm}m} ddlm}m}m}m} ddlm}m} ddlm}m} ddlm }m!} dd	l"m#}m$} dd
lm%} ddlm&} ddlm'}m(} m)}!m*}" ddlm+}# ddl,m-}$ | .|j/ | .|#j/ | .| j/ | .|j/ | .|!j/ | .|"j/ | .|$j0 t1j2j34  ddl5m6}% d S )Nr   )builtinscharseqenumimplhashingheapq	iteratorslistobjnumbersrangeobjsetobjslicingtupleobjunicode)optional)gdb_hookliteral)linalg
polynomial	arraymatharrayobj)generator_coregenerator_methods)	typeddictdictimpl)	typedlist
listobject)jitclassfunction_type)
npdatetime)npyimpl)	cmathimplmathimpl	printimpl
randomimpl)cffiimpl)ClassBuilder)ndarray)7r   
initializenumba.cpythonr;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   
numba.corerH   
numba.miscrI   rJ   numba.nprK   rL   rM   rN   Znumba.np.randomrO   rP   numba.typedrQ   rR   rS   rT   Znumba.experimentalrU   rV   rW   rX   rY   rZ   r[   r\   r]   Z numba.experimental.jitclass.baser^   install_registryregistryZclass_impl_registrynumbacoreentrypointsinit_allZnumba.np.unsafer_   )&r)   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   Zjitclassimplr_   r   r   r    load_additional_registries<   s.    
<z%CPUContext.load_additional_registriesc                 C   s   | j jS r&   )r.   target_datar9   r   r   r    rm   h   s    zCPUContext.target_datac                 K   s   t j|f|}| j|ddS )NT)r.   aot_mode)r   ZAOTCPUCodegen	subtarget)r)   r/   Zaot_optionsZaot_codegenr   r   r    with_aot_codegenl   s    zCPUContext.with_aot_codegenc                 C   s   | j S r&   )r.   r9   r   r   r    r   q   s    zCPUContext.codegenc                 C   s
   t | S r&   )r
   CPUCallConvr9   r   r   r    	call_convt   s    zCPUContext.call_convc                 C   s$   t ||tjd }t| ||ddS )z
        From the given *envptr* (a pointer to a _dynfunc.Environment object),
        get a EnvBody allowing structured access to environment fields.
        Zoffsetof_env_bodyT)refcast_ref)r	   pointer_addr   
_impl_infor!   )r)   builderenvptrZbody_ptrr   r   r    get_env_bodyx   s      zCPUContext.get_env_bodyFc                 C   sZ   |  |j| | j}||}| |}|j||| jjd | ||}|	| j
||S )N)return_pyobject	debug_msg)declare_env_globalmoduleget_env_namefndescloadget_python_apiemit_environment_sentryenv_namery   get_env_managerenvironment)r)   rw   rz   Zenvgvenvargpyapienv_bodyr   r   r    r      s    


zCPUContext.get_env_managerc                 C   s   t j||tjd |dS )z~
        From the given *genptr* (a pointer to a _dynfunc.Generator object),
        get a pointer to its state area.
        Zoffsetof_generator_state)return_type)r	   ru   r   rv   )r)   rw   genptrr   r   r   r    get_generator_state   s      zCPUContext.get_generator_statec                 C   s   ddl m} || |||S )zR
        Build a list from the Numba *list_type* and its initial *items*.
        r   )rA   )ra   rA   
build_list)r)   rw   Z	list_typeitemsrA   r   r   r    r      s    zCPUContext.build_listc                 C   s   ddl m} || |||S )zP
        Build a set from the Numba *set_type* and its initial *items*.
        r   )rD   )ra   rD   	build_set)r)   rw   set_typer   rD   r   r   r    r      s    zCPUContext.build_setc                 C   s   ddl m} || ||||S )Nr   )
dictobject)re   r   	build_map)r)   rw   Z	dict_typeZ
item_typesr   r   r   r   r    r      s    zCPUContext.build_mapc                 C   s4   | j rt|| j  | jr$t| |tj d S r&   )	fastmathr   Zrewrite_moduler3   r   Z
fix_divmodadd_linking_libraryr   library)r)   modr   r   r   r    post_lowering   s
    
zCPUContext.post_loweringc           
   	   C   sX   |  d}| j|j|j}t|||j}t| ||||||d}	|		  |
| d S )Nwrapper)call_helperrelease_gil)r0   rr   get_function_typerestypeargtypesr   Functionllvm_func_namer   buildadd_ir_module)
r)   r   r   r   r   r   wrapper_modulefntywrapper_calleerw   r   r   r    create_cpython_wrapper   s    
  z!CPUContext.create_cpython_wrapperc              	      s*    d} j|j|j}t|||j} fdd|jD } |j}	t	|	|}
t||
|j
}t|d} jj|||j|j|jdd\}}|j|jddb  |}| } j|||  |jt }||}|| || || W 5 Q R X || || d S )	NZcfunc_wrapperc                    s   g | ]}  |qS r   )get_value_type).0tyr9   r   r    
<listcomp>   s     z3CPUContext.create_cfunc_wrapper.<locals>.<listcomp>entry)noinline)attrsF)likely)r0   rr   r   r   r   r   r   r   r   FunctionTypellvm_cfunc_wrapper_name	IRBuilderappend_basic_blockcall_functionargsif_thenis_errorr   
gil_ensureraise_errorinsert_const_stringr}   reprstring_from_stringerr_write_unraisabledecrefgil_releaseretr   )r)   r   r   r   r   r   r   r   Zll_argtypesZll_return_typeZwraptyZwrapfnrw   statusoutr   	gil_statecstrstrobjr   r9   r    create_cfunc_wrapper   s>    
    





zCPUContext.create_cfunc_wrapperc                 C   sV   | |j}d|jf }t| |jdd ||||f}|j| 	|| |S )z
        Returns
        -------
        (cfunc, fnptr)

        - cfunc
            callable function (Can be None)
        - fnptr
            callable function address
        - env
            an execution environment (from _dynfunc)
        zcompiled wrapper for %r.)
get_pointer_to_functionllvm_cpython_wrapper_namequalnamer   make_functionlookup_modulesplitr   set_envr~   )r)   r   r   r   Zfnptrdoccfuncr   r   r    get_executable   s    
  zCPUContext.get_executablec                 C   s    t t j|d}| | |S )zI
        Calculate the size of an array struct on the CPU target
        A)r   Arrayint32get_abi_sizeofr   )r)   ndimarytyr   r   r    calc_array_sizeof   s    zCPUContext.calc_array_sizeofc                 C   s
   t |S r&   )r   get_ufunc_info)r)   	ufunc_keyr   r   r    r     s    zCPUContext.get_ufunc_info)r%   )F)F)r   r   r   __doc__allow_dynamic_globalsr(   r0   r   r:   rl   propertyrm   rp   r   rr   ry   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r,   r    r$   #   s4   
,

	
	 
 r$   nopythonforceobjZloopliftZ_nrtdebugboundscheckZnogilno_rewritesno_cpython_wrapperno_cfunc_wrapperparallelr   error_modelinlineforceinlinetarget_backendZ_dbg_extend_lifetimesZ_dbg_optnonec                   @   s   e Zd Zdd ZdS )CPUTargetOptionsc                 C   s   | dsd|_| ds d|_|jddd | ds@tj|_| ds`|jrXd|_ntj|_| dsr|j|_	d|_
|d	 |jd
dd |d |d |jrd|_d S )Nenable_pyobjectTenable_loopliftnrt)default	debuginfodbg_extend_lifetimesr   r   r   pythonr   r   F)is_setr   r   inherit_if_not_setr   DEBUGINFO_DEFAULTr   r   EXTEND_VARIABLE_LIFETIMESr   enable_pyobject_loopliftr   optnone)r)   flagsoptionsr   r   r    finalize%  s(    







zCPUTargetOptions.finalizeN)r   r   r   r   r   r   r   r    r   $  s   r   )*r4   llvmlite.bindingbindingr6   llvmliter   rh   r   Znumba.core.callwrapperr   numba.core.baser   rb   r   r   r   r	   r
   r   r   r   r   Znumba.core.optionsr   r   Znumba.core.runtimer   numba.core.compiler_lockr   Znumba.core.entrypointsnumba.core.cpu_optionsr   r   r   rd   r   	Structurer   r!   r$   Z_options_mixinr   r   r   r   r    <module>   sJ   , k