diff --git a/vyper/venom/basicblock.py b/vyper/venom/basicblock.py index 57c8a13a99..cf6c7f10a5 100644 --- a/vyper/venom/basicblock.py +++ b/vyper/venom/basicblock.py @@ -259,6 +259,12 @@ def is_pseudo(self) -> bool: """ return self.is_phi or self.is_param + def get_read_effects(self): + return effects.reads.get(self.opcode, effects.EMPTY) + + def get_write_effects(self): + return effects.writes.get(self.opcode, effects.EMPTY) + def get_label_operands(self) -> Iterator[IRLabel]: """ Get all labels in instruction. diff --git a/vyper/venom/effects.py b/vyper/venom/effects.py index 9198cbe16d..b018357898 100644 --- a/vyper/venom/effects.py +++ b/vyper/venom/effects.py @@ -1,48 +1,59 @@ -_ALL = ("storage", "transient", "memory", "immutables", "balance", "returndata") +from enum import Flag, auto -_writes = { - "sstore": "storage", - "tstore": "transient", - "mstore": "memory", - "istore": "immutables", - "call": _ALL, - "delegatecall": _ALL, - "staticcall": "memory", - "create": _ALL, - "create2": _ALL, - "invoke": _ALL, # could be smarter, look up the effects of the invoked function - "dloadbytes": "memory", - "returndatacopy": "memory", - "calldatacopy": "memory", - "codecopy": "memory", - "extcodecopy": "memory", - "mcopy": "memory", -} -_reads = { - "sload": "storage", - "tload": "transient", - "iload": "immutables", - "mload": "memory", - "mcopy": "memory", - "call": _ALL, - "delegatecall": _ALL, - "staticcall": _ALL, - "returndatasize": "returndata", - "returndatacopy": "returndata", - "balance": "balance", - "selfbalance": "balance", - "log": "memory", - "revert": "memory", - "return": "memory", - "sha3": "memory", -} + +class Effects(Flag): + STORAGE = auto() + TRANSIENT = auto() + MEMORY = auto() + IMMUTABLES = auto() + BALANCE = auto() + RETURNDATA = auto() -def _mktuple(x): - if not isinstance(x, tuple): - x = (x,) - return x +EMPTY = Effects(0) +ALL = ~EMPTY +STORAGE = Effects.STORAGE +TRANSIENT = Effects.TRANSIENT +MEMORY = Effects.MEMORY +IMMUTABLES = Effects.IMMUTABLES +BALANCE = Effects.BALANCE +RETURNDATA = Effects.RETURNDATA -writes = {k: _mktuple(v) for k, v in _writes.items()} -reads = {k: _mktuple(v) for k, v in _reads.items()} \ No newline at end of file +writes = { + "sstore": STORAGE, + "tstore": TRANSIENT, + "mstore": MEMORY, + "istore": IMMUTABLES, + "call": ALL, + "delegatecall": ALL, + "staticcall": MEMORY | RETURNDATA, + "create": ALL, + "create2": ALL, + "invoke": ALL, # could be smarter, look up the effects of the invoked function + "dloadbytes": MEMORY, + "returndatacopy": MEMORY, + "calldatacopy": MEMORY, + "codecopy": MEMORY, + "extcodecopy": MEMORY, + "mcopy": MEMORY, +} + +reads = { + "sload": STORAGE, + "tload": TRANSIENT, + "iload": IMMUTABLES, + "mload": MEMORY, + "mcopy": MEMORY, + "call": ALL, + "delegatecall": ALL, + "staticcall": ALL, + "returndatasize": RETURNDATA, + "returndatacopy": RETURNDATA, + "balance": BALANCE, + "selfbalance": BALANCE, + "log": MEMORY, + "revert": MEMORY, + "return": MEMORY, + "sha3": MEMORY, +}