Merge pull request #2398 from ethereum/assembly-cleanup

Remove obsolete features from libevmasm
This commit is contained in:
chriseth 2017-06-15 08:41:14 +02:00 committed by GitHub
commit 3cb71ac516
5 changed files with 18 additions and 22 deletions

View File

@ -40,7 +40,7 @@ void Assembly::append(Assembly const& _a)
auto newDeposit = m_deposit + _a.deposit(); auto newDeposit = m_deposit + _a.deposit();
for (AssemblyItem i: _a.m_items) for (AssemblyItem i: _a.m_items)
{ {
if (i.type() == Tag || (i.type() == PushTag && i != errorTag())) if (i.type() == Tag || i.type() == PushTag)
i.setData(i.data() + m_usedTags); i.setData(i.data() + m_usedTags);
else if (i.type() == PushSub || i.type() == PushSubSize) else if (i.type() == PushSub || i.type() == PushSubSize)
i.setData(i.data() + m_subs.size()); i.setData(i.data() + m_subs.size());
@ -72,13 +72,6 @@ void Assembly::append(Assembly const& _a, int _deposit)
} }
} }
string Assembly::out() const
{
stringstream ret;
stream(ret);
return ret.str();
}
unsigned Assembly::bytesRequired(unsigned subTagSize) const unsigned Assembly::bytesRequired(unsigned subTagSize) const
{ {
for (unsigned tagSize = subTagSize; true; ++tagSize) for (unsigned tagSize = subTagSize; true; ++tagSize)

View File

@ -69,7 +69,13 @@ public:
AssemblyItem appendJumpI() { auto ret = append(newPushTag()); append(solidity::Instruction::JUMPI); return ret; } AssemblyItem appendJumpI() { auto ret = append(newPushTag()); append(solidity::Instruction::JUMPI); return ret; }
AssemblyItem appendJump(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMP); return ret; } AssemblyItem appendJump(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMP); return ret; }
AssemblyItem appendJumpI(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMPI); return ret; } AssemblyItem appendJumpI(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMPI); return ret; }
AssemblyItem errorTag() { return AssemblyItem(PushTag, 0); }
/// Adds a subroutine to the code (in the data section) and pushes its size (via a tag)
/// on the stack. @returns the pushsub assembly item.
AssemblyItem appendSubroutine(AssemblyPointer const& _assembly) { auto sub = newSub(_assembly); append(newPushSubSize(size_t(sub.data()))); return sub; }
void pushSubroutineSize(size_t _subRoutine) { append(newPushSubSize(_subRoutine)); }
/// Pushes the offset of the subroutine.
void pushSubroutineOffset(size_t _subRoutine) { append(AssemblyItem(PushSub, _subRoutine)); }
/// Appends @a _data literally to the very end of the bytecode. /// Appends @a _data literally to the very end of the bytecode.
void appendAuxiliaryDataToEnd(bytes const& _data) { m_auxiliaryData += _data; } void appendAuxiliaryDataToEnd(bytes const& _data) { m_auxiliaryData += _data; }
@ -85,10 +91,7 @@ public:
void ignored() { m_baseDeposit = m_deposit; } void ignored() { m_baseDeposit = m_deposit; }
void endIgnored() { m_deposit = m_baseDeposit; m_baseDeposit = 0; } void endIgnored() { m_deposit = m_baseDeposit; m_baseDeposit = 0; }
void popTo(int _deposit) { while (m_deposit > _deposit) append(solidity::Instruction::POP); }
void injectStart(AssemblyItem const& _i); void injectStart(AssemblyItem const& _i);
std::string out() const;
int deposit() const { return m_deposit; } int deposit() const { return m_deposit; }
void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); }
void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); }

View File

@ -515,8 +515,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireMaxSize(3); requireMaxSize(3);
requireDeposit(1, 1); requireDeposit(1, 1);
auto subPush = m_asm.newSub(make_shared<Assembly>(code[0].assembly(ns))); auto subPush = m_asm.appendSubroutine(make_shared<Assembly>(code[0].assembly(ns)));
m_asm.append(m_asm.newPushSubSize(subPush.data()));
m_asm.append(Instruction::DUP1); m_asm.append(Instruction::DUP1);
if (code.size() == 3) if (code.size() == 3)
{ {
@ -571,7 +570,9 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
{ {
for (auto const& i: code) for (auto const& i: code)
m_asm.append(i.m_asm); m_asm.append(i.m_asm);
m_asm.popTo(1); // Leave only the last item on stack.
while (m_asm.deposit() > 1)
m_asm.append(Instruction::POP);
} }
else if (us == "BYTECODESIZE") else if (us == "BYTECODESIZE")
{ {

View File

@ -69,10 +69,11 @@ std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::v
{ {
CompilerState cs; CompilerState cs;
cs.populateStandard(); cs.populateStandard();
string ret = CodeFragment::compile(_src, cs).assembly(cs).optimise(_opt).out(); stringstream ret;
CodeFragment::compile(_src, cs).assembly(cs).optimise(_opt).stream(ret);
for (auto i: cs.treesToKill) for (auto i: cs.treesToKill)
killBigints(i); killBigints(i);
return ret; return ret.str();
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {

View File

@ -141,8 +141,6 @@ public:
CompilerContext& appendInvalid(); CompilerContext& appendInvalid();
/// Appends a conditional INVALID instruction /// Appends a conditional INVALID instruction
CompilerContext& appendConditionalInvalid(); CompilerContext& appendConditionalInvalid();
/// Returns an "ErrorTag"
eth::AssemblyItem errorTag() { return m_asm->errorTag(); }
/// Appends a JUMP to a specific tag /// Appends a JUMP to a specific tag
CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm->appendJump(_tag); return *this; } CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm->appendJump(_tag); return *this; }
/// Appends pushing of a new tag and @returns the new tag. /// Appends pushing of a new tag and @returns the new tag.
@ -151,10 +149,10 @@ public:
eth::AssemblyItem newTag() { return m_asm->newTag(); } eth::AssemblyItem newTag() { return m_asm->newTag(); }
/// Adds a subroutine to the code (in the data section) and pushes its size (via a tag) /// Adds a subroutine to the code (in the data section) and pushes its size (via a tag)
/// on the stack. @returns the pushsub assembly item. /// on the stack. @returns the pushsub assembly item.
eth::AssemblyItem addSubroutine(eth::AssemblyPointer const& _assembly) { auto sub = m_asm->newSub(_assembly); m_asm->append(m_asm->newPushSubSize(size_t(sub.data()))); return sub; } eth::AssemblyItem addSubroutine(eth::AssemblyPointer const& _assembly) { return m_asm->appendSubroutine(_assembly); }
void pushSubroutineSize(size_t _subRoutine) { m_asm->append(m_asm->newPushSubSize(_subRoutine)); } void pushSubroutineSize(size_t _subRoutine) { m_asm->pushSubroutineSize(_subRoutine); }
/// Pushes the offset of the subroutine. /// Pushes the offset of the subroutine.
void pushSubroutineOffset(size_t _subRoutine) { m_asm->append(eth::AssemblyItem(eth::PushSub, _subRoutine)); } void pushSubroutineOffset(size_t _subRoutine) { m_asm->pushSubroutineOffset(_subRoutine); }
/// Pushes the size of the final program /// Pushes the size of the final program
void appendProgramSize() { m_asm->appendProgramSize(); } void appendProgramSize() { m_asm->appendProgramSize(); }
/// Adds data to the data section, pushes a reference to the stack /// Adds data to the data section, pushes a reference to the stack