
    xKgy"                     V   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z ddlZddlmZ ddlmZ ddlmZ ddlmZ dZdZd	Z ej0                  ej2                  ej2                  ej2                        Z G d
 de      Z G d de      Zedk(  r ej<                          yy)z
Tests for numba.core.codegen.
    N)njit)JITCPUCodegen)global_compiler_lock)TestCasezb
    define i32 @sum(i32 %.1, i32 %.2) {
      %.3 = add i32 %.1, %.2
      ret i32 %.3
    }
    z
    define i32 @"__main__.ising_element_update$1.array(int8,_2d,_C).int64.int64"(i32 %.1, i32 %.2) {
      %.3 = add i32 %.1, %.2
      ret i32 %.3
    }
a  
    declare i32 @"__main__.ising_element_update$1.array(int8,_2d,_C).int64.int64"(i32 %.1, i32 %.2)

    define i32 @sum(i32 %.1, i32 %.2) {
      %.3 = call i32 @"__main__.ising_element_update$1.array(int8,_2d,_C).int64.int64"(i32 %.1, i32 %.2)
      ret i32 %.3
    }
c                       e Zd ZdZd Zd ZddZed        Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zej&                  d        Zy)JITCPUCodegenTestCasez'
    Test the JIT code generation.
    c                 L    t        j                          t        d      | _        y )Ntest_codegen)r   acquirer   codegenselfs    \/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_codegen.pysetUpzJITCPUCodegenTestCase.setUp;   s    $$&$^4    c                 0    | ` t        j                          y N)r   r   releaser   s    r   tearDownzJITCPUCodegenTestCase.tearDown?   s    L$$&r   Nc                 p   | j                   j                  d      }t        j                  |      }|j	                          |j                  |       |rb| j                   j                  d      }t        j                  |      }|j	                          |j                  |       |j                  |       |S )Ncompiled_modulelinking_module)r   create_libraryllparse_assemblyverifyadd_llvm_moduleadd_linking_library)r   asmlinking_asmlibrary	ll_modulelinking_librarys         r   compile_modulez$JITCPUCodegenTestCase.compile_moduleC   s    ,,--.?@%%c*		*"ll99:JKO))+6I++I6''8r   c                     t        d      }|j                  |      }|j                  d      }|sJ |       t        |      } |dd      }|dk(  sJ |       y )Nother_codegensum         )r   unserialize_libraryget_pointer_to_functionctypes_sum_ty)clsstater   r!   ptrcfuncress          r   _check_unserialize_sumz,JITCPUCodegenTestCase._check_unserialize_sumP   s]    0--e4--e4Csc"Aqkaxxr   c                    | j                  t              }|j                  d      }| j                  |t               t        |      }| j                   |dd      d       | j                  t        t              }|j                  d      }| j                  |t               t        |      }| j                   |dd      d       y )Nr'   r(   r)   r*   )	r$   asm_sumr,   assertIsInstanceintr-   assertEqualasm_sum_outerasm_sum_inner)r   r!   r0   r1   library2s        r   test_get_pointer_to_functionz2JITCPUCodegenTestCase.test_get_pointer_to_functionZ   s    %%g.--e4c3'c"q!a( &&}mD..u5c3'c"q!a(r   c                     | j                   j                         }t        j                  |       t	        d      }| j                  |j                         |       y )Nxxx)r   magic_tuplepickledumpsr   r8   )r   tupcg2s      r   test_magic_tuplez&JITCPUCodegenTestCase.test_magic_tuplel   sA    ll&&(SE"*C0r   c                 &    | j                  |       y r   )r3   )r   r/   s     r   _check_serialize_unserializez2JITCPUCodegenTestCase._check_serialize_unserializet   s    ##E*r   c                    t        j                  t        j                  |d            }dt	        | j
                  j                        z  }t        j                  t        j                  d||j                         g       y )Na  if 1:
            import base64
            import pickle
            import sys
            from numba.tests.test_codegen import %(test_class)s

            state = pickle.loads(base64.b64decode(sys.argv[1]))
            %(test_class)s._check_unserialize_sum(state)
            )
test_classz-c)base64	b64encoder@   rA   dict	__class____name__
subprocess
check_callsys
executabledecode)r   r/   argcodes       r    _check_unserialize_other_processz6JITCPUCodegenTestCase._check_unserialize_other_processw   s`    v||E267 $.."9"9:; 	s~~tT3::<HIr   c                 z    | j                  t        t              }|j                         }| j	                  |       y r   )r$   r9   r:   serialize_using_bitcoderF   r   r!   r/   s      r   "test_serialize_unserialize_bitcodez8JITCPUCodegenTestCase.test_serialize_unserialize_bitcode   s0    %%m]C//1))%0r   c                 z    | j                  t        t              }|j                         }| j	                  |       y r   )r$   r9   r:   rX   rV   rY   s      r   &test_unserialize_other_process_bitcodez<JITCPUCodegenTestCase.test_unserialize_other_process_bitcode   s0    %%m]C//1--e4r   c                     | j                  t        t              }|j                          |j	                         }| j                  |       y r   )r$   r9   r:   enable_object_cachingserialize_using_object_coderF   rY   s      r   &test_serialize_unserialize_object_codez<JITCPUCodegenTestCase.test_serialize_unserialize_object_code   s<    %%m]C%%'335))%0r   c                     | j                  t        t              }|j                          |j	                         }| j                  |       y r   )r$   r9   r:   r^   r_   rV   rY   s      r   *test_unserialize_other_process_object_codez@JITCPUCodegenTestCase.test_unserialize_other_process_object_code   s<    %%m]C%%'335--e4r   c                    | j                  t        t              }|j                          |j	                         }t        j                  d      5 }|j                         }|j                         }|j                  d       ddd       | j                  t              d       t        d      }|j                  |      }t        j                  d      5 }t        j                  d       | j                  |j                                ddd       | j                  t        |      d       | j!                  d	t#        |d   j$                               t        j                  d      5 }t        j                  d       | j                  |j                                ddd       | j                  t        |      d       | j!                  d	t#        |d   j$                               t        j                  d      5 }t        j                  d       | j'                  t(              5 }|j                  d       ddd       ddd       | j                  t        |      d       | j!                  d	t#        |d   j$                               | j!                  dt#        j*                               y# 1 sw Y   ;xY w# 1 sw Y   xY w# 1 sw Y   3xY w# 1 sw Y   xY w# 1 sw Y   xY w)
z	
        T)recordr'   Nr   r&   always   zInspection disabled)r$   r9   r:   r^   r_   warningscatch_warningsget_llvm_strget_asm_strget_function_cfgr8   lenr   r+   simplefilterassertNotEqualassertInstrmessageassertRaises	NameError	exception)r   r!   r/   wold_llvmold_asmr   raisess           r   test_cache_disabled_inspectionz4JITCPUCodegenTestCase.test_cache_disabled_inspection   s?    %%m]C%%'335 $$D1Q++-H))+G$$U+ 2 	Q#  0--e4 $$D1Q!!(+'*>*>*@A 2 	Q#+S1->?$$D1Q!!(+ 3 3 5w? 2 	Q#+S1->?$$D1Q!!(+""9-((/ . 2 	Q#+S1->?eS!1!123; 21 21 21 .- 21sH   2J<6K	/6K+K/1K#K/<K	KK #K,	(K//K8c                 ^   | j                  t        t              }|j                          |j	                          |j                          t        j                  |      }t        j                  |j                        }~| j                   |       d        | j                   |       d        y r   )
