o
    1&i=F                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ edd	 ZG d
d dejdZG dd deZdZG dd deZdS )z-
Implements helpers to build LLVM debuginfo.
    N)contextmanager)ir)cgutilstypes)ComplexModelUniTupleModel)configc                 c   s*    | j }d| _ z	dV  W || _ dS || _ w )zZSuspends the emission of debug_metadata for the duration of the context
    managed block.N)debug_metadata)builderref r   ?C:\wamp64\www\opt\env\Lib\site-packages\numba/core/debuginfo.pysuspend_emission   s   r   c                   @   sV   e Zd Zej	dddZejdd Zejdd Zejdd	 Zejd
d Z	dS )AbstractDIBuilderNc	           	      C      dS )z*Emit debug info for the variable.
        Nr   	selfr
   allocavaluenamelltypesizeline	datamodelargidxr   r   r   mark_variable   s   zAbstractDIBuilder.mark_variablec                 C   r   )zAEmit source location information to the given IRBuilder.
        Nr   r   r
   r   r   r   r   mark_location$      zAbstractDIBuilder.mark_locationc                 C   r   )zAEmit source location information for the given function.
        Nr   r   functionqualnameargnamesargtypesr   r   r   r   mark_subprogram*   r   z!AbstractDIBuilder.mark_subprogramc                 C   r   )zvInitialize the debug info. An opportunity for the debuginfo to
        prepare any necessary data structures.
        Nr   r   r   r   r   
initialize0   s    zAbstractDIBuilder.initializec                 C   r   )zCFinalize the debuginfo by emitting all necessary metadata.
        Nr   r$   r   r   r   finalize6   r   zAbstractDIBuilder.finalizeNN)
__name__
__module____qualname__abcabstractmethodr   r   r#   r%   r&   r   r   r   r   r      s    


r   )	metaclassc                   @   s@   e Zd Zdd Z	dddZdd Zdd	 Zd
d Zdd ZdS )DummyDIBuilderc                 C      d S Nr   r   modulefilepathcgctxZdirectives_onlyr   r   r   __init__?      zDummyDIBuilder.__init__Nc	           	      C   r/   r0   r   r   r   r   r   r   B   s   zDummyDIBuilder.mark_variablec                 C   r/   r0   r   r   r   r   r   r   F   r6   zDummyDIBuilder.mark_locationc                 C   r/   r0   r   r   r   r   r   r#   I   r6   zDummyDIBuilder.mark_subprogramc                 C   r/   r0   r   r$   r   r   r   r%   L   r6   zDummyDIBuilder.initializec                 C   r/   r0   r   r$   r   r   r   r&   O   r6   zDummyDIBuilder.finalizer'   )	r(   r)   r*   r5   r   r   r#   r%   r&   r   r   r   r   r.   =   s    
r.      c                   @   s   e Zd ZdZdZdZdZdd Zdd Zd)d
dZ			d*ddZ
dd Zdd Zdd Zdd Zdd Zdd Zed+ddZedd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd	S ),	DIBuilder      zllvm.dbg.cuFc                 C   sH   || _ tj|| _|  | _g | _|| _|rd| _	nd| _	| 
  d S )NZDebugDirectivesOnlyZ	FullDebug)r2   ospathabspathr3   _di_filedifilesubprogramsr4   emission_kindr%   r1   r   r   r   r5   \   s   
zDIBuilder.__init__c                 C   s   |   | _d S r0   )_di_compile_unitdicompileunitr$   r   r   r   r%   j   s   zDIBuilder.initializeNc                 C   s  | j rtd|||t|dd | j}t| }tjf}tjtjf}t	||| ra|d u r:t
|}t	||r7d}	nd}	nt
|j}t	|jtjrP|jjrMd}	nd}	nd}	|d||t|	d}
|
S t	|trg }d	}td
D ]<\}}|j| }| j|}|dt
|t| tdd}|dtd||t| |d}|| |t| 7 }qn|jdtd|j dt
| dt
||||ddd}
|
S t	|tr|j}| j|}| ||}|j dt
| d}|| }|dd|i}|dtd|||t
|||gd}
|
S t	|tjr?t|dd }| |j| j|j|}|dtd|t| j| d}
|
S t	|tjrg }d	}|d u sT| sdt
| d}t|jD ]1\}}| j|}| ||}|dtdd| d|t| |d}|| |t| 7 }qanF|j dt
| d}t|j|j | D ]0\}}}| j|}| j|||d}|dtd||t| |d}|| |t| 7 }q|jdtd|t
||||ddd}
|
S t	|tj!r.|j}| j|}| ||}|| }|dd|i}|dtd|t
||t
|||gd}
|
S |}|dd|i}|dd ttd!d}|dtd|t
||t
|||gd}
|
S )"Nz-->fe_typez
NO FE TYPEZDW_ATE_unsignedZDW_ATE_floatZDW_ATE_signedZDIBasicType)r   r   encodingr   )realimagZDIDerivedTypeZDW_TAG_member)tagr   baseTyper   offsetZDICompositeTypeZDW_TAG_structure_typez ())rH   r   
identifierelementsr   TZis_distinctZ
DISubrangecountZDW_TAG_array_type)rH   rI   r   r   rL   rM   Z_pointee_modelZDW_TAG_pointer_type)rH   rI   r   zAnonymous struct (z<field >r   byteZDW_ATE_unsigned_char)"_DEBUGprintgetattrr2   
_BYTE_SIZEr   IntTypeZ	FloatTypeZ
DoubleType
isinstancestrrD   r   Integersignedadd_debug_infoDITokenr   	enumeraterM   r4   get_abi_sizeofappendadd_metadatar   element	_var_typeZPointerTypeZpointeeZLiteralStructTypeZinner_modelszip_fields	ArrayType)r   r   r   r   mZbitsizeZint_typeZ	real_typer   ZditokmdtypemetarJ   Zix	componentZcomponent_sizeZcomponent_basetypeZderived_typerb   Zel_sizeZbasetyperO   ZmdrangemodelZfield_idfieldZmdbaser   r   r   rc   o   sN  



  


