From bb997c42078dab0f943b7cc81e1e9ab4b827c1db Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Mon, 5 Dec 2022 19:45:55 +0100 Subject: [PATCH] Make eofVersion member of Assembly class --- libevmasm/Assembly.cpp | 10 +++++----- libevmasm/Assembly.h | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 45b95d552..df289c20d 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -482,7 +482,7 @@ map 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(pushInstruction(bytesPerTag)); - unsigned bytesRequiredIncludingData = (eof ? 10 : 0) + bytesRequiredForCode + 1 + static_cast(m_auxiliaryData.size()); + unsigned bytesRequiredIncludingData = (m_eofVersion.has_value() ? 10 : 0) + bytesRequiredForCode + 1 + static_cast(m_auxiliaryData.size()); for (auto const& sub: m_subs) bytesRequiredIncludingData += static_cast(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(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); diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index efaa28fbe..1da4ac541 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -49,7 +49,7 @@ using AssemblyPointer = std::shared_ptr; class Assembly { public: - Assembly(bool _creation, std::string _name): m_creation(_creation), m_name(std::move(_name)) { } + Assembly(bool _creation, std::optional _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 m_eofVersion; /// Internal name of the assembly object, only used with the Yul backend /// currently std::string m_name;