mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove LLL specific features from libevmasm
This commit is contained in:
parent
106ac296b9
commit
9c19b93c37
@ -38,48 +38,6 @@ using namespace solidity::evmasm;
|
|||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
|
|
||||||
void Assembly::append(Assembly const& _a)
|
|
||||||
{
|
|
||||||
auto newDeposit = m_deposit + _a.deposit();
|
|
||||||
for (AssemblyItem i: _a.m_items)
|
|
||||||
{
|
|
||||||
switch (i.type())
|
|
||||||
{
|
|
||||||
case Tag:
|
|
||||||
case PushTag:
|
|
||||||
i.setData(i.data() + m_usedTags);
|
|
||||||
break;
|
|
||||||
case PushSub:
|
|
||||||
case PushSubSize:
|
|
||||||
i.setData(i.data() + m_subs.size());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
append(i);
|
|
||||||
}
|
|
||||||
m_deposit = newDeposit;
|
|
||||||
m_usedTags += _a.m_usedTags;
|
|
||||||
// This does not transfer the names of named tags on purpose. The tags themselves are
|
|
||||||
// transferred, but their names are only available inside the assembly.
|
|
||||||
for (auto const& i: _a.m_data)
|
|
||||||
m_data.insert(i);
|
|
||||||
for (auto const& i: _a.m_strings)
|
|
||||||
m_strings.insert(i);
|
|
||||||
m_subs += _a.m_subs;
|
|
||||||
for (auto const& lib: _a.m_libraries)
|
|
||||||
m_libraries.insert(lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Assembly::append(Assembly const& _a, int _deposit)
|
|
||||||
{
|
|
||||||
assertThrow(_deposit <= _a.m_deposit, InvalidDeposit, "");
|
|
||||||
|
|
||||||
append(_a);
|
|
||||||
while (_deposit++ < _a.m_deposit)
|
|
||||||
append(Instruction::POP);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssemblyItem const& Assembly::append(AssemblyItem const& _i)
|
AssemblyItem const& Assembly::append(AssemblyItem const& _i)
|
||||||
{
|
{
|
||||||
assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
|
assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
|
||||||
@ -88,12 +46,7 @@ AssemblyItem const& Assembly::append(AssemblyItem const& _i)
|
|||||||
if (m_items.back().location().isEmpty() && !m_currentSourceLocation.isEmpty())
|
if (m_items.back().location().isEmpty() && !m_currentSourceLocation.isEmpty())
|
||||||
m_items.back().setLocation(m_currentSourceLocation);
|
m_items.back().setLocation(m_currentSourceLocation);
|
||||||
m_items.back().m_modifierDepth = m_currentModifierDepth;
|
m_items.back().m_modifierDepth = m_currentModifierDepth;
|
||||||
return back();
|
return m_items.back();
|
||||||
}
|
|
||||||
|
|
||||||
void Assembly::injectStart(AssemblyItem const& _i)
|
|
||||||
{
|
|
||||||
m_items.insert(m_items.begin(), _i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Assembly::bytesRequired(unsigned subTagSize) const
|
unsigned Assembly::bytesRequired(unsigned subTagSize) const
|
||||||
|
@ -56,7 +56,6 @@ public:
|
|||||||
AssemblyItem newPushLibraryAddress(std::string const& _identifier);
|
AssemblyItem newPushLibraryAddress(std::string const& _identifier);
|
||||||
|
|
||||||
AssemblyItem const& append(AssemblyItem const& _i);
|
AssemblyItem const& append(AssemblyItem const& _i);
|
||||||
AssemblyItem const& append(std::string const& _data) { return append(newPushString(_data)); }
|
|
||||||
AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); }
|
AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); }
|
||||||
|
|
||||||
template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; }
|
template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; }
|
||||||
@ -137,18 +136,6 @@ public:
|
|||||||
StringMap const& _sourceCodes = StringMap()
|
StringMap const& _sourceCodes = StringMap()
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
public:
|
|
||||||
// These features are only used by LLL
|
|
||||||
AssemblyItem newPushString(std::string const& _data) { util::h256 h(util::keccak256(_data)); m_strings[h] = _data; return AssemblyItem(PushString, h); }
|
|
||||||
|
|
||||||
void append(Assembly const& _a);
|
|
||||||
void append(Assembly const& _a, int _deposit);
|
|
||||||
|
|
||||||
void injectStart(AssemblyItem const& _i);
|
|
||||||
|
|
||||||
AssemblyItem const& back() const { return m_items.back(); }
|
|
||||||
std::string backString() const { return m_items.size() && m_items.back().type() == PushString ? m_strings.at((util::h256)m_items.back().data()) : std::string(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Does the same operations as @a optimise, but should only be applied to a sub and
|
/// Does the same operations as @a optimise, but should only be applied to a sub and
|
||||||
/// returns the replaced tags. Also takes an argument containing the tags of this assembly
|
/// returns the replaced tags. Also takes an argument containing the tags of this assembly
|
||||||
|
@ -74,8 +74,6 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
|||||||
_assembly.appendLibraryAddress("someLibrary");
|
_assembly.appendLibraryAddress("someLibrary");
|
||||||
// PushTag + Operation
|
// PushTag + Operation
|
||||||
_assembly.appendJump(tag);
|
_assembly.appendJump(tag);
|
||||||
// PushString
|
|
||||||
_assembly.append("Unused feature for pushing string");
|
|
||||||
// PushData
|
// PushData
|
||||||
_assembly.append(bytes{0x1, 0x2, 0x3, 0x4});
|
_assembly.append(bytes{0x1, 0x2, 0x3, 0x4});
|
||||||
// PushSubSize
|
// PushSubSize
|
||||||
@ -93,9 +91,8 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
|||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
_assembly.assemble().toHex(),
|
_assembly.assemble().toHex(),
|
||||||
"5b6001600220606773__$bf005014d9d0f534b8fcb268bd84c491a2$__"
|
"5b6001600220604673__$bf005014d9d0f534b8fcb268bd84c491a2$__"
|
||||||
"6000567f556e75736564206665617475726520666f722070757368696e"
|
"600056603e6001603d73000000000000000000000000000000000000000000fe"
|
||||||
"6720737472696e605f6001605e73000000000000000000000000000000000000000000fe"
|
|
||||||
"fe010203044266eeaa"
|
"fe010203044266eeaa"
|
||||||
);
|
);
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
@ -106,7 +103,6 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
|||||||
" bytecodeSize\n"
|
" bytecodeSize\n"
|
||||||
" linkerSymbol(\"bf005014d9d0f534b8fcb268bd84c491a2380f4acd260d1ccfe9cd8201f7e994\")\n"
|
" linkerSymbol(\"bf005014d9d0f534b8fcb268bd84c491a2380f4acd260d1ccfe9cd8201f7e994\")\n"
|
||||||
" jump(tag_1)\n"
|
" jump(tag_1)\n"
|
||||||
" data_027497964124140851e8a9992ba16b5c1aaf9730b78d6036c8d65e3bb5ea4c8f\n"
|
|
||||||
" data_a6885b3731702da62e8e4a8f584ac46a7f6822f4e2ba50fba902f67b1588d23b\n"
|
" data_a6885b3731702da62e8e4a8f584ac46a7f6822f4e2ba50fba902f67b1588d23b\n"
|
||||||
" dataSize(sub_0)\n"
|
" dataSize(sub_0)\n"
|
||||||
" dataOffset(sub_0)\n"
|
" dataOffset(sub_0)\n"
|
||||||
@ -133,7 +129,6 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
|||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSHLIB\",\"value\":\"someLibrary\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"PUSHLIB\",\"value\":\"someLibrary\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH [tag]\",\"value\":\"1\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"PUSH [tag]\",\"value\":\"1\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"JUMP\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"JUMP\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH tag\",\"value\":\"Unused feature for pushing string\"},"
|
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH data\",\"value\":\"A6885B3731702DA62E8E4A8F584AC46A7F6822F4E2BA50FBA902F67B1588D23B\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"PUSH data\",\"value\":\"A6885B3731702DA62E8E4A8F584AC46A7F6822F4E2BA50FBA902F67B1588D23B\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH #[$]\",\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"PUSH #[$]\",\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH [$]\",\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"PUSH [$]\",\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
|
||||||
|
Loading…
Reference in New Issue
Block a user