Remove "using namespace" from header and move Instruction to dev::eth.

This commit is contained in:
chriseth
2019-03-28 13:48:11 +01:00
parent 77b8b4874d
commit 2308904f68
66 changed files with 190 additions and 220 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ struct SourceLocation;
namespace dev
{
namespace solidity
namespace eth
{
enum class Instruction: uint8_t;
}
@@ -63,7 +63,7 @@ public:
/// at the beginning.
virtual int stackHeight() const = 0;
/// Append an EVM instruction.
virtual void appendInstruction(dev::solidity::Instruction _instruction) = 0;
virtual void appendInstruction(dev::eth::Instruction _instruction) = 0;
/// Append a constant.
virtual void appendConstant(dev::u256 const& _constant) = 0;
/// Append a label.
+3 -3
View File
@@ -57,7 +57,7 @@ int EthAssemblyAdapter::stackHeight() const
return m_assembly.deposit();
}
void EthAssemblyAdapter::appendInstruction(solidity::Instruction _instruction)
void EthAssemblyAdapter::appendInstruction(dev::eth::Instruction _instruction)
{
m_assembly.append(_instruction);
}
@@ -94,7 +94,7 @@ void EthAssemblyAdapter::appendLinkerSymbol(std::string const& _linkerSymbol)
void EthAssemblyAdapter::appendJump(int _stackDiffAfter)
{
appendInstruction(solidity::Instruction::JUMP);
appendInstruction(dev::eth::Instruction::JUMP);
m_assembly.adjustDeposit(_stackDiffAfter);
}
@@ -107,7 +107,7 @@ void EthAssemblyAdapter::appendJumpTo(LabelID _labelId, int _stackDiffAfter)
void EthAssemblyAdapter::appendJumpToIf(LabelID _labelId)
{
appendLabelReference(_labelId);
appendInstruction(solidity::Instruction::JUMPI);
appendInstruction(dev::eth::Instruction::JUMPI);
}
void EthAssemblyAdapter::appendBeginsub(LabelID, int)
+1 -1
View File
@@ -44,7 +44,7 @@ public:
explicit EthAssemblyAdapter(dev::eth::Assembly& _assembly);
void setSourceLocation(langutil::SourceLocation const& _location) override;
int stackHeight() const override;
void appendInstruction(dev::solidity::Instruction _instruction) override;
void appendInstruction(dev::eth::Instruction _instruction) override;
void appendConstant(dev::u256 const& _constant) override;
void appendLabel(LabelID _labelId) override;
void appendLabelReference(LabelID _labelId) override;
+14 -13
View File
@@ -26,6 +26,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace langutil;
using namespace yul;
@@ -43,23 +44,23 @@ void EVMAssembly::setSourceLocation(SourceLocation const&)
// Ignored for now;
}
void EVMAssembly::appendInstruction(solidity::Instruction _instr)
void EVMAssembly::appendInstruction(dev::eth::Instruction _instr)
{
m_bytecode.push_back(uint8_t(_instr));
m_stackHeight += solidity::instructionInfo(_instr).ret - solidity::instructionInfo(_instr).args;
m_stackHeight += instructionInfo(_instr).ret - instructionInfo(_instr).args;
}
void EVMAssembly::appendConstant(u256 const& _constant)
{
bytes data = toCompactBigEndian(_constant, 1);
appendInstruction(solidity::pushInstruction(data.size()));
appendInstruction(pushInstruction(data.size()));
m_bytecode += data;
}
void EVMAssembly::appendLabel(LabelID _labelId)
{
setLabelToCurrentPosition(_labelId);
appendInstruction(solidity::Instruction::JUMPDEST);
appendInstruction(dev::eth::Instruction::JUMPDEST);
}
void EVMAssembly::appendLabelReference(LabelID _labelId)
@@ -67,7 +68,7 @@ void EVMAssembly::appendLabelReference(LabelID _labelId)
solAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
// @TODO we now always use labelReferenceSize for all labels, it could be shortened
// for some of them.
appendInstruction(solidity::pushInstruction(labelReferenceSize));
appendInstruction(dev::eth::pushInstruction(labelReferenceSize));
m_labelReferences[m_bytecode.size()] = _labelId;
m_bytecode += bytes(labelReferenceSize);
}
@@ -94,7 +95,7 @@ void EVMAssembly::appendLinkerSymbol(string const&)
void EVMAssembly::appendJump(int _stackDiffAfter)
{
solAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(solidity::Instruction::JUMP);
appendInstruction(dev::eth::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
@@ -102,7 +103,7 @@ void EVMAssembly::appendJumpTo(LabelID _labelId, int _stackDiffAfter)
{
if (m_evm15)
{
m_bytecode.push_back(uint8_t(solidity::Instruction::JUMPTO));
m_bytecode.push_back(uint8_t(dev::eth::Instruction::JUMPTO));
appendLabelReferenceInternal(_labelId);
m_stackHeight += _stackDiffAfter;
}
@@ -117,14 +118,14 @@ void EVMAssembly::appendJumpToIf(LabelID _labelId)
{
if (m_evm15)
{
m_bytecode.push_back(uint8_t(solidity::Instruction::JUMPIF));
m_bytecode.push_back(uint8_t(dev::eth::Instruction::JUMPIF));
appendLabelReferenceInternal(_labelId);
m_stackHeight--;
}
else
{
appendLabelReference(_labelId);
appendInstruction(solidity::Instruction::JUMPI);
appendInstruction(dev::eth::Instruction::JUMPI);
}
}
@@ -133,7 +134,7 @@ void EVMAssembly::appendBeginsub(LabelID _labelId, int _arguments)
solAssert(m_evm15, "BEGINSUB used for EVM 1.0");
solAssert(_arguments >= 0, "");
setLabelToCurrentPosition(_labelId);
m_bytecode.push_back(uint8_t(solidity::Instruction::BEGINSUB));
m_bytecode.push_back(uint8_t(dev::eth::Instruction::BEGINSUB));
m_stackHeight += _arguments;
}
@@ -141,7 +142,7 @@ void EVMAssembly::appendJumpsub(LabelID _labelId, int _arguments, int _returns)
{
solAssert(m_evm15, "JUMPSUB used for EVM 1.0");
solAssert(_arguments >= 0 && _returns >= 0, "");
m_bytecode.push_back(uint8_t(solidity::Instruction::JUMPSUB));
m_bytecode.push_back(uint8_t(dev::eth::Instruction::JUMPSUB));
appendLabelReferenceInternal(_labelId);
m_stackHeight += _returns - _arguments;
}
@@ -150,7 +151,7 @@ void EVMAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
solAssert(m_evm15, "RETURNSUB used for EVM 1.0");
solAssert(_returns >= 0, "");
m_bytecode.push_back(uint8_t(solidity::Instruction::RETURNSUB));
m_bytecode.push_back(uint8_t(dev::eth::Instruction::RETURNSUB));
m_stackHeight += _stackDiffAfter - _returns;
}
@@ -189,7 +190,7 @@ void EVMAssembly::appendLabelReferenceInternal(LabelID _labelId)
void EVMAssembly::appendAssemblySize()
{
appendInstruction(solidity::pushInstruction(assemblySizeReferenceSize));
appendInstruction(dev::eth::pushInstruction(assemblySizeReferenceSize));
m_assemblySizePositions.push_back(m_bytecode.size());
m_bytecode += bytes(assemblySizeReferenceSize);
}
+1 -1
View File
@@ -46,7 +46,7 @@ public:
/// at the beginning.
int stackHeight() const override { return m_stackHeight; }
/// Append an EVM instruction.
void appendInstruction(dev::solidity::Instruction _instruction) override;
void appendInstruction(dev::eth::Instruction _instruction) override;
/// Append a constant.
void appendConstant(dev::u256 const& _constant) override;
/// Append a label.
+22 -23
View File
@@ -32,7 +32,6 @@
using namespace std;
using namespace dev;
using namespace yul;
using namespace dev::solidity;
void VariableReferenceCounter::operator()(Identifier const& _identifier)
{
@@ -155,7 +154,7 @@ void CodeTransform::freeUnusedVariables()
while (m_unusedStackSlots.count(m_assembly.stackHeight() - 1))
{
solAssert(m_unusedStackSlots.erase(m_assembly.stackHeight() - 1), "");
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
--m_stackAdjustment;
}
}
@@ -203,7 +202,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
{
m_context->variableStackHeights.erase(&var);
m_assembly.setSourceLocation(_varDecl.location);
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
--m_stackAdjustment;
}
else
@@ -218,8 +217,8 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
m_context->variableStackHeights[&var] = slot;
m_assembly.setSourceLocation(_varDecl.location);
if (int heightDiff = variableHeightDiff(var, varName, true))
m_assembly.appendInstruction(solidity::swapInstruction(heightDiff - 1));
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::swapInstruction(heightDiff - 1));
m_assembly.appendInstruction(dev::eth::Instruction::POP);
--m_stackAdjustment;
}
}
@@ -228,10 +227,10 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
void CodeTransform::stackError(StackTooDeepError _error, int _targetStackHeight)
{
m_assembly.appendInstruction(solidity::Instruction::INVALID);
m_assembly.appendInstruction(dev::eth::Instruction::INVALID);
// Correct the stack.
while (m_assembly.stackHeight() > _targetStackHeight)
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
while (m_assembly.stackHeight() < _targetStackHeight)
m_assembly.appendConstant(u256(0));
// Store error.
@@ -324,11 +323,11 @@ void CodeTransform::operator()(FunctionCall const& _call)
void CodeTransform::operator()(FunctionalInstruction const& _instruction)
{
if (m_evm15 && (
_instruction.instruction == solidity::Instruction::JUMP ||
_instruction.instruction == solidity::Instruction::JUMPI
_instruction.instruction == dev::eth::Instruction::JUMP ||
_instruction.instruction == dev::eth::Instruction::JUMPI
))
{
bool const isJumpI = _instruction.instruction == solidity::Instruction::JUMPI;
bool const isJumpI = _instruction.instruction == dev::eth::Instruction::JUMPI;
if (isJumpI)
{
solAssert(_instruction.arguments.size() == 2, "");
@@ -366,7 +365,7 @@ void CodeTransform::operator()(Identifier const& _identifier)
// TODO: opportunity for optimization: Do not DUP if this is the last reference
// to the top most element of the stack
if (int heightDiff = variableHeightDiff(_var, _identifier.name, false))
m_assembly.appendInstruction(solidity::dupInstruction(heightDiff));
m_assembly.appendInstruction(dev::eth::dupInstruction(heightDiff));
else
// Store something to balance the stack
m_assembly.appendConstant(u256(0));
@@ -403,8 +402,8 @@ void CodeTransform::operator()(Literal const& _literal)
void CodeTransform::operator()(yul::Instruction const& _instruction)
{
solAssert(!m_allowStackOpt, "");
solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5");
solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5");
solAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5");
solAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5");
m_assembly.setSourceLocation(_instruction.location);
m_assembly.appendInstruction(_instruction.instruction);
checkStackHeight(&_instruction);
@@ -414,7 +413,7 @@ void CodeTransform::operator()(If const& _if)
{
visitExpression(*_if.condition);
m_assembly.setSourceLocation(_if.location);
m_assembly.appendInstruction(solidity::Instruction::ISZERO);
m_assembly.appendInstruction(dev::eth::Instruction::ISZERO);
AbstractAssembly::LabelID end = m_assembly.newLabelId();
m_assembly.appendJumpToIf(end);
(*this)(_if.body);
@@ -440,8 +439,8 @@ void CodeTransform::operator()(Switch const& _switch)
AbstractAssembly::LabelID bodyLabel = m_assembly.newLabelId();
caseBodies[&c] = bodyLabel;
solAssert(m_assembly.stackHeight() == expressionHeight + 1, "");
m_assembly.appendInstruction(solidity::dupInstruction(2));
m_assembly.appendInstruction(solidity::Instruction::EQ);
m_assembly.appendInstruction(dev::eth::dupInstruction(2));
m_assembly.appendInstruction(dev::eth::Instruction::EQ);
m_assembly.appendJumpToIf(bodyLabel);
}
else
@@ -467,7 +466,7 @@ void CodeTransform::operator()(Switch const& _switch)
m_assembly.setSourceLocation(_switch.location);
m_assembly.appendLabel(end);
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
checkStackHeight(&_switch);
}
@@ -573,12 +572,12 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
while (!stackLayout.empty() && stackLayout.back() != int(stackLayout.size() - 1))
if (stackLayout.back() < 0)
{
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
stackLayout.pop_back();
}
else
{
m_assembly.appendInstruction(swapInstruction(stackLayout.size() - stackLayout.back() - 1));
m_assembly.appendInstruction(dev::eth::swapInstruction(stackLayout.size() - stackLayout.back() - 1));
swap(stackLayout[stackLayout.back()], stackLayout.back());
}
for (int i = 0; size_t(i) < stackLayout.size(); ++i)
@@ -612,7 +611,7 @@ void CodeTransform::operator()(ForLoop const& _forLoop)
visitExpression(*_forLoop.condition);
m_assembly.setSourceLocation(_forLoop.location);
m_assembly.appendInstruction(solidity::Instruction::ISZERO);
m_assembly.appendInstruction(dev::eth::Instruction::ISZERO);
m_assembly.appendJumpToIf(loopEnd);
int const stackHeightBody = m_assembly.stackHeight();
@@ -732,7 +731,7 @@ void CodeTransform::finalizeBlock(Block const& _block, int blockStartStackHeight
m_stackAdjustment++;
}
else
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::Instruction::POP);
}
int deposit = m_assembly.stackHeight() - blockStartStackHeight;
@@ -754,8 +753,8 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
{
Scope::Variable const& _var = boost::get<Scope::Variable>(*var);
if (int heightDiff = variableHeightDiff(_var, _variableName.name, true))
m_assembly.appendInstruction(solidity::swapInstruction(heightDiff - 1));
m_assembly.appendInstruction(solidity::Instruction::POP);
m_assembly.appendInstruction(dev::eth::swapInstruction(heightDiff - 1));
m_assembly.appendInstruction(dev::eth::Instruction::POP);
decreaseReference(_variableName.name, _var);
}
else
+1 -3
View File
@@ -34,8 +34,6 @@
using namespace std;
using namespace dev;
using namespace yul;
using namespace dev::solidity;
EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVersion _evmVersion):
Dialect{_flavour}, m_objectAccess(_objectAccess), m_evmVersion(_evmVersion)
@@ -84,7 +82,7 @@ EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess, langutil::EVMVer
std::function<void()> _visitArguments
) {
_visitArguments();
_assembly.appendInstruction(solidity::Instruction::CODECOPY);
_assembly.appendInstruction(dev::eth::Instruction::CODECOPY);
});
}
+11 -11
View File
@@ -30,25 +30,25 @@ using namespace langutil;
using namespace yul;
void NoOutputAssembly::appendInstruction(solidity::Instruction _instr)
void NoOutputAssembly::appendInstruction(dev::eth::Instruction _instr)
{
m_stackHeight += solidity::instructionInfo(_instr).ret - solidity::instructionInfo(_instr).args;
m_stackHeight += instructionInfo(_instr).ret - instructionInfo(_instr).args;
}
void NoOutputAssembly::appendConstant(u256 const&)
{
appendInstruction(solidity::pushInstruction(1));
appendInstruction(dev::eth::pushInstruction(1));
}
void NoOutputAssembly::appendLabel(LabelID)
{
appendInstruction(solidity::Instruction::JUMPDEST);
appendInstruction(dev::eth::Instruction::JUMPDEST);
}
void NoOutputAssembly::appendLabelReference(LabelID)
{
solAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
appendInstruction(solidity::pushInstruction(1));
appendInstruction(dev::eth::pushInstruction(1));
}
NoOutputAssembly::LabelID NoOutputAssembly::newLabelId()
@@ -69,7 +69,7 @@ void NoOutputAssembly::appendLinkerSymbol(string const&)
void NoOutputAssembly::appendJump(int _stackDiffAfter)
{
solAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(solidity::Instruction::JUMP);
appendInstruction(dev::eth::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
@@ -91,7 +91,7 @@ void NoOutputAssembly::appendJumpToIf(LabelID _labelId)
else
{
appendLabelReference(_labelId);
appendInstruction(solidity::Instruction::JUMPI);
appendInstruction(dev::eth::Instruction::JUMPI);
}
}
@@ -118,7 +118,7 @@ void NoOutputAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
void NoOutputAssembly::appendAssemblySize()
{
appendInstruction(solidity::Instruction::PUSH1);
appendInstruction(dev::eth::Instruction::PUSH1);
}
pair<shared_ptr<AbstractAssembly>, AbstractAssembly::SubID> NoOutputAssembly::createSubAssembly()
@@ -129,12 +129,12 @@ pair<shared_ptr<AbstractAssembly>, AbstractAssembly::SubID> NoOutputAssembly::cr
void NoOutputAssembly::appendDataOffset(AbstractAssembly::SubID)
{
appendInstruction(solidity::Instruction::PUSH1);
appendInstruction(dev::eth::Instruction::PUSH1);
}
void NoOutputAssembly::appendDataSize(AbstractAssembly::SubID)
{
appendInstruction(solidity::Instruction::PUSH1);
appendInstruction(dev::eth::Instruction::PUSH1);
}
AbstractAssembly::SubID NoOutputAssembly::appendData(bytes const&)
@@ -153,7 +153,7 @@ NoOutputEVMDialect::NoOutputEVMDialect(shared_ptr<EVMDialect> const& _copyFrom):
{
_visitArguments();
for (size_t i = 0; i < parameters; i++)
_assembly.appendInstruction(dev::solidity::Instruction::POP);
_assembly.appendInstruction(dev::eth::Instruction::POP);
for (size_t i = 0; i < returns; i++)
_assembly.appendConstant(u256(0));
+1 -1
View File
@@ -49,7 +49,7 @@ public:
void setSourceLocation(langutil::SourceLocation const&) override {}
int stackHeight() const override { return m_stackHeight; }
void appendInstruction(dev::solidity::Instruction _instruction) override;
void appendInstruction(dev::eth::Instruction _instruction) override;
void appendConstant(dev::u256 const& _constant) override;
void appendLabel(LabelID _labelId) override;
void appendLabelReference(LabelID _labelId) override;