ir: IRAssignable add helper property to give a sorted list of all uses (read or write) of the value

This commit is contained in:
Antoine Viallon 2024-01-05 23:28:07 +01:00
parent 4469a94096
commit 393615b234
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -128,6 +128,15 @@ class IRAssignable(IRValue, metaclass=abc.ABCMeta):
super().__init__(location) super().__init__(location)
self.writers: list[IRAction] = [] self.writers: list[IRAction] = []
@property
def sorted_users(self) -> list[IRAction]:
assert all((x.ir_location.line != -1 for x in self.readers))
assert all((x.ir_location.line != -1 for x in self.writers))
users = self.readers + self.writers
users.sort(key=lambda user: user.ir_location)
return users
def __str__(self): def __str__(self):
return self.codegen() return self.codegen()