
    sh>F                        S SK r S SKrS SKrS SKJr  S SKJr  S SKJr	  S SK
Jr  S SKJrJr  S SKJr  S SKJr  S S	KJr  S S
KJr  \ R.                  " \5      rS/r\R6                  " \	R8                  S5      r\R6                  " \	R<                  S 5      r\R6                  " \	R<                  S5      r \R6                  " \	R<                  S5      r!S r" " S S\#5      r$ " S S\#5      r% " S S\%5      r&g)    N)ir)Linkage)
llvm_types)create_constant_array)compile_extraFlags)global_compiler_lock)
cpu_target)	nrtdynmod)cgutilsCompiler      c                  N    SS K n SS KnUR                  S[        U S5      -  5      $ )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     g/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/pycc/compiler.py
get_headerr      s/    ?? : %
&;' ( (    c                   $    \ rS rSrSrS rS rSrg)ExportEntryB   z(
A simple record for exporting symbols.
c                 (    Xl         X l        X0l        g N)symbol	signaturefunction)selfr   r   r    s       r   __init__ExportEntry.__init__G   s    " r   c                 @    SU R                   < SU R                  < S3$ )NzExportEntry(, ))r   r   )r!   s    r   __repr__ExportEntry.__repr__L   s    (,T^^DDr   )r    r   r   N)__name__
__module____qualname____firstlineno____doc__r"   r'   __static_attributes__ r   r   r   r   B   s    !
Er   r   c                      \ rS rSrSr\R                  " \R                  \R                  \R                  \R                  45      r\R                  " \5      r\R                  " \R                  \R                  \R                  \R                  \R                  45      r\R                  " \5      rSS jrS rS r\S 5       rSS jrSS jrS	 rS
 rS rS rS rS rSrg)_ModuleCompilerP   zA 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.
