
    d9              
          d dl Z d dlmZmZmZmZmZmZmZ d dl	m
Z
 d dlmZmZ d Z G d de          Zd Zd	 Zd
 ZddddZddZd Z G d de
j                  Z eg d          Z eg d          Z G d de
j                  Z G d de
j                  Zd Z ee          ge
j        j         _!         ee          ge
j        j"        _!        ee
j        j"        _#         ee          ge
j        j$        _!         ee          ge
j        j%        _!        ege
j        j&        _!        ee
j        j&        _#        ege
j        j'        _!        e
j(        e
j        j'        _#        e
j(         ee          ge
j        j)        _!        e
j(        ge
j        j*        _!        e
j(        e
j+        ge
j        j,        _!        ee
j        j,        _#        e
j(        e
j+        ege
j        j-        _!        ee
j        j-        _#        e
j(        e
j+        ge
j        j.        _!        ee
j        j.        _#        e
j(        e
j+        ge
j        j/        _!        ee
j        j/        _#        e ee          ge
j        j0        _!        e
j1        e
j        j0        _#        e
j1        ge
j        j2        _!        ee
j        j2        _#        e
j1        ge
j        j3        _!        ee
j        j3        _#        e
j1        eeeeeeeeeg
e
j        j4        _!        e
j5        e
j        j4        _#        e
j5        ge
j        j6        _!        e
j5         ee          ge
j        j7        _!        e
j5        ege
j        j8        _!        e
j5        e
j9        ge
j        j:        _!        e
j5        e
j;        e ee          ge
j        j<        _!        e
j=        e
j        j<        _#        e
j=        ge
j        j>        _!        ee
j        j>        _#        e
j=        ge
j        j?        _!        ee
j        j?        _#        e
j=        ge
j        j@        _!        e
j5        ge
j        jA        _!        e
j(        e
j        jA        _#        g e
j        jB        _!        ee
j        jB        _#        dS )    N)POINTERc_char_p
c_longlongc_intc_size_tc_void_p	string_at)ffi)_decode_string_encode_stringc                      t          j                    5 } t           j                            |            t	          |           cddd           S # 1 swxY w Y   dS )a  
    Return a target triple suitable for generating code for the current process.
    An example when the default triple from ``get_default_triple()`` is not be
    suitable is when LLVM is compiled for 32-bit but the process is executing
    in 64-bit mode.
    N)r
   OutputStringlibLLVMPY_GetProcessTriplestrouts    8lib/python3.11/site-packages/llvmlite/binding/targets.pyget_process_tripler   	   s     
			 s'',,,3xx                    .AAAc                       e Zd ZdZddZdS )
FeatureMapz
    Maps feature name to a boolean indicating the availability of the feature.
    Extends ``dict`` to add `.flatten()` method.
    Tc                     |r!t          |                                           n t          |                                           }dddd                    fd|D                       S )ap  
        Args
        ----
        sort: bool
            Optional.  If True, the features are sorted by name; otherwise,
            the ordering is unstable between python session due to hash
            randomization.  Defaults to True.

        Returns a string suitable for use as the ``features`` argument to
        ``Target.create_target_machine()``.

        +-)TF,c              3   V   K   | ]#\  }}d                      |         |          V  $dS )z{0}{1}N)format).0kvflag_maps      r   	<genexpr>z%FeatureMap.flatten.<locals>.<genexpr>*   sM       . . Aq !Q77 . . . . . .    )sorteditemsiterjoin)selfsortiteratorr"   s      @r   flattenzFeatureMap.flatten   s}     ,0G6$**,,'''T$**,,5G5Gc**xx . . . .$,. . . . . 	.r$   N)T)__name__
__module____qualname____doc__r,    r$   r   r   r      s2         
. . . . . .r$   r   c                  h   t          j                    5 } t                      }t           j                            |           s|cddd           S ddd}t          |           }|r3|                    d          D ]}|r||d                  ||dd         <   |cddd           S # 1 swxY w Y   dS )ac  
    Returns a dictionary-like object indicating the CPU features for current
    architecture and whether they are enabled for this CPU.  The key-value pairs
    are the feature name as string and a boolean indicating whether the feature
    is available.  The returned value is an instance of ``FeatureMap`` class,
    which adds a new method ``.flatten()`` for returning a string suitable for
    use as the "features" argument to ``Target.create_target_machine()``.

    If LLVM has not implemented this feature or it fails to get the information,
    this function will raise a RuntimeError exception.
    NTF)r   r   r   r      )r
   r   r   r   LLVMPY_GetHostCPUFeaturesr   split)r   outdictr"   contentfeats        r   get_host_cpu_featuresr9   .   s$    
			 
