From c097842455d21357b74879212cc5552313b339a5 Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Mon, 14 Mar 2022 09:24:26 -0500 Subject: [PATCH] rebase --- libevmasm/Assembly.cpp | 21 +------------ libevmasm/Assembly.h | 7 ----- libsolidity/interface/CompilerStack.cpp | 4 +-- solc/CommandLineParser.cpp | 40 ++++++++++++------------- test/libevmasm/Assembler.cpp | 4 +-- 5 files changed, 25 insertions(+), 51 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 3aebf57c0..881107cf2 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -602,7 +602,7 @@ bool Assembly::loadFromAssemblyJSON(Json::Value const& _json, bool _loadSources this->m_data[h256(fromHex(key))] = fromHex(code.asString()); else { - shared_ptr subassembly = make_shared(); + shared_ptr subassembly = make_shared(false, ""); subassembly->setSources(this->sources()); result &= subassembly->loadFromAssemblyJSON(code, false); this->m_subs.emplace_back(subassembly); @@ -646,25 +646,6 @@ AssemblyItem Assembly::newImmutableAssignment(string const& _identifier) return AssemblyItem{AssignImmutable, h}; } -Assembly& Assembly::optimise(bool _enable, EVMVersion _evmVersion, bool _isCreation, size_t _runs) -{ - OptimiserSettings settings; - settings.isCreation = _isCreation; - settings.runInliner = true; - settings.runJumpdestRemover = true; - settings.runPeephole = true; - if (_enable) - { - settings.runDeduplicate = true; - settings.runCSE = true; - settings.runConstantOptimiser = true; - } - settings.evmVersion = _evmVersion; - settings.expectedExecutionsPerDeployment = _runs; - optimise(settings); - return *this; -} - Assembly& Assembly::optimise(OptimiserSettings const& _settings) { optimiseInternal(_settings, {}); diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 1f46c3d68..5f0f98abc 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -134,13 +134,6 @@ public: /// is optimised according to the settings in @a _settings. Assembly& optimise(OptimiserSettings const& _settings); - /// Modify (if @a _enable is set) and return the current assembly such that creation and - /// execution gas usage is optimised. @a _isCreation should be true for the top-level assembly. - /// @a _runs specifes an estimate on how often each opcode in this assembly will be executed, - /// i.e. use a small value to optimise for size and a large value to optimise for runtime. - /// If @a _enable is not set, will perform some simple peephole optimizations. - Assembly& optimise(bool _enable, langutil::EVMVersion _evmVersion, bool _isCreation, size_t _runs); - /// Create a text representation of the assembly. std::string assemblyString( langutil::DebugInfoSelection const& _debugInfoSelection = langutil::DebugInfoSelection::Default(), diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 9cbe2baeb..a5190cd82 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -692,13 +692,13 @@ bool CompilerStack::compile(State _stopAfter) optimiserSettings.runJumpdestRemover = m_optimiserSettings.runJumpdestRemover; optimiserSettings.runPeephole = m_optimiserSettings.runPeephole; - m_contracts[evmSourceName].evmAssembly = make_shared(evmSourceName); + m_contracts[evmSourceName].evmAssembly = make_shared(true, evmSourceName); m_contracts[evmSourceName].evmAssembly->loadFromAssemblyJSON(m_evmAssemblyJson[evmSourceName]); if (m_optimiserSettings.enabled) m_contracts[evmSourceName].evmAssembly->optimise(optimiserSettings); m_contracts[evmSourceName].object = m_contracts[evmSourceName].evmAssembly->assemble(); - m_contracts[evmSourceName].evmRuntimeAssembly = make_shared(evmSourceName); + m_contracts[evmSourceName].evmRuntimeAssembly = make_shared(false, evmSourceName); m_contracts[evmSourceName].evmRuntimeAssembly->setSources(m_contracts[evmSourceName].evmAssembly->sources()); m_contracts[evmSourceName].evmRuntimeAssembly->loadFromAssemblyJSON(m_evmAssemblyJson[evmSourceName][".data"]["0"], false); if (m_optimiserSettings.enabled) diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 2a139c8cb..bbb0c2f99 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -168,7 +168,7 @@ ostream& operator<<(ostream& _out, CompilerOutputs const& _selection) if (_selection.*component) serializedSelection.push_back(CompilerOutputs::componentName(component)); - return _out << joinHumanReadable(serializedSelection, ","); + return _out << util::joinHumanReadable(serializedSelection, ","); } string const& CompilerOutputs::componentName(bool CompilerOutputs::* _component) @@ -199,7 +199,7 @@ ostream& operator<<(ostream& _out, CombinedJsonRequests const& _requests) if (_requests.*component) serializedRequests.push_back(CombinedJsonRequests::componentName(component)); - return _out << joinHumanReadable(serializedRequests, ","); + return _out << util::joinHumanReadable(serializedRequests, ","); } string const& CombinedJsonRequests::componentName(bool CombinedJsonRequests::* _component) @@ -347,17 +347,17 @@ void CommandLineParser::parseLibraryOption(string const& _input) try { if (fs::is_regular_file(_input)) - data = readFileAsString(_input); + data = util::readFileAsString(_input); } catch (fs::filesystem_error const&) { // Thrown e.g. if path is too long. } - catch (FileNotFound const&) + catch (util::FileNotFound const&) { // Should not happen if `fs::is_regular_file` is correct. } - catch (NotAFile const&) + catch (util::NotAFile const&) { // Should not happen if `fs::is_regular_file` is correct. } @@ -422,15 +422,15 @@ void CommandLineParser::parseLibraryOption(string const& _input) "Invalid length for address for library \"" + libName + "\": " + to_string(addrString.length()) + " instead of 40 characters." ); - if (!passesAddressChecksum(addrString, false)) + if (!util::passesAddressChecksum(addrString, false)) solThrow( CommandLineValidationError, "Invalid checksum on address for library \"" + libName + "\": " + addrString + "\n" - "The correct checksum is " + getChecksummedAddress(addrString) + "The correct checksum is " + util::getChecksummedAddress(addrString) ); - bytes binAddr = fromHex(addrString); - h160 address(binAddr, h160::AlignRight); - if (binAddr.size() > 20 || address == h160()) + bytes binAddr = util::fromHex(addrString); + util::h160 address(binAddr, util::h160::AlignRight); + if (binAddr.size() > 20 || address == util::h160()) solThrow( CommandLineValidationError, "Invalid address for library \"" + libName + "\": " + addrString @@ -595,15 +595,15 @@ General Information)").c_str(), ) ( g_strRevertStrings.c_str(), - po::value()->value_name(joinHumanReadable(g_revertStringsArgs, ",")), + po::value()->value_name(util::joinHumanReadable(g_revertStringsArgs, ",")), "Strip revert (and require) reason strings or add additional debugging information." ) ( g_strDebugInfo.c_str(), - po::value()->default_value(toString(DebugInfoSelection::Default())), + po::value()->default_value(util::toString(DebugInfoSelection::Default())), ("Debug info components to be included in the produced EVM assembly and Yul code. " "Value can be all, none or a comma-separated list containing one or more of the " - "following components: " + joinHumanReadable(DebugInfoSelection::componentMap() | ranges::views::keys) + ".").c_str() + "following components: " + util::joinHumanReadable(DebugInfoSelection::componentMap() | ranges::views::keys) + ".").c_str() ) ( g_strStopAfter.c_str(), @@ -665,12 +665,12 @@ General Information)").c_str(), assemblyModeOptions.add_options() ( g_strMachine.c_str(), - po::value()->value_name(joinHumanReadable(g_machineArgs, ",")), + po::value()->value_name(util::joinHumanReadable(g_machineArgs, ",")), "Target machine in assembly or Yul mode." ) ( g_strYulDialect.c_str(), - po::value()->value_name(joinHumanReadable(g_yulDialectArgs, ",")), + po::value()->value_name(util::joinHumanReadable(g_yulDialectArgs, ",")), "Input dialect to use in assembly or yul mode." ) ; @@ -743,7 +743,7 @@ General Information)").c_str(), ) ( g_strCombinedJson.c_str(), - po::value()->value_name(joinHumanReadable(CombinedJsonRequests::componentMap() | ranges::views::keys, ",")), + po::value()->value_name(util::joinHumanReadable(CombinedJsonRequests::componentMap() | ranges::views::keys, ",")), "Output a single json document containing the specified information." ) ; @@ -753,7 +753,7 @@ General Information)").c_str(), metadataOptions.add_options() ( g_strMetadataHash.c_str(), - po::value()->value_name(joinHumanReadable(g_metadataHashArgs, ",")), + po::value()->value_name(util::joinHumanReadable(g_metadataHashArgs, ",")), "Choose hash method for the bytecode metadata or disable it." ) ( @@ -1047,11 +1047,11 @@ void CommandLineParser::processArgs() if (m_args.count(g_strPrettyJson) > 0) { - m_options.formatting.json.format = JsonFormat::Pretty; + m_options.formatting.json.format = util::JsonFormat::Pretty; } if (!m_args[g_strJsonIndent].defaulted()) { - m_options.formatting.json.format = JsonFormat::Pretty; + m_options.formatting.json.format = util::JsonFormat::Pretty; m_options.formatting.json.indent = m_args[g_strJsonIndent].as(); } @@ -1329,7 +1329,7 @@ size_t CommandLineParser::countEnabledOptions(vector const& _optionNames string CommandLineParser::joinOptionNames(vector const& _optionNames, string _separator) { - return joinHumanReadable( + return util::joinHumanReadable( _optionNames | ranges::views::transform([](string const& _option){ return "--" + _option; }), _separator ); diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 5a026d345..1dd524851 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items) auto sub_asm = make_shared("sub.asm"); _subAsm.setSourceLocation({6, 8, sub_asm}); - Assembly _verbatimAsm; + Assembly _verbatimAsm(true, ""); auto verbatim_asm = make_shared("verbatim.asm"); _verbatimAsm.setSourceLocation({8, 18, verbatim_asm}); @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items) BOOST_CHECK(util::jsonParseStrict(json, jsonValue)); BOOST_CHECK_EQUAL(util::jsonCompactPrint(_assembly.assemblyJSON(indices)), util::jsonCompactPrint(jsonValue)); - Assembly _assemblyFromJson; + Assembly _assemblyFromJson(true, ""); _assemblyFromJson.loadFromAssemblyJSON(_assembly.assemblyJSON(indices)); BOOST_CHECK_EQUAL(util::jsonCompactPrint(_assemblyFromJson.assemblyJSON(indices)), util::jsonCompactPrint(jsonValue)); BOOST_CHECK_EQUAL(_assembly.assemble().toHex(), _assemblyFromJson.assemble().toHex());