From 6af9c367c6d4440700b449619dfb746d836fa82c Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 5 Jan 2024 23:22:37 +0100 Subject: [PATCH] ir: automatically add read-from/written-to values in IRAction if declared --- compiler/ir.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/ir.py b/compiler/ir.py index 6035c61..a269d8f 100644 --- a/compiler/ir.py +++ b/compiler/ir.py @@ -5,7 +5,7 @@ from abc import abstractmethod from .errors import OverrideMandatoryError from .logger import Logger -from .source import SourceLocation +from .source import SourceLocation, IRLocation as Location from .typechecking import typecheck logger = Logger(__name__) @@ -28,7 +28,19 @@ class IRItem: class IRAction(IRItem, abc.ABC): - pass + def __init__(self, location: SourceLocation, reads: list[IRValue], writes: list[IRAssignable]): + super().__init__(location) + + # Must be changed updated in a second pass, when every item has been generated + self.ir_location: Location = Location(-1, []) + self.reads = reads + self.writes = writes + + for read in reads: + read.readers += [self] + + for write in writes: + write.writers += [self] class IRNop(IRAction):