Skip to content

Commit

Permalink
Don't stick jit_stencils.h in a temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed May 11, 2024
1 parent bc32227 commit dc9404c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,18 @@ async def _compile(
await _llvm.run("clang", args_o, echo=self.verbose)
return await self._parse(o)

async def _build_stencils(
self, work: pathlib.Path
) -> dict[str, _stencils.StencilGroup]:
async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
generated_cases = PYTHON_EXECUTOR_CASES_C_H.read_text()
opnames = sorted(re.findall(r"\n {8}case (\w+): \{\n", generated_cases))
tasks = []
async with asyncio.TaskGroup() as group:
coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work)
tasks.append(group.create_task(coro, name="trampoline"))
for opname in opnames:
coro = self._compile(opname, TOOLS_JIT_TEMPLATE_C, work)
tasks.append(group.create_task(coro, name=opname))
with tempfile.TemporaryDirectory() as tempdir:
work = pathlib.Path(tempdir).resolve()
async with asyncio.TaskGroup() as group:
coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work)
tasks.append(group.create_task(coro, name="trampoline"))
for opname in opnames:
coro = self._compile(opname, TOOLS_JIT_TEMPLATE_C, work)
tasks.append(group.create_task(coro, name=opname))
return {task.get_name(): task.result() for task in tasks}

def build(
Expand All @@ -211,18 +211,19 @@ def build(
and jit_stencils.read_text().startswith(digest)
):
return
with tempfile.TemporaryDirectory() as tempdir:
work = pathlib.Path(tempdir).resolve()
stencil_groups = asyncio.run(self._build_stencils(work))
new_jit_stencils = work / "jit_stencils.h"
with new_jit_stencils.open("w") as file:
stencil_groups = asyncio.run(self._build_stencils())
jit_stencils_new = out / "jit_stencils.h.new"
try:
with jit_stencils_new.open("w") as file:
file.write(digest)
if comment:
file.write(f"// {comment}\n\n")
file.write("")
for line in _writer.dump(stencil_groups):
file.write(f"{line}\n")
new_jit_stencils.replace(jit_stencils)
jit_stencils_new.replace(jit_stencils)
finally:
jit_stencils_new.unlink(True)


class _COFF(
Expand Down

0 comments on commit dc9404c

Please sign in to comment.