MCPcopy Index your code
hub / github.com/python/cpython / Hole

Class Hole

Tools/jit/_stencils.py:149–197  ·  view source on GitHub ↗

A "hole" in the stencil to be patched with a computed runtime value. Analogous to relocation records in an object file.

Source from the content-addressed store, hash-verified

147
148@dataclasses.dataclass
149class Hole:
150 """
151 A "hole" in the stencil to be patched with a computed runtime value.
152
153 Analogous to relocation records in an object file.
154 """
155
156 offset: int
157 kind: _schema.HoleKind
158 # Patch with this base value:
159 value: HoleValue
160 # ...plus the address of this symbol:
161 symbol: str | None
162 # ...plus this addend:
163 addend: int
164 need_state: bool = False
165 custom_location: str = ""
166 custom_value: str = ""
167 func: str = dataclasses.field(init=False)
168 # Convenience method:
169 replace = dataclasses.replace
170
171 def __post_init__(self) -> None:
172 self.func = _PATCH_FUNCS[self.kind]
173
174 def as_c(self, where: str) -> str:
175 """Dump this hole as a call to a patch_* function."""
176 if self.custom_location:
177 location = self.custom_location
178 else:
179 location = f"{where} + {self.offset:#x}"
180 if self.custom_value:
181 value = self.custom_value
182 else:
183 value = _HOLE_EXPRS[self.value]
184 if self.symbol:
185 if value:
186 value += " + "
187 if self.symbol.startswith("CONST"):
188 value += f"instruction->{self.symbol[10:].lower()}"
189 else:
190 value += f"(uintptr_t)&{self.symbol}"
191 if _signed(self.addend) or not value:
192 if value:
193 value += " + "
194 value += f"{_signed(self.addend):#x}"
195 if self.need_state:
196 return f"{self.func}({location}, {value}, state);"
197 return f"{self.func}({location}, {value});"
198
199
200@dataclasses.dataclass

Callers 3

Calls 1

fieldMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…