s,,w0055 	
 
 
 
 
 
 
 
 E**c(( 	:c** : : :(0a(9GDH%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   /B'A
B''B+.B+c                      t          j                    5 } t           j                            |            t	          |           cddd           S # 1 swxY w Y   dS )zR
    Return the default target triple LLVM is configured to produce code for.
    N)r
   r   r   LLVMPY_GetDefaultTargetTripler   r   s    r   get_default_tripler<   G   s     
			 s--c2223xx                 r   c                      t          j                    5 } t           j                            |            t	          |           cddd           S # 1 swxY w Y   dS )zm
    Get the name of the host's CPU, suitable for using with
    :meth:`Target.create_target_machine()`.
    N)r
   r   r   LLVMPY_GetHostCPUNamer   r   s    r   get_host_cpu_namer?   P   s    
 
			 s%%c***3xx                 r   COFFELFMachO)r3         c                     | t                      } t          j                            t	          |                     }t
          |         S )z~
    Get the object format for the given *triple* string (or the default
    triple if omitted).
    A string is returned
    )r<   r
   r   LLVMPY_GetTripleObjectFormatr   _object_formats)tripleress     r   get_object_formatrJ   a   s<     ~#%%
'
.
.~f/E/E
F
FC3r$   c                 t    t          t          j                            t	          |                               S )zE
    Create a TargetData instance for the given *layout* string.
    )
TargetDatar
   r   LLVMPY_CreateTargetDatar   )layouts    r   create_target_datarO   m   s*     cg55nV6L6LMMNNNr$   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	rL   z{
    A TargetData provides structured access to a data layout.
    Use :func:`create_target_data` to create instances.
    c                     | j         rdS t          j                    5 }t          j                            | |           t          |          cd d d            S # 1 swxY w Y   d S )Nz<dead TargetData>)_closedr
   r   r    LLVMPY_CopyStringRepOfTargetDatar   r)   r   s     r   __str__zTargetData.__str__z   s    < 	'&& 	3G44T3???s88	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AA Ac                 :    | j                             |            d S N)_capiLLVMPY_DisposeTargetDatar)   s    r   _disposezTargetData._dispose   s    
++D11111r$   c                 B    t           j                            | |          S )z1
        Get ABI size of LLVM type *ty*.
        )r
   r   LLVMPY_ABISizeOfType)r)   tys     r   get_abi_sizezTargetData.get_abi_size   s     w++D"555r$   c                     t           j                            | ||          }|dk    r0t          d                    |t          |                              |S )zL
        Get byte offset of type's ty element at the given position
        zQCould not determined offset of {}th element of the type '{}'. Is it a structtype?)r
   r   LLVMPY_OffsetOfElement
ValueErrorr   r   )r)   r^   positionoffsets       r   get_element_offsetzTargetData.get_element_offset   s\    
 //b(CCR<< %%+VHc"gg%>%>@ @ @ r$   c                 v    t           j                            | |          }|dk    rt          d|          |S )zI
        Get ABI size of pointee type of LLVM pointer type *ty*.
        ra   Not a pointer type: )r
   r   LLVMPY_ABISizeOfElementTypeRuntimeErrorr)   r^   sizes      r   get_pointee_abi_sizezTargetData.get_pointee_abi_size   s>     w224<<2::,22?@@@r$   c                 v    t           j                            | |          }|dk    rt          d|          |S )zV
        Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
        ra   rh   )r
   r    LLVMPY_ABIAlignmentOfElementTyperj   rk   s      r   get_pointee_abi_alignmentz$TargetData.get_pointee_abi_alignment   s>     w77bAA2::,22?@@@r$   N)
