a
    	_E8                     @   s  d dl mZ d dlZd dlZddlmZ ejd  dkrFG dd dZnd dlZejdej	ej
B d	Zejd
ej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	ej
B d	Zejdej	d	Zejdej	d	Zejdej	d	ZedZedZ edZ!ed Z"d!d" Z#d#d$ Z$d%d& Z%d'd( Z&d)d* Z'd+d, Z(d-d. Z)d/d0 Z*d1d2 Z+d3d4 Z,d5d6 Z-d7d8 Z.d9d: Z/d;d< Z0d=d> Z1dS )?    )print_functionN   )common   c                   @   s   e Zd ZejZdS )stringN)__name__
__module____qualname__str
expandtabs r   r   k/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-project/llvm/utils/UpdateTestChecks/asm.pyr      s   r   z^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?(?P<body>^##?[ \t]+[^:]+:.*?)\s*^\s*(?:[^:\n]+?:\s*\n\s*\.size|\.cfi_endproc|\.globl|\.comm|\.(?:sub)?section|#+ -- End function))flagszI^(?P<func>[0-9a-zA-Z_]+):\n\s+\.fnstart\n(?P<body>.*?)\n.Lfunc_end[0-9]+:z^_?(?P<func>[^:]+):[ \t]*\/\/[ \t]*@"?(?P=func)"?( (Function|Tail Call))?\n(?:[ \t]+.cfi_startproc\n)?(?P<body>.*?)\n.Lfunc_end[0-9]+:\nzj^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?(?P<body>.*?)\n^\s*(\.Lfunc_end[0-9]+:\n|\.section)zY^_?(?P<func>[^:]+):[ \t]*//[ \t]*@"?(?P=func)"?\n[^:]*?(?P<body>.*?)\n.Lfunc_end[0-9]+:\nz^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n[^:]*?(?:^[ \t]+\.(frame|f?mask|set).*?\n)+(?P<body>.*?)\n(?:(^[ \t]+\.set[^\n]*?\n)*^[ \t]+\.end.*?\n)(\$|\.L)func_end[0-9]+:\nz_^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?(?P<body>.*?)\n(\$|\.L)func_end[0-9]+:\nz^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n.*?\.Lfunc_begin[0-9]+:\n(?:[ \t]+.cfi_startproc\n)?(?:\.Lfunc_[gl]ep[0-9]+:\n(?:[ \t]+.*?\n)*)*(?P<body>.*?)\n(?:^[ \t]*(?:\.long[ \t]+[^\n]+|\.quad[ \t]+[^\n]+)\n)*.Lfunc_end[0-9]+:\nz^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n(?:\s*\.?L(?P=func)\$local:\n)?(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?(?P<body>^##?[ \t]+[^:]+:.*?)\s*.Lfunc_end[0-9]+:\nzo^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n(?:[ \t]+.cfi_startproc\n)?(?P<body>.*?)\s*.Lfunc_end[0-9]+:\nzT^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n(?P<body>.*?)\s*.Lfunc_end[0-9]+:\nzi^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n[ \t]+.cfi_startproc\n(?P<body>.*?)\n.Lfunc_end[0-9]+:\nz^_(?P<func>[^:]+):[ \t]*;[ \t]@"?(?P=func)"?\n([ \t]*.cfi_startproc\n[\s]*)?(?P<body>.*?)([ \t]*.cfi_endproc\n[\s]*)?^[ \t]*;[ \t]--[ \t]End[ \t]functionz^[ \t]*\.globl[ \t]*_(?P<func>[^ \t])[ \t]*@[ \t]--[ \t]Begin[ \t]function[ \t]"?(?P=func)"?(?P<directives>.*?)^_(?P=func):\n[ \t]*(?P<body>.*?)^[ \t]*@[ \t]--[ \t]End[ \t]functionz]^_(?P<func>[^:]+):[ \t]*\n([ \t]*.cfi_startproc\n[ \t]*)?(?P<body>.*?)\n[ \t]*\.cfi_endproc\nz^_(?P<func>[^:]+):[ \t]*\n^Lfunc_begin(?P<id>[0-9][1-9]*):\n(?P<body>.*?)^Lfunc_end(?P=id):\n^[ \t]*@[ \t]--[ \t]End[ \t]functionzg^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n(?P<body>.*?)\n^\s*(\.Lfunc_end[0-9]+:\n|end_function)zD^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$zQ^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = (?!.*(?:mem)).*)$z*-?\d+\(%([er])[sb]p\)(.*(?:Spill|Reload))$z\d+\(%(esp|rsp)\)z[.\w]+\(%rip\)z\.LCPI[0-9]+_[0-9]+zret[l|q]c                 C   s   t jd| } t| d} t|ddr4td| } ntd| } td| } t	d| } t|dd	rpt
d
| } td| } t|dd	rtd| } t jd| } t jd| } | S )N r   Zno_x86_scrub_mem_shuffleTz\1 {{.*#+}} \2z{{[-0-9]+}}(%\1{{[sb]}}p)\2z{{[0-9]+}}(%\1)x86_scrub_ripFz{{.*}}(%rip)z{{\.LCPI.*}}Zextra_scrubzret{{[l|q]}} )r   SCRUB_WHITESPACE_REsubr   r   getattrSCRUB_X86_SHUFFLES_NO_MEM_RESCRUB_X86_SHUFFLES_RESCRUB_X86_SPILL_RELOAD_RESCRUB_X86_SP_RESCRUB_X86_RIP_RESCRUB_X86_LCP_RESCRUB_X86_RET_RESCRUB_KILL_COMMENT_RESCRUB_TRAILING_WHITESPACE_REasmargsr   r   r   scrub_asm_x86   s    r!   c                 C   s,   t jd| } t| d} t jd| } | S Nr   r   r   r   r   r   r   r   r   r   r   r   r   scrub_asm_amdgpu   s    r$   c                 C   s:   t jd| } t| d} t jd| } t jd| } | S r"   )r   r   r   r   r   r   r   r   r   r   r   scrub_asm_arm_eabi   s
    r%   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_hexagon   s    r&   c                 C   sH   t jd| } t| d} t jd| } t jd| } t jd| } | S )Nr   r   #r   )r   r   r   r   r   ZSCRUB_LOOP_COMMENT_REr   ZSCRUB_TAILING_COMMENT_TOKEN_REr   r   r   r   scrub_asm_powerpc   s    r(   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_mips   s    r)   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_msp430   s    r*   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_riscv  s    r+   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_lanai  s    r,   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_sparc  s    r-   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_systemz$  s    r.   c                 C   s,   t jd| } t| d} t jd| } | S r"   r#   r   r   r   r   scrub_asm_wasm32.  s    r/   c                 C   sF   dddddd}|  D ]\}}| |r|  S qtdtjd d	S )
