
    I/Ph+                        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mZ d dlmZ ddZdd	Z G d
 de	j                  Z G d de	j                  Z G d de          Z G d de          Z G d de          Ze	j        e ee          ge	j        j        _        e	j         e	j        j        _!        e	j        ee ee          ge	j        j"        _        e	j         e	j        j"        _!        e	j         ge	j        j#        _        e	j          ee          ge	j        j$        _        e	j          ee           ee          ge	j        j%        _        e	j         ege	j        j&        _        e	j'        e	j        j&        _!        e	j          ee          ge	j        j(        _        ee	j        j(        _!        e	j          ee          ge	j        j)        _        e	j         ege	j        j*        _        e	j          ee          ge	j        j+        _        e	j         ege	j        j,        _        e	j         ege	j        j-        _        e	j'        e	j        j-        _!        e	j         ege	j        j.        _        e	j/        e	j        j.        _!        e	j         ge	j        j0        _        e	j1        e	j        j0        _!        e	j1        ge	j        j2        _        e	j1        ge	j        j3        _        e	j'        e	j        j3        _!        e	j         ge	j        j4        _        e	j5        e	j        j4        _!        e	j         ge	j        j6        _        e	j7        e	j        j6        _!        e	j5        ge	j        j8        _        e	j7        ge	j        j9        _        e	j5        ge	j        j:        _        e	j'        e	j        j:        _!        e	j7        ge	j        j;        _        e	j/        e	j        j;        _!        e	j         ge	j        j<        _        e	j         e	j        j<        _!        e	j         ge	j        j=        _        ee	j        j=        _!        e	j         ege	j        j>        _        e	j         ge	j        j?        _        ee	j        j?        _!        dS )    )c_char_pbyrefPOINTERc_boolcreate_string_bufferc_size_t	string_at)ffi)link_modules)_decode_string_encode_string)ValueRefTypeRef)get_global_contextNc                    |t                      }t          |           } t          |           }t          j                    5 }t          t          j                            |||          |          }|r6|                                 t          d
                    |                    	 ddd           n# 1 swxY w Y   |S )z-
    Create Module from a LLVM IR string
    NzLLVM IR parsing error
{0})r   r   r   r
   OutputString	ModuleReflibLLVMPY_ParseAssemblycloseRuntimeErrorformat)llvmircontextstrbuferrmsgmods        W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/llvmlite/binding/module.pyparse_assemblyr      s
    $&&F##FfF				 LvG((&&AA   	LIIKKK;BB6JJKKK	L	L L L L L L L L L L L L L L L Js   A(B77B;>B;c           	         |t                      }t          |           }t          |           }t          j                    5 }t          t          j                            ||||          |          }|r6|                                 t          d
                    |                    	 ddd           n# 1 swxY w Y   |S )z?
    Create Module from a LLVM *bitcode* (a bytes object).
    NzLLVM bitcode parsing error
{0})r   r   lenr
   r   r   r   LLVMPY_ParseBitcoder   r   r   )bitcoder   bufbufsizer   r   s         r   parse_bitcoder&      s    $&&
7

C'llG				 Bv33S'6+ +,35 5 	BIIKKK188@@B B B	BB B B B B B B B B B B B B B B Js   A)B88B<?B<c                   T    e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zed
             Zej        d             Zed             Zed             Zej        d             Zed             Zej        d             ZddZed             Zed             Zed             Zd Z xZS )r   z'
    A reference to a LLVM module.
    c                 f    t          t          |                               |           || _        d S N)superr   __init___context)self
module_ptrr   	__class__s      r   r+   zModuleRef.__init__4   s,    i''
333    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_PrintModuleToStringstr)r-   outstrs     r   __str__zModuleRef.__str__8   s     	6G..tV<<<v;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AAAc                    t          d          }t          d          }t          j                            | t          |          t          |                     |st          	 |j        dk    sJ t          ||j                  t          j        	                    |           S # t          j        	                    |           w xY w)zF
        Return the module's LLVM bitcode, as a bytes object.
        Nr   )
r   r   r
   r   LLVMPY_WriteBitcodeToStringr   MemoryErrorvaluer	   LLVMPY_DisposeString)r-   ptrsizes      r   