r-   r.   r/   r0   rU   r[   r_   rf   rm   rp   r1   r$   r   rL   rL   t   sx         
  2 2 26 6 6
 
 
      r$   rL   )defaultstaticpicdynamicnopic)rq   
jitdefaultsmallkernelmediumlargec                       e Zd ZdZed             Zed             Zed             Zed             Z	ed             Z
d Z	 	 	 ddZdS )Target c                 H    t                      }|                     |          S )zB
        Create a Target instance for the default triple.
        )r<   from_triple)clsrH   s     r   from_default_triplezTarget.from_default_triple   s!    
 $%%v&&&r$   c                 &   t          j                    5 }t           j                            |                    d          |          }|st          t          |                     | |          }||_        |cddd           S # 1 swxY w Y   dS )zK
        Create a Target instance for the given triple (a string).
        utf8N)r
   r   r   LLVMPY_GetTargetFromTripleencoderj   r   _triple)r   rH   outerrtargets       r   r~   zTarget.from_triple   s    
  	6W77f8M8M8>@ @F 0"3v;;///S[[F#FN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A%BB
B
c                 ^    t           j                            |           }t          |          S rW   )r
   r   LLVMPY_GetTargetNamer   r)   ss     r   namezTarget.name   s%    G((..a   r$   c                 ^    t           j                            |           }t          |          S rW   )r
   r   LLVMPY_GetTargetDescriptionr   r   s     r   descriptionzTarget.description   s%    G//55a   r$   c                     | j         S rW   )r   rZ   s    r   rH   zTarget.triple   s
    |r$   c                 B    d                     | j        | j                  S )Nz<Target {0} ({1})>)r   r   r   rZ   s    r   rU   zTarget.__str__   s    #**49d6FGGGr$   rC   rq   ru   Fc	                    d|cxk    rdk    sn J |t           v sJ |t          v sJ | j        }	t          j        dk    r|dk    r|	dz  }	t
          j                            | t          |	          t          |          t          |          |t          |          t          |          t          |          t          |          t          |          
  
        }
|
rt          |
          S t          d          )am  
        Create a new TargetMachine for this target and the given options.

        Specifying codemodel='default' will result in the use of the "small"
        code model. Specifying codemodel='jitdefault' will result in the code
        model being picked based on platform bitness (32="small", 64="large").

        The `printmc` option corresponds to llvm's `-print-machineinstrs`.

        The `jit` option should be set when the target-machine is to be used
        in a JIT engine.

        The `abiname` option specifies the ABI. RISC-V targets with hard-float
        needs to pass the ABI name to LLVM.
        r   rD   ntru   z-elfzCannot create target machine)RELOC	CODEMODELr   osr   r
   r   LLVMPY_CreateTargetMachiner   intTargetMachinerj   )r)   cpufeaturesoptreloc	codemodelprintmcjitabinamerH   tms              r   create_target_machinezTarget.create_target_machine   s    $ C}}}}1}}}}}}~~~~I%%%% 7d??yL88fFW//0>v0F0F0>s0C0C0>x0H0H030>u0E0E0>y0I0I03G03C0>w0G0G
2 
2  	? $$$=>>>r$   N)r|   r|   rC   rq   ru   FFr|   )r-   r.   r/   r   classmethodr   r~   propertyr   r   rH   rU   r   r1   r$   r   r{   r{      s        G
 ' ' ['   [ ! ! X! ! ! X!   XH H H 68@L@B)? )? )? )? )? )?r$   r{   c                   `    e Zd Zd Zd Zd Zd Zd ZddZe	d             Z
e	d	             Zd
S )r   c                 :    | j                             |            d S rW   )rX   LLVMPY_DisposeTargetMachinerZ   s    r   r[   zTargetMachine._dispose	  s    
..t44444r$   c                 F    t           j                            | |           dS )zW
        Register analysis passes for this target machine with a pass manager.
        N)r
   r   LLVMPY_AddAnalysisPasses)r)   pms     r   add_analysis_passesz!TargetMachine.add_analysis_passes  s"     	((r22222r$   c                 F    t           j                            | |           dS )z
        Set whether this target machine will emit assembly with human-readable
        comments describing control flow, debug information, and so on.
        N)r
   r   #LLVMPY_SetTargetMachineAsmVerbosity)r)   verboses     r   set_asm_verbosityzTargetMachine.set_asm_verbosity  s"    
 	33D'BBBBBr$   c                 0    |                      |d          S )z
        Represent the module as a code object, suitable for use with
        the platform's linker.  Returns a byte string.
        T
