
    J/Ph>F                        d dl Z d dlZ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mZ d dlmZ d dlmZ d d	lmZ d d
lmZ  e j        e          ZdgZ ej        e	j        d          Z ej        e	j        d           Z ej        e	j        d          Z  ej        e	j        d          Z!d Z" G d de#          Z$ G d de#          Z% G d de%          Z&dS )    N)ir)Linkage)
llvm_types)create_constant_array)compile_extraFlags)global_compiler_lock)
cpu_target)	nrtdynmod)cgutilsCompiler      c                  ^    dd l } dd l}|                    dt          | d          z            S )Nr   a      #include <stdint.h>

    #ifndef HAVE_LONGDOUBLE
        #define HAVE_LONGDOUBLE %d
    #endif

    typedef struct {
        float real;
        float imag;
    } complex64;

    typedef struct {
        double real;
        double imag;
    } complex128;

    #if HAVE_LONGDOUBLE
    typedef struct {
        long double real;
        long double imag;
    } complex256;
    #endif

    typedef float float32;
    typedef double float64;
    #if HAVE_LONGDOUBLE
    typedef long double float128;
    #endif
    
complex256)numpytextwrapdedenthasattr)r   r   s     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/pycc/compiler.py
get_headerr      sC    LLLOOO?? : %
&
&;' ( ( (    c                       e Zd ZdZd Zd ZdS )ExportEntryz0
    A simple record for exporting symbols.
    c                 0    || _         || _        || _        d S N)symbol	signaturefunction)selfr   r   r   s       r   __init__zExportEntry.__init__G   s    " r   c                 (    d| j         d| j        dS )NzExportEntry(, ))r   r   )r    s    r   __repr__zExportEntry.__repr__L   s     (,T^^^DDr   N)__name__
__module____qualname____doc__r!   r%    r   r   r   r   B   sA         ! ! !
E E E E Er   r   c                   \   e Zd ZdZ ej        ej        ej        ej	        ej        f          Z
 ej        e
          Z ej        ej        ej	        ej        ej        ej	        f          Z ej        e          ZddZd Zd Zed             ZddZddZd	 Zd
 Zd Zd Zd Zd ZdS )_ModuleCompilerzA base class to compile Python modules to a single shared library or
    extension module.

    :param export_entries: a list of ExportEntry instances.
    :param module_name: the name of the exported module.
    Fc                     || _         d| _        g | _        || _        d | _        || _        t          j        | _        t          j        j	        | j         fi || _
        d S )NF)module_nameexport_python_wrapdll_exportsexport_entriesexternal_init_functionuse_nrtr
   typing_contexttarget_contextwith_aot_codegencontext)r    r1   r.   r3   aot_optionss        r   r!   z_ModuleCompiler.__init__p   sj    &"',&*#(7!0A- - +- -r   c                     d|S )Nz._pycc_method_r*   )r    	func_names     r   _mangle_method_symbolz%_ModuleCompiler._mangle_method_symbol~   s     %.Y00r   c                     t           )zAEmit generated Python wrapper and extension module code.
        )NotImplementedError)r    llvm_modules     r   _emit_python_wrapperz$_ModuleCompiler._emit_python_wrapper   s
     "!r   c                 j   i | _         i | _        i | _        | j                                        }|                    | j                  }t                      }d|_        | j	        sd|_
        d|_        | j        r8d|_        t          j        | j                  \  }}|                    |           | j        D ]K}t%          | j        | j        |j        |j        j        |j        j        |i |          }|j        j        }|j                            |          }	| j	        rd|	_        |j        j        }
|j                            |
          }|                     |j                  |_         d|_        |j!        j"        #                    |j        j$        |j        j%                  }|| j         |<   |j&        | j        |<   |j        j'        | j        |<    |j        |	_         | j(        )                    |j                   M| j	        r?|*                    d          }| +                    |           |                    |           |,                                 |-                                D ]>}|j         | j(        vr.|j        t\          j/        t\          j0        hv rd|_1        7d|_1        ?|S )zRead all the exported functions/modules in the translator
        environment, and join them into a single LLVM module.
        T)localslibraryinternalexternalwrapperdefaulthidden)2exported_function_typesfunction_environmentsenvironment_gvsr7   codegencreate_libraryr.   r   
