
    6|hC              
          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
jB                        Z" e#g d"      Z$ e#g d#      Z% G d$ d%e
jB                        Z& G d& d'e
jB                        Z'd( Z( ee      ge
jR                  jT                  _+        e ee       ee       ee       ee      ge
jR                  jX                  _+         ee      ge
jR                  jZ                  _+        ee
jR                  jZ                  _.         ee      ge
jR                  j^                  _+         ee      ge
jR                  j`                  _+        ege
jR                  jb                  _+        ee
jR                  jb                  _.        ege
jR                  jd                  _+        e
jf                  e
jR                  jd                  _.        e
jf                   ee      ge
jR                  jh                  _+        e
jf                  ge
jR                  jj                  _+        e
jf                  e
jl                  ge
jR                  jn                  _+        ee
jR                  jn                  _.        e
jf                  e
jl                  ege
jR                  jp                  _+        ee
jR                  jp                  _.        e
jf                  e
jl                  ge
jR                  jr                  _+        ee
jR                  jr                  _.        e
jf                  e
jl                  ge
jR                  jt                  _+        ee
jR                  jt                  _.        e
jf                  e
jl                  ge
jR                  jv                  _+        ee
jR                  jv                  _.        e ee      ge
jR                  jx                  _+        e
jz                  e
jR                  jx                  _.        e
jz                  ge
jR                  j|                  _+        ee
jR                  j|                  _.        e
jz                  ge
jR                  j~                  _+        ee
jR                  j~                  _.        e
jz                  eeeeeeeeeg
e
jR                  j                  _+        e
j                  e
jR                  j                  _.        e
j                  ge
jR                  j                  _+        e
j                   ee      ge
jR                  j                  _+        e
j                  ege
jR                  j                  _+        e
j                  e
j                  ge
jR                  j                  _+        e
j                  e
j                  e ee      ge
jR                  j                  _+        e
j                  e
jR                  j                  _.        e
j                  ge
jR                  j                  _+        ee
jR                  j                  _.        e
j                  ge
jR                  j                  _+        ee
jR                  j                  _.        e
j                  ge
jR                  j                  _+        e
j                  ge
jR                  j                  _+        e
jf                  e
jR                  j                  _.        g e
jR                  j                  _+        ee
jR                  j                  _.        y)*    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                  j                  |        t	        |       cddd       S # 1 sw Y   yxY w)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    W/var/www/html/test/engine/venv/lib/python3.12/site-packages/llvmlite/binding/targets.pyget_process_tripler      s@     
			 s'',3x     *A		Atriplec                    t        j                         5 }t        j                         5 }t        j                         5 }t        j                         5 }t         j                  j                  | j	                  d      ||||       t        |      }d}| j                  d      D ]#  }|j                  |      s|t        |      d } n t        ||t        |      t        |      t        |      t        |             cddd       cddd       cddd       cddd       S # 1 sw Y   nxY wddd       n# 1 sw Y   nxY wddd       n# 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)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      s5    
			 ;t;"(;"$c&6&6&8;<?%%fmmF&;&*FB	=4yLL% 	Dt$s4yz*	 dGS[#b'#h 1& 9;; ; ; ; ; ; ; ; ; ; ; ; ; ; ;se   E"ED8A%D#	:AD#	>	D8	E	E"#D,(D8/	E8E=E	E"E	E""E+c                       e Zd ZdZddZy)
FeatureMapz
    Maps feature name to a boolean indicating the availability of the feature.
    Extends ``dict`` to add `.flatten()` method.
    c                     |rt        | j                               nt        | j                               }ddddj                  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   N   K   | ]  \  }}d j                  |   |        yw)z{0}{1}N)format).0kvflag_maps      r   	<genexpr>z%FeatureMap.flatten.<locals>.<genexpr>F   s,      . Aq !Q7 .s   "%)sorteditemsiterjoin)selfsortiteratorr=   s      @r   flattenzFeatureMap.flatten7   sL     ,06$**,'T$**,5Gc*xx .$,. . 	.    N)T)__name__
__module____qualname____doc__rF    rG   r   r4   r4   1   s    
.rG   r4   c                  4   t        j                         5 } t               }t         j                  j	                  |       s|cddd       S ddd}t        |       }|r'|j                  d      D ]  }|s||d      ||dd <    |cddd       S # 1 sw Y   yxY w)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,ww005
 
 E*c(c* :(0a(9GDH%: 
 
 
s   +B
(B3BBc                      t        j                         5 } t         j                  j                  |        t	        |       cddd       S # 1 sw Y   yxY w)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3x  r    c                      t        j                         5 } t         j                  j                  |        t	        |       cddd       S # 1 sw Y   yxY w)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*3x  r       UnknownCOFFDXContainerELFGOFFMachOSPIRVWasmXCOFF)	r   rN                        )r   rN   rd   re   rf   rg   rh   c                 |    | 
t               } t        j                  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+      s5     ~#%
''
.
.~f/E
FC3rG   c                 d    t        t        j                  j                  t	        |                   S )zE
    Create a TargetData instance for the given *layout* string.
    )
TargetDatar
   r   LLVMPY_CreateTargetDatar   )layouts    r   create_target_datars      s#     cgg55nV6LMNNrG   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
rp   z{
    A TargetData provides structured access to a data layout.
    Use :func:`create_target_data` to create instances.
    c                     | j                   ryt        j                         5 }t        j                  j	                  | |       t        |      cd d d        S # 1 sw Y   y xY w)Nz<dead TargetData>)_closedr
   r   r    LLVMPY_CopyStringRepOfTargetDatar   rC   r   s     r   __str__zTargetData.__str__   sJ    <<& 	3GG44T3?s8	 	 	s   +AA c                 :    | j                   j                  |        y N)_capiLLVMPY_DisposeTargetDatarC   s    r   _disposezTargetData._dispose   s    

++D1rG   c                 B    t         j                  j                  | |      S )z1
        Get ABI size of LLVM type *ty*.
        )r
   r   LLVMPY_ABISizeOfTyperC   tys     r   get_abi_sizezTargetData.get_abi_size   s     ww++D"55rG   c                     t         j                  j                  | ||      }|dk(  r$t        dj	                  |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   )rC   r   positionoffsets       r   get_element_offsetzTargetData.get_element_offset   sN    
 //b(CR< %%+VHc"g%>@ @ rG   c                 B    t         j                  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     ww00r::rG   c                     t         rt        d      t        j                  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rC   r   sizes      r   get_pointee_abi_sizezTargetData.get_pointee_abi_size   sI     #  ' ( (ww224<2:2?@@rG   c                     t         rt        d      t        j                  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   sI     #  ' ( (ww77bA2:2?@@rG   N)rH   rI   rJ   rK   ry   r   r   r   r   r   r   rL   rG   r   rp   rp      s*    
26
;

rG   rp   )defaultstaticpicdynamicnopic)r   
jitdefaultsmallkernelmediumlargec                   t    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y	)Targetr$   c                 8    t               }| j                  |      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&&rG   c                    t        j                         5 }t         j                  j                  |j	                  d      |      }|st        t        |             | |      }||_        |cddd       S # 1 sw Y   yxY w)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   so    
  	6WW77f8M8>@F"3v;//[F#FN	 	 	s   AA55A>c                 V    t         j                  j                  |       }t        |      S r{   )r
   r   LLVMPY_GetTargetNamer   rC   ss     r   namezTarget.name  s!    GG((.a  rG   c                 V    t         j                  j                  |       }t        |      S r{   )r
   r   LLVMPY_GetTargetDescriptionr   r   s     r   descriptionzTarget.description  s!    GG//5a  rG   c                     | j                   S r{   )r   r~   s    r   r!   zTarget.triple  s    ||rG   c                 N    dj                  | j                  | j                        S )Nz<Target {0} ({1})>)r9   r   r   r~   s    r   ry   zTarget.__str__  s    #**499d6F6FGGrG   c	                    d|cxk  rdk  sJ  J |t         v sJ |t        v sJ | j                  }	t        j                  dk(  r
|dk(  r|	dz  }	t
        j                  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   )rC   cpufeaturesoptreloc	codemodelprintmcjitabinamer!   tms              r   create_target_machinezTarget.create_target_machine  s    $ C}1}}}~~I%%% 77d?yL8fFWW//0>v0F0>s0C0>x0H030>u0E0>y0I03G03C0>w0G
2  $$=>>rG   N)r$   r$   rd   r   r   FFr$   )rH   rI   rJ   r   classmethodr   r   propertyr   r   r!   ry   r   rL   rG   r   r   r      s    G
 ' '   ! ! ! !  H 68@L@B)?rG   r   c                   R    e Zd Zd Zd Zd Zd Zd Zd
dZe	d        Z
e	d        Zy	)r   c                 :    | j                   j                  |        y r{   )r|   LLVMPY_DisposeTargetMachiner~   s    r   r   zTargetMachine._disposeF  s    

..t4rG   c                 D    t         j                  j                  | |       y)zW
        Register analysis passes for this target machine with a pass manager.
        N)r
   r   LLVMPY_AddAnalysisPasses)rC   pms     r   add_analysis_passesz!TargetMachine.add_analysis_passesI  s     	((r2rG   c                 D    t         j                  j                  | |       y)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)rC   verboses     r   set_asm_verbosityzTargetMachine.set_asm_verbosityO  s    
 	33D'BrG   c                 (    | j                  |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rC   modules     r   emit_objectzTargetMachine.emit_objectV  s    
 ##Ft#<<rG   c                 :    t        | j                  |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MMrG   c                    t        j                         5 }t         j                  j                  | |t	        |      |      }|st        t        |            	 ddd       t         j                  j                        }t         j                  j                  |      }	 t        ||      t         j                  j                  |       S # 1 sw Y   sxY w# t         j                  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)rC   r   r   r   mbbufptrbufszs          r   r   zTargetMachine._emit_to_memorye  s      	0699$:=j/:@BB "3v;// 		0 ..r2,,R0	3VU+GG..r2	0 	0 GG..r2s   AC
C 
C!C7c                 R    t        t        j                  j                  |             S r{   )rp   r
   r   LLVMPY_CreateTargetMachineDatar~   s    r   target_datazTargetMachine.target_data{  s    #''@@FGGrG   c                     t        j                         5 }t         j                  j                  | |       t	        |      cd d d        S # 1 sw Y   y xY wr{   )r
   r   r   LLVMPY_GetTargetMachineTripler   rx   s     r   r!   zTargetMachine.triple  s@     	3GG11$<s8	 	 	s   +A

AN)F)rH   rI   rJ   r   r   r   r   r   r   r   r   r!   rL   rG   r   r   r   D  sL    53C=N3, H H  rG   r   c                  H    t         j                  j                         dk(  ryy)zG
    Returns True if SVML was enabled at FFI support compile time.
    r   FT)r
   r   LLVMPY_HasSVMLSupportrL   rG   r   has_svmlr     s     ww$$&!+rG   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   rG   r   <module>r     s   	) ) ) ! 7 B " -	H < 
=	;S ;&. .22 'q)  
O O	 O> >B 	>?   !	V?S]] V?r?CMM ?D -4H,=+>   (*2GH4E*1(*;WX=N*1(*;*=   & /6h.?-@ ! ! *,1 ! ! )29(2C1D % % .*1(*;)<   &19
 $ $ -/4 $ $ ,,4:   (*-*?*?   ' H5 ( ( 1 -     ) *-)>)>),):   %'1   $+.+@+@+.??+0+2   ' *4   &.1.C.C.1oo.? ! ! *,6 ! ! ) 140E0E030A # # ,.8 # # + 695J5J58__5F ( ( 13= ( ( 0/79J.K " " +-0->-> " " *),):):(;   %'/   $030A0A/B # # ,.6 # # + 			'/ " " +* .1-E-E " " *030H0H/I # # ,252J2J29(2C2E % % . e8% + + 4 -     ) 	H	5 ( ( 1 473J3J ( ( 0*-*A*A)B   &(0   %),)@)@(A   %'/   $/2/F/F.G " " + 3 & & / 251F1F & & .)+   &(-   %rG   