mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make eofVersion member of Assembly class
This commit is contained in:
parent
aeb58ee5b9
commit
bb997c4207
@ -482,7 +482,7 @@ map<u256, u256> const& Assembly::optimiseInternal(
|
|||||||
return *m_tagReplacements;
|
return *m_tagReplacements;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkerObject const& Assembly::assemble(bool eof) const
|
LinkerObject const& Assembly::assemble() const
|
||||||
{
|
{
|
||||||
assertThrow(!m_invalid, AssemblyException, "Attempted to assemble invalid Assembly object.");
|
assertThrow(!m_invalid, AssemblyException, "Attempted to assemble invalid Assembly object.");
|
||||||
// Return the already assembled object, if present.
|
// Return the already assembled object, if present.
|
||||||
@ -539,7 +539,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
|
|||||||
unsigned bytesPerTag = numberEncodingSize(bytesRequiredForCode);
|
unsigned bytesPerTag = numberEncodingSize(bytesRequiredForCode);
|
||||||
uint8_t tagPush = static_cast<uint8_t>(pushInstruction(bytesPerTag));
|
uint8_t tagPush = static_cast<uint8_t>(pushInstruction(bytesPerTag));
|
||||||
|
|
||||||
unsigned bytesRequiredIncludingData = (eof ? 10 : 0) + bytesRequiredForCode + 1 + static_cast<unsigned>(m_auxiliaryData.size());
|
unsigned bytesRequiredIncludingData = (m_eofVersion.has_value() ? 10 : 0) + bytesRequiredForCode + 1 + static_cast<unsigned>(m_auxiliaryData.size());
|
||||||
for (auto const& sub: m_subs)
|
for (auto const& sub: m_subs)
|
||||||
bytesRequiredIncludingData += static_cast<unsigned>(sub->assemble().bytecode.size());
|
bytesRequiredIncludingData += static_cast<unsigned>(sub->assemble().bytecode.size());
|
||||||
|
|
||||||
@ -550,7 +550,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
|
|||||||
// Insert EOF1 header.
|
// Insert EOF1 header.
|
||||||
bytesRef eofCodeLength(&ret.bytecode.back(), 0);
|
bytesRef eofCodeLength(&ret.bytecode.back(), 0);
|
||||||
bytesRef eofDataLength(&ret.bytecode.back(), 0);
|
bytesRef eofDataLength(&ret.bytecode.back(), 0);
|
||||||
if (eof)
|
if (m_eofVersion.has_value())
|
||||||
{
|
{
|
||||||
// TODO: empty data is disallowed
|
// TODO: empty data is disallowed
|
||||||
ret.bytecode.push_back(0xef);
|
ret.bytecode.push_back(0xef);
|
||||||
@ -702,7 +702,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
|
|||||||
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;
|
auto const codeLength = ret.bytecode.size() - codeStart;
|
||||||
if (eof)
|
if (m_eofVersion.has_value())
|
||||||
{
|
{
|
||||||
assertThrow(codeLength > 0 && codeLength <= 0xffff, AssemblyException, "Invalid code section size.");
|
assertThrow(codeLength > 0 && codeLength <= 0xffff, AssemblyException, "Invalid code section size.");
|
||||||
toBigEndian(codeLength, eofCodeLength);
|
toBigEndian(codeLength, eofCodeLength);
|
||||||
@ -775,7 +775,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto const dataLength = ret.bytecode.size() - dataStart;
|
auto const dataLength = ret.bytecode.size() - dataStart;
|
||||||
if (eof)
|
if (m_eofVersion.has_value())
|
||||||
{
|
{
|
||||||
assertThrow(/*dataLength >= 0 && */ dataLength <= 0xffff, AssemblyException, "Invalid data section size.");
|
assertThrow(/*dataLength >= 0 && */ dataLength <= 0xffff, AssemblyException, "Invalid data section size.");
|
||||||
toBigEndian(dataLength, eofDataLength);
|
toBigEndian(dataLength, eofDataLength);
|
||||||
|
@ -49,7 +49,7 @@ using AssemblyPointer = std::shared_ptr<Assembly>;
|
|||||||
class Assembly
|
class Assembly
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Assembly(bool _creation, std::string _name): m_creation(_creation), m_name(std::move(_name)) { }
|
Assembly(bool _creation, std::optional<uint8_t> _eofVersion, std::string _name): m_creation(_creation), m_eofVersion(_eofVersion), m_name(std::move(_name)) { }
|
||||||
|
|
||||||
AssemblyItem newTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(Tag, m_usedTags++); }
|
AssemblyItem newTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(Tag, m_usedTags++); }
|
||||||
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
|
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
|
||||||
@ -115,7 +115,7 @@ public:
|
|||||||
|
|
||||||
/// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached.
|
/// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached.
|
||||||
/// @param eof If true, assemble for EOF, otherwise for legacy EVM output.
|
/// @param eof If true, assemble for EOF, otherwise for legacy EVM output.
|
||||||
LinkerObject const& assemble(bool eof = false) const;
|
LinkerObject const& assemble() const;
|
||||||
|
|
||||||
struct OptimiserSettings
|
struct OptimiserSettings
|
||||||
{
|
{
|
||||||
@ -212,6 +212,7 @@ protected:
|
|||||||
int m_deposit = 0;
|
int m_deposit = 0;
|
||||||
/// True, if the assembly contains contract creation code.
|
/// True, if the assembly contains contract creation code.
|
||||||
bool const m_creation = false;
|
bool const m_creation = false;
|
||||||
|
std::optional<uint8_t> m_eofVersion;
|
||||||
/// Internal name of the assembly object, only used with the Yul backend
|
/// Internal name of the assembly object, only used with the Yul backend
|
||||||
/// currently
|
/// currently
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
Loading…
Reference in New Issue
Block a user