o
    Td)                     @   s   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jZe ZG d
d deZG dd deZdS )    )	distutils)	build_ext)	ExtensionN)typingsigutils)global_compiler_lock)ModuleCompilerExportEntry)	Toolchain)cextc                   @   s  e Zd ZdZdge Zi Zi Zd+ddZe	dd Z
e	dd	 Zejd
d	 Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Zdd Ze	dd Zdd Zdd Zdd  Zd!d" Zd#d$ Zed%d& Zed'd( Zd)d* ZdS ),CCz_
    An ahead-of-time compiler to create extension modules that don't
    depend on Numba.
    zmodulemixin.cNc                 C   s   d|v rt d|| _d| | _i | _td}|d u r$|j}|d }nt|dr0|j}|j	}ntj
| j}|dd| _|| _t | _d| _tj| j| _| j|| _d	| _d| _d S )
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dct r/   `/home/ncw/WWW/www-new/content/articles/pi-bbp/venv/lib/python3.10/site-packages/numba/pycc/cc.py__init__/   s*   




zCC.__init__c                 C      | j S )z=
        The name of the extension module to create.
        )r   r*   r/   r/   r0   nameL      zCC.namec                 C   r2   )zJ
        The specific output file (a DLL) that will be generated.
        r'   r3   r/   r/   r0   output_fileS   r5   zCC.output_filec                 C   
   || _ d S Nr6   r*   valuer/   r/   r0   r7   Z      
c                 C   r2   )z?
        The directory the output file will be put in.
        r%   r3   r/   r/   r0   
output_dir^   r5   zCC.output_dirc                 C   r8   r9   r=   r:   r/   r/   r0   r>   e   r<   c                 C   r2   r9   r(   r3   r/   r/   r0   use_nrti   s   z
CC.use_nrtc                 C   r8   r9   r?   r:   r/   r/   r0   r@   m   r<   c                 C   r2   )z;
        The target CPU model for code generation.
        r)   r3   r/   r/   r0   
target_cpuq   r5   zCC.target_cpuc                 C   r8   r9   rA   r:   r/   r/   r0   rB   x   r<   c                 C   r2   )zI
        Whether to display detailed information when compiling.
        r!   r3   r/   r/   r0   verbose|   r5   z
CC.verbosec                 C   r8   r9   rC   r:   r/   r/   r0   rD      r<   c                    sJ   t \}}tj|g|R   jv rtd   fdd}|S )zH
        Mark a function for exporting in the extension module.
        zduplicated export symbol %sc                    s   t  | }|j < | S r9   )r	   r   )funcentryexported_namer*   sigr/   r0   	decorator   s   
zCC.export.<locals>.decorator)r   normalize_signaturer   	signaturer   KeyError)r*   rH   rI   fn_argsfn_rettyrJ   r/   rG   r0   export   s   
z	CC.exportc                 C   s   t | j dd dS )Nc                 S   r2   r9   )symbol)rF   r/   r/   r0   <lambda>   s    z$CC._export_entries.<locals>.<lambda>)key)sortedr   valuesr3   r/   r/   r0   _export_entries   s   
zCC._export_entriesc                    s<   t jt | jd d  }| jr|d  fdd|D S )Nz../core/runtime/nrt.cppc                    s   g | ]	}t j |qS r/   )r"   r#   join).0r-   herer/   r0   
<listcomp>   s    z)CC._get_mixin_sources.<locals>.<listcomp>)r"   r#   r$   r   _mixin_sourcesr(   append)r*   mixin_sourcesr/   rY   r0   _get_mixin_sources   s
   
zCC._get_mixin_sourcesc                 C   s   d| j fdt| jfgS )NPYCC_MODULE_NAMEPYCC_USE_NRT)r   intr(   r3   r/   r/   r0   _get_mixin_defines   s   zCC._get_mixin_definesc                 C   s(   | j tjg }|s| j tjg }|S r9   )_extra_cflagsr   r   platformr"   r4   )r*   extra_cflagsr/   r/   r0   _get_extra_cflags   s   zCC._get_extra_cflagsc                 C   sF   | j tjg }|s| j tjg }tjdr!d|vr!|d |S )Nlinuxz-pthread)_extra_ldflagsr   r   re   r"   r4   
startswithr]   )r*   extra_ldflagsr/   r/   r0   _get_extra_ldflags   s   
zCC._get_extra_ldflagsc                 C   s<   |   }|  }| j }|  }| jj|||||d}|S )N)include_dirsmacrosrf   )r_   rc   r    get_python_include_dirsrg   compile_objects)r*   	build_dirsourcesrn   rm   rf   objectsr/   r/   r0   _compile_mixins   s   

zCC._compile_mixinsc                 C   sj   t | j| j| j| jd}| j|_tj	|tj
| jd d }td| j| |j|dd |g|jfS )N)cpu_namer   z.oz%generating LLVM code for '%s' into %sT)wrap)r   rV   r   r(   r)   r   external_init_functionr"   r#   rW   splitextr'   loginfowrite_native_objectdll_exports)r*   rq   compilertemp_objr/   r/   r0   _compile_object_files   s   
zCC._compile_object_filesc                 C   s   | j | j_ tjd| j d}| |\}}|| |7 }|  }tj	
| j| j}| j }| j }| jj||||||d t| dS )z/
        Compile the extension module.
        zpycc-build-%s-)prefix)export_symbolsrk   N)rD   r    tempfilemkdtempr   r   rt   rl   r"   r#   rW   r%   r'   get_python_librariesget_python_library_dirslink_sharedshutilrmtree)r*   rq   rs   r|   rk   
output_dll	librarieslibrary_dirsr/   r/   r0   compile   s   



z
CC.compilec                 K   s   | dg |   }| dg | jg }| dg |   }| dg |   }| dg | j  }| dg | j  }| dg | j  }| j	d| j	
d	d
  }	td|	| j |  |||||||d	|}
|
  | |
_|
S )z`
        Create a distutils extension object that can be used in your
        setup.py.
        rn   dependsextra_compile_argsextra_link_argsrm   r   r   Nr   r   )	r4   rr   r   define_macrosrm   r   r   r   r   r/   )poprc   r   rg   rl   r    ro   r   r   r   rfind_CCExtensionr   r_   monkey_patch_distutils_cc)r*   kwargsrn   r   r   r   rm   r   r   python_package_pathextr/   r/   r0   distutils_extension   sB   




	
