
    shN0                     N   S SK r S SKrS SKrS SKJr  S SKJrJr  S SK	J
r
  S r\" S5      r\" S5      r\" S5      r\" S5      r\" S	5      r\" S
5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r \" S5      r!\" S5      r"\" S5      r#\" S5      r$\" S5      r%\" S5      r&\" S 5      r'\" S!5      r(\" S"5      r)\" S#5      r*\" S$5      r+ " S% S&5      r, " S' S(5      r- " S) S*\.5      r/ " S+ S,\.5      r0S- r1\ Rd                  SS. S/:  a  \1O\Rf                  r4\/" 5       r5S0 r6S1 r7 " S2 S3\.5      r8 " S4 S5\.5      r9S6 r:S7 r; " S8 S9\.5      r<g):    N)_decode_string_is_shutting_down)get_library_namec                 f    [        U [        R                  40 5      n[        R                  " U5      $ N)typectypes	StructurePOINTER)namenewclss     h/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/llvmlite/binding/ffi.py_make_opaque_refr   
   s(    $))+R0F>>&!!    LLVMContext
LLVMModule	LLVMValueLLVMTypeLLVMExecutionEngineLLVMPassManagerBuilderLLVMPassManagerLLVMTargetDataLLVMTargetLibraryInfo
LLVMTargetLLVMTargetMachineLLVMMemoryBufferLLVMAttributeListIteratorLLVMElementIteratorLLVMAttributeSetIteratorLLVMGlobalsIteratorLLVMFunctionsIteratorLLVMBlocksIteratorLLVMArgumentsIteratorLLVMInstructionsIteratorLLVMOperandsIteratorLLVMIncomingBlocksIteratorLLVMTypesIteratorLLVMObjectCacheLLVMObjectFileLLVMSectionIteratorLLVMOrcLLJITRefLLVMOrcDylibTrackerRefLLVMPipeLineTuningOptionsLLVMModulePassManagerLLVMFunctionPassManagerLLVMPassBuilderc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
	_LLVMLock2   a"  A Lock to guarantee thread-safety for the LLVM C-API.

This class implements __enter__ and __exit__ for acquiring and releasing
the lock as a context manager.

Also, callbacks can be attached so that every time the lock is acquired
and released the corresponding callbacks will be invoked.
c                 F    [         R                  " 5       U l        / U l        g r   )	threadingRLock_lock_cblistselfs    r   __init___LLVMLock.__init__;   s     __&
r   c                 <    U R                   R                  X45        g)zRegister callbacks that are invoked immediately after the lock is
acquired (``acq_fn()``) and immediately before the lock is released
(``rel_fn()``).
N)r8   appendr:   acq_fnrel_fns      r   register_LLVMLock.registerA   s    
 	V,-r   c                 <    U R                   R                  X45        g)z)Remove the registered callbacks.
        N)r8   remover?   s      r   
unregister_LLVMLock.unregisterH   s     	V,-r   c                 p    U R                   R                  5         U R                   H  u  pU" 5         M     g r   )r7   acquirer8   r?   s      r   	__enter___LLVMLock.__enter__M   s'    

"llNFH +r   c                 p    U R                    H  u  p#U" 5         M     U R                  R                  5         g r   )r8   r7   release)r:   exc_detailsr@   rA   s       r   __exit___LLVMLock.__exit__S   s'    "llNFH +

r   )r8   r7   N)__name__
__module____qualname____firstlineno____doc__r;   rB   rF   rJ   rO   __static_attributes__ r   r   r2   r2   2   s     ..
r   r2   c                   &    \ rS rSrS rS rS rSrg)_suppress_cleanup_errorsZ   c                     Xl         g r   _context)r:   contexts     r   r;   !_suppress_cleanup_errors.__init__[   s    r   c                 6    U R                   R                  5       $ r   )r]   rJ   r9   s    r   rJ   "_suppress_cleanup_errors.__enter__^   s    }}&&((r   c                 \     U R                   R                  XU5      $ ! [         a     g f = fr   )r]   rO   PermissionError)r:   exc_type	exc_value	tracebacks       r   rO   !_suppress_cleanup_errors.__exit__a   s0    	==))(yII 		s    
++r\   N)rQ   rR   rS   rT   r;   rJ   rO   rV   rW   r   r   rY   rY   Z   s     )r   rY   c                   b    \ rS rSrSr/ SQrS rS r\S 5       r	S r
\S 5       r\S	 5       rS
rg)_lib_wrapperh   zoWrap libllvmlite with a lock such that only one thread may access it at
a time.