use_object)_emit_to_memoryr)   modules     r   emit_objectzTargetMachine.emit_object  s    
 ##Ft#<<<r$   c                 J    t          |                     |d                    S )z
        Return the raw assembler of the module, as a string.

        llvm.initialize_native_asmprinter() must have been called first.
        Fr   )r   r   r   s     r   emit_assemblyzTargetMachine.emit_assembly   s%     d226e2LLMMMr$   Fc                    t          j                    5 }t           j                            | |t	          |          |          }|st          t          |                    	 ddd           n# 1 swxY w Y   t           j                            |          }t           j                            |          }	 t          ||          t           j        
                    |           S # t           j        
                    |           w xY w)zReturns bytes of object code of the module.

        Args
        ----
        use_object : bool
            Emit object code or (if False) emit assembly code.
        N)r
   r   r    LLVMPY_TargetMachineEmitToMemoryr   rj   r   LLVMPY_GetBufferStartLLVMPY_GetBufferSizer	   LLVMPY_DisposeMemoryBuffer)r)   r   r   r   mbbufptrbufszs          r   r   zTargetMachine._emit_to_memory(  s$     	0699$:=j//:@B BB  0"3v;;///0		0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 ..r22,,R00	3VU++G..r2222CG..r2222s   AA//A36A39C( (!D	c                 Z    t          t          j                            |                     S rW   )rL   r
   r   LLVMPY_CreateTargetMachineDatarZ   s    r   target_datazTargetMachine.target_data>  s     #'@@FFGGGr$   c                     t          j                    5 }t           j                            | |           t	          |          cd d d            S # 1 swxY w Y   d S rW   )r
   r   r   LLVMPY_GetTargetMachineTripler   rT   s     r   rH   zTargetMachine.tripleB  s     	3G11$<<<s88	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AAAN)F)r-   r.   r/   r[   r   r   r   r   r   r   r   rH   r1   r$   r   r   r     s        5 5 53 3 3C C C= = =N N N3 3 3 3, H H XH   X  r$   r   c                  N    t           j                                        dk    rdS dS )zG
    Returns True if SVML was enabled at FFI support compile time.
    r   FT)r
   r   LLVMPY_HasSVMLSupportr1   r$   r   has_svmlr   I  s'     w$$&&!++utr$   rW   )Cr   ctypesr   r   r   r   r   r   r	   llvmlite.bindingr
   llvmlite.binding.commonr   r   r   dictr   r9   r<   r?   rG   rJ   rO   	ObjectRefrL   	frozensetr   r   r{   r   r   r   r   argtypesr4   restyper;   r>   rF   rM   LLVMTargetDataRefrS   rY   LLVMTypeRefr]   rb   ri   ro   r   LLVMTargetRefr   r   r   LLVMTargetMachineRefr   r   r   LLVMPassManagerRefr   LLVMModuleRefr   LLVMMemoryBufferRefr   r   r   r   r   r1   r$   r   <module>r      s   				) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) !           B B B B B B B B	 	 	. . . . . . . .2  2      	  	  	  	 O O O2 2 2 2 2 2 2 2j 		>>>??I       ! !	V? V? V? V? V?S] V? V? V?r? ? ? ? ?CM ? ? ?D   -4GH,=,=+>  (.5gh.?.?-@ ! *,1 ! )29'(2C2C1D % .*1'(*;*;)<  &19
 $ -/4 $ ,,4:  (*-*?  ' GH5 ( 1 -   ) *-)>),):  %'1  $+.+@+.?+0+2  ' *4  &030E030A # ,.8 # +585J58_5F ( 13= ( 0/79J9J.K " +-0-> " *),):(;  %'/  $030A/B # ,.6 # + 			'/ " +* .1-E " *030H/I # ,252J29'(2C2C2E % . e8% + 4 -   ) 	GH	5 ( 1 473J ( 0*-*A)B  &(0  %),)@(A  %'/  $/2/F.G " + 3 & / 251F & .)+  &(-  % % %r$   