Make eofVersion member of Assembly class

This commit is contained in:
Rodrigo Q. Saramago 2022-12-05 19:45:55 +01:00 committed by Daniel Kirchner
parent aeb58ee5b9
commit bb997c4207
2 changed files with 8 additions and 7 deletions

View File

@ -482,7 +482,7 @@ map<u256, u256> const& Assembly::optimiseInternal(
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.");
// Return the already assembled object, if present.
@ -539,7 +539,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
unsigned bytesPerTag = numberEncodingSize(bytesRequiredForCode);
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)
bytesRequiredIncludingData += static_cast<unsigned>(sub->assemble().bytecode.size());
@ -550,7 +550,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
// Insert EOF1 header.
bytesRef eofCodeLength(&ret.bytecode.back(), 0);
bytesRef eofDataLength(&ret.bytecode.back(), 0);
if (eof)
if (m_eofVersion.has_value())
{
// TODO: empty data is disallowed
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));
auto const codeLength = ret.bytecode.size() - codeStart;
if (eof)
if (m_eofVersion.has_value())
{
assertThrow(codeLength > 0 && codeLength <= 0xffff, AssemblyException, "Invalid code section size.");
toBigEndian(codeLength, eofCodeLength);
@ -775,7 +775,7 @@ LinkerObject const& Assembly::assemble(bool eof) const
}
auto const dataLength = ret.bytecode.size() - dataStart;
if (eof)
if (m_eofVersion.has_value())
{
assertThrow(/*dataLength >= 0 && */ dataLength <= 0xffff, AssemblyException, "Invalid data section size.");
toBigEndian(dataLength, eofDataLength);

View File

@ -49,7 +49,7 @@ using AssemblyPointer = std::shared_ptr<Assembly>;
class Assembly
{
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 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.
/// @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
{
@ -212,6 +212,7 @@ protected:
int m_deposit = 0;
/// True, if the assembly contains contract creation code.
bool const m_creation = false;
std::optional<uint8_t> m_eofVersion;
/// Internal name of the assembly object, only used with the Yul backend
/// currently
std::string m_name;