This class duck-types a CDLL.
)_lib_handle_fntabr7   c                 >    S U l         0 U l        [        5       U l        g r   )rk   rl   r2   r7   r9   s    r   r;   _lib_wrapper.__init__p   s    [
r   c                 d    [        [        [        R                  S5      S   [	        5       5      5       n[
        R                  " [        U5      5      U l        U R                  R                  5       nS S S 5        g ! , (       d  f       g = f! [        [        4 a  n[        S5      UeS nAff = f)N.r   z&Could not find/load shared object file)rY   _importlib_resources_pathrQ   
rpartitionr   r	   CDLLstrrk   LLVMPY_GetVersionInfoOSErrorAttributeError)r:   lib_path_es       r   	_load_lib_lib_wrapper._load_libu   s    	K)*C'',Q/$&+( ),4#);;s8}#= $$::<) ) ) ( 	K
 BCJ	Ks4   3B ?A=4B =
BB B B/B**B/c                 \    U R                   (       d  U R                  5         U R                   $ r   )rk   r{   r9   s    r   _lib_lib_wrapper._lib   s#     NNr   c                      U R                   U   $ ! [         a?    [        U R                  U5      n[	        U R
                  U5      nX0R                   U'   Us $ f = fr   )rl   KeyErrorgetattrr~   _lib_fn_wrapperr7   )r:   r   cfnwrappeds       r   __getattr___lib_wrapper.__getattr__   sV    	;;t$$ 	$))T*C%djj#6G 'KKN	s    AAAc                 .    U R                   R                  $ )zWThe name of the library passed in the CDLL constructor.

For duck-typing a ctypes.CDLL
)r~   _namer9   s    r   r   _lib_wrapper._name   s     yyr   c                 .    U R                   R                  $ )zMThe system handle used to access the library.

For duck-typing a ctypes.CDLL
)r~   _handler9   s    r   r   _lib_wrapper._handle   s     yy   r   )rl   rk   r7   N)rQ   rR   rS   rT   rU   	__slots__r;   r{   propertyr~   r   r   r   rV   rW   r   r   ri   ri   h   sZ    
 3I!
K       ! !r   ri   c                       \ rS rSrSrSS/rS r\S 5       r\R                  S 5       r\S 5       r
\
R                  S	 5       r
S
 rSrg)r      zWraps and duck-types a ctypes.CFUNCTYPE to provide
automatic locking when the wrapped function is called.

TODO: we can add methods to mark the function as threadsafe
      and remove the locking-step on call when marked.
r7   _cfnc                     Xl         X l        g r   r7   r   )r:   lockr   s      r   r;   _lib_fn_wrapper.__init__   s    
	r   c                 .    U R                   R                  $ r   r   argtypesr9   s    r   r   _lib_fn_wrapper.argtypes   s    yy!!!r   c                 $    XR                   l        g r   r   )r:   r   s     r   r   r      s    %		r   c                 .    U R                   R                  $ r   r   restyper9   s    r   r   _lib_fn_wrapper.restype   s    yy   r   c                 $    XR                   l        g r   r   )r:   r   s     r   r   r      s    #		r   c                 t    U R                      U R                  " U0 UD6sS S S 5        $ ! , (       d  f       g = fr   r   )r:   argskwargss      r   __call___lib_fn_wrapper.__call__   s$    ZZ99d-f- ZZs   )
7)r   r7   N)rQ   rR   rS   rT   rU   r   r;   r   r   setterr   r   rV   rW   r   r   r   r      su     &!I " " __& & ! ! ^^$ $.r   r   c                 \    [         R                  " [         R                  " U 5      U-  5      $ )a  Replacement implementation of `import.resources.path` to avoid
deprecation warning following code at importlib_resources/_legacy.py
as suggested by https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy

