@@ -15,6 +15,11 @@ class string:
15
15
# RegEx: this is where the magic happens.
16
16
17
17
##### Assembly parser
18
+ #
19
+ # The set of per-arch regular expressions define several groups.
20
+ # The required groups are "func" (function name) and "body" (body of the function).
21
+ # Although some backends require some additional groups like: "directives"
22
+ # and "func_name_separator"
18
23
19
24
ASM_FUNCTION_X86_RE = re .compile (
20
25
r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?'
@@ -197,6 +202,14 @@ class string:
197
202
flags = (re .M | re .S ),
198
203
)
199
204
205
+ # We parse the function name from OpName, and grab the variable name 'var'
206
+ # for this function. Then we match that when the variable is assigned with
207
+ # OpFunction and match its body.
208
+ ASM_FUNCTION_SPIRV_RE = re .compile (
209
+ r'OpName (?P<var>%[0-9]+) "(?P<func>[^"]+)(?P<func_name_separator>)".*(?P<body>(?P=var) = OpFunction.+?OpFunctionEnd)' ,
210
+ flags = (re .M | re .S ),
211
+ )
212
+
200
213
ASM_FUNCTION_VE_RE = re .compile (
201
214
r"^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n"
202
215
r"(?:\s*\.?L(?P=func)\$local:\n)?" # optional .L<func>$local: due to -fno-semantic-interposition
@@ -433,6 +446,17 @@ def scrub_asm_sparc(asm, args):
433
446
return asm
434
447
435
448
449
+ def scrub_asm_spirv (asm , args ):
450
+ # Scrub runs of whitespace out of the assembly, but leave the leading
451
+ # whitespace in place.
452
+ asm = common .SCRUB_WHITESPACE_RE .sub (r" " , asm )
453
+ # Expand the tabs used for indentation.
454
+ asm = string .expandtabs (asm , 2 )
455
+ # Strip trailing whitespace.
456
+ asm = common .SCRUB_TRAILING_WHITESPACE_RE .sub (r"" , asm )
457
+ return asm
458
+
459
+
436
460
def scrub_asm_systemz (asm , args ):
437
461
# Scrub runs of whitespace out of the assembly, but leave the leading
438
462
# whitespace in place.
@@ -547,6 +571,8 @@ def get_run_handler(triple):
547
571
"riscv64" : (scrub_asm_riscv , ASM_FUNCTION_RISCV_RE ),
548
572
"lanai" : (scrub_asm_lanai , ASM_FUNCTION_LANAI_RE ),
549
573
"sparc" : (scrub_asm_sparc , ASM_FUNCTION_SPARC_RE ),
574
+ "spirv32" : (scrub_asm_spirv , ASM_FUNCTION_SPIRV_RE ),
575
+ "spirv64" : (scrub_asm_spirv , ASM_FUNCTION_SPIRV_RE ),
550
576
"s390x" : (scrub_asm_systemz , ASM_FUNCTION_SYSTEMZ_RE ),
551
577
"wasm32" : (scrub_asm_wasm , ASM_FUNCTION_WASM_RE ),
552
578
"wasm64" : (scrub_asm_wasm , ASM_FUNCTION_WASM_RE ),
0 commit comments