diff options
author | chriseth <chris@ethereum.org> | 2017-11-22 18:11:48 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-01-13 00:48:51 +0800 |
commit | 95cf9266abafc07bb4d7b33dff6932c191c36970 (patch) | |
tree | f3b1f16f930398d928c34a5a9c0be4a43d6599db /libevmasm | |
parent | 937b95cbe5bcef6c1324c380f37629e5a2a5811a (diff) | |
download | dexon-solidity-95cf9266abafc07bb4d7b33dff6932c191c36970.tar.gz dexon-solidity-95cf9266abafc07bb4d7b33dff6932c191c36970.tar.zst dexon-solidity-95cf9266abafc07bb4d7b33dff6932c191c36970.zip |
Movability.
Diffstat (limited to 'libevmasm')
-rw-r--r-- | libevmasm/SemanticInformation.cpp | 25 | ||||
-rw-r--r-- | libevmasm/SemanticInformation.h | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index 61a6ccda..4c2290c4 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -153,6 +153,31 @@ bool SemanticInformation::isDeterministic(AssemblyItem const& _item) } } +bool SemanticInformation::movable(Instruction _instruction) +{ + // These are not really functional. + if (isDupInstruction(_instruction) || isSwapInstruction(_instruction)) + return false; + InstructionInfo info = instructionInfo(_instruction); + if (info.sideEffects) + return false; + switch (_instruction) + { + case Instruction::KECCAK256: + case Instruction::BALANCE: + case Instruction::EXTCODESIZE: + case Instruction::RETURNDATASIZE: + case Instruction::SLOAD: + case Instruction::PC: + case Instruction::MSIZE: + case Instruction::GAS: + return false; + default: + return true; + } + return true; +} + bool SemanticInformation::invalidatesMemory(Instruction _instruction) { switch (_instruction) diff --git a/libevmasm/SemanticInformation.h b/libevmasm/SemanticInformation.h index e5ea7c18..83656252 100644 --- a/libevmasm/SemanticInformation.h +++ b/libevmasm/SemanticInformation.h @@ -49,6 +49,10 @@ struct SemanticInformation /// @returns false if the value put on the stack by _item depends on anything else than /// the information in the current block header, memory, storage or stack. static bool isDeterministic(AssemblyItem const& _item); + /// @returns true if the instruction can be moved or copied (together with its arguments) + /// without altering the semantics. This means it cannot depend on storage or memory, + /// cannot have any side-effects, but it can depend on a call-constant state of the blockchain. + static bool movable(solidity::Instruction _instruction); /// @returns true if the given instruction modifies memory. static bool invalidatesMemory(solidity::Instruction _instruction); /// @returns true if the given instruction modifies storage (even indirectly). |