diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index 1267c1a2d..63e362e3f 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -37,10 +37,10 @@ namespace solidity::frontend class Compiler { public: - Compiler(langutil::EVMVersion _evmVersion, RevertStrings _revertStrings, OptimiserSettings _optimiserSettings): + Compiler(langutil::EVMVersion _evmVersion, std::optional _eofVersion, RevertStrings _revertStrings, OptimiserSettings _optimiserSettings): m_optimiserSettings(std::move(_optimiserSettings)), - m_runtimeContext(_evmVersion, _revertStrings), - m_context(_evmVersion, _revertStrings, &m_runtimeContext) + m_runtimeContext(_evmVersion, _eofVersion, _revertStrings), + m_context(_evmVersion, _eofVersion, _revertStrings, &m_runtimeContext) { } /// Compiles a contract. diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 4f7fd3abd..b6a0a9602 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -62,10 +62,11 @@ class CompilerContext public: explicit CompilerContext( langutil::EVMVersion _evmVersion, + std::optional _eofVersion, RevertStrings _revertStrings, CompilerContext* _runtimeContext = nullptr ): - m_asm(std::make_shared(_runtimeContext != nullptr, std::string{})), + m_asm(std::make_shared(_runtimeContext != nullptr, _eofVersion, std::string{})), m_evmVersion(_evmVersion), m_revertStrings(_revertStrings), m_reservedMemory{0}, diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 14fa3c528..7d1eeeff0 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1333,7 +1333,7 @@ void CompilerStack::compileContract( Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName()); - shared_ptr compiler = make_shared(m_evmVersion, m_revertStrings, m_optimiserSettings); + shared_ptr compiler = make_shared(m_evmVersion, m_eofVersion, m_revertStrings, m_optimiserSettings); compiledContract.compiler = compiler; solAssert(!m_viaIR, ""); diff --git a/libyul/YulStack.cpp b/libyul/YulStack.cpp index b33026949..8d3df8b9b 100644 --- a/libyul/YulStack.cpp +++ b/libyul/YulStack.cpp @@ -264,7 +264,7 @@ YulStack::assembleEVMWithDeployed(optional _deployName) const yulAssert(m_parserResult->code, ""); yulAssert(m_parserResult->analysisInfo, ""); - evmasm::Assembly assembly(true, {}); + evmasm::Assembly assembly(true, m_eofVersion, {}); EthAssemblyAdapter adapter(assembly); compileEVM(adapter, m_optimiserSettings.optimizeStackAllocation); diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index 2d7be9001..5e1b0272c 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -98,7 +98,7 @@ public: /// Append the assembled size as a constant. virtual void appendAssemblySize() = 0; /// Creates a new sub-assembly, which can be referenced using dataSize and dataOffset. - virtual std::pair, SubID> createSubAssembly(bool _creation, std::string _name = "") = 0; + virtual std::pair, SubID> createSubAssembly(bool _creation, std::optional _eofVersion, std::string _name = "") = 0; /// Appends the offset of the given sub-assembly or data. virtual void appendDataOffset(std::vector const& _subPath) = 0; /// Appends the size of the given sub-assembly or data. diff --git a/libyul/backends/evm/EVMObjectCompiler.cpp b/libyul/backends/evm/EVMObjectCompiler.cpp index e7eae69ba..401aa64d3 100644 --- a/libyul/backends/evm/EVMObjectCompiler.cpp +++ b/libyul/backends/evm/EVMObjectCompiler.cpp @@ -57,7 +57,7 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize) if (auto* subObject = dynamic_cast(subNode.get())) { bool isCreation = !boost::ends_with(subObject->name.str(), "_deployed"); - auto subAssemblyAndID = m_assembly.createSubAssembly(isCreation, subObject->name.str()); + auto subAssemblyAndID = m_assembly.createSubAssembly(isCreation, m_eofVersion, subObject->name.str()); context.subIDs[subObject->name] = subAssemblyAndID.second; subObject->subId = subAssemblyAndID.second; compile(*subObject, *subAssemblyAndID.first, m_dialect, _optimize, m_eofVersion); diff --git a/libyul/backends/evm/EthAssemblyAdapter.cpp b/libyul/backends/evm/EthAssemblyAdapter.cpp index 685f56cbc..3d451afa2 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.cpp +++ b/libyul/backends/evm/EthAssemblyAdapter.cpp @@ -122,9 +122,9 @@ void EthAssemblyAdapter::appendAssemblySize() m_assembly.appendProgramSize(); } -pair, AbstractAssembly::SubID> EthAssemblyAdapter::createSubAssembly(bool _creation, string _name) +pair, AbstractAssembly::SubID> EthAssemblyAdapter::createSubAssembly(bool _creation, std::optional _eofVersion, string _name) { - shared_ptr assembly{make_shared(_creation, std::move(_name))}; + shared_ptr assembly{make_shared(_creation, _eofVersion, std::move(_name))}; auto sub = m_assembly.newSub(assembly); return {make_shared(*assembly), static_cast(sub.data())}; } diff --git a/libyul/backends/evm/EthAssemblyAdapter.h b/libyul/backends/evm/EthAssemblyAdapter.h index 87047ccbf..1a14447b4 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.h +++ b/libyul/backends/evm/EthAssemblyAdapter.h @@ -55,7 +55,7 @@ public: void appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType) override; void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override; void appendAssemblySize() override; - std::pair, SubID> createSubAssembly(bool _creation, std::string _name = {}) override; + std::pair, SubID> createSubAssembly(bool _creation, std::optional _eofVersion, std::string _name = {}) override; void appendDataOffset(std::vector const& _subPath) override; void appendDataSize(std::vector const& _subPath) override; SubID appendData(bytes const& _data) override; diff --git a/libyul/backends/evm/NoOutputAssembly.cpp b/libyul/backends/evm/NoOutputAssembly.cpp index e26204201..d4bd24516 100644 --- a/libyul/backends/evm/NoOutputAssembly.cpp +++ b/libyul/backends/evm/NoOutputAssembly.cpp @@ -98,7 +98,7 @@ void NoOutputAssembly::appendAssemblySize() appendInstruction(evmasm::Instruction::PUSH1); } -pair, AbstractAssembly::SubID> NoOutputAssembly::createSubAssembly(bool, std::string) +pair, AbstractAssembly::SubID> NoOutputAssembly::createSubAssembly(bool, std::optional, std::string) { yulAssert(false, "Sub assemblies not implemented."); return {}; diff --git a/libyul/backends/evm/NoOutputAssembly.h b/libyul/backends/evm/NoOutputAssembly.h index 1103392ef..ef5aeb24c 100644 --- a/libyul/backends/evm/NoOutputAssembly.h +++ b/libyul/backends/evm/NoOutputAssembly.h @@ -65,7 +65,7 @@ public: void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override; void appendAssemblySize() override; - std::pair, SubID> createSubAssembly(bool _creation, std::string _name = "") override; + std::pair, SubID> createSubAssembly(bool _creation, std::optional _eofVersion, std::string _name = "") override; void appendDataOffset(std::vector const& _subPath) override; void appendDataSize(std::vector const& _subPath) override; SubID appendData(bytes const& _data) override; diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 680531799..94051e801 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -59,15 +60,15 @@ BOOST_AUTO_TEST_CASE(all_assembly_items) { "sub.asm", 1 }, { "verbatim.asm", 2 } }; - Assembly _assembly{false, {}}; + Assembly _assembly{false, solidity::test::CommonOptions::get().eofVersion(), {}}; auto root_asm = make_shared("root.asm"); _assembly.setSourceLocation({1, 3, root_asm}); - Assembly _subAsm{false, {}}; + Assembly _subAsm{false, solidity::test::CommonOptions::get().eofVersion(), {}}; auto sub_asm = make_shared("sub.asm"); _subAsm.setSourceLocation({6, 8, sub_asm}); - Assembly _verbatimAsm(true, ""); + Assembly _verbatimAsm(true, solidity::test::CommonOptions::get().eofVersion(), ""); auto verbatim_asm = make_shared("verbatim.asm"); _verbatimAsm.setSourceLocation({8, 18, verbatim_asm}); @@ -243,7 +244,7 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps) { *subName, 1 } }; - auto subAsm = make_shared(false, string{}); + auto subAsm = make_shared(false, solidity::test::CommonOptions::get().eofVersion(), string{}); for (char i = 0; i < numImmutables; ++i) { for (int r = 0; r < numActualRefs; ++r) @@ -253,7 +254,7 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps) } } - Assembly assembly{true, {}}; + Assembly assembly{true, solidity::test::CommonOptions::get().eofVersion(), {}}; for (char i = 1; i <= numImmutables; ++i) { assembly.setSourceLocation({10*i, 10*i + 3+i, assemblyName}); @@ -302,11 +303,11 @@ BOOST_AUTO_TEST_CASE(immutable) { "root.asm", 0 }, { "sub.asm", 1 } }; - Assembly _assembly{true, {}}; + Assembly _assembly{true, solidity::test::CommonOptions::get().eofVersion(), {}}; auto root_asm = make_shared("root.asm"); _assembly.setSourceLocation({1, 3, root_asm}); - Assembly _subAsm{false, {}}; + Assembly _subAsm{false, solidity::test::CommonOptions::get().eofVersion(), {}}; auto sub_asm = make_shared("sub.asm"); _subAsm.setSourceLocation({6, 8, sub_asm}); _subAsm.appendImmutable("someImmutable"); @@ -395,10 +396,10 @@ BOOST_AUTO_TEST_CASE(immutable) BOOST_AUTO_TEST_CASE(subobject_encode_decode) { - Assembly assembly{true, {}}; + Assembly assembly{true, solidity::test::CommonOptions::get().eofVersion(), {}}; - shared_ptr subAsmPtr = make_shared(false, string{}); - shared_ptr subSubAsmPtr = make_shared(false, string{}); + shared_ptr subAsmPtr = make_shared(false, solidity::test::CommonOptions::get().eofVersion(), string{}); + shared_ptr subSubAsmPtr = make_shared(false, solidity::test::CommonOptions::get().eofVersion(), string{}); assembly.appendSubroutine(subAsmPtr); subAsmPtr->appendSubroutine(subSubAsmPtr); diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 6fc3c5a74..db93c3257 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -1250,8 +1250,8 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies) // tag unifications (due to block deduplication) is also // visible at the super-assembly. - Assembly main{false, {}}; - AssemblyPointer sub = make_shared(true, string{}); + Assembly main{false, solidity::test::CommonOptions::get().eofVersion(), {}}; + AssemblyPointer sub = make_shared(true, solidity::test::CommonOptions::get().eofVersion(), string{}); sub->append(u256(1)); auto t1 = sub->newTag(); diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index f12c12ca9..ebf3e6dc3 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -87,6 +87,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr _sourceCode) { Compiler compiler( solidity::test::CommonOptions::get().evmVersion(), + solidity::test::CommonOptions::get().eofVersion(), RevertStrings::Default, solidity::test::CommonOptions::get().optimize ? OptimiserSettings::standard() : OptimiserSettings::minimal() ); diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index 2741290fc..a9c8abdf5 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -144,6 +144,7 @@ bytes compileFirstExpression( CompilerContext context( solidity::test::CommonOptions::get().evmVersion(), + solidity::test::CommonOptions::get().eofVersion(), RevertStrings::Default ); context.resetVisitedNodes(contract); diff --git a/test/libyul/EVMCodeTransformTest.cpp b/test/libyul/EVMCodeTransformTest.cpp index 744fa8c03..bd8c5f5f9 100644 --- a/test/libyul/EVMCodeTransformTest.cpp +++ b/test/libyul/EVMCodeTransformTest.cpp @@ -66,7 +66,7 @@ TestCase::TestResult EVMCodeTransformTest::run(ostream& _stream, string const& _ return TestResult::FatalError; } - evmasm::Assembly assembly{false, {}}; + evmasm::Assembly assembly{false, nullopt, {}}; EthAssemblyAdapter adapter(assembly); EVMObjectCompiler::compile( *stack.parserResult(), diff --git a/test/tools/fuzzer_common.cpp b/test/tools/fuzzer_common.cpp index 25ad6986c..64af34e1f 100644 --- a/test/tools/fuzzer_common.cpp +++ b/test/tools/fuzzer_common.cpp @@ -189,7 +189,7 @@ void FuzzerUtil::testConstantOptimizer(string const& _input, bool _quiet) for (bool isCreation: {false, true}) { - Assembly assembly{isCreation, {}}; + Assembly assembly{isCreation, nullopt, {}}; for (u256 const& n: numbers) { if (!_quiet)