mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Count instructions without metadata hash.
This commit is contained in:
parent
f1907bbb12
commit
5098e1eb15
@ -79,17 +79,13 @@ public:
|
|||||||
bytes nonOptimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, false);
|
bytes nonOptimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, false);
|
||||||
m_nonOptimizedContract = m_contractAddress;
|
m_nonOptimizedContract = m_contractAddress;
|
||||||
bytes optimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, true);
|
bytes optimizedBytecode = compileAndRunWithOptimizer(_sourceCode, _value, _contractName, true);
|
||||||
size_t nonOptimizedSize = 0;
|
size_t nonOptimizedSize = numInstructions(nonOptimizedBytecode);
|
||||||
solidity::eachInstruction(nonOptimizedBytecode, [&](Instruction, u256 const&) {
|
size_t optimizedSize = numInstructions(optimizedBytecode);
|
||||||
nonOptimizedSize++;
|
|
||||||
});
|
|
||||||
size_t optimizedSize = 0;
|
|
||||||
solidity::eachInstruction(optimizedBytecode, [&](Instruction, u256 const&) {
|
|
||||||
optimizedSize++;
|
|
||||||
});
|
|
||||||
BOOST_CHECK_MESSAGE(
|
BOOST_CHECK_MESSAGE(
|
||||||
nonOptimizedSize > optimizedSize,
|
optimizedSize < nonOptimizedSize,
|
||||||
"Optimizer did not reduce bytecode size."
|
string("Optimizer did not reduce bytecode size. Non-optimized size: ") +
|
||||||
|
std::to_string(nonOptimizedSize) + " - optimized size: " +
|
||||||
|
std::to_string(optimizedSize)
|
||||||
);
|
);
|
||||||
m_optimizedContract = m_contractAddress;
|
m_optimizedContract = m_contractAddress;
|
||||||
}
|
}
|
||||||
@ -173,6 +169,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// @returns the number of intructions in the given bytecode, not taking the metadata hash
|
||||||
|
/// into account.
|
||||||
|
size_t numInstructions(bytes const& _bytecode)
|
||||||
|
{
|
||||||
|
BOOST_REQUIRE(_bytecode.size() > 5);
|
||||||
|
size_t metadataSize = (_bytecode[_bytecode.size() - 2] << 8) + _bytecode[_bytecode.size() - 1];
|
||||||
|
BOOST_REQUIRE_MESSAGE(metadataSize == 0x29, "Invalid metadata size");
|
||||||
|
BOOST_REQUIRE(_bytecode.size() >= metadataSize + 2);
|
||||||
|
bytes realCode = bytes(_bytecode.begin(), _bytecode.end() - metadataSize - 2);
|
||||||
|
size_t instructions = 0;
|
||||||
|
solidity::eachInstruction(realCode, [&](Instruction, u256 const&) {
|
||||||
|
instructions++;
|
||||||
|
});
|
||||||
|
return instructions;
|
||||||
|
}
|
||||||
|
|
||||||
Address m_optimizedContract;
|
Address m_optimizedContract;
|
||||||
Address m_nonOptimizedContract;
|
Address m_nonOptimizedContract;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user