C++ namespace cleanup (except tests).

This commit is contained in:
Christian Parpart
2020-01-07 15:51:50 +01:00
committed by Daniel Kirchner
parent 8385256bdc
commit 6b23412fae
403 changed files with 1656 additions and 1926 deletions
+3 -3
View File
@@ -148,9 +148,9 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
evmc_message message = _message;
if (message.depth == 0)
{
message.gas -= message.kind == EVMC_CREATE ? eth::GasCosts::txCreateGas : eth::GasCosts::txGas;
message.gas -= message.kind == EVMC_CREATE ? evmasm::GasCosts::txCreateGas : evmasm::GasCosts::txGas;
for (size_t i = 0; i < message.input_size; ++i)
message.gas -= message.input_data[i] == 0 ? eth::GasCosts::txDataZeroGas : eth::GasCosts::txDataNonZeroGas(m_evmVersion);
message.gas -= message.input_data[i] == 0 ? evmasm::GasCosts::txDataZeroGas : evmasm::GasCosts::txDataNonZeroGas(m_evmVersion);
if (message.gas < 0)
{
evmc::result result({});
@@ -200,7 +200,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
if (message.kind == EVMC_CREATE)
{
result.gas_left -= eth::GasCosts::createDataGas * result.output_size;
result.gas_left -= evmasm::GasCosts::createDataGas * result.output_size;
if (result.gas_left < 0)
{
result.gas_left = 0;
+1 -1
View File
@@ -42,7 +42,7 @@ namespace test
namespace
{
void checkCompilation(::dev::eth::Assembly const& _assembly)
void checkCompilation(::evmasm::Assembly const& _assembly)
{
LinkerObject output = _assembly.assemble();
BOOST_CHECK(output.bytecode.size() > 0);
+10 -10
View File
@@ -57,20 +57,20 @@ namespace
return input;
}
eth::KnownState createInitialState(AssemblyItems const& _input)
evmasm::KnownState createInitialState(AssemblyItems const& _input)
{
eth::KnownState state;
evmasm::KnownState state;
for (auto const& item: addDummyLocations(_input))
state.feedItem(item, true);
return state;
}
AssemblyItems CSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState())
AssemblyItems CSE(AssemblyItems const& _input, evmasm::KnownState const& _state = evmasm::KnownState())
{
AssemblyItems input = addDummyLocations(_input);
bool usesMsize = (find(_input.begin(), _input.end(), AssemblyItem{Instruction::MSIZE}) != _input.end());
eth::CommonSubexpressionEliminator cse(_state);
evmasm::CommonSubexpressionEliminator cse(_state);
BOOST_REQUIRE(cse.feedItems(input.begin(), input.end(), usesMsize) == input.end());
AssemblyItems output = cse.getOptimizedItems();
@@ -84,7 +84,7 @@ namespace
void checkCSE(
AssemblyItems const& _input,
AssemblyItems const& _expectation,
KnownState const& _state = eth::KnownState()
KnownState const& _state = evmasm::KnownState()
)
{
AssemblyItems output = CSE(_input, _state);
@@ -118,8 +118,8 @@ BOOST_AUTO_TEST_SUITE(Optimiser)
BOOST_AUTO_TEST_CASE(cse_intermediate_swap)
{
eth::KnownState state;
eth::CommonSubexpressionEliminator cse(state);
evmasm::KnownState state;
evmasm::CommonSubexpressionEliminator cse(state);
AssemblyItems input{
Instruction::SWAP1, Instruction::POP, Instruction::ADD, u256(0), Instruction::SWAP1,
Instruction::SLOAD, Instruction::SWAP1, u256(100), Instruction::EXP, Instruction::SWAP1,
@@ -651,7 +651,7 @@ BOOST_AUTO_TEST_CASE(cse_keccak256_twice_same_content_noninterfering_store_in_be
BOOST_AUTO_TEST_CASE(cse_with_initially_known_stack)
{
eth::KnownState state = createInitialState(AssemblyItems{
evmasm::KnownState state = createInitialState(AssemblyItems{
u256(0x12),
u256(0x20),
Instruction::ADD
@@ -664,7 +664,7 @@ BOOST_AUTO_TEST_CASE(cse_with_initially_known_stack)
BOOST_AUTO_TEST_CASE(cse_equality_on_initially_known_stack)
{
eth::KnownState state = createInitialState(AssemblyItems{Instruction::DUP1});
evmasm::KnownState state = createInitialState(AssemblyItems{Instruction::DUP1});
AssemblyItems input{
Instruction::EQ
};
@@ -677,7 +677,7 @@ BOOST_AUTO_TEST_CASE(cse_access_previous_sequence)
{
// Tests that the code generator detects whether it tries to access SLOAD instructions
// from a sequenced expression which is not in its scope.
eth::KnownState state = createInitialState(AssemblyItems{
evmasm::KnownState state = createInitialState(AssemblyItems{
u256(0),
Instruction::SLOAD,
u256(1),
+1 -1
View File
@@ -53,7 +53,7 @@ namespace test
namespace
{
eth::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
{
ErrorList errors;
ErrorReporter errorReporter(errors);
+1 -1
View File
@@ -122,7 +122,7 @@ public:
}
protected:
map<ASTNode const*, eth::GasMeter::GasConsumption> m_gasCosts;
map<ASTNode const*, evmasm::GasMeter::GasConsumption> m_gasCosts;
};
BOOST_FIXTURE_TEST_SUITE(GasMeterTests, GasMeterTestFramework)
@@ -59,7 +59,7 @@ bytes SolidityExecutionFramework::compileContract(
formatter.printErrorInformation(*error);
BOOST_ERROR("Compiling contract failed");
}
eth::LinkerObject obj;
evmasm::LinkerObject obj;
if (m_compileViaYul)
{
yul::AssemblyStack asmStack(
@@ -164,7 +164,7 @@ bytes compileFirstExpression(
));
bytes instructions = context.assembledObject().bytecode;
// debug
// cout << eth::disassemble(instructions) << endl;
// cout << evmasm::disassemble(instructions) << endl;
return instructions;
}
BOOST_FAIL("No contract found in source.");
+1 -1
View File
@@ -109,7 +109,7 @@ public:
bytes realCode = bytecodeSansMetadata(_bytecode);
BOOST_REQUIRE_MESSAGE(!realCode.empty(), "Invalid or missing metadata in bytecode.");
size_t instructions = 0;
dev::eth::eachInstruction(realCode, [&](Instruction _instr, u256 const&) {
evmasm::eachInstruction(realCode, [&](Instruction _instr, u256 const&) {
if (!_which || *_which == _instr)
instructions++;
});
+1 -1
View File
@@ -82,7 +82,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
"Bytecode: " +
toHex(obj.bytecode->bytecode) +
"\nOpcodes: " +
boost::trim_copy(dev::eth::disassemble(obj.bytecode->bytecode)) +
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode)) +
"\n";
if (m_expectation != m_obtainedResult)
+1 -1
View File
@@ -39,7 +39,7 @@ string assemble(string const& _input)
settings.optimizeStackAllocation = true;
AssemblyStack asmStack(langutil::EVMVersion{}, AssemblyStack::Language::StrictAssembly, settings);
BOOST_REQUIRE_MESSAGE(asmStack.parseAndAnalyze("", _input), "Source did not parse: " + _input);
return dev::eth::disassemble(asmStack.assemble(AssemblyStack::Machine::EVM).bytecode->bytecode);
return evmasm::disassemble(asmStack.assemble(AssemblyStack::Machine::EVM).bytecode->bytecode);
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ dev::bytes SolidityCompilationFramework::compileContract(
);
std::cerr << "Compiling contract failed" << std::endl;
}
dev::eth::LinkerObject obj = m_compiler.object(
evmasm::LinkerObject obj = m_compiler.object(
_contractName.empty() ?
m_compiler.lastContractName() :
_contractName
+1 -1
View File
@@ -124,7 +124,7 @@ DEFINE_PROTO_FUZZER(Contract const& _input)
hexEncodedInput = methodIdentifiers["test()"].asString();
}
// Ignore stack too deep errors during compilation
catch (eth::StackTooDeepException const&)
catch (evmasm::StackTooDeepException const&)
{
return;
}
@@ -77,12 +77,12 @@ void copyZeroExtended(
using u512 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<512, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
u256 EVMInstructionInterpreter::eval(
dev::eth::Instruction _instruction,
evmasm::Instruction _instruction,
vector<u256> const& _arguments
)
{
using namespace dev::eth;
using dev::eth::Instruction;
using evmasm::Instruction;
auto info = instructionInfo(_instruction);
yulAssert(size_t(info.args) == _arguments.size(), "");
@@ -484,9 +484,9 @@ void EVMInstructionInterpreter::writeMemoryWord(u256 const& _offset, u256 const&
}
void EVMInstructionInterpreter::logTrace(dev::eth::Instruction _instruction, std::vector<u256> const& _arguments, bytes const& _data)
void EVMInstructionInterpreter::logTrace(evmasm::Instruction _instruction, std::vector<u256> const& _arguments, bytes const& _data)
{
logTrace(dev::eth::instructionInfo(_instruction).name, _arguments, _data);
logTrace(evmasm::instructionInfo(_instruction).name, _arguments, _data);
}
void EVMInstructionInterpreter::logTrace(std::string const& _pseudoInstruction, std::vector<u256> const& _arguments, bytes const& _data)
@@ -26,13 +26,10 @@
#include <vector>
namespace dev
{
namespace eth
namespace solidity::evmasm
{
enum class Instruction: uint8_t;
}
}
namespace yul
{
@@ -70,7 +67,7 @@ public:
m_state(_state)
{}
/// Evaluate instruction
dev::u256 eval(dev::eth::Instruction _instruction, std::vector<dev::u256> const& _arguments);
dev::u256 eval(evmasm::Instruction _instruction, std::vector<dev::u256> const& _arguments);
/// Evaluate builtin function
dev::u256 evalBuiltin(BuiltinFunctionForEVM const& _fun, std::vector<dev::u256> const& _arguments);
@@ -89,7 +86,7 @@ private:
/// Does not adjust msize, use @a accessMemory for that
void writeMemoryWord(dev::u256 const& _offset, dev::u256 const& _value);
void logTrace(dev::eth::Instruction _instruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});
void logTrace(evmasm::Instruction _instruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});
/// Appends a log to the trace representing an instruction or similar operation by string,
/// with arguments and auxiliary data (if nonempty).
void logTrace(std::string const& _pseudoInstruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});
@@ -95,7 +95,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
return {};
else if (_fun == "unreachable"_yulstring)
{
logTrace(eth::Instruction::INVALID, {});
logTrace(evmasm::Instruction::INVALID, {});
throw ExplicitlyTerminated();
}
else if (_fun == "i64.add"_yulstring)
@@ -188,7 +188,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
{
// TODO read args from memory
// TODO use readAddress to read address.
logTrace(eth::Instruction::CALL, {});
logTrace(evmasm::Instruction::CALL, {});
return arg[0] & 1;
}
else if (_fun == "eth.callDataCopy"_yulstring)
@@ -208,21 +208,21 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
{
// TODO read args from memory
// TODO use readAddress to read address.
logTrace(eth::Instruction::CALLCODE, {});
logTrace(evmasm::Instruction::CALLCODE, {});
return arg[0] & 1;
}
else if (_fun == "eth.callDelegate"_yulstring)
{
// TODO read args from memory
// TODO use readAddress to read address.
logTrace(eth::Instruction::DELEGATECALL, {});
logTrace(evmasm::Instruction::DELEGATECALL, {});
return arg[0] & 1;
}
else if (_fun == "eth.callStatic"_yulstring)
{
// TODO read args from memory
// TODO use readAddress to read address.
logTrace(eth::Instruction::STATICCALL, {});
logTrace(evmasm::Instruction::STATICCALL, {});
return arg[0] & 1;
}
else if (_fun == "eth.storageStore"_yulstring)
@@ -266,7 +266,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
{
// TODO access memory
// TODO use writeAddress to store resulting address
logTrace(eth::Instruction::CREATE, {});
logTrace(evmasm::Instruction::CREATE, {});
return 0xcccccc + arg[1];
}
else if (_fun == "eth.getBlockDifficulty"_yulstring)
@@ -302,7 +302,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
uint64_t numberOfTopics = arg[2];
if (numberOfTopics > 4)
throw ExplicitlyTerminated();
logTrace(eth::logInstruction(numberOfTopics), {});
logTrace(evmasm::logInstruction(numberOfTopics), {});
return 0;
}
else if (_fun == "eth.getBlockNumber"_yulstring)
@@ -317,7 +317,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
bytes data;
if (accessMemory(arg[0], arg[1]))
data = readMemory(arg[0], arg[1]);
logTrace(eth::Instruction::RETURN, {}, data);
logTrace(evmasm::Instruction::RETURN, {}, data);
throw ExplicitlyTerminated();
}
else if (_fun == "eth.revert"_yulstring)
@@ -325,7 +325,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
bytes data;
if (accessMemory(arg[0], arg[1]))
data = readMemory(arg[0], arg[1]);
logTrace(eth::Instruction::REVERT, {}, data);
logTrace(evmasm::Instruction::REVERT, {}, data);
throw ExplicitlyTerminated();
}
else if (_fun == "eth.getReturnDataSize"_yulstring)
@@ -344,7 +344,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
else if (_fun == "eth.selfDestruct"_yulstring)
{
// TODO use readAddress to read address.
logTrace(eth::Instruction::SELFDESTRUCT, {});
logTrace(evmasm::Instruction::SELFDESTRUCT, {});
throw ExplicitlyTerminated();
}
else if (_fun == "eth.getBlockTimestamp"_yulstring)
@@ -417,9 +417,9 @@ u256 EwasmBuiltinInterpreter::readU256(uint64_t _offset, size_t _croppedTo)
return value;
}
void EwasmBuiltinInterpreter::logTrace(dev::eth::Instruction _instruction, std::vector<u256> const& _arguments, bytes const& _data)
void EwasmBuiltinInterpreter::logTrace(evmasm::Instruction _instruction, std::vector<u256> const& _arguments, bytes const& _data)
{
logTrace(dev::eth::instructionInfo(_instruction).name, _arguments, _data);
logTrace(evmasm::instructionInfo(_instruction).name, _arguments, _data);
}
void EwasmBuiltinInterpreter::logTrace(std::string const& _pseudoInstruction, std::vector<u256> const& _arguments, bytes const& _data)
@@ -99,7 +99,7 @@ private:
dev::u256 readU128(uint64_t _offset) { return readU256(_offset, 16); }
dev::u256 readAddress(uint64_t _offset) { return readU256(_offset, 20); }
void logTrace(dev::eth::Instruction _instruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});
void logTrace(evmasm::Instruction _instruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});
/// Appends a log to the trace representing an instruction or similar operation by string,
/// with arguments and auxiliary data (if nonempty).
void logTrace(std::string const& _pseudoInstruction, std::vector<dev::u256> const& _arguments = {}, dev::bytes const& _data = {});