p
`S


+

	zDIBuilder._var_typec	              
   C   s   |d u rdn|}	| j }
tt t gd }t|
|d}| j|||d}|dd}|
	d||	| j
d | j||d	}|
	d
i }|||||gS )Nr   r:   zllvm.dbg.declarerQ   .$ZDILocalVariable)r   argscopefiler   typeZDIExpression)r2   r   FunctionTypeZVoidTypeZMetaDataTyper   Zget_or_insert_functionrc   replacer\   r@   r?   call)r   r
   r   r   r   r   r   r   r   Z	arg_indexrg   Zfntydeclrh   Z
mdlocalvarZmdexprr   r   r   r   $  s    zDIBuilder.mark_variablec                 C   s   |  ||_d S r0   )_add_locationr	   r   r   r   r   r   :  s   zDIBuilder.mark_locationc           	      C   s8   |}t t||}| j||j|||d}|d| d S )N)r   linkagenamer   r   argmapZdbg)dictrd   _add_subprogramr   Zset_metadata)	r   r   r    r!   r"   r   r   rz   Zdi_subpr   r   r   r#   =  s   
zDIBuilder.mark_subprogramc                 C   s(   t | j| j}|| j |   d S r0   )r   get_or_insert_named_metadatar2   DBG_CU_NAMEaddrC   _set_module_flags)r   Zdbgcur   r   r   r&   E  s   zDIBuilder.finalizec                 C   s   | j }t|d}| d}| jdur)||d| | jg}||jvr)|| ||d| | jg}||jvrA|| dS dS )z&Set the module flags metadata
        zllvm.module.flags   NzDwarf VersionzDebug Info Version)	r2   r   r}   
_const_intDWARF_VERSIONra   Zoperandsr   DEBUG_INFO_VERSION)r   r2   ZmflagsZrequire_warning_behaviorZdwarf_versionZdebuginfo_versionr   r   r   r   N  s&   






zDIBuilder._set_module_flagsc                 C   s"   |  |||||}| j| |S )z!Emit subprogram metadata
        )_di_subprogramr@   r`   )r   r   ry   r   r   rz   Zsubpr   r   r   r|   f  s   zDIBuilder._add_subprogramc                 C   s   |  |}|S )zEmit location metatdaa
        )_di_location)r   r   locr   r   r   rx   m  s   
zDIBuilder._add_location    c                 C   s   t ||S )z0Util to create constant int in metadata
        r   rW   )clsnumbitsr   r   r   r   s     zDIBuilder._const_intc                 C   s   t d|S )z4Util to create constant boolean in metadata
           r   )r   booleanr   r   r   _const_booly  r   zDIBuilder._const_boolc                 C   s(   | j dtj| jtj| jdS )NZDIFile)	directoryfilename)r2   r\   r;   r<   dirnamer3   basenamer$   r   r   r   r>     s   zDIBuilder._di_filec              
   C   s6   | j jdtd| jddtjdkt| jdddS )NZDICompileUnitZDW_LANG_C_plus_pluszclang (Numba)r   )languagerr   ZproducerZruntimeVersionisOptimizedZemissionKindTrN   )r2   r\   r   r]   r?   r   OPTrA   r$   r   r   r   rB     s   	
zDIBuilder._di_compile_unitc                 C   s   |}g }t |jD ]'\}}|jds0|jdd}|j}	| j|	}
| j|	|
d d}|	| q	t |
 D ]+\}\}}|dd}| jj| }| j|}	| j|	}
| j|	|
|d}|	| q7| jdd| j|iS )Nzarg.rm   rn   rQ   ZDISubroutineTyper   )r^   argsr   
startswithru   rs   r4   r_   rc   r`   itemsZdata_model_managerZget_value_typer2   r\   ra   )r   r   r   rz   ZllfuncmdidxZllargr   r   r   rh   Znbtyper   r   r   r   _di_subroutine_type  s(   
zDIBuilder._di_subroutine_typec                 C   s@   | j jd||| j| j|| |||dd|tjdk| jdddS )NZDISubprogramFTr   )r   ZlinkageNamerq   rr   r   rs   ZisLocalZisDefinitionZ	scopeLiner   unitrN   )r2   r\   r?   r   r   r   rC   )r   r   ry   r   r   rz   r   r   r   r     s   zDIBuilder._di_subprogramc                 C   s   | j d|d| jd dS )NZ
DILocationr   ro   )r   columnrq   )r2   r\   r@   )r   r   r   r   r   r     s
   zDIBuilder._di_locationr0   r'   )r   )r(   r)   r*   r   r   r~   rS   r5   r%   rc   r   r   r#   r&   r   r|   rx   classmethodr   r   r>   rB   r   r   r   r   r   r   r   r8   V   s4    
 7
	
	r8   )__doc__r+   Zos.pathr;   
contextlibr   Zllvmliter   Z
numba.corer   r   Znumba.core.datamodel.modelsr   r   r   r   ABCMetar   r.   rV   r8   r   r   r   r   <module>   s    
!