From 393615b23455003aeec5f1720c1f7d1bf486c14c Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 5 Jan 2024 23:28:07 +0100 Subject: [PATCH] ir: IRAssignable add helper property to give a sorted list of all uses (read or write) of the value --- compiler/ir.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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()