Merge pull request #4398 from rnaby/libevmasm/KnownState-125

As SWITCH..CASE is better than ELSE..IF
This commit is contained in:
chriseth 2018-07-02 13:00:59 +02:00 committed by GitHub
commit 8a4980c05e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,28 +121,33 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
vector<Id> arguments(info.args); vector<Id> arguments(info.args);
for (int i = 0; i < info.args; ++i) for (int i = 0; i < info.args; ++i)
arguments[i] = stackElement(m_stackHeight - i, _item.location()); arguments[i] = stackElement(m_stackHeight - i, _item.location());
switch (_item.instruction())
if (_item.instruction() == Instruction::SSTORE) {
case Instruction::SSTORE:
op = storeInStorage(arguments[0], arguments[1], _item.location()); op = storeInStorage(arguments[0], arguments[1], _item.location());
else if (_item.instruction() == Instruction::SLOAD) break;
case Instruction::SLOAD:
setStackElement( setStackElement(
m_stackHeight + _item.deposit(), m_stackHeight + _item.deposit(),
loadFromStorage(arguments[0], _item.location()) loadFromStorage(arguments[0], _item.location())
); );
else if (_item.instruction() == Instruction::MSTORE) break;
case Instruction::MSTORE:
op = storeInMemory(arguments[0], arguments[1], _item.location()); op = storeInMemory(arguments[0], arguments[1], _item.location());
else if (_item.instruction() == Instruction::MLOAD) break;
case Instruction::MLOAD:
setStackElement( setStackElement(
m_stackHeight + _item.deposit(), m_stackHeight + _item.deposit(),
loadFromMemory(arguments[0], _item.location()) loadFromMemory(arguments[0], _item.location())
); );
else if (_item.instruction() == Instruction::KECCAK256) break;
case Instruction::KECCAK256:
setStackElement( setStackElement(
m_stackHeight + _item.deposit(), m_stackHeight + _item.deposit(),
applyKeccak256(arguments.at(0), arguments.at(1), _item.location()) applyKeccak256(arguments.at(0), arguments.at(1), _item.location())
); );
else break;
{ default:
bool invMem = SemanticInformation::invalidatesMemory(_item.instruction()); bool invMem = SemanticInformation::invalidatesMemory(_item.instruction());
bool invStor = SemanticInformation::invalidatesStorage(_item.instruction()); bool invStor = SemanticInformation::invalidatesStorage(_item.instruction());
// We could be a bit more fine-grained here (CALL only invalidates part of // We could be a bit more fine-grained here (CALL only invalidates part of