@@ -15,6 +15,11 @@ class string:
1515# RegEx: this is where the magic happens.
1616
1717##### 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"
1823
1924ASM_FUNCTION_X86_RE = re .compile (
2025 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?'
@@ -197,6 +202,14 @@ class string:
197202 flags = (re .M | re .S ),
198203)
199204
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+
200213ASM_FUNCTION_VE_RE = re .compile (
201214 r"^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n"
202215 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):
433446 return asm
434447
435448
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+
436460def scrub_asm_systemz (asm , args ):
437461 # Scrub runs of whitespace out of the assembly, but leave the leading
438462 # whitespace in place.
@@ -547,6 +571,8 @@ def get_run_handler(triple):
547571 "riscv64" : (scrub_asm_riscv , ASM_FUNCTION_RISCV_RE ),
548572 "lanai" : (scrub_asm_lanai , ASM_FUNCTION_LANAI_RE ),
549573 "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 ),
550576 "s390x" : (scrub_asm_systemz , ASM_FUNCTION_SYSTEMZ_RE ),
551577 "wasm32" : (scrub_asm_wasm , ASM_FUNCTION_WASM_RE ),
552578 "wasm64" : (scrub_asm_wasm , ASM_FUNCTION_WASM_RE ),
0 commit comments