mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Nicer code in the assembler
This commit is contained in:
parent
ada477e7bd
commit
be16f251dd
@ -548,19 +548,22 @@ LinkerObject const& Assembly::assemble() const
|
|||||||
ret.bytecode.reserve(bytesRequiredIncludingData);
|
ret.bytecode.reserve(bytesRequiredIncludingData);
|
||||||
|
|
||||||
// Insert EOF1 header.
|
// Insert EOF1 header.
|
||||||
|
// TODO: empty data is disallowed
|
||||||
ret.bytecode.push_back(0xef);
|
ret.bytecode.push_back(0xef);
|
||||||
ret.bytecode.push_back(0x00);
|
ret.bytecode.push_back(0x00);
|
||||||
ret.bytecode.push_back(0x01); // version 1
|
ret.bytecode.push_back(0x01); // version 1
|
||||||
ret.bytecode.push_back(0x01); // kind=code
|
ret.bytecode.push_back(0x01); // kind=code
|
||||||
auto eofCodeLength = ret.bytecode.size();
|
|
||||||
ret.bytecode.push_back(0x00); // length of code
|
ret.bytecode.push_back(0x00); // length of code
|
||||||
ret.bytecode.push_back(0x00);
|
ret.bytecode.push_back(0x00);
|
||||||
|
bytesRef eofCodeLength(&ret.bytecode.back() + 1 - 2, 2);
|
||||||
ret.bytecode.push_back(0x02); // kind=data
|
ret.bytecode.push_back(0x02); // kind=data
|
||||||
auto eofDataLength = ret.bytecode.size();
|
|
||||||
ret.bytecode.push_back(0x00); // length of data
|
ret.bytecode.push_back(0x00); // length of data
|
||||||
ret.bytecode.push_back(0x00);
|
ret.bytecode.push_back(0x00);
|
||||||
|
bytesRef eofDataLength(&ret.bytecode.back() + 1 - 2, 2);
|
||||||
ret.bytecode.push_back(0x00); // terminator
|
ret.bytecode.push_back(0x00); // terminator
|
||||||
|
|
||||||
|
auto const codeStart = ret.bytecode.size();
|
||||||
|
|
||||||
for (AssemblyItem const& i: m_items)
|
for (AssemblyItem const& i: m_items)
|
||||||
{
|
{
|
||||||
// store position of the invalid jump destination
|
// store position of the invalid jump destination
|
||||||
@ -693,13 +696,11 @@ LinkerObject const& Assembly::assemble() const
|
|||||||
// Append an INVALID here to help tests find miscompilation.
|
// Append an INVALID here to help tests find miscompilation.
|
||||||
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::INVALID));
|
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::INVALID));
|
||||||
|
|
||||||
|
auto const codeLength = ret.bytecode.size() - codeStart;
|
||||||
|
assertThrow(codeLength > 0 && codeLength <= 0xffff, AssemblyException, "Invalid code section size.");
|
||||||
|
toBigEndian(uint16_t(codeLength), eofCodeLength);
|
||||||
|
|
||||||
auto const dataStart = ret.bytecode.size();
|
auto const dataStart = ret.bytecode.size();
|
||||||
auto const codeLength = dataStart - /*eof1*/10;
|
|
||||||
|
|
||||||
ret.bytecode[eofCodeLength] = (codeLength >> 8) & 0xff;
|
|
||||||
ret.bytecode[eofCodeLength + 1] = codeLength & 0xff;
|
|
||||||
|
|
||||||
//-- Data section --
|
|
||||||
|
|
||||||
for (auto const& [subIdPath, bytecodeOffset]: subRef)
|
for (auto const& [subIdPath, bytecodeOffset]: subRef)
|
||||||
{
|
{
|
||||||
@ -766,9 +767,8 @@ LinkerObject const& Assembly::assemble() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto const dataLength = ret.bytecode.size() - dataStart;
|
auto const dataLength = ret.bytecode.size() - dataStart;
|
||||||
|
assertThrow(dataLength >= 0 && dataLength <= 0xffff, AssemblyException, "Invalid data section size.");
|
||||||
ret.bytecode[eofDataLength] = (dataLength >> 8) & 0xff;
|
toBigEndian(uint16_t(dataLength), eofDataLength);
|
||||||
ret.bytecode[eofDataLength + 1] = dataLength & 0xff;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user