r$   r9   r:   r^   rX   r_   weakrefref_final_moduleassertIs)r   r!   uvs       r   test_library_lifetimez+JITCPUCodegenTestCase.test_library_lifetime   s}    %%m]C%%''')++-KK KK--.ac4 ac4 r   r   )rN   
__module____qualname____doc__r   r   r$   classmethodr3   r<   rD   rF   rV   rZ   r\   r`   rb   ry   unittestexpectedFailurer    r   r   r   r   6   ss    5'  )$1+J1
5
15%4R ! !r   r   c                       e Zd Zd Zy)TestWrappersc                 n   t         d        } |        |j                  d   }|j                  |   }|j                  j                  j                  dd      }dj                  |      }d}t        j                  ||z         }|j                  |      j                         }g }	|D ]8  }
|j                  |
      }|s|	j                  |j                         d          : | j                  t        |	      d       | j                  |	d   |	d          d	j                  |	d         }d
}t        j                  ||z         }t!        |      D ]V  }
|j                  |
      }|s|j                         d   }|j#                         j%                  d      }|D ]	  }d|v s  y  X | j'                  d      S )Nc                       y r   r   r   r   r   fooz4TestWrappers.test_noinline_on_main_call.<locals>.foo   s    r   r   $z\$z
.*call.*{}z.*(#[0-9]+).*r(   rf   z^attributes\s+{}z\s+=\s+{(.*)}.*$ noinlinez!Metadata did not match 'noinline')r   
signatures	overloadsfndescmangled_namereplaceformatrecompileinspect_llvm
splitlinesmatchappendgroupsr8   rl   reversedstripsplitfail)r   r   sigolnamep1p2	call_sitelinesmeta_data_idxlmatched	attr_site	meta_datalmetaxs                   r   test_noinline_on_main_callz'TestWrappers.test_noinline_on_main_call   s    
	 
	 	nnQ]]3yy%%--c59!!$'JJrBw'	  %002Aooa(G$$W^^%5a%89  	]+Q/q)=+;< ''a(89 JJrBw'	%Aooa(G#NN,Q/	!)//4A!Q    ! 99@AAr   N)rN   r   r   r   r   r   r   r   r      s    -Br   r   __main__)r   rg   rJ   ctypesr@   r   rO   rQ   r{   llvmlite.bindingbindingr   r   numbar   numba.core.codegenr   numba.core.compiler_lockr   numba.tests.supportr   r5   r:   r9   	CFUNCTYPEc_intr-   r   r   rN   mainr   r   r   <module>r      s   
     	  
     , 9 ( !  v||V\\JY!H Y!x/B8 /Bd zHMMO r   