66
77import _schema
88
9- # Number of 32-bit words needed to store the bit mask of external symbols
10- SYMBOL_MASK_SIZE : int = 4
11-
12- known_symbols : dict [str | None , int ] = {}
13-
149
1510@enum .unique
1611class HoleValue (enum .Enum ):
@@ -252,9 +247,14 @@ class StencilGroup:
252247 default_factory = dict , init = False
253248 )
254249 _got : dict [str , int ] = dataclasses .field (default_factory = dict , init = False )
255- trampolines : set [int ] = dataclasses .field (default_factory = set , init = False )
256-
257- def process_relocations (self , * , alignment : int = 1 ) -> None :
250+ _trampolines : set [int ] = dataclasses .field (default_factory = set , init = False )
251+
252+ def process_relocations (
253+ self ,
254+ known_symbols : dict [str | None , int ],
255+ * ,
256+ alignment : int = 1 ,
257+ ) -> None :
258258 """Fix up all GOT and internal relocations for this stencil group."""
259259 for hole in self .code .holes .copy ():
260260 if (
@@ -268,7 +268,7 @@ def process_relocations(self, *, alignment: int = 1) -> None:
268268 else :
269269 ordinal = len (known_symbols )
270270 known_symbols [hole .symbol ] = ordinal
271- self .trampolines .add (ordinal )
271+ self ._trampolines .add (ordinal )
272272 hole .addend = ordinal
273273 hole .symbol = None
274274 self .code .remove_jump (alignment = alignment )
@@ -328,18 +328,17 @@ def _emit_global_offset_table(self) -> None:
328328 def _get_trampoline_mask (self ) -> str :
329329 bitmask : int = 0
330330 trampoline_mask : list [str ] = []
331- for ordinal in self .trampolines :
331+ for ordinal in self ._trampolines :
332332 bitmask |= 1 << ordinal
333- if bitmask :
334- trampoline_mask = [
335- f"0x{ (bitmask >> i * 32 ) & ((1 << 32 ) - 1 ):x} "
336- for i in range (0 , SYMBOL_MASK_SIZE )
337- ]
338- return ", " .join (trampoline_mask )
333+ while bitmask :
334+ word = bitmask & ((1 << 32 ) - 1 )
335+ trampoline_mask .append (f"{ word :#04x} " )
336+ bitmask >>= 32
337+ return "{" + ", " .join (trampoline_mask ) + "}"
339338
340339 def as_c (self , opname : str ) -> str :
341340 """Dump this hole as a StencilGroup initializer."""
342- return f"{{emit_{ opname } , { len (self .code .body )} , { len (self .data .body )} , {{ { self ._get_trampoline_mask ()} } }}}"
341+ return f"{{emit_{ opname } , { len (self .code .body )} , { len (self .data .body )} , { self ._get_trampoline_mask ()} }}"
343342
344343
345344def symbol_to_value (symbol : str ) -> tuple [HoleValue , str | None ]:
0 commit comments