no_compiler/   no_cpython_wrapperno_cfunc_wrapperr3   nrtr   create_nrt_moduleadd_ir_moduler1   r   r4   r   r   argsreturn_typefndescllvm_func_namerB   get_functionlinkagellvm_cpython_wrapper_namer;   r   namer5   	call_convget_function_typerestypeargtypesenvironmentenv_namer0   appendcreate_ir_moduler?   finalizeget_defined_functionsr   privaterC   
visibility)r    rK   rB   flags
nrt_module_entrycresr:   	llvm_funcwrappernamerE   fntywrapper_modulefns                  r   _cull_exportsz_ModuleCompiler._cull_exports   s   
 (*$%'"!,&&(((()9:: & 	*'+E$%)E"< 	.EI%7EEMJ!!*---( 	6 	6E !4dl % % 4 % ;U')7	< < <D 2I11)<<I& 6$.	!"kC,33K@@#99%,GG",*4FFK')=? ?6:,U3484D*51.2k.B$U++!&	 ''5555" 	2$55i@@N%%n555!!.111 	//11 	- 	-Bwd...:'/73C!DDD$-BMM$,BMr   c                     || _         |                                 }t          |d          5 }|                    |                                           d d d            d S # 1 swxY w Y   d S Nwb)r/   rq   openwriteemit_bitcoder    outputwrapkwsrB   fouts         r   write_llvm_bitcodez"_ModuleCompiler.write_llvm_bitcode   s    "&$$&&&$ 	/4JJw++--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/   (A!!A%(A%c                     || _         |                                 }t          |d          5 }|                    |                                           d d d            d S # 1 swxY w Y   d S rs   )r/   rq   ru   rv   emit_native_objectrx   s         r   write_native_objectz#_ModuleCompiler.write_native_object   s    "&$$&&&$ 	54JJw1133444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5r~   c                 `    t          |          }d|v r|                    d          r|dz  }|S )Nint)8163264_t)strendswith)r    tyobjret_vals      r   	emit_typez_ModuleCompiler.emit_type   s=    e**G 788  4r   c                     t           j                            |          \  }}t          |dz   d          5 }|                    t                                 |                    d            j        D ]r}|j        }                     |j	        j
                  }d                     fd|j	        j        D                       }|                    d|d|d|d	           s	 d d d            d S # 1 swxY w Y   d S )
