
    wg)                     
   d dl mZ d dlmZ d dlmZ d dlZd dlZd dl	Z	d dl
Z
d dlmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ ej.                  Zej0                  Z ej2                         Z G d
 de      Z G d de      Zy)    )	distutils)	build_ext)	ExtensionN)typingsigutils)global_compiler_lock)ModuleCompilerExportEntry)	Toolchain)cextc                      e Zd ZdZdgez   Zi Zi ZddZe	d        Z
e	d        Zej                  d        Ze	d        Zej                  d	        Ze	d
        Zej                  d        Ze	d        Zej                  d        Ze	d        Zej                  d        Zd Ze	d        Zd Zd Zd Zd Zd Zed        Zed        Zd Zy)CCz_
    An ahead-of-time compiler to create extension modules that don't
    depend on Numba.
    zmodulemixin.cNc                 H   d|v rt        d      || _        d|z   | _        i | _        t	        j
                  d      }||j                  }|d   }nBt        |d      r|j                  }|j                  }nt        j                  |   j                  }|j                  dd      | _        || _        t               | _        d| _        t"        j$                  j'                  | j                        | _        | j                  j+                  |      | _        d	| _        d| _        y )
N.z;basename should be a simple module name, not qualified name
pycc_init_   __name____file__ FT)
ValueError	_basename_init_function_exported_functionssys	_getframe	f_globalshasattr__dict__r   modulesget_source_path_source_moduler   
_toolchain_verboseospathdirname_output_dirget_ext_filename_output_file_use_nrt_target_cpu)selfextension_namesource_modulefdcts        R/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numba/pycc/cc.py__init__zCC.__init__/   s    .  . / / (*^;#% MM! ++C
OM]J/((C)22M++m,55CGGJ3+#+77??4+<+<= OO<<^L    c                     | j                   S )z=
        The name of the extension module to create.
        )r   r-   s    r2   namezCC.nameL   s    
 ~~r4   c                     | j                   S )zJ
        The specific output file (a DLL) that will be generated.
        r*   r6   s    r2   output_filezCC.output_fileS   s    
    r4   c                     || _         y Nr9   r-   values     r2   r:   zCC.output_fileZ   s
    !r4   c                     | j                   S )z?
        The directory the output file will be put in.
        r(   r6   s    r2   
output_dirzCC.output_dir^       
 r4   c                     || _         y r<   r@   r=   s     r2   rA   zCC.output_dire   
     r4   c                     | j                   S r<   r+   r6   s    r2   use_nrtz
CC.use_nrti   s    }}r4   c                     || _         y r<   rF   r=   s     r2   rG   z
CC.use_nrtm   	    r4   c                     | j                   S )z;
        The target CPU model for code generation.
        r,   r6   s    r2   
target_cpuzCC.target_cpuq   rB   r4   c                     || _         y r<   rK   r=   s     r2   rL   zCC.target_cpux   rD   r4   c                     | j                   S )zI
        Whether to display detailed information when compiling.
        r$   r6   s    r2   verbosez
CC.verbose|   s    
 }}r4   c                     || _         y r<   rO   r=   s     r2   rP   z
