Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.rom.is_ram(pc):
return
if stack_trace is None:
stack_trace = []
# Assign a label to the subroutine (or retrieve the existing one).
preserved_label = self.preserved_labels.get(pc)
if preserved_label:
label = preserved_label
elif not label:
label = "sub_{:06X}".format(pc)
# Create and register subroutine (unless it exists already).
subroutine = self.subroutines.get(pc)
if subroutine is None:
subroutine = Subroutine(self, pc, label)
self.subroutines[pc] = subroutine
self.subroutines_by_label[label] = subroutine
subroutine.stack_traces.add(tuple(stack_trace) if stack_trace else ())
# Apply existing state change assertions.
state_changes = self.subroutine_assertions.get(pc, {})
for state_change in state_changes.items():
subroutine.assert_state_change(*state_change)
def _clear(self, preserve_labels=True) -> None:
# Preserve currently assigned labels.
if preserve_labels:
self._preserve_labels()
# Invalidate Subroutine and Instruction objects.
if hasattr(self, "subroutines"):
bulk_invalidate(self.subroutines.values())
# Clear all data structures.
self.local_labels: DefaultDict[int, Dict[str, int]] = defaultdict(bidict)
self.instructions: DefaultDict[int, Set[InstructionID]] = defaultdict(set)
self.subroutines: Dict[int, Subroutine] = SortedDict()
self.subroutines_by_label: Dict[str, Subroutine] = {}
self.references: DefaultDict[int, Set[Tuple[int, int]]] = defaultdict(set)
gc.collect()
# Add entry points.
for pc, entry in self.entry_points.items():
self.add_subroutine(pc, label=entry.name)
self.dirty = False