diff --git a/compiler/ir.py b/compiler/ir.py index 6730a5b..711e4e0 100644 --- a/compiler/ir.py +++ b/compiler/ir.py @@ -128,6 +128,15 @@ class IRAssignable(IRValue, metaclass=abc.ABCMeta): super().__init__(location) 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): return self.codegen()