c                     X l         SU l        / U l        Xl        S U l        X0l        [        R                  U l        [        R                  R                  " U R                   40 UD6U l
        g )NF)module_nameexport_python_wrapdll_exportsexport_entriesexternal_init_functionuse_nrtr
   typing_contexttarget_contextwith_aot_codegencontext)r!   r7   r4   r9   aot_optionss        r   r"   _ModuleCompiler.__init__p   sb    &"',&*#(77!00AA- +-r   c                     SU< 3$ )Nz._pycc_method_r/   )r!   	func_names     r   _mangle_method_symbol%_ModuleCompiler._mangle_method_symbol~   s    %.00r   c                     [         e)zAEmit generated Python wrapper and extension module code.
        )NotImplementedError)r!   llvm_modules     r   _emit_python_wrapper$_ModuleCompiler._emit_python_wrapper   s
     "!r   c                    0 U l         0 U l        0 U l        U R                  R	                  5       nUR                  U R                  5      n[        5       nSUl        U R                  (       d  SUl
        SUl        U R                  (       a:  SUl        [        R                  " U R                  5      u  pEUR!                  U5        U R"                   GH  n[%        U R&                  U R                  UR(                  UR*                  R,                  UR*                  R.                  U0 US9nUR0                  R2                  nUR4                  R7                  U5      n	U R                  (       a  SU	l        UR0                  R:                  n
UR4                  R7                  U
5      nU R=                  UR>                  5      Ul         SUl        URB                  RD                  RG                  UR0                  RH                  UR0                  RJ                  5      nXR                   U'   URL                  U R                  U'   UR0                  RN                  U R                  U'   GM  UR>                  U	l         U RP                  RS                  UR>                  5        GM     U R                  (       a3  URU                  S5      nU RW                  U5        UR!                  U5        URY                  5         UR[                  5        H]  nUR@                  U RP                  ;  d  M  UR8                  [\        R^                  [\        R`                  1;   a	  SUl1        MV  SUl1        M_     U$ )zpRead 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_gvsr=   codegencreate_libraryr4   r   
no_compiler5   no_cpython_wrapperno_cfunc_wrapperr9   nrtr   create_nrt_moduleadd_ir_moduler7   r   r:   r    r   argsreturn_typefndescllvm_func_namerK   get_functionlinkagellvm_cpython_wrapper_namerB   r   namer;   	call_convget_function_typerestypeargtypesenvironmentenv_namer6   appendcreate_ir_modulerG   finalizeget_defined_functionsr   privaterL   
visibility)r!   rT   rK   flags
nrt_module_entrycresrA   	llvm_funcwrappernamerN   fntywrapper_modulefns                  r   _cull_exports_ModuleCompiler._cull_exports   s   
 (*$%'"!,,&&((()9)9: &&'+E$%)E"<<EI%77EMJ!!*-((E !4!4dll % % 4 4 % ; ;U')7	<D 22I11)<I&&$.	!"kkCC,,33K@#99%,,G",**44FFKK'')=)=?6:,,U3484D4D**51.2kk.B.B$$U+!&	  ''5/ )2 ""$55i@N%%n5!!.1 	//1Bwwd...::'//73C3C!DD$-BM$,BM 2 r   c                     X l         U R                  5       n[        US5       nUR                  UR	                  5       5        S S S 5        g ! , (       d  f       g = fNwb)r5   rz   openwriteemit_bitcoder!   outputwrapkwsrK   fouts         r   write_llvm_bitcode"_ModuleCompiler.write_llvm_bitcode   sC    "&$$&&$4JJw++-.      A
Ac                     X l         U R                  5       n[        US5       nUR                  UR	                  5       5        S S S 5        g ! , (       d  f       g = fr}   )r5   rz   r   r   emit_native_objectr   s         r   write_native_object#_ModuleCompiler.write_native_object   sC    "&$$&&$4JJw1134  r   c                 ^    [        U5      nSU;   a  UR                  S5      (       a  US-  nU$ )Nint)8163264_t)strendswith)r!   tyobjret_vals      r   	emit_type_ModuleCompiler.emit_type   s3    e*G 7884r   c                   ^  [         R                  R                  U5      u  p#[        US-   S5       nUR	                  [        5       5        UR	                  S5        T R                   H  nUR                  nT R                  UR                  R                  5      nSR                  U 4S jUR                  R                   5       5      nUR	                  SU< SU< SU< S	35        M     S S S 5        g ! , (       d  f       g = f)
Nz.hwz
/* Prototypes */
r%   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r   ).0argtyper!   s     r   	<genexpr>._ModuleCompiler.emit_header.<locals>.<genexpr>   s%      !M0KW "&!8!80Ks   !zextern  (z);
)ospathsplitextr   r   r   r7   r   r   r   r]   joinr\   )	r!   r   fnameextr   export_entryrc   rf   r\   s	   `        r   emit_header_ModuleCompiler.emit_header   s    WW%%f-
%$,$JJz|$JJ-. $ 3 3#**..)?)?)K)KLyy !M0<0F0F0K0K!M M

GT4HI !4 %$$s   B<C77
Dc                 "   / nU R                    H  nUR                  nU R                  U5      nU R                  U   n[        R
                  " XU5      nU R                  R                  X5      n[        R                  R                  U[        R                  R                  U[        R                  5      [        [        45      n	UR                  U	5        M     [        R                  R                  [        [        [         [        /5      n
UR                  U
5        [#        U R$                  U5      n[&        R(                  " UUR*                  S5      nXl        SUl        [        R                  R1                  U[         [         /5      nU$ )zg
Collect exported methods and emit a PyMethodDef array.

:returns: a pointer to the PyMethodDef array.
z.module_methodsrL   )r7   r   rB   rQ   r   Functionr=   insert_const_stringConstantliteral_structbitcastlt
_void_starMETH_VARARGS_AND_KEYWORDSNULLrj   ZEROr   method_def_tyr   add_global_variabletypeinitializerra   gep)r!   rF   method_defsrs   rc   r_   rw   lfuncmethod_namemethod_def_constsentinelmethod_array_initmethod_arraymethod_array_ptrs                 r   _emit_method_array"_ModuleCompiler._emit_method_array   s@    ((E<<D!77=N//6DKK>BE,,::;MK!{{99$$UBMM:* 
 /0 ) ;;--tT4.FG8$1$2D2DkR22;3D3I3I3DF $5 );;??<$Fr   c                 >   / nU R                    H>  nU R                  U   nUR                  UR                  5      nUR	                  U5        M@     [        U R                  U5      nU R                  R                  USU5      n	U	R                  [        [        /5      $ )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)r7   rR   serialize_uncachedconstsrj   r   
env_def_tyr=   insert_unique_constr   r   )
r!   rF   builderpyapienv_defsrs   envenv_defenv_defs_initgvs
             r   _emit_environment_array'_ModuleCompiler._emit_environment_array  s     ((E,,U3C..szz:GOOG$	 )
 .dooxH\\--k.D.;= vvtTl##r   c                    / nU R                    H]  nU R                  U   nU R                  R                  X5      nUR	                  [
        R                  5      nUR                  U5        M_     [        [
        R                  U5      n	U R                  R                  USU	5      nUR                  [        [        /5      $ )zR
Emit an array of Environment pointers that needs to be filled at
initialization.
z.module_envgvs)r7   rS   r=   declare_env_globalr   r   r   rj   r   r   r   r   )
r!   rF   r   r   env_settersrs   
envgv_namer   envgvenv_setters_inits
             r   _emit_envgvs_array"_ModuleCompiler._emit_envgvs_array  s    
 ((E--e4J00IBJJr}}-Eu%	 ) 1L\\--k.>.>@ vvtTl##r   c                 2   U R                   (       a  [        R                  " [        R                  UR
                  U R                  U R                  UR
                  /5      n[        R                  " XU R                   5      nUR                  XXEU/5      $ g)z0
Emit call to "external" init function, if any.
N)
r8   r   FunctionTyper   _int32r   method_def_ptrenv_def_ptrr   call)	r!   rF   r   modobjr   	env_arrayenvgv_arrayrw   ry   s	            r   _emit_module_init_code&_ModuleCompiler._emit_module_init_code*  s    
 &&??299$*KK1D1D$($4$4k6F6F$HID [0K0KLB<<\%0%2 3 3 r   )r=   r6   rS   r7   r5   rQ   r8   rR   r4   r:   r9   N)F)r)   r*   r+   r,   r-   r   LiteralStructTyper   
_int8_starr   r   r   PointerTyper   r   r   r"   rB   rG   r	   rz   r   r   r   r   r   r   r   r   r.   r/   r   r   r1   r1   P   s     (("--*,--*,))*,--*9 :M
 ^^M2N %%r}}')yy')}}')}}')yy	'2 3J
 ..,K-1"
 > >@/5
J @$$$$r   r1   c                   B   \ rS rSrS r\" \R                  \R                  5      r\" \R                  \R                  5      r	\" \R                  \R                  \\R                  5      r\" \R                  \R                  5      r\" \R                  5      r\R                  r\R"                  " \R$                  \\R&                  \R                  45      r\R"                  " \\\\R&                  \R,                  \	\\	\4	5      r\S 5       r\S 5       rS rSrg)ModuleCompileri:  c                 V    [         R                  " [         R                  " X5      5      $ r   )r   r   r   )retr\   s     r   <lambda>ModuleCompiler.<lambda><  s    "..1K"Lr   c                     [         R                  " [        R                  [         R                  " U R
                  5      [        R                  45      nSn[        R                  (       a  US-  nX4$ )zV
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   rc   s      r   module_create_definition'ModuleCompiler.module_create_definition|  sX     OOB$7$7%'^^D4F4F%G%'YY%01	 "??KDr   c                 n    [         R                  " [        R                  S5      nUSU R                  -   4$ )zH
Return the name and signature of the module's initialization function.
r/   PyInit_)r   r   r   r   r4   )r!   r   s     r   module_init_definition%ModuleCompiler.module_init_definition  s0    
 OOB$7$7<	)d&6&6666r   c                    [         R                  " U/U R                  Q76 nSUl        U R                  R                  UU R                  5      n[         R                  R                  [        R                  [         R                  " U R                  S 5      [         R                  " [        R                  S 5      [         R                  " [        R                  S 5      45      n[        R                  " UUR                   S5      nXEl        SUl        U R%                  U5      n[         R                  R                  UU[         R                  " U R&                  S 5      [         R                  " [        R                  S5      U[         R                  " U R(                  S 5      [         R                  " U R*                  S 5      [         R                  " U R(                  S 5      [         R                  " U R,                  S 5      4	5      n[        R                  " XR                   S5      nXxl        SUl        [         R                  " U/U R.                  Q76 n	U	R1                  S5      n
[         R2                  " U
5      nU R                  R5                  U5      nUR7                  UU[         R                  " [        R8                  [:        R<                  5      45      nUR?                  [        R@                  " X5      5         URC                  [D        RG                  U	R                   RH                  RJ                  5      5        S S S 5        U RM                  XU5      nU RO                  XU5      nU RQ                  XUXnU5      nUb_  UR?                  [        RR                  " UU5      5         URC                  [         R                  " UR                   S 5      5        S S S 5        URC                  U5        U RT                  RW                  U	RX                  5        g ! , (       d  f       N= f! , (       d  f       NV= f)NrM   z.module_def_baserL   z.module_defEntry)-r   r   r   ra   r=   r   r4   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   pointeer]   r   r   r   is_not_nullr6   rj   rc   )r!   rF   create_module_fnmod_name_constmod_def_base_initmod_def_baser   mod_def_initmod_defmod_init_fnrs   r   r   modr   r   r   s                    r   rG   #ModuleCompiler._emit_python_wrapper  s"    ;;{ST5R5RS#-  99+:>:J:JL KK66##[[.[[,,d3[[,,d3
 22;3D3I3I3EG $5 )..{;{{11[[$/[[,,b1[[$/[[--t4[[$/[[))40	
 --k;L;L.;=*$ kk+L0K0KL..w7,,u%++G4ll+#KK		3??CEF __W__W:;KK[%5%5%=%=%I%IJK < 00uM	--kEJ))+*6;P?!4!4Wc!BCBKK$78 D 	C 0 01 <; DCs   AP"21P3"
P03
Qr/   N)r)   r*   r+   r,   _ptr_funr   _int8r   visitproc_tyr  r   r  r  r  r   r  r   r   _pyobject_headr  module_def_base_tyr1   r   r   propertyr   r   rG   r.   r/   r   r   r   r   :  s6   LH BHH//1L "((--/J rxx!22+!}}.O 288==*K "IJ --		
( ((**
	
M   7 7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   r1   r   r/   r   r   <module>r.     s     	 
  $ ' 4 4 9 * (  
		8	$,	{{2==$'	{{299a kk"))QKK		37 !(HE& Egf gTb2_ b2r   