zCC.distutils_extensionr9   )r   
__module____qualname____doc__extension_libsr\   rd   ri   r1   propertyr4   r7   setterr>   r@   rB   rD   rP   rV   r_   rc   rg   rl   rt   r   r   r   r   r/   r/   r/   r0   r      sR    
















r   c                   @   s,   e Zd ZdZdZdZdd Zedd ZdS )r   zj
    A Numba-specific Extension subclass to LLVM-compile pure Python code
    to an extension module.
    NFc                 C   sL   | j }ttjj|jg| jdd d R   |	|j\}}|| _
d S )Nr   )r   dir_utilmkpathr"   r#   rW   
build_tempr4   splitr   extra_objects)r*   r   ccrs   _r/   r/   r0   _prepare_object_files  s   ,
z"_CCExtension._prepare_object_filesc                    s4   | j rdS tj G  fddd }|t_d| _ dS )z}
        Monkey-patch distutils with our own build_ext class knowing
        about pycc-compiled extensions modules.
        Nc                       s   e Zd Z fddZdS )z:_CCExtension.monkey_patch_distutils.<locals>._CC_build_extc                    s$   t |tr
||   | | d S r9   )
isinstancer   r   build_extension)r*   r   _orig_build_extr/   r0   r   -  s   

zJ_CCExtension.monkey_patch_distutils.<locals>._CC_build_ext.build_extensionN)r   r   r   r   r/   r   r/   r0   _CC_build_ext+  s    r   T)_distutils_monkey_patchedr   )clsr   r/   r   r0   r      s   
z#_CCExtension.monkey_patch_distutils)	r   r   r   r   r   r   r   classmethodr   r/   r/   r/   r0   r     s    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   ry   get_extension_libsr   objectr   r   r/   r/   r/   r0   <module>   s$     {