
    J/PhC              
       F
   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 d dlmZmZ d dlmZ d dlmZ  edg d	          Zd
 ZdefdZ G d de          Zd Zd Zd Zed          Zedk    rdddddddddd	Zn
dddd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e           ee           ee           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)        j0        _+        ege
j)        j1        _+        ee
j)        j1        _.        ege
j)        j2        _+        e
j3        e
j)        j2        _.        e
j3         ee          ge
j)        j4        _+        e
j3        ge
j)        j5        _+        e
j3        e
j6        ge
j)        j7        _+        ee
j)        j7        _.        e
j3        e
j6        ege
j)        j8        _+        ee
j)        j8        _.        e
j3        e
j6        ge
j)        j9        _+        ee
j)        j9        _.        e
j3        e
j6        ge
j)        j:        _+        ee
j)        j:        _.        e
j3        e
j6        ge
j)        j;        _+        ee
j)        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=        eeeeeeeeeg
e
j)        j@        _+        e
jA        e
j)        j@        _.        e
jA        ge
j)        jB        _+        e
jA         ee          ge
j)        jC        _+        e
jA        ege
j)        jD        _+        e
jA        e
jE        ge
j)        jF        _+        e
jA        e
jG        e ee          ge
j)        jH        _+        e
jI        e
j)        jH        _.        e
jI        ge
j)        jJ        _+        ee
j)        jJ        _.        e
jI        ge
j)        jK        _+        ee
j)        jK        _.        e
jI        ge
j)        jL        _+        e
jA        ge
j)        jM        _+        e
j3        e
j)        jM        _.        g e
j)        jN        _+        ee
j)        jN        _.        dS )*    N)POINTERc_char_p
c_longlongc_intc_size_tc_void_p	string_at)ffi)llvm_version_info)_decode_string_encode_string)
namedtuple)opaque_pointers_enabledTriple)ArchSubArchVendorOSEnvObjectFormatc                      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    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/llvmlite/binding/targets.pyget_process_tripler      s     
			 s'',,,3xx                    .AAAtriplec                 R   t          j                    5 }t          j                    5 }t          j                    5 }t          j                    5 }t           j                            |                     d          ||||           t          |          }d}|                     d          D ]0}|                    |          r|t          |          d         } n1t          ||t          |          t          |          t          |          t          |                     cddd           cddd           cddd           cddd           S # 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z:
    Return a tuple of the parts of the given triple.
    utf8 -N)r
   r   r   LLVMPY_GetTriplePartsencoder   split