Notes on differences from importlib.resources implementation:

The `_common.normalize_path(resource)` call is skipped because it is an
internal API and it is unnecessary for the use here. What it does is
ensuring `resource` is a str and that it does not contain path separators.
)_impresas_filefiles)packageresources     r   _importlib_resources_path_replr      s!     ??7==1H<==r      )   
   c                 B    [         R                  R                  X5        g)zvRegister callback functions for lock acquire and release.
*acq_fn* and *rel_fn* are callables that take no arguments.
N)libr7   rB   r@   rA   s     r   register_lock_callbackr      s     IIv&r   c                 B    [         R                  R                  X5        g)zRemove the registered callback functions for lock acquire and release.
The arguments are the same as used in `register_lock_callback()`.
N)r   r7   rF   r   s     r   unregister_lock_callbackr      s     II(r   c                       \ rS rSrSrSrg)_DeadPointer   z2
Dummy class to make error messages more helpful.
rW   N)rQ   rR   rS   rT   rU   rV   rW   r   r   r   r      s    r   r   c                   ~    \ rS rSrSr\" 5       r\S 5       rSS jr	S r
S rS r\4S	 jrS
 rS r\r\S 5       rSrg)OutputString   z4
Object for managing the char* output of LLVM APIs.
c                 T    U " [         R                  " U[         R                  5      S9$ )zConstructing from a pointer returned from the C-API.
The pointer must be allocated with LLVMPY_CreateString.

Note
----
Because ctypes auto-converts *restype* of *c_char_p* into a python
string, we must use *c_void_p* to obtain the raw pointer.
)init)r	   castc_char_p)clsptrs     r   from_returnOutputString.from_return   s     C9::r   Nc                     Ub  UO[         R                  " S 5      U l        [         R                  " U R                  5      U l        Xl        g r   )r	   r   _ptrbyref_as_parameter__owned)r:   ownedr   s      r   r;   OutputString.__init__  s3     ,D&//$2G	$ll4995r   c                     U R                   b:  U R                  (       a  [        R                  U R                   5        S U l         U ?g g r   )r   r   r   LLVMPY_DisposeStringr   r9   s    r   closeOutputString.close	  s7    99 {{((3DI#	 !r   c                     U $ r   rW   r9   s    r   rJ   OutputString.__enter__  s    r   c                 $    U R                  5         g r   r   r:   rd   exc_valexc_tbs       r   rO   OutputString.__exit__      

r   c                 Z    U" 5       (       d  U R                   b  U R                  5         g g g r   r   r:   r   s     r   __del__OutputString.__del__  s*     !""zz%

 & #r   c                 j    U R                   c  gU R                   R                  nUc   e[        U5      $ )Nz<dead OutputString>)r   valuer   )r:   ss     r   __str__OutputString.__str__  s1    99(IIOO}}a  r   c                 ,    [        U R                  5      $ r   boolr   r9   s    r   __bool__OutputString.__bool__$      DIIr   c                 .    U R                   R                  $ )z:Get the raw bytes of content of the char pointer.
        )r   r   r9   s    r   bytesOutputString.bytes)  s     yyr   )r   r   r   )TN)rQ   rR   rS   rT   rU   r   r   classmethodr   r;   r   rJ   rO   r   r   r   r   __nonzero__r   r   rV   rW   r   r   r   r      sc     "^N	; 	;
$ ): ! K r   r   c                 F    U b  [        [        R                  U 5      5      $ g)z,To wrap string return-value from C-API.
    N)rt   r   r   r   s    r   
ret_stringr   0  s$     <++C011 r   c                 H    U b  [         R                  U 5      R                  $ g)z+To wrap bytes return-value from C-API.
    N)r   r   r   r   s    r   	ret_bytesr   7  s%     '',222 r   c                       \ rS rSrSrSr\" 5       rSrS r	S r
S rS r\S 5       rS	 rS
 r\4S jrS rS r\rS rSrg)	ObjectRefi>  zB
