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>.*?)\n' # (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'.Lfunc_end[0-9]+:\n', 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]*\.globl[ \t]*_(?P<func>[^ \t])[ \t]*@[ \t]--[ \t]Begin[ \t]function[ \t]"?(?P=func)"?' 132 r'(?P<directives>.*?)' 133 r'^_(?P=func):\n[ \t]*' 134 r'(?P<body>.*?)' 135 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 136 flags=(re.M | re.S )) 137 138ASM_FUNCTION_ARM_MACHO_RE = re.compile( 139 r'^_(?P<func>[^:]+):[ \t]*\n' 140 r'([ \t]*.cfi_startproc\n[ \t]*)?' 141 r'(?P<body>.*?)\n' 142 r'[ \t]*\.cfi_endproc\n', 143 flags=(re.M | re.S)) 144 145ASM_FUNCTION_THUMBS_DARWIN_RE = re.compile( 146 r'^_(?P<func>[^:]+):\n' 147 r'(?P<body>.*?)\n' 148 r'[ \t]*\.data_region\n', 149 flags=(re.M | re.S)) 150 151ASM_FUNCTION_THUMB_DARWIN_RE = re.compile( 152 r'^_(?P<func>[^:]+):\n' 153 r'(?P<body>.*?)\n' 154 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 155 flags=(re.M | re.S)) 156 157ASM_FUNCTION_ARM_IOS_RE = re.compile( 158 r'^_(?P<func>[^:]+):\n' 159 r'(?P<body>.*?)' 160 r'^[ \t]*@[ \t]--[ \t]End[ \t]function', 161 flags=(re.M | re.S)) 162 163ASM_FUNCTION_WASM32_RE = re.compile( 164 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n' 165 r'(?P<body>.*?)\n' 166 r'^\s*(\.Lfunc_end[0-9]+:\n|end_function)', 167 flags=(re.M | re.S)) 168 169ASM_FUNCTION_VE_RE = re.compile( 170 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n' 171 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 172 r'.Lfunc_end[0-9]+:\n', 173 flags=(re.M | re.S)) 174 175ASM_FUNCTION_CSKY_RE = re.compile( 176 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?' 177 r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' 178 r'.Lfunc_end[0-9]+:\n', 179 flags=(re.M | re.S)) 180 181ASM_FUNCTION_NVPTX_RE = re.compile( 182 # function attributes and retval 183 # .visible .func (.param .align 16 .b8 func_retval0[32]) 184 #r'^(\.visible\s+)?\.func\s+(\([^\)]*\)\s*)?' 185 r'^(\.(func|visible|weak|entry|noreturn|extern)\s+)+(\([^\)]*\)\s*)?' 186 187 # function name 188 r'(?P<func>[^\(\n]+)' 189 190 # function name separator (opening brace) 191 r'(?P<func_name_separator>\()' 192 193 # function parameters 194 # ( 195 # .param .align 16 .b8 callee_St8x4_param_0[32] 196 # ) // -- Begin function callee_St8x4 197 r'[^\)]*\)(\s*//[^\n]*)?\n' 198 199 # function body 200 r'(?P<body>.*?)\n' 201 202 # function body end marker 203 r'\s*// -- End function', 204 flags=(re.M | re.S)) 205 206SCRUB_X86_SHUFFLES_RE = ( 207 re.compile( 208 r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$', 209 flags=re.M)) 210 211SCRUB_X86_SHUFFLES_NO_MEM_RE = ( 212 re.compile( 213 r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = (?!.*(?:mem)).*)$', 214 flags=re.M)) 215 216SCRUB_X86_SPILL_RELOAD_RE = ( 217 re.compile( 218 r'-?\d+\(%([er])[sb]p\)(.*(?:Spill|Reload))$', 219 flags=re.M)) 220SCRUB_X86_SP_RE = re.compile(r'\d+\(%(esp|rsp)\)') 221SCRUB_X86_RIP_RE = re.compile(r'[.\w]+\(%rip\)') 222SCRUB_X86_LCP_RE = re.compile(r'\.?LCPI[0-9]+_[0-9]+') 223SCRUB_X86_RET_RE = re.compile(r'ret[l|q]') 224 225def scrub_asm_x86(asm, args): 226 # Scrub runs of whitespace out of the assembly, but leave the leading 227 # whitespace in place. 228 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 229 # Expand the tabs used for indentation. 230 asm = string.expandtabs(asm, 2) 231 232 # Detect shuffle asm comments and hide the operands in favor of the comments. 233 if getattr(args, 'no_x86_scrub_mem_shuffle', True): 234 asm = SCRUB_X86_SHUFFLES_NO_MEM_RE.sub(r'\1 {{.*#+}} \2', asm) 235 else: 236 asm = SCRUB_X86_SHUFFLES_RE.sub(r'\1 {{.*#+}} \2', asm) 237 238 # Detect stack spills and reloads and hide their exact offset and whether 239 # they used the stack pointer or frame pointer. 240 asm = SCRUB_X86_SPILL_RELOAD_RE.sub(r'{{[-0-9]+}}(%\1{{[sb]}}p)\2', asm) 241 if getattr(args, 'x86_scrub_sp', True): 242 # Generically match the stack offset of a memory operand. 243 asm = SCRUB_X86_SP_RE.sub(r'{{[0-9]+}}(%\1)', asm) 244 if getattr(args, 'x86_scrub_rip', False): 245 # Generically match a RIP-relative memory operand. 246 asm = SCRUB_X86_RIP_RE.sub(r'{{.*}}(%rip)', asm) 247 # Generically match a LCP symbol. 248 asm = SCRUB_X86_LCP_RE.sub(r'{{\.?LCPI[0-9]+_[0-9]+}}', asm) 249 if getattr(args, 'extra_scrub', False): 250 # Avoid generating different checks for 32- and 64-bit because of 'retl' vs 'retq'. 251 asm = SCRUB_X86_RET_RE.sub(r'ret{{[l|q]}}', asm) 252 # Strip kill operands inserted into the asm. 253 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 254 # Strip trailing whitespace. 255 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 256 return asm 257 258def scrub_asm_amdgpu(asm, args): 259 # Scrub runs of whitespace out of the assembly, but leave the leading 260 # whitespace in place. 261 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 262 # Expand the tabs used for indentation. 263 asm = string.expandtabs(asm, 2) 264 # Strip trailing whitespace. 265 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 266 return asm 267 268def scrub_asm_arm_eabi(asm, args): 269 # Scrub runs of whitespace out of the assembly, but leave the leading 270 # whitespace in place. 271 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 272 # Expand the tabs used for indentation. 273 asm = string.expandtabs(asm, 2) 274 # Strip kill operands inserted into the asm. 275 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 276 # Strip trailing whitespace. 277 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 278 return asm 279 280def scrub_asm_hexagon(asm, args): 281 # Scrub runs of whitespace out of the assembly, but leave the leading 282 # whitespace in place. 283 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 284 # Expand the tabs used for indentation. 285 asm = string.expandtabs(asm, 2) 286 # Strip trailing whitespace. 287 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 288 return asm 289 290def scrub_asm_powerpc(asm, args): 291 # Scrub runs of whitespace out of the assembly, but leave the leading 292 # whitespace in place. 293 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 294 # Expand the tabs used for indentation. 295 asm = string.expandtabs(asm, 2) 296 # Strip unimportant comments, but leave the token '#' in place. 297 asm = common.SCRUB_LOOP_COMMENT_RE.sub(r'#', asm) 298 # Strip trailing whitespace. 299 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 300 # Strip the tailing token '#', except the line only has token '#'. 301 asm = common.SCRUB_TAILING_COMMENT_TOKEN_RE.sub(r'', asm) 302 return asm 303 304def scrub_asm_m68k(asm, args): 305 # Scrub runs of whitespace out of the assembly, but leave the leading 306 # whitespace in place. 307 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 308 # Expand the tabs used for indentation. 309 asm = string.expandtabs(asm, 2) 310 # Strip trailing whitespace. 311 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 312 return asm 313 314def scrub_asm_mips(asm, args): 315 # Scrub runs of whitespace out of the assembly, but leave the leading 316 # whitespace in place. 317 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 318 # Expand the tabs used for indentation. 319 asm = string.expandtabs(asm, 2) 320 # Strip trailing whitespace. 321 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 322 return asm 323 324def scrub_asm_msp430(asm, args): 325 # Scrub runs of whitespace out of the assembly, but leave the leading 326 # whitespace in place. 327 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 328 # Expand the tabs used for indentation. 329 asm = string.expandtabs(asm, 2) 330 # Strip trailing whitespace. 331 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 332 return asm 333 334def scrub_asm_avr(asm, args): 335 # Scrub runs of whitespace out of the assembly, but leave the leading 336 # whitespace in place. 337 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 338 # Expand the tabs used for indentation. 339 asm = string.expandtabs(asm, 2) 340 # Strip trailing whitespace. 341 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 342 return asm 343 344def scrub_asm_riscv(asm, args): 345 # Scrub runs of whitespace out of the assembly, but leave the leading 346 # whitespace in place. 347 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 348 # Expand the tabs used for indentation. 349 asm = string.expandtabs(asm, 2) 350 # Strip trailing whitespace. 351 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 352 return asm 353 354def scrub_asm_lanai(asm, args): 355 # Scrub runs of whitespace out of the assembly, but leave the leading 356 # whitespace in place. 357 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 358 # Expand the tabs used for indentation. 359 asm = string.expandtabs(asm, 2) 360 # Strip trailing whitespace. 361 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 362 return asm 363 364def scrub_asm_sparc(asm, args): 365 # Scrub runs of whitespace out of the assembly, but leave the leading 366 # whitespace in place. 367 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 368 # Expand the tabs used for indentation. 369 asm = string.expandtabs(asm, 2) 370 # Strip trailing whitespace. 371 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 372 return asm 373 374def scrub_asm_systemz(asm, args): 375 # Scrub runs of whitespace out of the assembly, but leave the leading 376 # whitespace in place. 377 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 378 # Expand the tabs used for indentation. 379 asm = string.expandtabs(asm, 2) 380 # Strip trailing whitespace. 381 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 382 return asm 383 384def scrub_asm_wasm32(asm, args): 385 # Scrub runs of whitespace out of the assembly, but leave the leading 386 # whitespace in place. 387 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 388 # Expand the tabs used for indentation. 389 asm = string.expandtabs(asm, 2) 390 # Strip trailing whitespace. 391 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 392 return asm 393 394def scrub_asm_ve(asm, args): 395 # Scrub runs of whitespace out of the assembly, but leave the leading 396 # whitespace in place. 397 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 398 # Expand the tabs used for indentation. 399 asm = string.expandtabs(asm, 2) 400 # Strip trailing whitespace. 401 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 402 return asm 403 404def scrub_asm_csky(asm, args): 405 # Scrub runs of whitespace out of the assembly, but leave the leading 406 # whitespace in place. 407 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 408 # Expand the tabs used for indentation. 409 asm = string.expandtabs(asm, 2) 410 # Strip kill operands inserted into the asm. 411 asm = common.SCRUB_KILL_COMMENT_RE.sub('', asm) 412 # Strip trailing whitespace. 413 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 414 return asm 415 416def scrub_asm_nvptx(asm, args): 417 # Scrub runs of whitespace out of the assembly, but leave the leading 418 # whitespace in place. 419 asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm) 420 # Expand the tabs used for indentation. 421 asm = string.expandtabs(asm, 2) 422 # Strip trailing whitespace. 423 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) 424 return asm 425 426 427# Returns a tuple of a scrub function and a function regex. Scrub function is 428# used to alter function body in some way, for example, remove traling spaces. 429# Function regex is used to match function name, body, etc. in raw llc output. 430def get_run_handler(triple): 431 target_handlers = { 432 'i686': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 433 'x86': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 434 'i386': (scrub_asm_x86, ASM_FUNCTION_X86_RE), 435 'arm64_32-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 436 'aarch64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE), 437 'aarch64-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 438 'aarch64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 439 'hexagon': (scrub_asm_hexagon, ASM_FUNCTION_HEXAGON_RE), 440 'r600': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE), 441 'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE), 442 'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), 443 'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE), 444 'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 445 'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 446 'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE), 447 'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE), 448 'thumb': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), 449 'thumb-macho': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE), 450 'thumbv5-macho': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE), 451 'thumbv7s-apple-darwin' : (scrub_asm_arm_eabi, ASM_FUNCTION_THUMBS_DARWIN_RE), 452 'thumbv7-apple-darwin' : (scrub_asm_arm_eabi, ASM_FUNCTION_THUMB_DARWIN_RE), 453 'thumbv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE), 454 'm68k': (scrub_asm_m68k, ASM_FUNCTION_M68K_RE), 455 'mips': (scrub_asm_mips, ASM_FUNCTION_MIPS_RE), 456 'msp430': (scrub_asm_msp430, ASM_FUNCTION_MSP430_RE), 457 'avr': (scrub_asm_avr, ASM_FUNCTION_AVR_RE), 458 'ppc32': (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE), 459 'powerpc': (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE), 460 'riscv32': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE), 461 'riscv64': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE), 462 'lanai': (scrub_asm_lanai, ASM_FUNCTION_LANAI_RE), 463 'sparc': (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE), 464 's390x': (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE), 465 'wasm32': (scrub_asm_wasm32, ASM_FUNCTION_WASM32_RE), 466 've': (scrub_asm_ve, ASM_FUNCTION_VE_RE), 467 'csky': (scrub_asm_csky, ASM_FUNCTION_CSKY_RE), 468 'nvptx': (scrub_asm_nvptx, ASM_FUNCTION_NVPTX_RE) 469 } 470 handler = None 471 best_prefix = '' 472 for prefix, s in target_handlers.items(): 473 if triple.startswith(prefix) and len(prefix) > len(best_prefix): 474 handler = s 475 best_prefix = prefix 476 477 if handler is None: 478 raise KeyError('Triple %r is not supported' % (triple)) 479 480 return handler 481 482##### Generator of assembly CHECK lines 483 484def add_checks(output_lines, comment_marker, prefix_list, func_dict, 485 func_name, is_filtered): 486 # Label format is based on ASM string. 487 check_label_format = '{} %s-LABEL: %s%s%s'.format(comment_marker) 488 global_vars_seen_dict = {} 489 common.add_checks(output_lines, comment_marker, prefix_list, func_dict, 490 func_name, check_label_format, True, False, 491 global_vars_seen_dict, is_filtered = is_filtered) 492