|
36 | 36 | "_R", _schema.COFFRelocation, _schema.ELFRelocation, _schema.MachORelocation |
37 | 37 | ) |
38 | 38 |
|
| 39 | +def _extract_jit_cases(generated_cases: str) -> list[tuple[str, str]]: |
| 40 | + begin_case = re.compile(r"\s*/\* BEGIN_JIT_CASE (\w+) \*/\n") |
| 41 | + cases_and_opnames: list[tuple[str, str]] = [] |
| 42 | + current_opname: str | None = None |
| 43 | + current_lines: list[str] = [] |
| 44 | + for line in generated_cases.splitlines(keepends=True): |
| 45 | + if current_opname is None: |
| 46 | + match = begin_case.fullmatch(line) |
| 47 | + if match is not None: |
| 48 | + current_opname = match.group(1) |
| 49 | + current_lines = [] |
| 50 | + continue |
| 51 | + if line.strip() == f"/* END_JIT_CASE {current_opname} */": |
| 52 | + cases_and_opnames.append(("".join(current_lines), current_opname)) |
| 53 | + current_opname = None |
| 54 | + current_lines = [] |
| 55 | + continue |
| 56 | + current_lines.append(line) |
| 57 | + if current_opname is not None: |
| 58 | + raise RuntimeError(f"Unterminated JIT case block for {current_opname}") |
| 59 | + return cases_and_opnames |
| 60 | + |
39 | 61 |
|
40 | 62 | @dataclasses.dataclass |
41 | 63 | class _Target(typing.Generic[_S, _R]): |
@@ -195,11 +217,7 @@ async def _compile( |
195 | 217 |
|
196 | 218 | async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]: |
197 | 219 | generated_cases = PYTHON_EXECUTOR_CASES_C_H.read_text() |
198 | | - cases_and_opnames = sorted( |
199 | | - re.findall( |
200 | | - r"\n {8}(case (\w+): \{\n.*?\n {8}\})", generated_cases, flags=re.DOTALL |
201 | | - ) |
202 | | - ) |
| 220 | + cases_and_opnames = _extract_jit_cases(generated_cases) |
203 | 221 | tasks = [] |
204 | 222 | with tempfile.TemporaryDirectory() as tempdir: |
205 | 223 | work = pathlib.Path(tempdir).resolve() |
|
0 commit comments