A wrapper around a ctypes pointer to a LLVM object ("resource").
Fc                 N    Uc  [        S5      eXl        Xl        [        U l        g )NzNULL pointer)
ValueErrorr   r   r   _capi)r:   r   s     r   r;   ObjectRef.__init__G  s$    ;^,,	!
r   c                      U R                   (       d!  U R                  (       d  U R                  5         U R                  5         g! U R                  5         f = f)z9
Close this object and do any required clean-up actions.
N)_closedr   _disposedetachr9   s    r   r   ObjectRef.closeN  s0    	<<KKMDKKMs   2A Ac                 H    U R                   (       d  U ?SU l         SU l        gg)z>
Detach the underlying LLVM resource without disposing of it.
TN)r   r   r   r9   s    r   r   ObjectRef.detachX  s$     ||#DLDI r   c                     g)z
Dispose of the underlying LLVM resource.  Should be overriden
by subclasses.  Automatically called by close(), __del__() and
__exit__() (unless the resource has been detached).
NrW   r9   s    r   r   ObjectRef._disposea  s    r   c                     U R                   $ )zN
Whether this object has been closed.  A closed object can't
be used anymore.
)r   r9   s    r   closedObjectRef.closedh  s     ||r   c                     [        U S5      (       d   eU R                  (       a  [        U R                  < S35      eU $ )Nr   z instance already closed)hasattrr   RuntimeError	__class__r9   s    r   rJ   ObjectRef.__enter__p  s3    tW%%%%<<t~~OPPr   c                 $    U R                  5         g r   r   r   s       r   rO   ObjectRef.__exit__v  r   r   c                 Z    U" 5       (       d  U R                   b  U R                  5         g g g r   r   r   s     r   r   ObjectRef.__del__y  s(     ""zz%

 & #r   c                 ,    [        U R                  5      $ r   r   r9   s    r   r   ObjectRef.__bool__~  r   r   c                     [        US5      (       d  g[        R                  " U R                  S   5      [        R                  " UR                  S   5      :H  $ )Nr   Fr   )r  r	   	addressofr   )r:   others     r   __eq__ObjectRef.__eq__  sH    uf%%		!-UZZ]+, 	,r   c                     [        [        R                  " U R                  [        R                  5      R
                  5      $ r   )hashr	   r   r   c_void_pr   r9   s    r   __hash__ObjectRef.__hash__  s&    FKK		6??;AABBr   )r   r   r   r   N)rQ   rR   rS   rT   rU   r   r   r   r   r;   r   r   r   r   r  rJ   rO   r   r   r   r  r   r  rV   rW   r   r   r   r   >  sm     G!^NF   ): 
, KCr   r   )=sysr	   r5   importlib.resources	resourcesr   llvmlite.binding.commonr   r   llvmlite.utilsr   r   LLVMContextRefLLVMModuleRefLLVMValueRefLLVMTypeRefLLVMExecutionEngineRefLLVMPassManagerBuilderRefLLVMPassManagerRefLLVMTargetDataRefLLVMTargetLibraryInfoRefLLVMTargetRefLLVMTargetMachineRefLLVMMemoryBufferRefr   r   r   r    r!   r"   r#   r$   r%   r&   r'   LLVMObjectCacheRefLLVMObjectFileRefLLVMSectionIteratorRefr+   r,   LLVMPipelineTuningOptionsRefLLVMModulePassManagerRefLLVMFunctionPassManagerRefLLVMPassBuilderRefr2   rY   objectri   r   r   version_infopathrq   r   r   r   r   r   r   r   r   rW   r   r   <module>r4     s5   
   % E +"
 "-0 .,z*)*?@ ,-EF %&78 $%56 +,CD  .'(;< &'9: ,-HI &'<= +,FG &'<= ()@A %&:; ()@A +,FG '(>? -.JK $%89 %&78 $%56 )*?@ "#45)*BC /0KL +,CD -.GH %&78 % %P ;!6 ;!|.f .D> !$ 0 0! 4 ? <"),, 
 n')6 ;6 ;|23MC MCr   