Namdgcnr600mipssparchexagon)r0   r1   r2   r3   r4   z"Cannot find a triple. Assume 'x86')filex86)items
startswithprintsysstderr)ZmarchZtriplesprefixtripler   r   r   get_triple_from_march8  s    

r>   c                 C   s$  t tft tft tfttfttfttfttfttftt	fttfttftt
fttftt	fttfttftt
fttfttfttfttfttfttfttfttfttfttfd}d }d}| D ]*\}	}
||	rt|	t|kr|
}|	}q|d u rt d| |\}}t!"||| g||||| j#dd
 d S )N)Zi686r6   Zi386Zaarch64zaarch64-apple-darwinr4   r1   r0   ZarmZarm64zarm64-apple-ioszarmv7-apple-ioszarmv7-apple-darwinZthumbzthumb-machozthumbv5-machozthumbv7-apple-iosr2   Zmsp430Zppc32ZpowerpcZriscv32Zriscv64Zlanair3   Zs390xZwasm32r   zTriple %r is not supportedF)$r!   ASM_FUNCTION_X86_REr%   ASM_FUNCTION_AARCH64_REASM_FUNCTION_AARCH64_DARWIN_REr&   ASM_FUNCTION_HEXAGON_REr$   ASM_FUNCTION_AMDGPU_REASM_FUNCTION_ARM_REASM_FUNCTION_ARM_IOS_REASM_FUNCTION_ARM_DARWIN_REASM_FUNCTION_ARM_MACHO_REr)   ASM_FUNCTION_MIPS_REr*   ASM_FUNCTION_MSP430_REr(   ASM_FUNCTION_PPC_REr+   ASM_FUNCTION_RISCV_REr,   ASM_FUNCTION_LANAI_REr-   ASM_FUNCTION_SPARC_REr.   ASM_FUNCTION_SYSTEMZ_REr/   ASM_FUNCTION_WASM32_REr7   r8   lenKeyErrorr   Zbuild_function_body_dictionaryverbose)r    raw_tool_outputr=   prefixes	func_dict
func_orderZtarget_handlersZhandlerZbest_prefixr<   sZscrubberZfunction_rer   r   r   )build_function_body_dictionary_for_tripleF  sR    rX   c                 C   s,   d |}i }t| |||||dd|	 d S )Nz{} %s-LABEL: %s%s:TF)formatr   Z
add_checks)output_linesZcomment_markerZprefix_listrU   	func_nameZcheck_label_formatZglobal_vars_seen_dictr   r   r   add_asm_checksv  s    
r\   )2
__future__r   rer:   r   r   version_infor   compileMSr?   rD   r@   rC   rB   rH   rI   rJ   rK   rL   rM   rN   rA   rF   rG   rE   rO   r   r   r   r   r   r   r   r!   r$   r%   r&   r(   r)   r*   r+   r,   r-   r.   r/   r>   rX   r\   r   r   r   r   <module>   s   







	













 








0