1717import _writer
1818
1919if sys .version_info < (3 , 11 ):
20- raise RuntimeError ("Building the JIT compiler requires Python 3.11 or newer!" )
20+ raise RuntimeError (
21+ "Building the JIT compiler requires Python 3.11 or newer!"
22+ )
2123
2224TOOLS_JIT_BUILD = pathlib .Path (__file__ ).resolve ()
2325TOOLS_JIT = TOOLS_JIT_BUILD .parent
2729TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
2830ASYNCIO_RUNNER = asyncio .Runner ()
2931
30- _S = typing .TypeVar ("_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection )
32+ _S = typing .TypeVar (
33+ "_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection
34+ )
3135_R = typing .TypeVar (
32- "_R" , _schema .COFFRelocation , _schema .ELFRelocation , _schema .MachORelocation
36+ "_R" ,
37+ _schema .COFFRelocation ,
38+ _schema .ELFRelocation ,
39+ _schema .MachORelocation ,
3340)
3441
3542
@@ -95,7 +102,9 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
95102 # ...and also COFF:
96103 output = output [output .index ("[" , 1 , None ) :]
97104 output = output [: output .rindex ("]" , None , - 1 ) + 1 ]
98- sections : list [dict [typing .Literal ["Section" ], _S ]] = json .loads (output )
105+ sections : list [dict [typing .Literal ["Section" ], _S ]] = json .loads (
106+ output
107+ )
99108 for wrapped_section in sections :
100109 self ._handle_section (wrapped_section ["Section" ], group )
101110 assert group .symbols ["_JIT_ENTRY" ] == (_stencils .HoleValue .CODE , 0 )
@@ -104,7 +113,9 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
104113 group .data .disassembly .append (line )
105114 return group
106115
107- def _handle_section (self , section : _S , group : _stencils .StencilGroup ) -> None :
116+ def _handle_section (
117+ self , section : _S , group : _stencils .StencilGroup
118+ ) -> None :
108119 raise NotImplementedError (type (self ))
109120
110121 def _handle_relocation (
@@ -160,7 +171,9 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
160171 generated_cases = PYTHON_EXECUTOR_CASES_C_H .read_text ()
161172 cases_and_opnames = sorted (
162173 re .findall (
163- r"\n {8}(case (\w+): \{\n.*?\n {8}\})" , generated_cases , flags = re .DOTALL
174+ r"\n {8}(case (\w+): \{\n.*?\n {8}\})" ,
175+ generated_cases ,
176+ flags = re .DOTALL ,
164177 )
165178 )
166179 tasks = []
@@ -200,7 +213,9 @@ def build(
200213 """Build jit_stencils.h in the given directory."""
201214 if not self .stable :
202215 warning = f"JIT support for { self .triple } is still experimental!"
203- request = "Please report any issues you encounter." .center (len (warning ))
216+ request = "Please report any issues you encounter." .center (
217+ len (warning )
218+ )
204219 outline = "=" * len (warning )
205220 print ("\n " .join (["" , outline , warning , request , outline , "" ]))
206221 digest = f"// { self ._compute_digest (out )} \n "
@@ -264,7 +279,9 @@ def _handle_section(
264279 hole = self ._handle_relocation (base , relocation , stencil .body )
265280 stencil .holes .append (hole )
266281
267- def _unwrap_dllimport (self , name : str ) -> tuple [_stencils .HoleValue , str | None ]:
282+ def _unwrap_dllimport (
283+ self , name : str
284+ ) -> tuple [_stencils .HoleValue , str | None ]:
268285 if name .startswith ("__imp_" ):
269286 name = name .removeprefix ("__imp_" )
270287 name = name .removeprefix (self .prefix )
@@ -291,13 +308,17 @@ def _handle_relocation(
291308 "Offset" : offset ,
292309 "Symbol" : s ,
293310 "Type" : {
294- "Name" : "IMAGE_REL_AMD64_REL32" | "IMAGE_REL_I386_REL32" as kind
311+ "Name" : "IMAGE_REL_AMD64_REL32"
312+ | "IMAGE_REL_I386_REL32" as kind
295313 },
296314 }:
297315 offset += base
298316 value , symbol = self ._unwrap_dllimport (s )
299317 addend = (
300- int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
318+ int .from_bytes (
319+ raw [offset : offset + 4 ], "little" , signed = True
320+ )
321+ - 4
301322 )
302323 case {
303324 "Offset" : offset ,
@@ -429,7 +450,12 @@ def _handle_section(
429450 base = section ["Address" ] - start_address
430451 group .symbols [section ["Index" ]] = value , base
431452 stencil .body .extend (
432- [0 ] * (section ["Address" ] - len (group .code .body ) - len (group .data .body ))
453+ [0 ]
454+ * (
455+ section ["Address" ]
456+ - len (group .code .body )
457+ - len (group .data .body )
458+ )
433459 )
434460 stencil .body .extend (section ["SectionData" ]["Bytes" ])
435461 assert "Symbols" in section
@@ -468,13 +494,19 @@ def _handle_relocation(
468494 case {
469495 "Offset" : offset ,
470496 "Symbol" : {"Name" : s },
471- "Type" : {"Name" : "X86_64_RELOC_GOT" | "X86_64_RELOC_GOT_LOAD" as kind },
497+ "Type" : {
498+ "Name" : "X86_64_RELOC_GOT"
499+ | "X86_64_RELOC_GOT_LOAD" as kind
500+ },
472501 }:
473502 offset += base
474503 s = s .removeprefix (self .prefix )
475504 value , symbol = _stencils .HoleValue .GOT , s
476505 addend = (
477- int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
506+ int .from_bytes (
507+ raw [offset : offset + 4 ], "little" , signed = True
508+ )
509+ - 4
478510 )
479511 case {
480512 "Offset" : offset ,
@@ -483,13 +515,19 @@ def _handle_relocation(
483515 } | {
484516 "Offset" : offset ,
485517 "Symbol" : {"Name" : s },
486- "Type" : {"Name" : "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind },
518+ "Type" : {
519+ "Name" : "X86_64_RELOC_BRANCH"
520+ | "X86_64_RELOC_SIGNED" as kind
521+ },
487522 }:
488523 offset += base
489524 s = s .removeprefix (self .prefix )
490525 value , symbol = _stencils .symbol_to_value (s )
491526 addend = (
492- int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
527+ int .from_bytes (
528+ raw [offset : offset + 4 ], "little" , signed = True
529+ )
530+ - 4
493531 )
494532 case {
495533 "Offset" : offset ,
0 commit comments