|
1 | 1 | """Target-specific code generation, parsing, and processing."""
|
| 2 | + |
2 | 3 | import asyncio
|
3 | 4 | import dataclasses
|
4 | 5 | import hashlib
|
@@ -40,8 +41,8 @@ class _Target(typing.Generic[_S, _R]):
|
40 | 41 | args: typing.Sequence[str] = ()
|
41 | 42 | ghccc: bool = False
|
42 | 43 | prefix: str = ""
|
| 44 | + stable: bool = False |
43 | 45 | debug: bool = False
|
44 |
| - force: bool = False |
45 | 46 | verbose: bool = False
|
46 | 47 |
|
47 | 48 | def _compute_digest(self, out: pathlib.Path) -> str:
|
@@ -186,12 +187,19 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
|
186 | 187 | tasks.append(group.create_task(coro, name=opname))
|
187 | 188 | return {task.get_name(): task.result() for task in tasks}
|
188 | 189 |
|
189 |
| - def build(self, out: pathlib.Path, *, comment: str = "") -> None: |
| 190 | + def build( |
| 191 | + self, out: pathlib.Path, *, comment: str = "", force: bool = False |
| 192 | + ) -> None: |
190 | 193 | """Build jit_stencils.h in the given directory."""
|
| 194 | + if not self.stable: |
| 195 | + warning = f"JIT support for {self.triple} is still experimental!" |
| 196 | + request = "Please report any issues you encounter.".center(len(warning)) |
| 197 | + outline = "=" * len(warning) |
| 198 | + print("\n".join(["", outline, warning, request, outline, ""])) |
191 | 199 | digest = f"// {self._compute_digest(out)}\n"
|
192 | 200 | jit_stencils = out / "jit_stencils.h"
|
193 | 201 | if (
|
194 |
| - not self.force |
| 202 | + not force |
195 | 203 | and jit_stencils.exists()
|
196 | 204 | and jit_stencils.read_text().startswith(digest)
|
197 | 205 | ):
|
@@ -450,9 +458,7 @@ def _handle_relocation(
|
450 | 458 | } | {
|
451 | 459 | "Offset": offset,
|
452 | 460 | "Symbol": {"Name": s},
|
453 |
| - "Type": { |
454 |
| - "Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind |
455 |
| - }, |
| 461 | + "Type": {"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind}, |
456 | 462 | }:
|
457 | 463 | offset += base
|
458 | 464 | s = s.removeprefix(self.prefix)
|
@@ -481,23 +487,26 @@ def _handle_relocation(
|
481 | 487 | def get_target(host: str) -> _COFF | _ELF | _MachO:
|
482 | 488 | """Build a _Target for the given host "triple" and options."""
|
483 | 489 | # ghccc currently crashes Clang when combined with musttail on aarch64. :(
|
| 490 | + target: _COFF | _ELF | _MachO |
484 | 491 | if re.fullmatch(r"aarch64-apple-darwin.*", host):
|
485 |
| - return _MachO(host, alignment=8, prefix="_") |
486 |
| - if re.fullmatch(r"aarch64-pc-windows-msvc", host): |
| 492 | + target = _MachO(host, alignment=8, prefix="_") |
| 493 | + elif re.fullmatch(r"aarch64-pc-windows-msvc", host): |
487 | 494 | args = ["-fms-runtime-lib=dll"]
|
488 |
| - return _COFF(host, alignment=8, args=args) |
489 |
| - if re.fullmatch(r"aarch64-.*-linux-gnu", host): |
| 495 | + target = _COFF(host, alignment=8, args=args) |
| 496 | + elif re.fullmatch(r"aarch64-.*-linux-gnu", host): |
490 | 497 | args = ["-fpic"]
|
491 |
| - return _ELF(host, alignment=8, args=args) |
492 |
| - if re.fullmatch(r"i686-pc-windows-msvc", host): |
| 498 | + target = _ELF(host, alignment=8, args=args) |
| 499 | + elif re.fullmatch(r"i686-pc-windows-msvc", host): |
493 | 500 | args = ["-DPy_NO_ENABLE_SHARED"]
|
494 |
| - return _COFF(host, args=args, ghccc=True, prefix="_") |
495 |
| - if re.fullmatch(r"x86_64-apple-darwin.*", host): |
496 |
| - return _MachO(host, ghccc=True, prefix="_") |
497 |
| - if re.fullmatch(r"x86_64-pc-windows-msvc", host): |
| 501 | + target = _COFF(host, args=args, ghccc=True, prefix="_") |
| 502 | + elif re.fullmatch(r"x86_64-apple-darwin.*", host): |
| 503 | + target = _MachO(host, ghccc=True, prefix="_") |
| 504 | + elif re.fullmatch(r"x86_64-pc-windows-msvc", host): |
498 | 505 | args = ["-fms-runtime-lib=dll"]
|
499 |
| - return _COFF(host, args=args, ghccc=True) |
500 |
| - if re.fullmatch(r"x86_64-.*-linux-gnu", host): |
| 506 | + target = _COFF(host, args=args, ghccc=True) |
| 507 | + elif re.fullmatch(r"x86_64-.*-linux-gnu", host): |
501 | 508 | args = ["-fpic"]
|
502 |
| - return _ELF(host, args=args, ghccc=True) |
503 |
| - raise ValueError(host) |
| 509 | + target = _ELF(host, args=args, ghccc=True) |
| 510 | + else: |
| 511 | + raise ValueError(host) |
| 512 | + return target |
0 commit comments