CC.verbose   rI   r4   c                      t        j                        \  }}t        j                  |g|  j                  v rt        dz         fd}|S )zH
        Mark a function for exporting in the extension module.
        zduplicated export symbol %sc                 @    t        |       }|j                  <   | S r<   )r
   r   )funcentryexported_namer-   sigs     r2   	decoratorzCC.export.<locals>.decorator   s&    sD9E6;D$$]3Kr4   )r   normalize_signaturer   	signaturer   KeyError)r-   rV   rW   fn_argsfn_rettyrX   s   ```   r2   exportz	CC.export   s[     %88=x2'2D4448MJKK	
 r4   c                 N    t        | j                  j                         d       S )Nc                     | j                   S r<   )symbol)rU   s    r2   <lambda>z$CC._export_entries.<locals>.<lambda>   s
     r4   )key)sortedr   valuesr6   s    r2   _export_entrieszCC._export_entries   s#    d..55746 	6r4   c                    t         j                  j                  t              }| j                  d d  }| j
                  r|j                  d       |D cg c]"  }t         j                  j                  ||      $ c}S c c}w )Nz../core/runtime/nrt.cpp)r%   r&   r'   r   _mixin_sourcesr+   appendjoin)r-   heremixin_sourcesr0   s       r2   _get_mixin_sourceszCC._get_mixin_sources   s]    wwx(++A.==  !:;/<=!T1%===s   'A>c                 L    d| j                   fdt        | j                        fgS )NPYCC_MODULE_NAMEPYCC_USE_NRT)r   intr+   r6   s    r2   _get_mixin_defineszCC._get_mixin_defines   s+      0S/0 	r4   c                     | j                   j                  t        j                  g       }|s*| j                   j                  t        j
                  g       }|S r<   )_extra_cflagsr    r   platformr%   r7   )r-   extra_cflagss     r2   _get_extra_cflagszCC._get_extra_cflags   sC    ))--cllB?--11"''2>Lr4   c                    | j                   j                  t        j                  g       }|s*| j                   j                  t        j
                  g       }t        j                  j                  d      rd|vr|j                  d       |S )Nlinuxz-pthread)_extra_ldflagsr    r   ru   r%   r7   
startswithri   )r-   extra_ldflagss     r2   _get_extra_ldflagszCC._get_extra_ldflags   sk    ++//bA //33BGGR@M<<""7+.$$Z0r4   c                     | j                         }| j                         }| j                  j                         }| j	                         }| j                  j                  |||||      }|S )N)include_dirsmacrosrv   )rm   rr   r#   get_python_include_dirsrw   compile_objects)r-   	build_dirsourcesr   r   rv   objectss          r2   _compile_mixinszCC._compile_mixins   sn    ))+((*>>@--/ //11'9?K9??K 2 M r4   c                    t        | j                  | j                  | j                  | j                        }| j
                  |_        t        j                  j                  |t        j                  j                  | j                        d   dz         }t        j                  d| j                  |       |j                  |d       |g|j                  fS )N)cpu_namer   z.oz%generating LLVM code for '%s' into %sT)wrap)r	   rf   r   r+   r,   r   external_init_functionr%   r&   rj   splitextr*   loginfowrite_native_objectdll_exports)r-   r   compilertemp_objs       r2   _compile_object_fileszCC._compile_object_files   s    !$"6"6 $8H8HJ*.*=*='77<<	 " 0 01B1B CA F MO8	*$$XD$9z8////r4   c                 ,   | j                   | j                  _         t        j                  d| j                  z        }| j                  |      \  }}|| j                  |      z  }| j                         }t        j                  j                  | j                  | j                        }| j                  j                         }| j                  j                         }| j                  j                  ||||||       t!        j"                  |       y)z/
        Compile the extension module.
        zpycc-build-%s-)prefix)export_symbolsr|   N)rP   r#   tempfilemkdtempr   r   r   r}   r%   r&   rj   r(   r*   get_python_librariesget_python_library_dirslink_sharedshutilrmtree)r-   r   r   r   r|   
output_dll	librarieslibrary_dirss           r2   compilez
CC.compile   s    
 #',,$$,<t~~,MN	  $99)D 	4''	22 //1WW\\$"2"2D4E4EF
OO88:	>>@##J$-|3>2? 	$ 	A
 	i r4   c                 
   |j                  dg       | j                         z   }|j                  dg       | j                  gz   }|j                  dg       | j                         z   }|j                  dg       | j	                         z   }|j                  dg       | j
                  j                         z   }|j                  dg       | j
                  j                         z   }|j                  dg       | j
                  j                         z   }| j                  d| j                  j                  d	      d
z    }	t        d|	| j                  z   | j                         |||||||d	|}
|
j                          | |
_        |
S )z`
        Create a distutils extension object that can be used in your
        setup.py.
        r   dependsextra_compile_argsextra_link_argsr   r   r   Nr   r   )	r7   r   r   define_macrosr   r   r   r   r    )poprr   r!   rw   r}   r#   r   r   r   r"   rfind_CCExtensionr   rm   monkey_patch_distutils_cc)r-   kwargsr   r   r   r   r   r   r   python_package_pathexts              r2   distutils_extensionzCC.distutils_extension   s   
 Hb)D,C,C,EE**Y+t/@/@.AA$jj)=rB $ 6 6 89!::&7<!4467

>26//AACDZZR0;;=>	

>26//AACD"112S43F3F3L3LS3QRS3ST 	% 3dnn D#'#:#:#<#*)/(4%.(4.@+:	% $	% 	""$
r4   r<   )r   
__module____qualname____doc__extension_libsrh   rt   rz   r3   propertyr7   r:   setterrA   rG   rL   rP   r^   rf   rm   rr   rw   r}   r   r   r   r   r   r   r4   r2   r   r      s~    &'>9N
M

N
:   ! ! " "     ! !   ^^      ! !   ^^   6 6> 	0 	0 ! !2r4   r   c                   .    e Zd ZdZdZdZd Zed        Zy)r   zj
    A Numba-specific Extension subclass to LLVM-compile pure Python code
    to an extension module.
    NFc                    | j                   }t        j                  t        j                  j
                  |j                  g| j                  j                  d      d d         |j                  |j                        \  }}|| _
        y )Nr   )r   dir_utilmkpathr%   r&   rj   
build_tempr7   splitr   extra_objects)r-   r   ccr   _s        r2   _prepare_object_filesz"_CCExtension._prepare_object_files  sg    XXY%9%9VDIIOOC<PQTRT<UVW--i.B.BC
$r4   c                 ~    | j                   ryt        j                   G fdd      }|t        _        d| _         y)z}
        Monkey-patch distutils with our own build_ext class knowing
        about pycc-compiled extensions modules.
        Nc                       e Zd Z fdZy):_CCExtension.monkey_patch_distutils.<locals>._CC_build_extc                 l    t        |t              r|j                  |        j                  | |       y r<   )
isinstancer   r   build_extension)r-   r   _orig_build_exts     r2   r   zJ_CCExtension.monkey_patch_distutils.<locals>._CC_build_ext.build_extension-  s+    c<0--d3//c:r4   N)r   r   r   r   )r   s   r2   _CC_build_extr   +  s    ;r4   r   T)_distutils_monkey_patchedr   )clsr   r   s     @r2   r   z#_CCExtension.monkey_patch_distutils   s:     ((#--	;O 	; ,	(,%r4   )	r   r   r   r   r   r   r   classmethodr   r   r4   r2   r   r     s-    
 C %% - -r4   r   )
setuptoolsr   dutilssetuptools.commandr   setuptools.extensionr   r%   r   r   r   
numba.corer   r   numba.core.compiler_lockr   numba.pycc.compilerr	   r
   numba.pycc.platformr   numbar   r   r   get_extension_libsr   objectr   r   r   r4   r2   <module>r      sh    * ( * 	  
  ' 9 ; )  ??jj(((*w wt%-9 %-r4   