1from __future__ import print_function 2import re 3import sys 4 5from . import common 6 7if sys.version_info[0] > 2: 8 class string: 9 expandtabs = str.expandtabs 10else: 11 import string 12 13# RegEx: this is where the magic happens. 14 15##### Assembly parser 16 17ASM_FUNCTION_X86_RE = re.compile( 18 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?' 19 r'(?:\.L[^$]+\$local:\n)?' # drop .L<func>$local: 20 r'(?:[ \t]+.cfi_startproc\n|.seh_proc[^\n]+\n)?' # drop optional cfi 21 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 22 r'^\s*(?:[^:\n]+?:\s*\n\s*\.size|\.cfi_endproc|\.globl|\.comm|\.(?:sub)?section|#+ -- End function)', 23 flags=(re.M | re.S)) 24 25ASM_FUNCTION_ARM_RE = re.compile( 26 r'^(?P<func>[0-9a-zA-Z_$]+):\n' # f: (name of function) 27 r'\s+\.fnstart\n' # .fnstart 28 r'(?P<body>.*?)' # (body of the function) 29 r'^.Lfunc_end[0-9]+:', # .Lfunc_end0: or # -- End function 30 flags=(re.M | re.S)) 31 32ASM_FUNCTION_AARCH64_RE = re.compile( 33 r'^_?(?P<func>[^:]+):[ \t]*\/\/[ \t]*@"?(?P=func)"?( (Function|Tail Call))?\n' 34 r'(?:[ \t]+.cfi_startproc\n)?' # drop optional cfi noise 35 r'(?P<body>.*?)\n' 36 # This list is incomplete 37 r'^\s*(\.Lfunc_end[0-9]+|// -- End function)', 38 flags=(re.M | re.S)) 39 40ASM_FUNCTION_AMDGPU_RE = re.compile( 41 r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?' 42 r'(?P<body>.*?)\n' # (body of the function) 43 # This list is incomplete 44 r'^\s*(\.Lfunc_end[0-9]+:\n|\.section)', 45 flags=(re.M | re.S)) 46 47ASM_FUNCTION_HEXAGON_RE = re.compile( 48 r'^_?(?P<func>[^:]+):[ \t]*//[ \t]*@"?(?P=func)"?\n[^:]*?' 49 r'(?P<body>.*?)\n' # (body of the function) 50 # This list is incomplete 51 r'.Lfunc_end[0-9]+:\n', 52 flags=(re.M | re.S)) 53 54ASM_FUNCTION_M68K_RE = re.compile( 55 r'^_?(?P<func>[^:]+):[ \t]*;[ \t]*@"?(?P=func)"?\n' 56 r'(?P<body>.*?)\s*' # (body of the function) 57 r'.Lfunc_end[0-9]+:\n', 58 flags=(re.M | re.S)) 59 60ASM_FUNCTION_MIPS_RE = re.compile( 61 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n[^:]*?' # f: (name of func) 62 r'(?:\s*\.?Ltmp[^:\n]*:\n)?[^:]*?' # optional .Ltmp<N> for EH 63 r'(?:^[ \t]+\.(frame|f?mask|set).*?\n)+' # Mips+LLVM standard asm prologue 64 r'(?P<body>.*?)\n' # (body of the function) 65 # Mips+LLVM standard asm epilogue 66 r'(?:(^[ \t]+\.set[^\n]*?\n)*^[ \t]+\.end.*?\n)' 67 r'(\$|\.L)func_end[0-9]+:\n', # $func_end0: (mips32 - O32) or 68 # .Lfunc_end0: (mips64 - NewABI) 69 flags=(re.M | re.S)) 70 71ASM_FUNCTION_MSP430_RE = re.compile( 72 r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?' 73 r'(?P<body>.*?)\n' 74 r'(\$|\.L)func_end[0-9]+:\n', # $func_end0: 75 flags=(re.M | re.S)) 76 77ASM_FUNCTION_AVR_RE = re.compile( 78 r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?' 79 r'(?P<body>.*?)\n' 80 r'.Lfunc_end[0-9]+:\n', 81 flags=(re.M | re.S)) 82 83ASM_FUNCTION_PPC_RE = re.compile( 84 r'#[ \-\t]*Begin function (?P<func>[^.:]+)\n' 85 r'.*?' 86 r'^[_.]?(?P=func):(?:[ \t]*#+[ \t]*@"?(?P=func)"?)?\n' 87 r'(?:^[^#]*\n)*' 88 r'(?P<body>.*?)\n' 89 # This list is incomplete 90 r'(?:^[ \t]*(?:\.(?:long|quad|v?byte)[ \t]+[^\n]+)\n)*' 91 r'(?:\.Lfunc_end|L\.\.(?P=func))[0-9]+:\n', 92 flags=(re.M | re.S)) 93 94ASM_FUNCTION_RISCV_RE = re.compile( 95 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n' 96 r'(?:\s*\.?L(?P=func)\$local:\n)?' # optional .L<func>$local: due to -fno-semantic-interposition 97 r'(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?' 98 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 99 r'.Lfunc_end[0-9]+:\n', 100 flags=(re.M | re.S)) 101 102ASM_FUNCTION_LANAI_RE = re.compile( 103 r'^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n' 104 r'(?:[ \t]+.cfi_startproc\n)?' # drop optional cfi noise 105 r'(?P<body>.*?)\s*' 106 r'.Lfunc_end[0-9]+:\n', 107 flags=(re.M | re.S)) 108 109ASM_FUNCTION_SPARC_RE = re.compile( 110 r'^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n' 111 r'(?P<body>.*?)\s*' 112 r'.Lfunc_end[0-9]+:\n', 113 flags=(re.M | re.S)) 114 115ASM_FUNCTION_SYSTEMZ_RE = re.compile( 116 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n' 117 r'[ \t]+.cfi_startproc\n' 118 r'(?P<body>.*?)\n' 119 r'.Lfunc_end[0-9]+:\n', 120 flags=(re.M | re.S)) 121 122ASM_FUNCTION_AARCH64_DARWIN_RE = re.compile( 123 r'^_(?P<func>[^:]+):[ \t]*;[ \t]@"?(?P=func)"?\n' 124 r'([ \t]*.cfi_startproc\n[\s]*)?' 125 r'(?P<body>.*?)' 126 r'([ \t]*.cfi_endproc\n[\s]*)?' 127 r'^[ \t]*;[ \t]--[ \t]End[ \t]function', 128 flags=(re.M | re.S)) 129 130ASM_FUNCTION_ARM_DARWIN_RE = re.compile( 131 r'@[ \t]--[ \t]Begin[ \t]function[ \t](?P<func>[^ \t]+?)\n' 132 r'^[ \t]*\.globl[ \t]*_(?P=func)[ \t]*' 133 r'(?P<directives>.*?)' 134 r'^_(?P=func):\n[ \t]*' 135 r'(?P<body>.*?)' 136 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 137 flags=(re.M | re.S )) 138 139ASM_FUNCTION_ARM_MACHO_RE = re.compile( 140 r'^_(?P<func>[^:]+):[ \t]*\n' 141 r'([ \t]*.cfi_startproc\n[ \t]*)?' 142 r'(?P<body>.*?)\n' 143 r'[ \t]*\.cfi_endproc\n', 144 flags=(re.M | re.S)) 145 146ASM_FUNCTION_THUMBS_DARWIN_RE = re.compile( 147 r'^_(?P<func>[^:]+):\n' 148 r'(?P<body>.*?)\n' 149 r'[ \t]*\.data_region\n', 150 flags=(re.M | re.S)) 151 152ASM_FUNCTION_THUMB_DARWIN_RE = re.compile( 153 r'^_(?P<func>[^:]+):\n' 154 r'(?P<body>.*?)\n' 155 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 156 flags=(re.M | re.S)) 157 158ASM_FUNCTION_ARM_IOS_RE = re.compile( 159 r'^_(?P<func>[^:]+):\n' 160 r'(?P<body>.*?)' 161 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 162 flags=(re.M | re.S)) 163 164ASM_FUNCTION_WASM32_RE = re.compile( 165 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n' 166 r'(?P<body>.*?)\n' 167 r'^\s*(\.Lfunc_end[0-9]+:\n|end_function)', 168 flags=(re.M | re.S)) 169 170ASM_FUNCTION_VE_RE = re.compile( 171 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n' 172 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 173 r'.Lfunc_end[0-9]+:\n', 174 flags=(re.M | re.S)) 175 176ASM_FUNCTION_CSKY_RE = re.compile( 177 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?' 178 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 179 r'.Lfunc_end[0-9]+:\n', 180 flags=(re.M | re.S)) 181 182ASM_FUNCTION_NVPTX_RE = re.compile( 183 # function attributes and retval 184 # .visible .func (.param .align 16 .b8 func_retval0[32]) 185 #r'^(\.visible\s+)?\.func\s+(\([^\)]*\)\s*)?' 186 r'^(\.(func|visible|weak|entry|noreturn|extern)\s+)+(\([^\)]*\)\s*)?' 187 188 # function name 189 r'(?P<func>[^\(\n]+)' 190 191 # function name separator (opening brace) 192 r'(?P<func_name_separator>\()' 193 194 # function parameters 195 # ( 196 # .param .align 16 .b8 callee_St8x4_param_0[32] 197 # ) // -- Begin function callee_St8x4 198 r'[^\)]*\)(\s*//[^\n]*)?\n' 199 200 # function body 201 r'(?P<body>.*?)\n' 202 203 # function body end marker 204 r'\s*// -- End function', 205 flags=(re.M | re.S)) 206 207ASM_FUNCTION_LOONGARCH_RE = re.compile( 208 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n' 209 r'(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?' 210 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 211 r'.Lfunc_end[0-9]+:\n', 212 flags=(re.M | re.S)) 213 214SCRUB_X86_SHUFFLES_RE = ( 215 re.compile( 216 r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$', 217 flags=re.M)) 218 219SCRUB_X86_SHUFFLES_NO_MEM_RE = ( 220 re.compile( 221 r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = (?!.*(?:mem)).*)$', 222 flags=re.M)) 223 224SCRUB_X86_SPILL_RELOAD_RE = ( 225 re.compile( 226 r'-?\d+\(%([er])[sb]p\)(.*(?:Spill|Reload))$', 227 flags=re.M)) 228SCRUB_X86_SP_RE = re.compile(r'\d+\(%(esp|rsp)\)') 229SCRUB_X86_RIP_RE = re.compile(r'[.\w]+\(%rip\)') 230SCRUB_X86_LCP_RE = re.compile(r'\.?LCPI[0-9]+_[0-9]+') 231SCRUB_X86_RET_RE = re.compile(r'ret[l|q]') 232 233def scrub_asm_x86(asm, args): 234 # Scrub runs of whitespace out of the assembly, but leave the leading 235 # whitespace in place. 236 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 237 # Expand the tabs used for indentation. 238 asm = string.expandtabs(asm, 2) 239 240 # Detect shuffle asm comments and hide the operands in favor of the comments. 241 if getattr(args, 'no_x86_scrub_mem_shuffle', True): 242 asm = SCRUB_X86_SHUFFLES_NO_MEM_RE.sub(r'\1 {{.*#+}} \2', asm) 243 else: 244 asm = SCRUB_X86_SHUFFLES_RE.sub(r'\1 {{.*#+}} \2', asm) 245 246 # Detect stack spills and reloads and hide their exact offset and whether 247 # they used the stack pointer or frame pointer. 248 asm = SCRUB_X86_SPILL_RELOAD_RE.sub(r'{{[-0-9]+}}(%\1{{[sb]}}p)\2', asm) 249 if getattr(args, 'x86_scrub_sp', True): 250 # Generically match the stack offset of a memory operand. 251 asm = SCRUB_X86_SP_RE.sub(r'{{[0-9]+}}(%\1)', asm) 252 if getattr(args, 'x86_scrub_rip', False): 253 # Generically match a RIP-relative memory operand. 254 asm = SCRUB_X86_RIP_RE.sub(r'{{.*}}(%rip)', asm) 255 # Generically match a LCP symbol. 256 asm = SCRUB_X86_LCP_RE.sub(r'{{\.?LCPI[0-9]+_[0-9]+}}', asm) 257 if getattr(args, 'extra_scrub', False): 258 # Avoid generating different checks for 32- and 64-bit because of 'retl' vs 'retq'. 259 asm = SCRUB_X86_RET_RE.sub(r'ret{{[l|q]}}', asm) 260 # Strip kill operands inserted into the asm. 261 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 262 # Strip trailing whitespace. 263 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 264 return asm 265 266def scrub_asm_amdgpu(asm, args): 267 # Scrub runs of whitespace out of the assembly, but leave the leading 268 # whitespace in place. 269 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 270 # Expand the tabs used for indentation. 271 asm = string.expandtabs(asm, 2) 272 # Strip trailing whitespace. 273 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 274 return asm 275 276def scrub_asm_arm_eabi(asm, args): 277 # Scrub runs of whitespace out of the assembly, but leave the leading 278 # whitespace in place. 279 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 280 # Expand the tabs used for indentation. 281 asm = string.expandtabs(asm, 2) 282 # Strip kill operands inserted into the asm. 283 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 284 # Strip trailing whitespace. 285 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 286 return asm 287 288def scrub_asm_hexagon(asm, args): 289 # Scrub runs of whitespace out of the assembly, but leave the leading 290 # whitespace in place. 291 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 292 # Expand the tabs used for indentation. 293 asm = string.expandtabs(asm, 2) 294 # Strip trailing whitespace. 295 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 296 return asm 297 298def scrub_asm_powerpc(asm, args): 299 # Scrub runs of whitespace out of the assembly, but leave the leading 300 # whitespace in place. 301 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 302 # Expand the tabs used for indentation. 303 asm = string.expandtabs(asm, 2) 304 # Strip unimportant comments, but leave the token '#' in place. 305 asm = common.SCRUB_LOOP_COMMENT_RE.sub(r'#', asm) 306 # Strip trailing whitespace. 307 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 308 # Strip the tailing token '#', except the line only has token '#'. 309 asm = common.SCRUB_TAILING_COMMENT_TOKEN_RE.sub(r'', asm) 310 return asm 311 312def scrub_asm_m68k(asm, args): 313 # Scrub runs of whitespace out of the assembly, but leave the leading 314 # whitespace in place. 315 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 316 # Expand the tabs used for indentation. 317 asm = string.expandtabs(asm, 2) 318 # Strip trailing whitespace. 319 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 320 return asm 321 322def scrub_asm_mips(asm, args): 323 # Scrub runs of whitespace out of the assembly, but leave the leading 324 # whitespace in place. 325 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 326 # Expand the tabs used for indentation. 327 asm = string.expandtabs(asm, 2) 328 # Strip trailing whitespace. 329 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 330 return asm 331 332def scrub_asm_msp430(asm, args): 333 # Scrub runs of whitespace out of the assembly, but leave the leading 334 # whitespace in place. 335 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 336 # Expand the tabs used for indentation. 337 asm = string.expandtabs(asm, 2) 338 # Strip trailing whitespace. 339 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 340 return asm 341 342def scrub_asm_avr(asm, args): 343 # Scrub runs of whitespace out of the assembly, but leave the leading 344 # whitespace in place. 345 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 346 # Expand the tabs used for indentation. 347 asm = string.expandtabs(asm, 2) 348 # Strip trailing whitespace. 349 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 350 return asm 351 352def scrub_asm_riscv(asm, args): 353 # Scrub runs of whitespace out of the assembly, but leave the leading 354 # whitespace in place. 355 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 356 # Expand the tabs used for indentation. 357 asm = string.expandtabs(asm, 2) 358 # Strip trailing whitespace. 359 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 360 return asm 361 362def scrub_asm_lanai(asm, args): 363 # Scrub runs of whitespace out of the assembly, but leave the leading 364 # whitespace in place. 365 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 366 # Expand the tabs used for indentation. 367 asm = string.expandtabs(asm, 2) 368 # Strip trailing whitespace. 369 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 370 return asm 371 372def scrub_asm_sparc(asm, args): 373 # Scrub runs of whitespace out of the assembly, but leave the leading 374 # whitespace in place. 375 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 376 # Expand the tabs used for indentation. 377 asm = string.expandtabs(asm, 2) 378 # Strip trailing whitespace. 379 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 380 return asm 381 382def scrub_asm_systemz(asm, args): 383 # Scrub runs of whitespace out of the assembly, but leave the leading 384 # whitespace in place. 385 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 386 # Expand the tabs used for indentation. 387 asm = string.expandtabs(asm, 2) 388 # Strip trailing whitespace. 389 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 390 return asm 391 392def scrub_asm_wasm32(asm, args): 393 # Scrub runs of whitespace out of the assembly, but leave the leading 394 # whitespace in place. 395 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 396 # Expand the tabs used for indentation. 397 asm = string.expandtabs(asm, 2) 398 # Strip trailing whitespace. 399 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 400 return asm 401 402def scrub_asm_ve(asm, args): 403 # Scrub runs of whitespace out of the assembly, but leave the leading 404 # whitespace in place. 405 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 406 # Expand the tabs used for indentation. 407 asm = string.expandtabs(asm, 2) 408 # Strip trailing whitespace. 409 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 410 return asm 411 412def scrub_asm_csky(asm, args): 413 # Scrub runs of whitespace out of the assembly, but leave the leading 414 # whitespace in place. 415 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 416 # Expand the tabs used for indentation. 417 asm = string.expandtabs(asm, 2) 418 # Strip kill operands inserted into the asm. 419 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 420 # Strip trailing whitespace. 421 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 422 return asm 423 424def scrub_asm_nvptx(asm, args): 425 # Scrub runs of whitespace out of the assembly, but leave the leading 426 # whitespace in place. 427 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 428 # Expand the tabs used for indentation. 429 asm = string.expandtabs(asm, 2) 430 # Strip trailing whitespace. 431 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 432 return asm 433 434def scrub_asm_loongarch(asm, args): 435 # Scrub runs of whitespace out of the assembly, but leave the leading 436 # whitespace in place. 437 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 438 # Expand the tabs used for indentation. 439 asm = string.expandtabs(asm, 2) 440 # Strip trailing whitespace. 441 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 442 return asm 443 444# Returns a tuple of a scrub function and a function regex. Scrub function is 445# used to alter function body in some way, for example, remove trailing spaces. 446# Function regex is used to match function name, body, etc. in raw llc output. 447def get_run_handler(triple): 448 target_handlers = { 449 'i686': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 450 'x86': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 451 'i386': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 452 'arm64_32-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 453 'arm64_32-apple-watchos2.0.0': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 454 'aarch64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE), 455 'aarch64-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 456 'aarch64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 457 'hexagon': (scrub_asm_hexagon, ASM_FUNCTION_HEXAGON_RE), 458 'r600': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE), 459 'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE), 460 'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), 461 'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE), 462 'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 463 'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 464 'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE), 465 'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE), 466 'thumb': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), 467 'thumb-macho': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE), 468 'thumbv5-macho': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE), 469 'thumbv7s-apple-darwin' : (scrub_asm_arm_eabi, ASM_FUNCTION_THUMBS_DARWIN_RE), 470 'thumbv7-apple-darwin' : (scrub_asm_arm_eabi, ASM_FUNCTION_THUMB_DARWIN_RE), 471 'thumbv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE), 472 'm68k': (scrub_asm_m68k, ASM_FUNCTION_M68K_RE), 473 'mips': (scrub_asm_mips, ASM_FUNCTION_MIPS_RE), 474 'msp430': (scrub_asm_msp430, ASM_FUNCTION_MSP430_RE), 475 'avr': (scrub_asm_avr, ASM_FUNCTION_AVR_RE), 476 'ppc32': (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE), 477 'powerpc': (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE), 478 'riscv32': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE), 479 'riscv64': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE), 480 'lanai': (scrub_asm_lanai, ASM_FUNCTION_LANAI_RE), 481 'sparc': (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE), 482 's390x': (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE), 483 'wasm32': (scrub_asm_wasm32, ASM_FUNCTION_WASM32_RE), 484 've': (scrub_asm_ve, ASM_FUNCTION_VE_RE), 485 'csky': (scrub_asm_csky, ASM_FUNCTION_CSKY_RE), 486 'nvptx': (scrub_asm_nvptx, ASM_FUNCTION_NVPTX_RE), 487 'loongarch32': (scrub_asm_loongarch, ASM_FUNCTION_LOONGARCH_RE), 488 'loongarch64': (scrub_asm_loongarch, ASM_FUNCTION_LOONGARCH_RE) 489 } 490 handler = None 491 best_prefix = '' 492 for prefix, s in target_handlers.items(): 493 if triple.startswith(prefix) and len(prefix) > len(best_prefix): 494 handler = s 495 best_prefix = prefix 496 497 if handler is None: 498 raise KeyError('Triple %r is not supported' % (triple)) 499 500 return handler 501 502##### Generator of assembly CHECK lines 503 504def add_checks(output_lines, comment_marker, prefix_list, func_dict, 505 func_name, global_vars_seen_dict, is_filtered): 506 # Label format is based on ASM string. 507 check_label_format = '{} %s-LABEL: %s%s%s'.format(comment_marker) 508 return common.add_checks(output_lines, comment_marker, prefix_list, func_dict, 509 func_name, check_label_format, True, False, 510 global_vars_seen_dict, is_filtered=is_filtered) 511