From 27ccb1a68ae4c4b674aab0300f88d98a9dcba7bc Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 5 Jan 2024 23:13:45 +0100 Subject: [PATCH] ir: IRValue: track readers --- compiler/ir.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compiler/ir.py b/compiler/ir.py index 360f2b8..84a5c5d 100644 --- a/compiler/ir.py +++ b/compiler/ir.py @@ -43,9 +43,25 @@ class IRNop(IRAction): class IRValue(IRItem, abc.ABC): + values: list[IRValue] = [] + + def __init__(self, location: SourceLocation): + super().__init__(location) + self.readers: list[IRAction] = [] + IRValue.values += [self] + + def __del__(self): + IRValue.values.remove(self) + def destination(self) -> IRValue: return self + def __str__(self): + return self.codegen() + + def __repr__(self) -> str: + return f"{self.codegen()} (readers: {repr(self.readers)})" + class IRMove(IRAction):