ir: track value reads and writes in every IRAction manipulating data
This commit is contained in:
parent
6af9c367c6
commit
4469a94096
1 changed files with 10 additions and 10 deletions
|
|
@ -45,7 +45,7 @@ class IRAction(IRItem, abc.ABC):
|
|||
|
||||
class IRNop(IRAction):
|
||||
def __init__(self, location: SourceLocation):
|
||||
super().__init__(location)
|
||||
super().__init__(location, reads=[], writes=[])
|
||||
|
||||
def codegen(self) -> str:
|
||||
return "NOP"
|
||||
|
|
@ -79,7 +79,7 @@ class IRMove(IRAction):
|
|||
|
||||
@typecheck
|
||||
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
|
||||
super().__init__(location)
|
||||
super().__init__(location, reads=[source], writes=[dest])
|
||||
self.dest = dest
|
||||
self.source = source
|
||||
|
||||
|
|
@ -92,13 +92,13 @@ class IRMove(IRAction):
|
|||
|
||||
class IRCall(IRAction):
|
||||
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.function = function
|
||||
self.arguments = arguments
|
||||
|
||||
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:
|
||||
return self.dest
|
||||
|
|
@ -169,7 +169,7 @@ class IRAdd(IRAction):
|
|||
|
||||
@typecheck
|
||||
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)
|
||||
|
||||
self.values = values
|
||||
|
|
@ -179,7 +179,7 @@ class IRAdd(IRAction):
|
|||
return self.dest
|
||||
|
||||
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}"
|
||||
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ class IRMul(IRAction):
|
|||
|
||||
@typecheck
|
||||
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)
|
||||
|
||||
self.values = values
|
||||
|
|
@ -197,7 +197,7 @@ class IRMul(IRAction):
|
|||
return self.dest
|
||||
|
||||
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}"
|
||||
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ class IRNegation(IRAction):
|
|||
|
||||
@typecheck
|
||||
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
|
||||
super().__init__(location)
|
||||
super().__init__(location, reads=[source], writes=[dest])
|
||||
|
||||
self.source = source
|
||||
self.dest = dest
|
||||
|
|
@ -221,7 +221,7 @@ class IRInvert(IRAction):
|
|||
|
||||
@typecheck
|
||||
def __init__(self, location: SourceLocation, dest: IRAssignable, source: IRValue):
|
||||
super().__init__(location)
|
||||
super().__init__(location, reads=[source], writes=[dest])
|
||||
|
||||
self.source = source
|
||||
self.dest = dest
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue