a
    –§»aq(  ã                   @   s¸   d dl mZ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 ¡ ZG d
d„ deƒZG dd„ deƒZdS )é    )Údir_utilÚlog)Ú	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 rH|j}|d }n$t|dƒr`|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 nameZ
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_dirZget_ext_filenameÚ_output_fileÚ_use_nrtÚ_target_cpu)ÚselfZextension_nameZsource_moduleÚfÚdct© r,   úG/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/pycc/cc.pyÚ__init__,   s*    



zCC.__init__c                 C   s   | j S )z=
        The name of the extension module to create.
        )r   ©r)   r,   r,   r-   ÚnameI   s    zCC.namec                 C   s   | j S )zJ
        The specific output file (a DLL) that will be generated.
        ©r&   r/   r,   r,   r-   Úoutput_fileP   s    zCC.output_filec                 C   s
   || _ d S ©Nr1   ©r)   Úvaluer,   r,   r-   r2   W   s    c                 C   s   | j S )z?
        The directory the output file will be put in.
        ©r%   r/   r,   r,   r-   Ú
output_dir[   s    zCC.output_dirc                 C   s
   || _ d S r3   r6   r4   r,   r,   r-   r7   b   s    c                 C   s   | j S r3   ©r'   r/   r,   r,   r-   Úuse_nrtf   s    z
CC.use_nrtc                 C   s
   || _ d S r3   r8   r4   r,   r,   r-   r9   j   s    c                 C   s   | j S )z;
        The target CPU model for code generation.
        ©r(   r/   r,   r,   r-   Ú
target_cpun   s    zCC.target_cpuc                 C   s
   || _ d S r3   r:   r4   r,   r,   r-   r;   u   s    c                 C   s   | j S )zI
        Whether to display detailed information when compiling.
        ©r!   r/   r,   r,   r-   Úverbosey   s    z
CC.verbosec                 C   s
   || _ d S r3   r<   r4   r,   r,   r-   r=   €   s    c                    sJ   t  ˆ¡\}}tj|g|¢R Ž ‰ˆ ˆjv r6tdˆ  ƒ‚‡ ‡‡fdd„}|S )zH
        Mark a function for exporting in the extension module.
        zduplicated export symbol %sc                    s   t ˆ ˆ| ƒ}|ˆjˆ < | S r3   )r
   r   )ÚfuncÚentry©Úexported_namer)   Úsigr,   r-   Ú	decorator�   s    
zCC.export.<locals>.decorator)r   Znormalize_signaturer   Ú	signaturer   ÚKeyError)r)   rA   rB   Zfn_argsZfn_rettyrC   r,   r@   r-   Úexport„   s    
z	CC.exportc                 C   s   t | j ¡ dd„ d�S )Nc                 S   s   | j S r3   )Úsymbol)r?   r,   r,   r-   Ú<lambda>—   ó    z$CC._export_entries.<locals>.<lambda>)Úkey)Úsortedr   Úvaluesr/   r,   r,   r-   Ú_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.cc                    s   g | ]}t j ˆ |¡‘qS r,   )r"   r#   Újoin)Ú.0r*   ©Úherer,   r-   Ú
<listcomp>ž   rI   z)CC._get_mixin_sources.<locals>.<listcomp>)r"   r#   r$   r   Ú_mixin_sourcesr'   Úappend)r)   Zmixin_sourcesr,   rP   r-   Ú_get_mixin_sources™   s
    
zCC._get_mixin_sourcesc                 C   s   d| j fdt| jƒfgS )NZPYCC_MODULE_NAMEZPYCC_USE_NRT)r   Úintr'   r/   r,   r,   r-   Ú_get_mixin_defines    s    þzCC._get_mixin_definesc                 C   s(   | j  tjg ¡}|s$| j  tjg ¡}|S r3   )Ú_extra_cflagsr   r   Úplatformr"   r0   )r)   Úextra_cflagsr,   r,   r-   Ú_get_extra_cflags§   s    zCC._get_extra_cflagsc                 C   s(   | j  tjg ¡}|s$| j  tjg ¡}|S r3   )Ú_extra_ldflagsr   r   rY   r"   r0   )r)   Úextra_ldflagsr,   r,   r-   Ú_get_extra_ldflags­   s    zCC._get_extra_ldflagsc                 C   s<   |   ¡ }|  ¡ }| j ¡ }|  ¡ }| jj|||||d�}|S )N)Úinclude_dirsÚmacrosrZ   )rU   rW   r    Úget_python_include_dirsr[   Zcompile_objects)r)   Ú	build_dirÚsourcesr`   r_   rZ   Úobjectsr,   r,   r-   Ú_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)Zcpu_namer   z.oz%generating LLVM code for '%s' into %sT)Úwrap)r	   rM   r   r'   r(   r   Zexternal_init_functionr"   r#   rN   Úsplitextr&   r   ÚinfoZwrite_native_objectÚdll_exports)r)   rb   ÚcompilerZtemp_objr,   r,   r-   Ú_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_symbolsr]   N)r=   r    ÚtempfileÚmkdtempr   rk   re   r^   r"   r#   rN   r%   r&   Úget_python_librariesÚget_python_library_dirsZlink_sharedÚshutilÚrmtree)r)   rb   rd   ri   r]   Z
output_dllÚ	librariesÚlibrary_dirsr,   r,   r-   Ú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f |	| j |  ¡ |||||||dœ	|¤Ž}
|
 ¡  | |
_|
S )z`
        Create a distutils extension object that can be used in your
        setup.py.
        r`   ÚdependsÚextra_compile_argsÚextra_link_argsr_   rt   ru   Nr   r   )	r0   rc   rw   Údefine_macrosr_   rt   ru   rx   ry   )ÚpoprW   r   r[   r^   r    ra   rp   rq   r   ÚrfindÚ_CCExtensionr   rU   Úmonkey_patch_distutilsÚ_cc)r)   Úkwargsr`   rw   rx   ry   r_   rt   ru   Zpython_package_pathÚextr,   r,   r-   Údistutils_extensionç   sB    
ÿ
ÿ
ÿ
ÿ
ÿø	÷
zCC.distutils_extension)N)r   Ú
__module__Ú__qualname__Ú__doc__Úextension_libsrS   rX   r\   r.   Úpropertyr0   r2   Úsetterr7   r9   r;   r=   rF   rM   rU   rW   r[   r^   re   r   rk   rv   r‚   r,   r,   r,   r-   r      sP   















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   r   Úmkpathr"   r#   rN   Ú
build_tempr0   Úsplitrk   Úextra_objects)r)   r   Úccrd   Ú_r,   r,   r-   Ú_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 r3   )Ú
isinstancer}   r�   Úbuild_extension)r)   r�   ©Z_orig_build_extr,   r-   r’   &  s    

zJ_CCExtension.monkey_patch_distutils.<locals>._CC_build_ext.build_extensionN)r   rƒ   r„   r’   r,   r“   r,   r-   Ú_CC_build_ext$  s   r”   T)Ú_distutils_monkey_patchedr   )Úclsr”   r,   r“   r-   r~     s    z#_CCExtension.monkey_patch_distutils)	r   rƒ   r„   r…   r   r•   r�   Úclassmethodr~   r,   r,   r,   r-   r}   	  s   r}   )Ú	distutilsr   r   Údistutils.commandr   Údistutils.extensionr   r"   rr   r   rn   Z
numba.corer   r   Znumba.core.compiler_lockr   Znumba.pycc.compilerr	   r
   Znumba.pycc.platformr   Znumbar   Zget_extension_libsr†   Úobjectr   r}   r,   r,   r,   r-   Ú<module>   s    w