as_bitcodezModuleRef.as_bitcode=   s     tnn||++D%**eDkkJJJ 		.:????S$*--G((----CG((----s   $!B% %!Cc                 :    | j                             |            d S r)   )_capiLLVMPY_DisposeModuler-   s    r   _disposezModuleRef._disposeL   s    
''-----r0   c                     t           j                            | t          |                    }|st	          |          t          |dt          |                     S )z~
        Get a ValueRef pointing to the function named *name*.
        NameError is raised if the symbol isn't found.
        functionmodule)r
   r   LLVMPY_GetNamedFunctionr   	NameErrorr   dictr-   nameps      r   get_functionzModuleRef.get_functionO   sT    
 G++D.2F2FGG 	"D//!:t4'8'8'8999r0   c                     t           j                            | t          |                    }|st	          |          t          |dt          |                     S )z
        Get a ValueRef pointing to the global variable named *name*.
        NameError is raised if the symbol isn't found.
        globalrF   )r
   r   LLVMPY_GetNamedGlobalVariabler   rI   r   rJ   rK   s      r   get_global_variablezModuleRef.get_global_variableY   sT    
 G11$t8L8LMM 	"D//!8T%6%6%6777r0   c                     t           j                            | t          |                    }|st	          |          t          |          S )z
        Get a TypeRef pointing to a structure type named *name*.
        NameError is raised if the struct type isn't found.
        )r
   r   LLVMPY_GetNamedStructTyper   rI   r   rK   s      r   get_struct_typezModuleRef.get_struct_typec   sC    
 G--dN44H4HII 	"D//!qzzr0   c                     t          j                    5 }t           j                            | |          rt	          t          |                    	 ddd           dS # 1 swxY w Y   dS )zW
        Verify the module IR's correctness.  RuntimeError is raised on error.
        N)r
   r   r   LLVMPY_VerifyModuler   r3   r-   outmsgs     r   verifyzModuleRef.verifym   s      	06w**488 0"3v;;///0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   =AA#&A#c                 Z    t          t          j                            |                     S )z*
        The module's identifier.
        )r   r
   r   LLVMPY_GetModuleNamerB   s    r   rL   zModuleRef.nameu   s"    
 cg::4@@AAAr0   c                 `    t           j                            | t          |                     d S r)   )r
   r   LLVMPY_SetModuleNamer   )r-   r:   s     r   rL   zModuleRef.name|   s(    $$T>%+@+@AAAAAr0   c                 Z    t          t          j                            |                     S )z8
        The module's original source file name
        )r   r
   r   LLVMPY_GetModuleSourceFileNamerB   s    r   source_filezModuleRef.source_file   s"    
 cgDDTJJKKKr0   c                     t          j        d          5 }t           j                            | |           t	          |          cddd           S # 1 swxY w Y   dS )zG
        This module's data layout specification, as a string.
        FownedN)r
   r   r   LLVMPY_GetDataLayoutr3   rX   s     r   data_layoutzModuleRef.data_layout   s     E*** 	fG((v666v;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   /AAAc                     t           j                            | t          |                    d                               d S Nutf8)r
   r   LLVMPY_SetDataLayoutr   encoder-   strreps     r   rf   zModuleRef.data_layout   sK    $$T%9)/v)>)>&@ &@	A 	A 	A 	A 	Ar0   c                     t          j        d          5 }t           j                            | |           t	          |          cddd           S # 1 swxY w Y   dS )zK
        This module's target "triple" specification, as a string.
        Frc   N)r
   r   r   LLVMPY_GetTargetr3   rX   s     r   triplezModuleRef.triple   s     E*** 	fG$$T6222v;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rg   c                     t           j                            | t          |                    d                               d S ri   )r
   r   LLVMPY_SetTargetr   rl   rm   s     r   rq   zModuleRef.triple   sD      !5%+]]6%:%:"< "<	= 	= 	= 	= 	=r0   Fc                 R    |r|                                 }t          | |           dS )z
        Link the *other* module into this one.  The *other* module will
        be destroyed unless *preserve* is true.
        N)cloner   )r-   otherpreserves      r   link_inzModuleRef.link_in   s/    
  	"KKMMET5!!!!!r0   c                 |    t           j                            |           }t          |t	          |                     S )a)  
        Return an iterator over this module's global variables.
        The iterator will yield a ValueRef for each global variable.

        Note that global variables don't include functions
        (a function is a "global value" but not a "global variable" in
         LLVM parlance)
        rF   )r
   r   LLVMPY_ModuleGlobalsIter_GlobalsIteratorrJ   r-   its     r   global_variableszModuleRef.global_variables   s4     W--d33D$5$5$5666r0   c                 |    t           j                            |           }t          |t	          |                     S )z
        Return an iterator over this module's functions.
        The iterator will yield a ValueRef for each function.
        rF   )r
   r   LLVMPY_ModuleFunctionsIter_FunctionsIteratorrJ   r|   s     r   	functionszModuleRef.functions   s4     W//55!"d$&7&7&7888r0   c                 |    t           j                            |           }t          |t	          |                     S )z|
        Return an iterator over the struct types defined in
        the module. The iterator will yield a TypeRef.
        rF   )r
   r   LLVMPY_ModuleTypesIter_TypesIteratorrJ   r|   s     r   struct_typeszModuleRef.struct_types   s4     W++D11b$d"3"3"3444r0   c                 f    t          t          j                            |           | j                  S r)   )r   r
   r   LLVMPY_CloneModuler,   rB   s    r   ru   zModuleRef.clone   s$    33D994=IIIr0   )F)__name__
__module____qualname____doc__r+   r5   r>   rC   rN   rR   rU   rZ   propertyrL   setterra   rf   rq   rx   r~   r   r   ru   __classcell__)r/   s   @r   r   r   /   s                   
. . .. . .: : :8 8 8  0 0 0 B B XB 
[B B [B L L XL   X A A A
   X ]= = ]=
" " " " 
7 
7 X
7 9 9 X9 5 5 X5J J J J J J Jr0   r   c                   (    e Zd ZdZd Zd ZeZd ZdS )	_IteratorNc                 f    t           j                            | |           || _        | j        J d S r)   )r
   	ObjectRefr+   _parentskind)r-   r<   parentss      r   r+   z_Iterator.__init__   s5    tS)))y$$$$$r0   c                 r    |                                  }|rt          || j        | j                  S t          r)   )_nextr   r   r   StopIterationr-   vps     r   __next__z_Iterator.__next__   s3    ZZ\\ 	 B	4=999r0   c                     | S r)    rB   s    r   __iter__z_Iterator.__iter__   s    r0   )r   r   r   r   r+   r   nextr   r   r0   r   r   r      sM        D% % %
      D    r0   r   c                       e Zd ZdZd Zd ZdS )r{   rP   c                 :    | j                             |            d S r)   )r@   LLVMPY_DisposeGlobalsIterrB   s    r   rC   z_GlobalsIterator._dispose   s    
,,T22222r0   c                 @    t           j                            |           S r)   )r
   r   LLVMPY_GlobalsIterNextrB   s    r   r   z_GlobalsIterator._next   s    w--d333r0   Nr   r   r   r   rC   r   r   r0   r   r{   r{      s7        D3 3 34 4 4 4 4r0   r{   c                       e Zd ZdZd Zd ZdS )r   rE   c                 :    | j                             |            d S r)   )r@   LLVMPY_DisposeFunctionsIterrB   s    r   rC   z_FunctionsIterator._dispose   s    
..t44444r0   c                 @    t           j                            |           S r)   )r
   r   LLVMPY_FunctionsIterNextrB   s    r   r   z_FunctionsIterator._next   s    w//555r0   Nr   r   r0   r   r   r      s7        D5 5 56 6 6 6 6r0   r   c                   (    e Zd ZdZd Zd Zd ZeZdS )r   typec                 :    | j                             |            d S r)   )r@   LLVMPY_DisposeTypesIterrB   s    r   rC   z_TypesIterator._dispose  s    
**400000r0   c                 Z    |                                  }|rt          |          S t          r)   )r   r   r   r   s     r   r   z_TypesIterator.__next__  s)    ZZ\\ 	 2;;r0   c                 @    t           j                            |           S r)   )r
   r   LLVMPY_TypesIterNextrB   s    r   r   z_TypesIterator._next  s    w++D111r0   N)r   r   r   r   rC   r   r   r   r   r0   r   r   r      sG        D1 1 1     2 2 2 DDDr0   r   r)   )@ctypesr   r   r   r   r   r   r	   llvmlite.bindingr
   llvmlite.binding.linkerr   llvmlite.binding.commonr   r   llvmlite.binding.valuer   r   llvmlite.binding.contextr   r   r&   r   r   r   r{   r   r   LLVMContextRefr   r   argtypesLLVMModuleRefrestyper"   rA   r2   r8   rH   LLVMValueRefrW   re   rk   rp   rs   rQ   rT   LLVMTypeRefrz   LLVMGlobalsIteratorr   r   r   LLVMFunctionsIteratorr   LLVMTypesIteratorr   r   r   r   r   r\   r^   r`   r   r0   r   <module>r      s@  ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) !           0 0 0 0 0 0 B B B B B B B B 4 4 4 4 4 4 4 4 7 7 7 7 7 7   $   $aJ aJ aJ aJ aJ aJ aJ aJH       ,4 4 4 4 4y 4 4 46 6 6 6 6 6 6 6    Y   . *-);)1)0):):)<  % (+'8  $(+(:(0((/(9(9(;  $ '*&7  #),):(;  %/2/@/6wx/@/@/B " +030A070A0A070A0A0C # , -0,=,4,6  (*-*:  '(+(9(/(9(9(;  $&,  #),):GGH<M<M(N  %),):H(E  %%(%68I8I$J  !%(%6$A  !252CX1N % .030@ % -.1.?-J ! *,/O ! )-0->,?   )+.+B   (.1.E-F ! *+.+B*C  '),)9  &/2/@.A " +-0-F " *+.+<*=  '),)>  &030I/J # ,,/,A+B  (-0-F,G   )+.+;   (),)>(?  %'*  $'*'8&9  #%(%6  "),):(;  %'/  $),):H(E  %363D2E & /19 & . . .r0   