ir: track value reads and writes in every IRAction manipulating data

This commit is contained in:
Antoine Viallon 2024-01-05 23:27:19 +01:00
parent 6af9c367c6
commit 4469a94096
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -45,7 +45,7 @@ class IRAction(IRItem, abc.ABC):
class IRNop(IRAction): class IRNop(IRAction):
def __init__(self, location: SourceLocation): def __init__(self, location: SourceLocation):
super().__init__(location) super().__init__(location, reads=[], writes=[])
def codegen(self) -> str: def codegen(self) -> str:
return "NOP" return "NOP"
@ -79,7 +79,7 @@ class IRMove(IRAction):
@typecheck @typecheck
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue): def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
super().__init__(location) super().__init__(location, reads=[source], writes=[dest])
self.dest = dest self.dest = dest
self.source = source self.source = source
@ -92,13 +92,13 @@ class IRMove(IRAction):
class IRCall(IRAction): class IRCall(IRAction):
def __init__(self, location: SourceLocation, dest: IRAssignable, function: IRVariable, arguments: list[IRValue]): def __init__(self, location: SourceLocation, dest: IRAssignable, function: IRVariable, arguments: list[IRValue]):
super().__init__(location) super().__init__(location, reads=arguments, writes=[dest])
self.dest = dest self.dest = dest
self.function = function self.function = function
self.arguments = arguments self.arguments = arguments
def codegen(self) -> str: def codegen(self) -> str:
return f"CALL {self.function} -> {self.dest} : {', '.join(repr(arg) for arg in self.arguments)}" return f"CALL {self.function} -> {self.dest} : {', '.join(str(arg) for arg in self.arguments)}"
def destination(self) -> IRValue: def destination(self) -> IRValue:
return self.dest return self.dest
@ -169,7 +169,7 @@ class IRAdd(IRAction):
@typecheck @typecheck
def __init__(self, location: SourceLocation, dest: IRAssignable, *values: IRValue): def __init__(self, location: SourceLocation, dest: IRAssignable, *values: IRValue):
super().__init__(location) super().__init__(location, reads=list(values), writes=[dest])
assert all(isinstance(v, IRValue) for v in values) assert all(isinstance(v, IRValue) for v in values)
self.values = values self.values = values
@ -179,7 +179,7 @@ class IRAdd(IRAction):
return self.dest return self.dest
def codegen(self) -> str: def codegen(self) -> str:
values = [repr(value) for value in self.values] values = [str(value) for value in self.values]
return f"ADD {', '.join(values)} -> {self.dest}" return f"ADD {', '.join(values)} -> {self.dest}"
@ -187,7 +187,7 @@ class IRMul(IRAction):
@typecheck @typecheck
def __init__(self, location: SourceLocation, dest: IRAssignable, *values: IRValue): def __init__(self, location: SourceLocation, dest: IRAssignable, *values: IRValue):
super().__init__(location) super().__init__(location, reads=list(values), writes=[dest])
assert all(isinstance(v, IRValue) for v in values) assert all(isinstance(v, IRValue) for v in values)
self.values = values self.values = values
@ -197,7 +197,7 @@ class IRMul(IRAction):
return self.dest return self.dest
def codegen(self) -> str: def codegen(self) -> str:
values = [repr(value) for value in self.values] values = [str(value) for value in self.values]
return f"MUL {', '.join(values)} -> {self.dest}" return f"MUL {', '.join(values)} -> {self.dest}"
@ -205,7 +205,7 @@ class IRNegation(IRAction):
@typecheck @typecheck
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue): def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
super().__init__(location) super().__init__(location, reads=[source], writes=[dest])
self.source = source self.source = source
self.dest = dest self.dest = dest
@ -221,7 +221,7 @@ class IRInvert(IRAction):
@typecheck @typecheck
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue): def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
super().__init__(location) super().__init__(location, reads=[source], writes=[dest])
self.source = source self.source = source
self.dest = dest self.dest = dest