startswithlenr   get_object_format)r!   archvendorosenvsubarch_strs          r   get_triple_partsr2      s    
			 ;t;"(;"$c&6&8&8;<?%%fmmF&;&;&*FB	= 	= 	=4yyLL%% 	 	Dt$$ s4yyzz* dGS[[#b''#hh 1& 9 9; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   FFE-CE	%E-1F=FEE-EE-!F-E11F4E15F8FF	FF	FF #F 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()``.

        +r%   )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>F   sM       . . Aq !Q77 . . . . . .    )sorteditemsiterjoin)selfsortiteratorr=   s      @r   flattenzFeatureMap.flatten7   s}     ,0G6$**,,'''T$**,,5G5Gc**xx . . . .$,. . . . . 	.r?   N)T)__name__
__module____qualname____doc__rG    r?   r   r4   r4   1   s2         
. . . . . .r?   r4   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)r6   r%   r7   r      )r
   r   r4   r   LLVMPY_GetHostCPUFeaturesr   r(   )r   outdictr=   contentfeats        r   get_host_cpu_featuresrS   J   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_triplerV   c   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_namerY   l   s    
 
			 s%%c***3xx                 r       UnknownCOFFDXContainerELFGOFFMachOSPIRVWasmXCOFF)	r   rN                        )r   rN   rd   re   rf   rg   rh   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
    )rV   r
   r   LLVMPY_GetTripleObjectFormatr   _object_formats)r!   ress     r   r+   r+      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_datars      s*     cg55nV6L6LMMNNNr?   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
rp   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   rD   r   s     r   __str__zTargetData.__str__   s    < 	'&& 	3G44T3???s88	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AA Ac                 :    | j                             |            d S N)_capiLLVMPY_DisposeTargetDatarD   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rD   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
ValueErrorr9   r   )rD   r   positionoffsets       r   get_element_offsetzTargetData.get_element_offset   s\    
 //b(CCR<< %%+VHc"gg%>%>@ @ @ r?   c                 B    t           j                            | |          S )z>
        Get minimum ABI alignment of LLVM type *ty*.
        )r
   r   LLVMPY_ABIAlignmentOfTyper   s     r   get_abi_alignmentzTargetData.get_abi_alignment   s     w00r:::r?   c                     t           rt          d          t          j                            | |          }|dk    rt          d|          |S )zI
        Get ABI size of pointee type of LLVM pointer type *ty*.
        /Cannot get pointee type in opaque pointer mode.r   Not a pointer type: )r   RuntimeErrorr
   r   LLVMPY_ABISizeOfElementTyperD   r   sizes      r   get_pointee_abi_sizezTargetData.get_pointee_abi_size   s]     # 	(  ' ( ( (w224<<2::,22?@@@r?   c                     t           rt          d          t          j                            | |          }|dk    rt          d|          |S )zV
        Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
        r   r   r   )r   r   r
   r    LLVMPY_ABIAlignmentOfElementTyper   s      r   get_pointee_abi_alignmentz$TargetData.get_pointee_abi_alignment   s]     # 	(  ' ( ( (w77bAA2::,22?@@@r?   N)rH   rI   rJ   rK   ry   r   r   r   r   r   r   rL   r?   r   rp   rp      s         
  2 2 26 6 6
 
 
; ; ;
 
 

 
 
 
 
r?   rp   )defaultstaticpicdynamicnopic)r   
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 )Targetr$   c                 H    t                      }|                     |          S )zB
        Create a Target instance for the default triple.
        )rV   from_triple)clsr!   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).
        r#   N)r
   r   r   LLVMPY_GetTargetFromTripler'   r   r   _triple)r   r!   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 r{   )r
   r   LLVMPY_GetTargetNamer   rD   ss     r   namezTarget.name  s%    G((..a   r?   c                 ^    t           j                            |           }t          |          S r{   )r
   r   LLVMPY_GetTargetDescriptionr   r   s     r   descriptionzTarget.description  s%    G//55a   r?   c                     | j         S r{   )r   r~   s    r   r!   zTarget.triple  s
    |r?   c                 B    d                     | j        | j                  S )Nz<Target {0} ({1})>)r9   r   r   r~   s    r   ry   zTarget.__str__  s    #**49d6FGGGr?   rd   r   r   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   re   ntr   z-elfzCannot create target machine)RELOC	CODEMODELr   r.   r   r
   r   LLVMPY_CreateTargetMachiner   intTargetMachiner   )rD   cpufeaturesoptreloc	codemodelprintmcjitabinamer!   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$   rd   r   r   FFr$   )rH   rI   rJ   r   classmethodr   r   propertyr   r   r!   ry   r   rL   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 r{   )r|   LLVMPY_DisposeTargetMachiner~   s    r   r   zTargetMachine._disposeF  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)rD   pms     r   add_analysis_passesz!TargetMachine.add_analysis_passesI  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)rD   verboses     r   set_asm_verbosityzTargetMachine.set_asm_verbosityO  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rD   modules     r   emit_objectzTargetMachine.emit_objectV  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   r   r   LLVMPY_GetBufferStartLLVMPY_GetBufferSizer	   LLVMPY_DisposeMemoryBuffer)rD   r   r   r   mbbufptrbufszs          r   r   zTargetMachine._emit_to_memorye  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 r{   )rp   r
   r   LLVMPY_CreateTargetMachineDatar~   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 r{   )r
   r   r   LLVMPY_GetTargetMachineTripler   rx   s     r   r!   zTargetMachine.triple  s     	3G11$<<<s88	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AAAN)F)rH   rI   rJ   r   r   r   r   r   r   r   r   r!   rL   r?   r   r   r   D  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_HasSVMLSupportrL   r?   r   has_svmlr     s'     w$$&&!++utr?   r{   )Or.   ctypesr   r   r   r   r   r   r	   llvmlite.bindingr
   llvmlite.binding.initfinir   llvmlite.binding.commonr   r   collectionsr   llvmliter   r   r   r   r2   dictr4   rS   rV   rY   llvm_version_majorrm   r+   rs   	ObjectRefrp   	frozensetr   r   r   r   r   r   r   argtypesr&   rO   restyperU   rX   rl   rq   LLVMTargetDataRefrw   r}   LLVMTypeRefr   r   r   r   r   r   LLVMTargetRefr   r   r   LLVMTargetMachineRefr   r   r   LLVMPassManagerRefr   LLVMModuleRefr   LLVMMemoryBufferRefr   r   r   r   r   rL   r?   r   <module>r     s   				) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) !           7 7 7 7 7 7 B B B B B B B B " " " " " " - , , , , ,	H < < < 
= 
=	 	 	;S ; ; ; ;&. . . . . . . .2  2     'q)  
 
OO  O	  	  	  	 O O O> > > > > > > >B 		>>>??I       ! !	V? V? V? V? V?S] V? V? V?r? ? ? ? ?CM ? ? ?D   -4GH,=,=+>  (*2GGH4E4E*1'(*;*;WWX=N=N*1'(*;*;*=  & /6gh.?.?-@ ! *,1 ! )29'(2C2C1D % .*1'(*;*;)<  &19
 $ -/4 $ ,,4:  (*-*?  ' GH5 ( 1 -   ) *-)>),):  %'1  $+.+@+.?+0+2  ' *4  &.1.C.1o.? ! *,6 ! ) 140E030A # ,.8 # + 695J58_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?   