1717import _writer
1818
1919if sys .version_info < (3 , 11 ):
20- raise RuntimeError (
21- "Building the JIT compiler requires Python 3.11 or newer!"
22- )
20+ raise RuntimeError ("Building the JIT compiler requires Python 3.11 or newer!" )
2321
2422TOOLS_JIT_BUILD = pathlib .Path (__file__ ).resolve ()
2523TOOLS_JIT = TOOLS_JIT_BUILD .parent
2927TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
3028ASYNCIO_RUNNER = asyncio .Runner ()
3129
32- _S = typing .TypeVar (
33- "_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection
34- )
30+ _S = typing .TypeVar ("_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection )
3531_R = typing .TypeVar (
36- "_R" ,
37- _schema .COFFRelocation ,
38- _schema .ELFRelocation ,
39- _schema .MachORelocation ,
32+ "_R" , _schema .COFFRelocation , _schema .ELFRelocation , _schema .MachORelocation
4033)
4134
4235
@@ -102,9 +95,7 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
10295 # ...and also COFF:
10396 output = output [output .index ("[" , 1 , None ) :]
10497 output = output [: output .rindex ("]" , None , - 1 ) + 1 ]
105- sections : list [dict [typing .Literal ["Section" ], _S ]] = json .loads (
106- output
107- )
98+ sections : list [dict [typing .Literal ["Section" ], _S ]] = json .loads (output )
10899 for wrapped_section in sections :
109100 self ._handle_section (wrapped_section ["Section" ], group )
110101 assert group .symbols ["_JIT_ENTRY" ] == (_stencils .HoleValue .CODE , 0 )
@@ -113,9 +104,7 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
113104 group .data .disassembly .append (line )
114105 return group
115106
116- def _handle_section (
117- self , section : _S , group : _stencils .StencilGroup
118- ) -> None :
107+ def _handle_section (self , section : _S , group : _stencils .StencilGroup ) -> None :
119108 raise NotImplementedError (type (self ))
120109
121110 def _handle_relocation (
@@ -171,9 +160,7 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
171160 generated_cases = PYTHON_EXECUTOR_CASES_C_H .read_text ()
172161 cases_and_opnames = sorted (
173162 re .findall (
174- r"\n {8}(case (\w+): \{\n.*?\n {8}\})" ,
175- generated_cases ,
176- flags = re .DOTALL ,
163+ r"\n {8}(case (\w+): \{\n.*?\n {8}\})" , generated_cases , flags = re .DOTALL
177164 )
178165 )
179166 tasks = []
@@ -213,9 +200,7 @@ def build(
213200 """Build jit_stencils.h in the given directory."""
214201 if not self .stable :
215202 warning = f"JIT support for { self .triple } is still experimental!"
216- request = "Please report any issues you encounter." .center (
217- len (warning )
218- )
203+ request = "Please report any issues you encounter." .center (len (warning ))
219204 outline = "=" * len (warning )
220205 print ("\n " .join (["" , outline , warning , request , outline , "" ]))
221206 digest = f"// { self ._compute_digest (out )} \n "
@@ -279,9 +264,7 @@ def _handle_section(
279264 hole = self ._handle_relocation (base , relocation , stencil .body )
280265 stencil .holes .append (hole )
281266
282- def _unwrap_dllimport (
283- self , name : str
284- ) -> tuple [_stencils .HoleValue , str | None ]:
267+ def _unwrap_dllimport (self , name : str ) -> tuple [_stencils .HoleValue , str | None ]:
285268 if name .startswith ("__imp_" ):
286269 name = name .removeprefix ("__imp_" )
287270 name = name .removeprefix (self .prefix )
@@ -308,17 +291,13 @@ def _handle_relocation(
308291 "Offset" : offset ,
309292 "Symbol" : s ,
310293 "Type" : {
311- "Name" : "IMAGE_REL_AMD64_REL32"
312- | "IMAGE_REL_I386_REL32" as kind
294+ "Name" : "IMAGE_REL_AMD64_REL32" | "IMAGE_REL_I386_REL32" as kind
313295 },
314296 }:
315297 offset += base
316298 value , symbol = self ._unwrap_dllimport (s )
317299 addend = (
318- int .from_bytes (
319- raw [offset : offset + 4 ], "little" , signed = True
320- )
321- - 4
300+ int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
322301 )
323302 case {
324303 "Offset" : offset ,
@@ -450,12 +429,7 @@ def _handle_section(
450429 base = section ["Address" ] - start_address
451430 group .symbols [section ["Index" ]] = value , base
452431 stencil .body .extend (
453- [0 ]
454- * (
455- section ["Address" ]
456- - len (group .code .body )
457- - len (group .data .body )
458- )
432+ [0 ] * (section ["Address" ] - len (group .code .body ) - len (group .data .body ))
459433 )
460434 stencil .body .extend (section ["SectionData" ]["Bytes" ])
461435 assert "Symbols" in section
@@ -494,19 +468,13 @@ def _handle_relocation(
494468 case {
495469 "Offset" : offset ,
496470 "Symbol" : {"Name" : s },
497- "Type" : {
498- "Name" : "X86_64_RELOC_GOT"
499- | "X86_64_RELOC_GOT_LOAD" as kind
500- },
471+ "Type" : {"Name" : "X86_64_RELOC_GOT" | "X86_64_RELOC_GOT_LOAD" as kind },
501472 }:
502473 offset += base
503474 s = s .removeprefix (self .prefix )
504475 value , symbol = _stencils .HoleValue .GOT , s
505476 addend = (
506- int .from_bytes (
507- raw [offset : offset + 4 ], "little" , signed = True
508- )
509- - 4
477+ int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
510478 )
511479 case {
512480 "Offset" : offset ,
@@ -515,19 +483,13 @@ def _handle_relocation(
515483 } | {
516484 "Offset" : offset ,
517485 "Symbol" : {"Name" : s },
518- "Type" : {
519- "Name" : "X86_64_RELOC_BRANCH"
520- | "X86_64_RELOC_SIGNED" as kind
521- },
486+ "Type" : {"Name" : "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind },
522487 }:
523488 offset += base
524489 s = s .removeprefix (self .prefix )
525490 value , symbol = _stencils .symbol_to_value (s )
526491 addend = (
527- int .from_bytes (
528- raw [offset : offset + 4 ], "little" , signed = True
529- )
530- - 4
492+ int .from_bytes (raw [offset : offset + 4 ], "little" , signed = True ) - 4
531493 )
532494 case {
533495 "Offset" : offset ,
0 commit comments