
    sh+                     j   S SK JrJrJrJrJrJrJr  S SKJ	r	  S SK
Jr  S SKJrJr  S SKJrJr  S SKJr  SS jrSS	 jr " S
 S\	R,                  5      r " S S\	R,                  5      r " S S\5      r " S S\5      r " S S\5      r\	R8                  \\" \5      /\	R:                  R<                  l        \	R@                  \	R:                  R<                  l!        \	R8                  \\\" \5      /\	R:                  RD                  l        \	R@                  \	R:                  RD                  l!        \	R@                  /\	R:                  RF                  l        \	R@                  \" \5      /\	R:                  RH                  l        \	R@                  \" \5      \" \5      /\	R:                  RJ                  l        \	R@                  \/\	R:                  RL                  l        \	RN                  \	R:                  RL                  l!        \	R@                  \" \5      /\	R:                  RP                  l        \\	R:                  RP                  l!        \	R@                  \" \5      /\	R:                  RR                  l        \	R@                  \/\	R:                  RT                  l        \	R@                  \" \5      /\	R:                  RV                  l        \	R@                  \/\	R:                  RX                  l        \	R@                  \/\	R:                  RZ                  l        \	RN                  \	R:                  RZ                  l!        \	R@                  \/\	R:                  R\                  l        \	R^                  \	R:                  R\                  l!        \	R@                  /\	R:                  R`                  l        \	Rb                  \	R:                  R`                  l!        \	Rb                  /\	R:                  Rd                  l        \	Rb                  /\	R:                  Rf                  l        \	RN                  \	R:                  Rf                  l!        \	R@                  /\	R:                  Rh                  l        \	Rj                  \	R:                  Rh                  l!        \	R@                  /\	R:                  Rl                  l        \	Rn                  \	R:                  Rl                  l!        \	Rj                  /\	R:                  Rp                  l        \	Rn                  /\	R:                  Rr                  l        \	Rj                  /\	R:                  Rt                  l        \	RN                  \	R:                  Rt                  l!        \	Rn                  /\	R:                  Rv                  l        \	R^                  \	R:                  Rv                  l!        \	R@                  /\	R:                  Rx                  l        \	R@                  \	R:                  Rx                  l!        \	R@                  /\	R:                  Rz                  l        \\	R:                  Rz                  l!        \	R@                  \/\	R:                  R|                  l        \	R@                  /\	R:                  R~                  l        \\	R:                  R~                  l!        g)    )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                 d   Uc
  [        5       n[        U 5      n [        U 5      n[        R                  " 5        n[        [        R                  R                  XU5      U5      nU(       a*  UR                  5         [        SR                  U5      5      e SSS5        U$ ! , (       d  f       W$ = f)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        k/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/llvmlite/binding/module.pyparse_assemblyr      s     $&F#FfF				vGG((&A IIK;BB6JKK 	 
 J 
	 J   AB  
B/c           	      d   Uc
  [        5       n[        U 5      n[        U 5      n[        R                  " 5        n[        [        R                  R                  XX45      U5      nU(       a*  UR                  5         [        SR                  U5      5      e SSS5        U$ ! , (       d  f       W$ = f)z7
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'lG				v33'+,35IIK188@B B  
 J 
	 Jr    c                   B  ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 r\S 5       r\R                  S 5       r\S 5       r\S 5       r\R                  S 5       r\S 5       r\R                  S 5       rSS jr\S 5       r\S 5       r\S 5       rS rSrU =r$ )r   /   z
A reference to a LLVM module.
c                 8   > [         [        U ]  U5        X l        g N)superr   __init___context)self
module_ptrr   	__class__s      r   r-   ModuleRef.__init__4   s    i'
3    c                     [         R                  " 5        n[         R                  R                  X5        [	        U5      sS S S 5        $ ! , (       d  f       g = fr+   )r
   r   r   LLVMPY_PrintModuleToStringstr)r/   outstrs     r   __str__ModuleRef.__str__8   s5    6GG..t<v;  s   *A


Ac                    [        S5      n[        S5      n[        R                  R	                  U [        U5      [        U5      5        U(       d  [        e UR                  S:  d   e[        XR                  5      [        R                  R                  U5        $ ! [        R                  R                  U5        f = f)z6
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_bitcodeModuleRef.as_bitcode=   s     tn|++D%*eDkJ	.::?"?S**-GG((-CGG((-s   &B !B?c                 :    U R                   R                  U 5        g r+   )_capiLLVMPY_DisposeModuler/   s    r   _disposeModuleRef._disposeL   s    

''-r3   c                     [         R                  R                  U [        U5      5      nU(       d  [	        U5      e[        US[        U S95      $ )zf
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_functionModuleRef.get_functionO   s@    
 GG++D.2FGD/!:t4'899r3   c                     [         R                  R                  U [        U5      5      nU(       d  [	        U5      e[        US[        U S95      $ )zm
Get a ValueRef pointing to the global variable named *name*.
NameError is raised if the symbol isn't found.
globalrL   )r
   r   LLVMPY_GetNamedGlobalVariabler   rO   r   rP   rQ   s      r   get_global_variableModuleRef.get_global_variableY   s@    
 GG11$t8LMD/!8T%677r3   c                     [         R                  R                  U [        U5      5      nU(       d  [	        U5      e[        U5      $ )zn
Get a TypeRef pointing to a structure type named *name*.
NameError is raised if the struct type isn't found.
)r
   r   LLVMPY_GetNamedStructTyper   rO   r   rQ   s      r   get_struct_typeModuleRef.get_struct_typec   s6    
 GG--dN44HID/!qzr3   c                     [         R                  " 5        n[         R                  R                  X5      (       a  [	        [        U5      5      e SSS5        g! , (       d  f       g= f)zG
Verify the module IR's correctness.  RuntimeError is raised on error.
N)r
   r   r   LLVMPY_VerifyModuler   r6   r/   outmsgs     r   verifyModuleRef.verifym   sG     6ww**488"3v;// 9  s   9A
A'c                 R    [        [        R                  R                  U 5      5      $ )z
The module's identifier.
)r   r
   r   LLVMPY_GetModuleNamerG   s    r   rR   ModuleRef.nameu   s    
 cgg::4@AAr3   c                 V    [         R                  R                  U [        U5      5        g r+   )r
   r   LLVMPY_SetModuleNamer   )r/   r>   s     r   rR   rg   |   s    $$T>%+@Ar3   c                 R    [        [        R                  R                  U 5      5      $ )z(
The module's original source file name
)r   r
   r   LLVMPY_GetModuleSourceFileNamerG   s    r   source_fileModuleRef.source_file   s    
 cggDDTJKKr3   c                     [         R                  " SS9 n[         R                  R                  X5        [	        U5      sSSS5        $ ! , (       d  f       g= f)z7
This module's data layout specification, as a string.
FownedN)r
   r   r   LLVMPY_GetDataLayoutr6   ra   s     r   data_layoutModuleRef.data_layout   s9     E*fGG((6v; +**   *A		
Ac                 t    [         R                  R                  U [        UR	                  S5      5      5        g Nutf8)r
   r   LLVMPY_SetDataLayoutr   encoder/   strreps     r   rr   rs      s,    $$T%9)/v)>&@	Ar3   c                     [         R                  " SS9 n[         R                  R                  X5        [	        U5      sSSS5        $ ! , (       d  f       g= f)z;
This module's target "triple" specification, as a string.
Fro   N)r
   r   r   LLVMPY_GetTargetr6   ra   s     r   tripleModuleRef.triple   s9     E*fGG$$T2v; +**rt   c                 t    [         R                  R                  U [        UR	                  S5      5      5        g rv   )r
   r   LLVMPY_SetTargetr   ry   rz   s     r   r~   r      s*      !5%+]]6%:"<	=r3   c                 H    U(       a  UR                  5       n[        X5        g)zi
Link the *other* module into this one.  The *other* module will
be destroyed unless *preserve* is true.
N)cloner   )r/   otherpreserves      r   link_inModuleRef.link_in   s    
 KKMET!r3   c                 f    [         R                  R                  U 5      n[        U[	        U S95      $ )z
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)
rL   )r
   r   LLVMPY_ModuleGlobalsIter_GlobalsIteratorrP   r/   its     r   global_variablesModuleRef.global_variables   s*     WW--d3D$566r3   c                 f    [         R                  R                  U 5      n[        U[	        U S95      $ )zh
Return an iterator over this module's functions.
The iterator will yield a ValueRef for each function.
rL   )r
   r   LLVMPY_ModuleFunctionsIter_FunctionsIteratorrP   r   s     r   	functionsModuleRef.functions   s*     WW//5!"d$&788r3   c                 f    [         R                  R                  U 5      n[        U[	        U S95      $ )zd
Return an iterator over the struct types defined in
the module. The iterator will yield a TypeRef.
rL   )r
   r   LLVMPY_ModuleTypesIter_TypesIteratorrP   r   s     r   struct_typesModuleRef.struct_types   s*     WW++D1b$d"344r3   c                 h    [        [        R                  R                  U 5      U R                  5      $ r+   )r   r
   r   LLVMPY_CloneModuler.   rG   s    r   r   ModuleRef.clone   s"    33D94==IIr3   )r.   )F)__name__
__module____qualname____firstlineno____doc__r-   r8   rB   rH   rT   rY   r]   rc   propertyrR   setterrl   rr   r~   r   r   r   r   r   __static_attributes____classcell__)r1   s   @r   r   r   /   s    
..:80 B B 
[[B B L L   A A
   ]]= =
" 
7 
7 9 9 5 5J Jr3   r   c                   .    \ rS rSrSrS rS r\rS rSr	g)	_Iterator   Nc                 l    [         R                  R                  X5        X l        U R                  c   eg r+   )r
   	ObjectRefr-   _parentskind)r/   r@   parentss      r   r-   _Iterator.__init__   s)    t)yy$$$r3   c                 |    U R                  5       nU(       a   [        XR                  U R                  5      $ [        er+   )_nextr   r   r   StopIterationr/   vps     r   __next___Iterator.__next__   s+    ZZ\B		4==99r3   c                     U $ r+    rG   s    r   __iter___Iterator.__iter__   s    r3   )r   )
r   r   r   r   r   r-   r   nextr   r   r   r3   r   r   r      s    D%
  Dr3   r   c                   $    \ rS rSrSrS rS rSrg)r      rW   c                 :    U R                   R                  U 5        g r+   )rE   LLVMPY_DisposeGlobalsIterrG   s    r   rH   _GlobalsIterator._dispose   s    

,,T2r3   c                 @    [         R                  R                  U 5      $ r+   )r
   r   LLVMPY_GlobalsIterNextrG   s    r   r   _GlobalsIterator._next   s    ww--d33r3   r   Nr   r   r   r   r   rH   r   r   r   r3   r   r   r      s    D34r3   r   c                   $    \ rS rSrSrS rS rSrg)r      rK   c                 :    U R                   R                  U 5        g r+   )rE   LLVMPY_DisposeFunctionsIterrG   s    r   rH   _FunctionsIterator._dispose   s    

..t4r3   c                 @    [         R                  R                  U 5      $ r+   )r
   r   LLVMPY_FunctionsIterNextrG   s    r   r   _FunctionsIterator._next   s    ww//55r3   r   Nr   r   r3   r   r   r      s    D56r3   r   c                   .    \ rS rSrSrS rS rS r\rSr	g)r      typec                 :    U R                   R                  U 5        g r+   )rE   LLVMPY_DisposeTypesIterrG   s    r   rH   _TypesIterator._dispose  s    

**40r3   c                 R    U R                  5       nU(       a  [        U5      $ [        er+   )r   r   r   r   s     r   r   _TypesIterator.__next__  s     ZZ\2;r3   c                 @    [         R                  R                  U 5      $ r+   )r
   r   LLVMPY_TypesIterNextrG   s    r   r   _TypesIterator._next  s    ww++D11r3   r   N)
r   r   r   r   r   rH   r   r   r   r   r   r3   r   r   r      s    D1 2 Dr3   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#   rF   r5   r<   rN   LLVMValueRefr`   rq   rx   r}   r   rX   r\   LLVMTypeRefr   LLVMGlobalsIteratorr   r   r   LLVMFunctionsIteratorr   LLVMTypesIteratorr   r   r   r   r   rf   ri   rk   r   r3   r   <module>r      s  ) ) ) ! 0 B 4 7$$aJ aJH ,4y 46 6Y . *-););)1)0):)<   % (+'8'8   $(+(:(:(0((/(9(;   $ '*&7&7   #),):):(;   %/2/@/@/6x/@/B " " +030A0A070A070A0C # # , -0,=,=,4,6   (*-*:*:   '(+(9(9(/(9(;   $&,   #),):):GH<M(N   %),):):H(E   %%(%6%68I$J   !%(%6%6$A   !252C2CX1N % % .030@0@ % % -.1.?.?-J ! ! *,/OO ! ! )-0->->,?     )+.+B+B     (.1.E.E-F ! ! *+.+B+B*C   '),)9)9   &/2/@/@.A " " +-0-F-F " " *+.+<+<*=   '),)>)>   &030I0I/J # # ,,/,A,A+B   (-0-F-F,G     )+.+;+;     (),)>)>(?   %'*   $'*'8'8&9   #%(%6%6   "),):):(;   %'/   $),):):H(E   %363D3D2E & & /19 & & .r3   