Nz.hwz
/* Prototypes */
r#   c              3   B   K   | ]}                     |          V  d S r   )r   ).0argtyper    s     r   	<genexpr>z._ModuleCompiler.emit_header.<locals>.<genexpr>   sK       !M !M%, "&!8!8 !M !M !M !M !M !Mr   zextern  (z);
)ospathsplitextru   rv   r   r1   r   r   r   rT   joinrS   )	r    ry   fnameextr|   export_entryrZ   r]   rS   s	   `        r   emit_headerz_ModuleCompiler.emit_header   sx   W%%f--
s%$,$$ 	JJJz||$$$JJ-... $ 3 J J#*..)?)KLLyy !M !M !M !M0<0F0K!M !M !M M M


GGGTTT444HIIIIJ	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   B1C66C:=C:c                    g }| j         D ]}|j        }|                     |          }| j        |         }t	          j        |||          }| j                            ||          }t          j        	                    |t          j        
                    |t          j                  t          t          f          }	|                    |	           t          j        	                    t          t          t           t          g          }
|                    |
           t#          | j        |          }t'          j        ||j        d          }||_        d|_        t          j                            |t           t           g          }|S )z
        Collect exported methods and emit a PyMethodDef array.

        :returns: a pointer to the PyMethodDef array.
        z.module_methodsrC   )r1   r   r;   rH   r   Functionr7   insert_const_stringConstantliteral_structbitcastlt
_void_starMETH_VARARGS_AND_KEYWORDSNULLra   ZEROr   method_def_tyr   add_global_variabletypeinitializerrX   gep)r    r>   method_defsrj   rZ   rV   rn   lfuncmethod_namemethod_def_constsentinelmethod_array_initmethod_arraymethod_array_ptrs                 r   _emit_method_arrayz"_ModuleCompiler._emit_method_array   sY    ( 	1 	1E<D!77==N/6DKT>BBE,::;MMK!{99$$UBM::*   
 /0000;--tT4.FGG8$$$1$2DkRR2;3D3I3DF F $5 );??<$FFr   c                 6   g }| j         D ]>}| j        |         }|                    |j                  }|                    |           ?t          | j        |          }| j                            |d|          }	|		                    t          t          g          S )z
        Emit an array of env_def_t structures (see modulemixin.c)
        storing the pickled environment constants for each of the
        exported functions.
        z.module_environments)r1   rI   serialize_uncachedconstsra   r   
env_def_tyr7   insert_unique_constr   r   )
r    r>   builderpyapienv_defsrj   envenv_defenv_defs_initgvs
             r   _emit_environment_arrayz'_ModuleCompiler._emit_environment_array  s     ( 	% 	%E,U3C..sz::GOOG$$$$-doxHH\--k.D.;= = vvtTl###r   c                    g }| j         D ]^}| j        |         }| j                            ||          }|                    t
          j                  }|                    |           _t          t
          j        |          }	| j        	                    |d|	          }|
                    t          t          g          S )zj
        Emit an array of Environment pointers that needs to be filled at
        initialization.
        z.module_envgvs)r1   rJ   r7   declare_env_globalr   r   r   ra   r   r   r   r   )
r    r>   r   r   env_settersrj   
envgv_namer   envgvenv_setters_inits
             r   _emit_envgvs_arrayz"_ModuleCompiler._emit_envgvs_array  s    
 ( 	& 	&E-e4J00jIIBJJr}--Eu%%%%0LL\--k.>.>@ @ vvtTl###r   c                     | j         rlt          j        t          j        |j        | j        | j        |j        g          }t          j        ||| j                   }|	                    |||||g          S dS )z@
        Emit call to "external" init function, if any.
        N)
r2   r   FunctionTyper   _int32r   method_def_ptrenv_def_ptrr   call)	r    r>   r   modobjr   	env_arrayenvgv_arrayrn   rp   s	            r   _emit_module_init_codez&_ModuleCompiler._emit_module_init_code*  s    
 & 	?29$*K1D$($4k6F$HI ID [$0KLLB<<V\9%0%2 3 3 3 4r   N)F)r&   r'   r(   r)   r   LiteralStructTyper   
_int8_starr   r   r   PointerTyper   r   r   r!   r;   r?   r	   rq   r}   r   r   r   r   r   r   r   r*   r   r   r,   r,   P   sz         )B("-*,-*,)*,-*9 : :M
 $R^M22N &%r}')y')}')}')y	'2 3 3J
 !".,,K- - - -1 1 1" " "
 > > >@/ / / /5 5 5 5  
J 
J 
J     @$ $ $$$ $ $$    r   r,   c                      e Zd Zd Z eej        ej                  Z eej        ej                  Z eej        ej        eej	                  Z
 eej        ej	                  Z eej                  Zej        Z ej        ej        eej        ej        f          Z ej        eeeej        ej        ee
eef	          Zed             Zed             Zd ZdS )ModuleCompilerc                 P    t          j        t          j        | |                    S r   )r   r   r   )retrS   s     r   <lambda>zModuleCompiler.<lambda><  s    ".d1K1K"L"L r   c                     t          j        t          j        t          j        | j                  t          j        f          }d}t          j        r|dz  }||fS )zn
        Return the signature and name of the Python C API function to
        initialize the module.
        PyModule_Create2	TraceRefs)r   r   r   _pyobject_head_pr   module_def_tyr   _trace_refs_)r    r   rZ   s      r   module_create_definitionz'ModuleCompiler.module_create_definition|  sY     OB$7%'^D4F%G%G%'Y%01 1	 "? 	 KD$r   c                 X    t          j        t          j        d          }|d| j        z   fS )zX
        Return the name and signature of the module's initialization function.
        r*   PyInit_)r   r   r   r   r.   )r    r   s     r   module_init_definitionz%ModuleCompiler.module_init_definition  s+    
 OB$7<<	)d&6666r   c                    t          j        |g| j        R  }d|_        | j                            || j                  }t           j                            t          j
        t          j        | j        d           t          j        t          j        d           t          j        t          j        d           f          }t          j        ||j        d          }||_        d|_        |                     |          }t           j                            ||t          j        | j        d           t          j        t          j        d          |t          j        | j        d           t          j        | j        d           t          j        | j        d           t          j        | j        d           f	          }t          j        ||j        d          }||_        d|_        t          j        |g| j        R  }	|	                    d          }
t          j        |
          }| j                            |          }|                    ||t          j        t          j        t:          j                  f          }|                    t          j         ||                    5  |!                    tD          #                    |	j        j$        j%                             d d d            n# 1 swxY w Y   | &                    |||          }| '                    |||          }| (                    ||||||          }|m|                    t          j)        ||                    5  |!                    t          j        |j        d                      d d d            n# 1 swxY w Y   |!                    |           | j*        +                    |	j,                   d S )NrD   z.module_def_baserC   z.module_defEntry)-r   r   r   rX   r7   r   r.   r   r   r   _pyobject_head_init	m_init_ty_llvm_py_ssize_tr   r   r   r   r   r   
_char_star
inquiry_tytraverseproc_tyfreefunc_tyr   append_basic_block	IRBuilderget_python_apir   r   sysapi_versionif_thenis_nullr   r   r   pointeerT   r   r   r   is_not_nullr0   ra   rZ   )r    r>   create_module_fnmod_name_constmod_def_base_initmod_def_baser   mod_def_initmod_defmod_init_fnrj   r   r   modr   r   r   s                    r   r?   z#ModuleCompiler._emit_python_wrapper  s    ;{ST5RSSS#-  99+:>:JL L K66#[..[,d33[,d33
 
 2;3D3I3EG G $5 )..{;;{11[$//[,b11[$//[-t44[$//[)400	
 
 -k<;L.;= =*$ k+L0KLLL..w77,u%%++G44ll+#K	3?CCEF F __W_Wc::;; 	L 	LKK[%5%=%IJJKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 00guMM	--k7EJJ))+w*6	;P P?!4Wc!B!BCC 9 9BK$778889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 	C 011111s$   #=K,,K03K0).N##N'*N'N)r&   r'   r(   _ptr_funr   _int8r   visitproc_tyr   r   r   r   r   r   r   r   r   _pyobject_headr   module_def_base_tyr,   r   r   propertyr   r   r?   r*   r   r   r   r   :  sh       LLH 8BH/1 1L "(-/ /J hrx!2+!}. .O (28=* *K ""IJ .-		
 ( )B(*
	
 M   X 7 7 X7G2 G2 G2 G2 G2r   r   )'loggingr   r   llvmliter   llvmlite.bindingr   
numba.pyccr   r   numba.core.cgutilsr   numba.core.compilerr   r   numba.core.compiler_lockr	   numba.core.registryr
   numba.core.runtimer   
numba.corer   	getLoggerr&   logger__all__r   r   r   r   r   ONEr   r   objectr   r,   r   r*   r   r   <module>r     s    				 



       $ $ $ $ $ $ ' ' ' ' ' ' 4 4 4 4 4 4 4 4 4 4 4 4 4 4 9 9 9 9 9 9 * * * * * * ( ( ( ( ( (       
	8	$	$,r{2=$''r{29a  bk")Q'BK	377 !( !( !(HE E E E E& E E Eg g g g gf g g gTb2 b2 b2 b2 b2_ b2 b2 b2 b2 b2r   