From 161f0b17daafad2c12ab19f4b9e09b1a870a12da Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Thu, 15 Feb 2024 21:47:11 +0100 Subject: [PATCH 1/3] [yul] Add support for parsing debug data attributes. --- liblangutil/DebugData.h | 16 +- libsolutil/CMakeLists.txt | 1 + libsolutil/Cache.h | 126 +++++++++++++ libyul/AsmParser.cpp | 151 ++++++++++++++-- libyul/AsmParser.h | 32 +++- test/CMakeLists.txt | 1 + .../ethdebug_large_debug_attributes/args | 1 + .../ethdebug_large_debug_attributes/input.yul | 16 ++ .../ethdebug_large_debug_attributes/output | 26 +++ test/libsolutil/Cache.cpp | 166 ++++++++++++++++++ test/libyul/Parser.cpp | 66 ++++++- .../invalid/invalid_debug_merge.yul | 7 + .../invalid/invalid_debug_patch.yul | 7 + .../invalid_debug_patch_patch_object.yul | 7 + .../invalid/invalid_debug_set.yul | 7 + 15 files changed, 600 insertions(+), 30 deletions(-) create mode 100644 libsolutil/Cache.h create mode 100644 test/cmdlineTests/ethdebug_large_debug_attributes/args create mode 100644 test/cmdlineTests/ethdebug_large_debug_attributes/input.yul create mode 100644 test/cmdlineTests/ethdebug_large_debug_attributes/output create mode 100644 test/libsolutil/Cache.cpp create mode 100644 test/libyul/yulSyntaxTests/invalid/invalid_debug_merge.yul create mode 100644 test/libyul/yulSyntaxTests/invalid/invalid_debug_patch.yul create mode 100644 test/libyul/yulSyntaxTests/invalid/invalid_debug_patch_patch_object.yul create mode 100644 test/libyul/yulSyntaxTests/invalid/invalid_debug_set.yul diff --git a/liblangutil/DebugData.h b/liblangutil/DebugData.h index 70259bd039f3..9e58d9f37794 100644 --- a/liblangutil/DebugData.h +++ b/liblangutil/DebugData.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include @@ -28,27 +29,32 @@ namespace solidity::langutil struct DebugData { typedef typename std::shared_ptr ConstPtr; + typedef std::optional>> Attributes; explicit DebugData( langutil::SourceLocation _nativeLocation = {}, langutil::SourceLocation _originLocation = {}, - std::optional _astID = {} + std::optional _astID = {}, + Attributes _attributes = {} ): nativeLocation(std::move(_nativeLocation)), originLocation(std::move(_originLocation)), - astID(_astID) + astID(_astID), + attributes(std::move(_attributes)) {} static DebugData::ConstPtr create( langutil::SourceLocation _nativeLocation, langutil::SourceLocation _originLocation = {}, - std::optional _astID = {} + std::optional _astID = {}, + Attributes _attributes = {} ) { return std::make_shared( std::move(_nativeLocation), std::move(_originLocation), - _astID + _astID, + std::move(_attributes) ); } @@ -65,6 +71,8 @@ struct DebugData langutil::SourceLocation originLocation; /// ID in the (Solidity) source AST. std::optional astID; + /// Additional debug data attributes. + Attributes attributes; }; } // namespace solidity::langutil diff --git a/libsolutil/CMakeLists.txt b/libsolutil/CMakeLists.txt index 0fdb23b0445f..363d48e5a65d 100644 --- a/libsolutil/CMakeLists.txt +++ b/libsolutil/CMakeLists.txt @@ -2,6 +2,7 @@ set(sources Algorithms.h AnsiColorized.h Assertions.h + Cache.h Common.h CommonData.cpp CommonData.h diff --git a/libsolutil/Cache.h b/libsolutil/Cache.h new file mode 100644 index 000000000000..4ec1e2e0aa95 --- /dev/null +++ b/libsolutil/Cache.h @@ -0,0 +1,126 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 +/** @file Cache.h + * @date 2024 + * + * Simple cache. + */ + +#pragma once + +#include + +#include +#include +#include + +#include + +#include + +namespace solidity::util +{ + +namespace detail +{ + +template typename TCache ,typename THash, typename TValue> +class CacheBase +{ +public: + typedef THash Hash; + typedef TValue Value; + typedef TCache Cache; + typedef std::shared_ptr Entry; + typedef std::shared_ptr Ptr; + + Entry set(Hash const& hash, Value const& value) + { + Entry result; + if (m_cache.find(hash) == m_cache.end()) + { + result = std::make_shared(value); + auto [_, inserted] = m_cache.emplace(std::make_pair(hash, result)); + solAssert(inserted); + } + else + result = m_cache[hash]; + return result; + } + + Entry set(Value const& value) { return set(Cache::hash(value), value); } + + std::map const& cache() { return m_cache; } + + typename std::map::iterator get(Hash const& hash) { return m_cache.find(hash); } + + typename std::map::iterator begin() { return m_cache.begin(); } + + typename std::map::iterator end() { return m_cache.end(); } + +private: + std::map m_cache; +}; + +} // namespace detail + +template +class Cache; + +template +class Cache: public detail::CacheBase +{ +public: + static size_t hash(TValue const& value) + { + boost::hash hasher; + return hasher(value); + } +}; + +template +class Cache: public detail::CacheBase +{ +public: + static h256 hash(TValue const& value) + { + std::stringstream stream; + stream << value; + return keccak256(stream.str()); + } +}; + +template<> +class Cache: public detail::CacheBase +{ +public: + static size_t hash(Json const& value) + { + boost::hash hasher; + return hasher(value.dump(0)); + } +}; + +template<> +class Cache: public detail::CacheBase +{ +public: + static h256 hash(Json const& value) { return keccak256(value.dump(0)); } +}; + +} // namespace solidity::util diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 2ae4dd805bc1..508ce7204581 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -62,14 +62,36 @@ std::optional toInt(std::string const& _value) langutil::DebugData::ConstPtr Parser::createDebugData() const { + solAssert(m_debugAttributeCache); switch (m_useSourceLocationFrom) { - case UseSourceLocationFrom::Scanner: - return DebugData::create(ParserBase::currentLocation(), ParserBase::currentLocation()); - case UseSourceLocationFrom::LocationOverride: - return DebugData::create(m_locationOverride, m_locationOverride); - case UseSourceLocationFrom::Comments: - return DebugData::create(ParserBase::currentLocation(), m_locationFromComment, m_astIDFromComment); + case UseSourceLocationFrom::Scanner: + return DebugData::create( + ParserBase::currentLocation(), + ParserBase::currentLocation(), + {}, + m_currentDebugAttributes.has_value() + ? DebugData::Attributes({m_debugAttributeCache->set(*m_currentDebugAttributes)}) + : DebugData::Attributes({}) + ); + case UseSourceLocationFrom::LocationOverride: + return DebugData::create( + m_locationOverride, + m_locationOverride, + {}, + m_currentDebugAttributes.has_value() + ? DebugData::Attributes({m_debugAttributeCache->set(*m_currentDebugAttributes)}) + : DebugData::Attributes({}) + ); + case UseSourceLocationFrom::Comments: + return DebugData::create( + ParserBase::currentLocation(), + m_locationFromComment, + m_astIDFromComment, + m_currentDebugAttributes.has_value() + ? DebugData::Attributes({m_debugAttributeCache->set(*m_currentDebugAttributes)}) + : DebugData::Attributes({}) + ); } solAssert(false, ""); } @@ -123,8 +145,7 @@ std::unique_ptr Parser::parseInline(std::shared_ptr const& _scan try { m_scanner = _scanner; - if (m_useSourceLocationFrom == UseSourceLocationFrom::Comments) - fetchDebugDataFromComment(); + fetchDebugDataFromComment(); return std::make_unique(parseBlock()); } catch (FatalError const& error) @@ -138,24 +159,20 @@ std::unique_ptr Parser::parseInline(std::shared_ptr const& _scan langutil::Token Parser::advance() { auto const token = ParserBase::advance(); - if (m_useSourceLocationFrom == UseSourceLocationFrom::Comments) - fetchDebugDataFromComment(); + fetchDebugDataFromComment(); return token; } void Parser::fetchDebugDataFromComment() { - solAssert(m_sourceNames.has_value(), ""); - static std::regex const tagRegex = std::regex( - R"~~((?:^|\s+)(@[a-zA-Z0-9\-_]+)(?:\s+|$))~~", // tag, e.g: @src + R"~~((?:^|\s+)(@[a-zA-Z0-9\-\._]+)(?:\s+|$))~~", // tag, e.g: @src std::regex_constants::ECMAScript | std::regex_constants::optimize ); std::string_view commentLiteral = m_scanner->currentCommentLiteral(); std::match_results match; - langutil::SourceLocation originLocation = m_locationFromComment; // Empty for each new node. std::optional astID; @@ -166,10 +183,14 @@ void Parser::fetchDebugDataFromComment() if (match[1] == "@src") { - if (auto parseResult = parseSrcComment(commentLiteral, m_scanner->currentCommentLocation())) - tie(commentLiteral, originLocation) = *parseResult; - else - break; + if (m_useSourceLocationFrom == UseSourceLocationFrom::Comments) + { + solAssert(m_sourceNames.has_value(), ""); + if (auto parseResult = parseSrcComment(commentLiteral, m_scanner->currentCommentLocation())) + tie(commentLiteral, m_locationFromComment) = *parseResult; + else + break; + } } else if (match[1] == "@ast-id") { @@ -178,15 +199,107 @@ void Parser::fetchDebugDataFromComment() else break; } + else if (match[1] == "@debug.set") + { + if (auto parseResult = parseDebugDataAttributeOperationComment(match[1], commentLiteral, m_scanner->currentCommentLocation())) + { + commentLiteral = parseResult->first; + if (parseResult->second.has_value()) + m_currentDebugAttributes = parseResult->second.value(); + } + else + break; + } + else if (match[1] == "@debug.merge") + { + if (auto parseResult = parseDebugDataAttributeOperationComment(match[1], commentLiteral, m_scanner->currentCommentLocation())) + { + commentLiteral = parseResult->first; + if (parseResult->second.has_value()) + { + if (!m_currentDebugAttributes.has_value()) + m_currentDebugAttributes = Json::object(); + m_currentDebugAttributes->merge_patch(parseResult->second.value()); + } + } + else + break; + } + else if (match[1] == "@debug.patch") + { + if (auto parseResult = parseDebugDataAttributeOperationComment(match[1], commentLiteral, m_scanner->currentCommentLocation())) + { + commentLiteral = parseResult->first; + if (parseResult->second.has_value()) + applyDebugDataAttributePatch(parseResult->second.value(), m_scanner->currentCommentLocation()); + } + else + break; + } else // Ignore unrecognized tags. continue; } - m_locationFromComment = originLocation; m_astIDFromComment = astID; } +std::optional>> Parser::parseDebugDataAttributeOperationComment( + std::string const& _command, + std::string_view _arguments, + langutil::SourceLocation const& _location +) +{ + std::optional jsonData; + try + { + jsonData = Json::parse(_arguments.begin(), _arguments.end(), nullptr, true); + } + catch (nlohmann::json::parse_error& e) + { + try + { + jsonData = Json::parse(_arguments.substr(0, e.byte - 1), nullptr, true); + } + catch(nlohmann::json::parse_error& ee) + { + m_errorReporter.syntaxError( + 5721_error, + _location, + _command + ": Could not parse debug data: " + removeNlohmannInternalErrorIdentifier(ee.what()) + ); + jsonData.reset(); + } + _arguments = _arguments.substr(e.byte - 1); + } + return {{_arguments, jsonData}}; +} + +void Parser::applyDebugDataAttributePatch(Json const& _jsonPatch, langutil::SourceLocation const& _location) +{ + try + { + if (!m_currentDebugAttributes.has_value()) + m_currentDebugAttributes = Json::object(); + if (_jsonPatch.is_object()) + { + Json array = Json::array(); + array.push_back(_jsonPatch); + m_currentDebugAttributes = m_currentDebugAttributes->patch(array); + } + else + m_currentDebugAttributes = m_currentDebugAttributes->patch(_jsonPatch); + } + catch(nlohmann::json::parse_error& ee) + { + m_errorReporter.syntaxError( + 9426_error, + _location, + "@debug.patch: Could not patch debug data: " + removeNlohmannInternalErrorIdentifier(ee.what()) + ); + } +} + std::optional> Parser::parseSrcComment( std::string_view const _arguments, langutil::SourceLocation const& _commentLocation diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index 3348904091f2..69f3df88425f 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -31,10 +31,11 @@ #include #include +#include + #include #include #include -#include #include namespace solidity::yul @@ -43,6 +44,8 @@ namespace solidity::yul class Parser: public langutil::ParserBase { public: + typedef util::Cache DebugAttributeCache; + enum class ForLoopComponent { None, ForLoopPre, ForLoopPost, ForLoopBody @@ -56,7 +59,8 @@ class Parser: public langutil::ParserBase explicit Parser( langutil::ErrorReporter& _errorReporter, Dialect const& _dialect, - std::optional _locationOverride = {} + std::optional _locationOverride = {}, + DebugAttributeCache::Ptr debugAttributesCache = {} ): ParserBase(_errorReporter), m_dialect(_dialect), @@ -65,7 +69,8 @@ class Parser: public langutil::ParserBase _locationOverride ? UseSourceLocationFrom::LocationOverride : UseSourceLocationFrom::Scanner - } + }, + m_debugAttributeCache(debugAttributesCache == nullptr ? std::make_shared() : debugAttributesCache) {} /// Constructs a Yul parser that is using the debug data @@ -73,7 +78,8 @@ class Parser: public langutil::ParserBase explicit Parser( langutil::ErrorReporter& _errorReporter, Dialect const& _dialect, - std::optional>> _sourceNames + std::optional>> _sourceNames, + DebugAttributeCache::Ptr debugAttributesCache = {} ): ParserBase(_errorReporter), m_dialect(_dialect), @@ -82,7 +88,8 @@ class Parser: public langutil::ParserBase m_sourceNames.has_value() ? UseSourceLocationFrom::Comments : UseSourceLocationFrom::Scanner - } + }, + m_debugAttributeCache(debugAttributesCache == nullptr ? std::make_shared() : debugAttributesCache) {} /// Parses an inline assembly block starting with `{` and ending with `}`. @@ -117,6 +124,14 @@ class Parser: public langutil::ParserBase langutil::SourceLocation const& _commentLocation ); + std::optional>> parseDebugDataAttributeOperationComment( + std::string const& _command, + std::string_view _arguments, + langutil::SourceLocation const& _commentLocation + ); + + void applyDebugDataAttributePatch(Json const& _jsonPatch, langutil::SourceLocation const& _location); + /// Creates a DebugData object with the correct source location set. langutil::DebugData::ConstPtr createDebugData() const; @@ -153,6 +168,11 @@ class Parser: public langutil::ParserBase static bool isValidNumberLiteral(std::string const& _literal); + DebugAttributeCache::Ptr debugAttributeCache() const + { + return m_debugAttributeCache; + } + private: Dialect const& m_dialect; @@ -163,6 +183,8 @@ class Parser: public langutil::ParserBase UseSourceLocationFrom m_useSourceLocationFrom = UseSourceLocationFrom::Scanner; ForLoopComponent m_currentForLoopComponent = ForLoopComponent::None; bool m_insideFunction = false; + std::optional m_currentDebugAttributes; + mutable DebugAttributeCache::Ptr m_debugAttributeCache; }; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d5435237ec7b..a264ef0c1160 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,6 +28,7 @@ set(contracts_sources detect_stray_source_files("${contracts_sources}" "contracts/") set(libsolutil_sources + libsolutil/Cache.cpp libsolutil/Checksum.cpp libsolutil/CommonData.cpp libsolutil/CommonIO.cpp diff --git a/test/cmdlineTests/ethdebug_large_debug_attributes/args b/test/cmdlineTests/ethdebug_large_debug_attributes/args new file mode 100644 index 000000000000..2c89c24e0a35 --- /dev/null +++ b/test/cmdlineTests/ethdebug_large_debug_attributes/args @@ -0,0 +1 @@ +--strict-assembly diff --git a/test/cmdlineTests/ethdebug_large_debug_attributes/input.yul b/test/cmdlineTests/ethdebug_large_debug_attributes/input.yul new file mode 100644 index 000000000000..42b90b56d3ba --- /dev/null +++ b/test/cmdlineTests/ethdebug_large_debug_attributes/input.yul @@ -0,0 +1,16 @@ +object "a" { + code { + /// @debug.set { + /// "A": "B", + /// "C": "........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................", + /// "D": "........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................" + /// } + let addr := linkersymbol("contract/test.sol:L") + /// @debug.merge { + /// "E": "........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................", + /// "F": "G", + /// "H": "........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................" + /// } + sstore(0, addr) + } +} diff --git a/test/cmdlineTests/ethdebug_large_debug_attributes/output b/test/cmdlineTests/ethdebug_large_debug_attributes/output new file mode 100644 index 000000000000..ad74f2ebeede --- /dev/null +++ b/test/cmdlineTests/ethdebug_large_debug_attributes/output @@ -0,0 +1,26 @@ + +======= ethdebug_large_debug_attributes/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + { + let addr := linkersymbol("contract/test.sol:L") + sstore(0, addr) + } + } +} + + +Binary representation: +73__$f919ba91ac99f96129544b80b9516b27a8$__5f5500 + +Text representation: + /* "ethdebug_large_debug_attributes/input.yul":54152:54187 */ + linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612") + /* "ethdebug_large_debug_attributes/input.yul":108313:108314 */ + 0x00 + /* "ethdebug_large_debug_attributes/input.yul":108306:108321 */ + sstore + /* "ethdebug_large_debug_attributes/input.yul":22:108327 */ + stop diff --git a/test/libsolutil/Cache.cpp b/test/libsolutil/Cache.cpp new file mode 100644 index 000000000000..eba1f62f887b --- /dev/null +++ b/test/libsolutil/Cache.cpp @@ -0,0 +1,166 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 +/** + * @date 2024 + * Unit tests for libsolutil/Cache.h. + */ + +#include +#include + +#include + +#include + + +namespace solidity::util::test +{ + +BOOST_AUTO_TEST_SUITE(CacheTest, *boost::unit_test::label("nooptions")) + +BOOST_AUTO_TEST_CASE(smoke_test) +{ + Cache::Entry cached_int; + Cache int_cache; + cached_int = int_cache.set(45); + BOOST_CHECK(int_cache.set(45) == cached_int); + BOOST_CHECK(int_cache.set(46) == int_cache.set(46)); + + Cache h256_int_cache; + cached_int = h256_int_cache.set(45); + BOOST_CHECK(h256_int_cache.set(45) == cached_int); + BOOST_CHECK(h256_int_cache.set(46) == h256_int_cache.set(46)); + + Cache string_cache; + std::shared_ptr cached_string = string_cache.set(""); + BOOST_CHECK(string_cache.set("") == cached_string); + BOOST_CHECK(string_cache.set("hello") == string_cache.set("hello")); + + Cache h256_string_cache; + cached_string = h256_string_cache.set(""); + BOOST_CHECK(h256_string_cache.set("") == cached_string); + BOOST_CHECK(h256_string_cache.set("hello") == h256_string_cache.set("hello")); + + Cache h256_json_cache; + Cache::Entry cached_json = h256_json_cache.set({}); + BOOST_CHECK(h256_json_cache.set({}) == cached_json); + BOOST_CHECK(h256_json_cache.set({{"a", "b"}}) == h256_json_cache.set({{"a", "b"}})); + + Cache json_cache; + cached_json = json_cache.set({}); + BOOST_CHECK(json_cache.set({}) == cached_json); + BOOST_CHECK(json_cache.set({{"a", "b"}}) == json_cache.set({{"a", "b"}})); + + Cache::Ptr json_cache_ptr = std::make_shared>(); + cached_json = json_cache_ptr->set({}); + BOOST_CHECK(json_cache_ptr->set({}) == cached_json); + BOOST_CHECK(json_cache_ptr->set({{"a", "b"}}) == json_cache_ptr->set({{"a", "b"}})); + + Cache::Ptr h256_json_cache_ptr = std::make_shared>(); + cached_json = h256_json_cache_ptr->set({}); + BOOST_CHECK(h256_json_cache_ptr->set({}) == cached_json); + BOOST_CHECK(h256_json_cache_ptr->set({{"a", "b"}}) == h256_json_cache_ptr->set({{"a", "b"}})); +} + +BOOST_AUTO_TEST_CASE(cache_hash_get) +{ + auto test = [](auto _value0, auto _hash0, auto _value1, auto _hash1) -> void + { + typedef decltype(_hash0) Hash; + typedef decltype(_value0) Value; + static_assert( + std::is_same_v, "types of _hash0 and _hash1 need to be the same" + ); + static_assert( + std::is_same_v, + "types of _value0 and _value1 need to be the same" + ); + typename Cache::Ptr cache = std::make_shared>(); + Hash hash0 = cache->hash(_value0); + Hash hash1 = cache->hash(_value1); + BOOST_CHECK_EQUAL(hash0, _hash0); + BOOST_CHECK_EQUAL(hash1, _hash1); + BOOST_CHECK(cache->get(_hash0) == cache->end()); + BOOST_CHECK(cache->get(_hash1) == cache->end()); + cache->set(_value0); + BOOST_CHECK(cache->get(_hash0) != cache->end()); + BOOST_CHECK(*(cache->get(_hash0)->second) == _value0); + BOOST_CHECK(cache->get(hash1) == cache->end()); + cache->set(_value1); + BOOST_CHECK(cache->get(hash1) != cache->end()); + BOOST_CHECK(*(cache->get(hash1)->second) == _value1); + }; + test(0, static_cast(0), 1, static_cast(1)); + test(0.1f, static_cast(1036831949), 0.2f, static_cast(1045220557)); + test(0.1, static_cast(4591870180066957722), 0.2, static_cast(4596373779694328218)); + test( + "", + // different boost versions seem to return different hashes for strings, so we just calculate the correct hashes here. + Cache::hash(""), + "HELLO WORLD", + Cache::hash("HELLO WORLD") + ); + test( + std::string(), + // different boost versions seem to return different hashes for strings, so we just calculate the correct hashes here. + Cache::hash(std::string()), + std::string("HELLO WORLD"), + Cache::hash("HELLO WORLD") + ); + test( + Json{}, + // different boost versions seem to return different hashes for strings, so we just calculate the correct hashes here. + Cache::hash(Json{}), + Json{{"HELLO", "WORLD"}}, + Cache::hash(Json{{"HELLO", "WORLD"}}) + ); + test( + 0, + static_cast("044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d"), + 1, + static_cast("c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6") + ); + test( + 0.1f, + static_cast("8cd160c72d102a6747abd189ac21d4a1f802e3fcc1bb8fc78cc4d558df0c7c21"), + 0.2f, + static_cast("c1907d585d0b0e66920f6383717e2e9e7c44e42ba86ef49b0e19983ffd702288") + ); + test( + 0.1, + static_cast("8cd160c72d102a6747abd189ac21d4a1f802e3fcc1bb8fc78cc4d558df0c7c21"), + 0.2, + static_cast("c1907d585d0b0e66920f6383717e2e9e7c44e42ba86ef49b0e19983ffd702288") + ); + test( + "", + static_cast("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"), + "HELLO WORLD", + static_cast("6c1223964c4674e3797678a0af4dee8b46a8ac1471d97cf37c136ce0937fa0df") + ); + test( + Json{}, + static_cast("efbde2c3aee204a69b7696d4b10ff31137fe78e3946306284f806e2dfc68b805"), + Json{{"HELLO", "WORLD"}}, + static_cast("90e22a3e1e4d820d1a76c04d130c08dd1cabb2c1d22ad7d582a0b5415d797bde") + ); +} + +BOOST_AUTO_TEST_SUITE_END() + +} diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index ca8784ddb6ef..3c3819b70ce4 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -54,7 +54,7 @@ namespace solidity::yul::test namespace { -std::shared_ptr parse(std::string const& _source, Dialect const& _dialect, ErrorReporter& errorReporter) +std::shared_ptr parse(std::string const& _source, Dialect const& _dialect, ErrorReporter& errorReporter, Parser::DebugAttributeCache::Ptr debugAttributesCache = {}) { auto stream = CharStream(_source, ""); std::map> indicesToSourceNames; @@ -64,7 +64,8 @@ std::shared_ptr parse(std::string const& _source, Dialect const& _dialect auto parserResult = yul::Parser( errorReporter, _dialect, - std::move(indicesToSourceNames) + std::move(indicesToSourceNames), + std::move(debugAttributesCache) ).parse(stream); if (parserResult) { @@ -1041,6 +1042,67 @@ BOOST_AUTO_TEST_CASE(customSourceLocations_multiple_src_tags_on_one_line) CHECK_LOCATION(varX.debugData->originLocation, "source1", 4, 5); } +BOOST_AUTO_TEST_CASE(ethdebug_debug_attributes_empty) +{ + Parser::DebugAttributeCache::Ptr cache = std::make_shared(); + ErrorList errorList; + ErrorReporter reporter(errorList); + auto const sourceText = R"( + {} + )"; + EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{}); + std::shared_ptr result = parse(sourceText, dialect, reporter, cache); + BOOST_REQUIRE(cache->cache().size() == 0); +} + +BOOST_AUTO_TEST_CASE(ethdebug_debug_attributes_set_empty) +{ + Parser::DebugAttributeCache::Ptr cache = std::make_shared(); + ErrorList errorList; + ErrorReporter reporter(errorList); + auto const sourceText = R"( + /// @debug.set {} + {} + )"; + EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{}); + std::shared_ptr result = parse(sourceText, dialect, reporter, cache); + BOOST_REQUIRE(cache->cache().size() == 1); +} + + +BOOST_AUTO_TEST_CASE(ethdebug_debug_attributes_set) +{ + Parser::DebugAttributeCache::Ptr cache = std::make_shared(); + ErrorList errorList; + ErrorReporter reporter(errorList); + auto const sourceText = R"( + /// @debug.set {"hello": "world"} + {} + )"; + EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{}); + std::shared_ptr result = parse(sourceText, dialect, reporter, cache); + BOOST_REQUIRE(cache->cache().size() == 1); +} + +BOOST_AUTO_TEST_CASE(ethdebug_debug_attributes_multiple_set) +{ + Parser::DebugAttributeCache::Ptr cache = std::make_shared(); + ErrorList errorList; + ErrorReporter reporter(errorList); + auto const sourceText = R"( + /// @debug.set {"hello": "world"} + { + /// @debug.set {"hello": "world!"} + {} + /// @debug.set {"hello": "world"} + {} + } + )"; + EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{}); + std::shared_ptr result = parse(sourceText, dialect, reporter, cache); + BOOST_REQUIRE(cache->cache().size() == 2); +} + BOOST_AUTO_TEST_SUITE_END() } // end namespaces diff --git a/test/libyul/yulSyntaxTests/invalid/invalid_debug_merge.yul b/test/libyul/yulSyntaxTests/invalid/invalid_debug_merge.yul new file mode 100644 index 000000000000..13200b008cb8 --- /dev/null +++ b/test/libyul/yulSyntaxTests/invalid/invalid_debug_merge.yul @@ -0,0 +1,7 @@ +object "object" { + code { + /// @debug.merge {"HELLO": 2 + } +} +// ---- +// SyntaxError 5721: (37-65): @debug.merge: Could not parse debug data: parse error at line 1, column 12: syntax error while parsing object - unexpected end of input; expected '}' diff --git a/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch.yul b/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch.yul new file mode 100644 index 000000000000..3f1d15e962da --- /dev/null +++ b/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch.yul @@ -0,0 +1,7 @@ +object "object" { + code { + /// @debug.patch {"HELLO": invalid + } +} +// ---- +// SyntaxError 5721: (37-71): @debug.patch: Could not parse debug data: parse error at line 1, column 11: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal diff --git a/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch_patch_object.yul b/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch_patch_object.yul new file mode 100644 index 000000000000..a5c02823f27c --- /dev/null +++ b/test/libyul/yulSyntaxTests/invalid/invalid_debug_patch_patch_object.yul @@ -0,0 +1,7 @@ +object "object" { + code { + /// @debug.patch { "op": "unknown_operation", "path": "/variable_a", "value": ["test"] } + } +} +// ---- +// SyntaxError 9426: (37-125): @debug.patch: Could not patch debug data: parse error: operation value 'unknown_operation' is invalid diff --git a/test/libyul/yulSyntaxTests/invalid/invalid_debug_set.yul b/test/libyul/yulSyntaxTests/invalid/invalid_debug_set.yul new file mode 100644 index 000000000000..3c99b7cb52bd --- /dev/null +++ b/test/libyul/yulSyntaxTests/invalid/invalid_debug_set.yul @@ -0,0 +1,7 @@ +object "object" { + code { + /// @debug.set {"HELLO": "WORLD + } +} +// ---- +// SyntaxError 5721: (37-68): @debug.set: Could not parse debug data: parse error at line 1, column 17: syntax error while parsing value - invalid string: missing closing quote; last read: '"WORLD' From 9ad6a0d8f6985da21bb23442cc45047633cd71be Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Tue, 12 Mar 2024 15:48:14 +0100 Subject: [PATCH 2/3] [yul] Initial transport of debug data to assembly. --- libevmasm/Assembly.cpp | 11 ++++ libevmasm/Assembly.h | 6 ++ libevmasm/AssemblyItem.h | 9 +++ libyul/AsmPrinter.cpp | 53 ++++++++++++--- libyul/AsmPrinter.h | 1 + libyul/backends/evm/AbstractAssembly.h | 4 +- libyul/backends/evm/EVMCodeTransform.cpp | 27 ++++++++ libyul/backends/evm/EthAssemblyAdapter.cpp | 5 ++ libyul/backends/evm/EthAssemblyAdapter.h | 1 + libyul/backends/evm/NoOutputAssembly.h | 1 + .../evm/OptimizedEVMCodeTransform.cpp | 13 ++++ .../ethdebug_large_debug_attributes/output | 8 ++- .../strict_asm_debug_attributes_merge/args | 1 + .../input.yul | 29 ++++++++ .../strict_asm_debug_attributes_merge/output | 66 +++++++++++++++++++ .../strict_asm_debug_attributes_patch/args | 1 + .../input.yul | 29 ++++++++ .../strict_asm_debug_attributes_patch/output | 66 +++++++++++++++++++ .../strict_asm_debug_attributes_set/args | 1 + .../strict_asm_debug_attributes_set/input.yul | 29 ++++++++ .../strict_asm_debug_attributes_set/output | 66 +++++++++++++++++++ 21 files changed, 415 insertions(+), 12 deletions(-) create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_merge/args create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_merge/input.yul create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_merge/output create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_patch/args create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_patch/input.yul create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_patch/output create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_set/args create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_set/input.yul create mode 100644 test/cmdlineTests/strict_asm_debug_attributes_set/output diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 356a2818a4cd..38c1fd71bfae 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -62,6 +62,7 @@ AssemblyItem const& Assembly::append(AssemblyItem _i) if (!m_items.back().location().isValid() && m_currentSourceLocation.isValid()) m_items.back().setLocation(m_currentSourceLocation); m_items.back().m_modifierDepth = m_currentModifierDepth; + m_items.back().setDebugAttributes(m_currentDebugAttributes); return m_items.back(); } @@ -314,6 +315,16 @@ class Functionalizer std::string expression = _item.toAssemblyText(m_assembly); + if (_item.debugData()->attributes.has_value()) + { + Json attributes = Json::array(); + for (auto const& attribute: *_item.debugData()->attributes) + if ((*attribute != Json::object()) && (*attribute != Json::array())) + attributes.emplace_back(*attribute); + if (!attributes.empty()) + expression += m_prefix + " // @debug.set " + (attributes.size() == 1 ? attributes.at(0).dump() : attributes.dump()); + } + if (!( _item.canBeFunctional() && _item.returnValues() <= 1 && diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 123d7f3ddd8c..d18097a2735d 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -111,6 +111,11 @@ class Assembly /// Changes the source location used for each appended item. void setSourceLocation(langutil::SourceLocation const& _location) { m_currentSourceLocation = _location; } langutil::SourceLocation const& currentSourceLocation() const { return m_currentSourceLocation; } + + /// Changes debug data used for each appended item. + void setDebugAttributes(langutil::DebugData::Attributes const& _debugAttributes) { m_currentDebugAttributes = _debugAttributes; } + langutil::DebugData::Attributes currentDebugAttributes() const { return m_currentDebugAttributes; } + langutil::EVMVersion const& evmVersion() const { return m_evmVersion; } /// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached. @@ -246,6 +251,7 @@ class Assembly /// currently std::string m_name; langutil::SourceLocation m_currentSourceLocation; + langutil::DebugData::Attributes m_currentDebugAttributes; // FIXME: This being static means that the strings won't be freed when they're no longer needed static std::map> s_sharedSourceNames; diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h index c2b3603c6352..c6ec60eb8819 100644 --- a/libevmasm/AssemblyItem.h +++ b/libevmasm/AssemblyItem.h @@ -194,6 +194,15 @@ class AssemblyItem m_debugData = std::move(_debugData); } + void setDebugAttributes(langutil::DebugData::Attributes const& _debugAttributes) + { + if (!m_debugData) + m_debugData = langutil::DebugData::create({}, {}, {}, _debugAttributes); + else + m_debugData = langutil::DebugData::create(m_debugData->nativeLocation, m_debugData->originLocation, m_debugData->astID, _debugAttributes); + } + + langutil::DebugData::ConstPtr debugData() const { return m_debugData; } void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; } diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 191fc5d2d6a1..4587f6405b68 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -49,7 +49,8 @@ std::string AsmPrinter::operator()(Literal const& _literal) std::string const locationComment = formatDebugData(_literal); std::string const formattedValue = formatLiteral(_literal); - + if ( _literal.debugData) + m_currentDebugAttributes = _literal.debugData->attributes; switch (_literal.kind) { case LiteralKind::Number: @@ -66,19 +67,24 @@ std::string AsmPrinter::operator()(Literal const& _literal) std::string AsmPrinter::operator()(Identifier const& _identifier) { yulAssert(!_identifier.name.empty(), "Invalid identifier."); + if (_identifier.debugData) + m_currentDebugAttributes = _identifier.debugData->attributes; return formatDebugData(_identifier) + _identifier.name.str(); } std::string AsmPrinter::operator()(ExpressionStatement const& _statement) { std::string const locationComment = formatDebugData(_statement); - + if (_statement.debugData) + m_currentDebugAttributes = _statement.debugData->attributes; return locationComment + std::visit(*this, _statement.expression); } std::string AsmPrinter::operator()(Assignment const& _assignment) { std::string const locationComment = formatDebugData(_assignment); + if (_assignment.debugData) + m_currentDebugAttributes = _assignment.debugData->attributes; yulAssert(_assignment.variableNames.size() >= 1, ""); std::string variables = (*this)(_assignment.variableNames.front()); @@ -91,7 +97,8 @@ std::string AsmPrinter::operator()(Assignment const& _assignment) std::string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) { std::string out = formatDebugData(_variableDeclaration); - + if (_variableDeclaration.debugData) + m_currentDebugAttributes = _variableDeclaration.debugData->attributes; out += "let "; out += boost::algorithm::join( _variableDeclaration.variables | ranges::views::transform( @@ -110,7 +117,8 @@ std::string AsmPrinter::operator()(VariableDeclaration const& _variableDeclarati std::string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) { yulAssert(!_functionDefinition.name.empty(), "Invalid function name."); - + if (_functionDefinition.debugData) + m_currentDebugAttributes = _functionDefinition.debugData->attributes; std::string out = formatDebugData(_functionDefinition); out += "function " + _functionDefinition.name.str() + "("; out += boost::algorithm::join( @@ -138,6 +146,8 @@ std::string AsmPrinter::operator()(FunctionCall const& _functionCall) { std::string const locationComment = formatDebugData(_functionCall); std::string const functionName = (*this)(_functionCall.functionName); + if (_functionCall.debugData) + m_currentDebugAttributes = _functionCall.debugData->attributes; return locationComment + functionName + "(" + @@ -150,7 +160,8 @@ std::string AsmPrinter::operator()(FunctionCall const& _functionCall) std::string AsmPrinter::operator()(If const& _if) { yulAssert(_if.condition, "Invalid if condition."); - + if (_if.debugData) + m_currentDebugAttributes = _if.debugData->attributes; std::string out = formatDebugData(_if); out += "if " + std::visit(*this, *_if.condition); @@ -165,7 +176,8 @@ std::string AsmPrinter::operator()(If const& _if) std::string AsmPrinter::operator()(Switch const& _switch) { yulAssert(_switch.expression, "Invalid expression pointer."); - + if (_switch.debugData) + m_currentDebugAttributes = _switch.debugData->attributes; std::string out = formatDebugData(_switch); out += "switch " + std::visit(*this, *_switch.expression); @@ -183,6 +195,8 @@ std::string AsmPrinter::operator()(Switch const& _switch) std::string AsmPrinter::operator()(ForLoop const& _forLoop) { yulAssert(_forLoop.condition, "Invalid for loop condition."); + if (_forLoop.debugData) + m_currentDebugAttributes = _forLoop.debugData->attributes; std::string const locationComment = formatDebugData(_forLoop); std::string pre = (*this)(_forLoop.pre); @@ -204,24 +218,31 @@ std::string AsmPrinter::operator()(ForLoop const& _forLoop) std::string AsmPrinter::operator()(Break const& _break) { + if (_break.debugData) + m_currentDebugAttributes = _break.debugData->attributes; return formatDebugData(_break) + "break"; } std::string AsmPrinter::operator()(Continue const& _continue) { + if (_continue.debugData) + m_currentDebugAttributes = _continue.debugData->attributes; return formatDebugData(_continue) + "continue"; } // '_leave' and '__leave' is reserved in VisualStudio std::string AsmPrinter::operator()(Leave const& leave_) { + if (leave_.debugData) + m_currentDebugAttributes = leave_.debugData->attributes; return formatDebugData(leave_) + "leave"; } std::string AsmPrinter::operator()(Block const& _block) { std::string const locationComment = formatDebugData(_block); - + if (_block.debugData) + m_currentDebugAttributes = _block.debugData->attributes; if (_block.statements.empty()) return locationComment + "{ }"; std::string body = boost::algorithm::join( @@ -240,6 +261,8 @@ std::string AsmPrinter::operator()(Block const& _block) std::string AsmPrinter::formatTypedName(TypedName _variable) { yulAssert(!_variable.name.empty(), "Invalid variable name."); + if (_variable.debugData) + m_currentDebugAttributes = _variable.debugData->attributes; return formatDebugData(_variable) + _variable.name.str() + appendTypeName(_variable.type); } @@ -331,7 +354,21 @@ std::string AsmPrinter::formatDebugData(langutil::DebugData::ConstPtr const& _de m_soliditySourceProvider )); } - + // if (m_currentDebugAttributes != _debugData->attributes) + // { + // Json diff = Json::diff(m_currentDebugAttributes, _debugData->attributes); + // if (!diff.empty()) + // items.emplace_back("@debug.patch " + diff.dump()); + // } + if (_debugData->attributes.has_value() && m_currentDebugAttributes != *_debugData->attributes) + { + Json attributes = Json::array(); + for (auto const& attribute:*_debugData->attributes) + if ((*attribute != Json::object()) && (*attribute != Json::array())) + attributes.emplace_back(*attribute); + if (!attributes.empty()) + items.emplace_back("@debug.set " + (attributes.size() == 1 ? attributes.at(0).dump() : attributes.dump())); + } std::string commentBody = joinHumanReadable(items, " "); if (commentBody.empty()) return ""; diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index d3f80b9a09d5..e178a2bdba2a 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -106,6 +106,7 @@ class AsmPrinter langutil::SourceLocation m_lastLocation = {}; langutil::DebugInfoSelection m_debugInfoSelection = {}; langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr; + langutil::DebugData::Attributes m_currentDebugAttributes; }; } diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index fe45008962c8..77d38a5067a8 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -26,9 +26,9 @@ #include #include -#include #include #include +#include #include #include @@ -62,6 +62,8 @@ class AbstractAssembly /// Set a new source location valid starting from the next instruction. virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0; + /// Set a new debug attributes for next instruction. + virtual void setDebugAttributes(langutil::DebugData::Attributes const& _debugAttributes) = 0; /// Retrieve the current height of the stack. This does not have to be zero /// at the beginning. virtual int stackHeight() const = 0; diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index bdce395ef89f..04c5f2ea926a 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -148,12 +148,14 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) else { m_assembly.setSourceLocation(originLocationOf(_varDecl)); + m_assembly.setDebugAttributes(debugDataOf(_varDecl)->attributes); size_t variablesLeft = numVariables; while (variablesLeft--) m_assembly.appendConstant(u256(0)); } m_assembly.setSourceLocation(originLocationOf(_varDecl)); + m_assembly.setDebugAttributes(debugDataOf(_varDecl)->attributes); bool atTopOfStack = true; for (size_t varIndex = 0; varIndex < numVariables; ++varIndex) { @@ -216,12 +218,14 @@ void CodeTransform::operator()(Assignment const& _assignment) expectDeposit(static_cast(_assignment.variableNames.size()), height); m_assembly.setSourceLocation(originLocationOf(_assignment)); + m_assembly.setDebugAttributes(debugDataOf(_assignment)->attributes); generateMultiAssignment(_assignment.variableNames); } void CodeTransform::operator()(ExpressionStatement const& _statement) { m_assembly.setSourceLocation(originLocationOf(_statement)); + m_assembly.setDebugAttributes(debugDataOf(_statement)->attributes); std::visit(*this, _statement.expression); } @@ -230,12 +234,14 @@ void CodeTransform::operator()(FunctionCall const& _call) yulAssert(m_scope, ""); m_assembly.setSourceLocation(originLocationOf(_call)); + m_assembly.setDebugAttributes(debugDataOf(_call)->attributes); if (BuiltinFunctionForEVM const* builtin = m_dialect.builtin(_call.functionName.name)) { for (auto&& [i, arg]: _call.arguments | ranges::views::enumerate | ranges::views::reverse) if (!builtin->literalArgument(i)) visitExpression(arg); m_assembly.setSourceLocation(originLocationOf(_call)); + m_assembly.setDebugAttributes(debugDataOf(_call)->attributes); builtin->generateCode(_call, m_assembly, m_builtinContext); } else @@ -253,6 +259,7 @@ void CodeTransform::operator()(FunctionCall const& _call) for (auto const& arg: _call.arguments | ranges::views::reverse) visitExpression(arg); m_assembly.setSourceLocation(originLocationOf(_call)); + m_assembly.setDebugAttributes(debugDataOf(_call)->attributes); m_assembly.appendJumpTo( functionEntryID(*function), static_cast(function->returns.size() - function->arguments.size()) - 1, @@ -265,6 +272,7 @@ void CodeTransform::operator()(FunctionCall const& _call) void CodeTransform::operator()(Identifier const& _identifier) { m_assembly.setSourceLocation(originLocationOf(_identifier)); + m_assembly.setDebugAttributes(debugDataOf(_identifier)->attributes); // First search internals, then externals. yulAssert(m_scope, ""); if (m_scope->lookup(_identifier.name, GenericVisitor{ @@ -297,6 +305,7 @@ void CodeTransform::operator()(Identifier const& _identifier) void CodeTransform::operator()(Literal const& _literal) { m_assembly.setSourceLocation(originLocationOf(_literal)); + m_assembly.setDebugAttributes(debugDataOf(_literal)->attributes); m_assembly.appendConstant(_literal.value.value()); } @@ -304,11 +313,13 @@ void CodeTransform::operator()(If const& _if) { visitExpression(*_if.condition); m_assembly.setSourceLocation(originLocationOf(_if)); + m_assembly.setDebugAttributes(debugDataOf(_if)->attributes); m_assembly.appendInstruction(evmasm::Instruction::ISZERO); AbstractAssembly::LabelID end = m_assembly.newLabelId(); m_assembly.appendJumpToIf(end); (*this)(_if.body); m_assembly.setSourceLocation(originLocationOf(_if)); + m_assembly.setDebugAttributes(debugDataOf(_if)->attributes); m_assembly.appendLabel(end); } @@ -324,6 +335,7 @@ void CodeTransform::operator()(Switch const& _switch) { (*this)(*c.value); m_assembly.setSourceLocation(originLocationOf(c)); + m_assembly.setDebugAttributes(debugDataOf(c)->attributes); AbstractAssembly::LabelID bodyLabel = m_assembly.newLabelId(); caseBodies[&c] = bodyLabel; yulAssert(m_assembly.stackHeight() == expressionHeight + 1, ""); @@ -336,23 +348,27 @@ void CodeTransform::operator()(Switch const& _switch) (*this)(c.body); } m_assembly.setSourceLocation(originLocationOf(_switch)); + m_assembly.setDebugAttributes(debugDataOf(_switch)->attributes); m_assembly.appendJumpTo(end); size_t numCases = caseBodies.size(); for (auto const& c: caseBodies) { m_assembly.setSourceLocation(originLocationOf(*c.first)); + m_assembly.setDebugAttributes(debugDataOf(*c.first)->attributes); m_assembly.appendLabel(c.second); (*this)(c.first->body); // Avoid useless "jump to next" for the last case. if (--numCases > 0) { m_assembly.setSourceLocation(originLocationOf(*c.first)); + m_assembly.setDebugAttributes(debugDataOf(*c.first)->attributes); m_assembly.appendJumpTo(end); } } m_assembly.setSourceLocation(originLocationOf(_switch)); + m_assembly.setDebugAttributes(debugDataOf(_switch)->attributes); m_assembly.appendLabel(end); m_assembly.appendInstruction(evmasm::Instruction::POP); } @@ -374,6 +390,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) } m_assembly.setSourceLocation(originLocationOf(_function)); + m_assembly.setDebugAttributes(debugDataOf(_function)->attributes); int const stackHeightBefore = m_assembly.stackHeight(); m_assembly.appendLabel(functionEntryID(function)); @@ -414,6 +431,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) m_assignedNamedLabels = std::move(subTransform.m_assignedNamedLabels); m_assembly.setSourceLocation(originLocationOf(_function)); + m_assembly.setDebugAttributes(debugDataOf(_function)->attributes); if (!subTransform.m_stackErrors.empty()) { m_assembly.markAsInvalid(); @@ -505,10 +523,12 @@ void CodeTransform::operator()(ForLoop const& _forLoop) AbstractAssembly::LabelID loopEnd = m_assembly.newLabelId(); m_assembly.setSourceLocation(originLocationOf(_forLoop)); + m_assembly.setDebugAttributes(debugDataOf(_forLoop)->attributes); m_assembly.appendLabel(loopStart); visitExpression(*_forLoop.condition); m_assembly.setSourceLocation(originLocationOf(_forLoop)); + m_assembly.setDebugAttributes(debugDataOf(_forLoop)->attributes); m_assembly.appendInstruction(evmasm::Instruction::ISZERO); m_assembly.appendJumpToIf(loopEnd); @@ -517,11 +537,13 @@ void CodeTransform::operator()(ForLoop const& _forLoop) (*this)(_forLoop.body); m_assembly.setSourceLocation(originLocationOf(_forLoop)); + m_assembly.setDebugAttributes(debugDataOf(_forLoop)->attributes); m_assembly.appendLabel(postPart); (*this)(_forLoop.post); m_assembly.setSourceLocation(originLocationOf(_forLoop)); + m_assembly.setDebugAttributes(debugDataOf(_forLoop)->attributes); m_assembly.appendJumpTo(loopStart); m_assembly.appendLabel(loopEnd); @@ -542,6 +564,7 @@ void CodeTransform::operator()(Break const& _break) { yulAssert(!m_context->forLoopStack.empty(), "Invalid break-statement. Requires surrounding for-loop in code generation."); m_assembly.setSourceLocation(originLocationOf(_break)); + m_assembly.setDebugAttributes(debugDataOf(_break)->attributes); Context::JumpInfo const& jump = m_context->forLoopStack.top().done; m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight)); @@ -551,6 +574,7 @@ void CodeTransform::operator()(Continue const& _continue) { yulAssert(!m_context->forLoopStack.empty(), "Invalid continue-statement. Requires surrounding for-loop in code generation."); m_assembly.setSourceLocation(originLocationOf(_continue)); + m_assembly.setDebugAttributes(debugDataOf(_continue)->attributes); Context::JumpInfo const& jump = m_context->forLoopStack.top().post; m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight)); @@ -561,6 +585,7 @@ void CodeTransform::operator()(Leave const& _leaveStatement) yulAssert(m_functionExitLabel, "Invalid leave-statement. Requires surrounding function in code generation."); yulAssert(m_functionExitStackHeight, ""); m_assembly.setSourceLocation(originLocationOf(_leaveStatement)); + m_assembly.setDebugAttributes(debugDataOf(_leaveStatement)->attributes); m_assembly.appendJumpTo(*m_functionExitLabel, appendPopUntil(*m_functionExitStackHeight)); } @@ -697,6 +722,7 @@ void CodeTransform::visitStatements(std::vector const& _statements) if (functionDefinition && !jumpTarget) { m_assembly.setSourceLocation(originLocationOf(*functionDefinition)); + m_assembly.setDebugAttributes(debugDataOf(*functionDefinition)->attributes); jumpTarget = m_assembly.newLabelId(); m_assembly.appendJumpTo(*jumpTarget, 0); } @@ -718,6 +744,7 @@ void CodeTransform::visitStatements(std::vector const& _statements) void CodeTransform::finalizeBlock(Block const& _block, std::optional blockStartStackHeight) { m_assembly.setSourceLocation(originLocationOf(_block)); + m_assembly.setDebugAttributes(debugDataOf(_block)->attributes); freeUnusedVariables(); diff --git a/libyul/backends/evm/EthAssemblyAdapter.cpp b/libyul/backends/evm/EthAssemblyAdapter.cpp index 79146f859c26..72773d89d087 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.cpp +++ b/libyul/backends/evm/EthAssemblyAdapter.cpp @@ -48,6 +48,11 @@ void EthAssemblyAdapter::setSourceLocation(SourceLocation const& _location) m_assembly.setSourceLocation(_location); } +void EthAssemblyAdapter::setDebugAttributes(langutil::DebugData::Attributes const& _debugAttributes) +{ + m_assembly.setDebugAttributes(_debugAttributes); +} + int EthAssemblyAdapter::stackHeight() const { return m_assembly.deposit(); diff --git a/libyul/backends/evm/EthAssemblyAdapter.h b/libyul/backends/evm/EthAssemblyAdapter.h index 011081dedaac..5f53f1254b16 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.h +++ b/libyul/backends/evm/EthAssemblyAdapter.h @@ -41,6 +41,7 @@ class EthAssemblyAdapter: public AbstractAssembly public: explicit EthAssemblyAdapter(evmasm::Assembly& _assembly); void setSourceLocation(langutil::SourceLocation const& _location) override; + void setDebugAttributes(langutil::DebugData::Attributes const& _debugAttributes) override; int stackHeight() const override; void setStackHeight(int height) override; void appendInstruction(evmasm::Instruction _instruction) override; diff --git a/libyul/backends/evm/NoOutputAssembly.h b/libyul/backends/evm/NoOutputAssembly.h index 8d7dda0bb50c..c35c85490f96 100644 --- a/libyul/backends/evm/NoOutputAssembly.h +++ b/libyul/backends/evm/NoOutputAssembly.h @@ -49,6 +49,7 @@ class NoOutputAssembly: public AbstractAssembly ~NoOutputAssembly() override = default; void setSourceLocation(langutil::SourceLocation const&) override {} + void setDebugAttributes(langutil::DebugData::Attributes const&) override {} int stackHeight() const override { return m_stackHeight; } void setStackHeight(int height) override { m_stackHeight = height; } void appendInstruction(evmasm::Instruction _instruction) override; diff --git a/libyul/backends/evm/OptimizedEVMCodeTransform.cpp b/libyul/backends/evm/OptimizedEVMCodeTransform.cpp index 047014e3dc43..23912fdc28c5 100644 --- a/libyul/backends/evm/OptimizedEVMCodeTransform.cpp +++ b/libyul/backends/evm/OptimizedEVMCodeTransform.cpp @@ -90,6 +90,7 @@ void OptimizedEVMCodeTransform::operator()(CFG::FunctionCall const& _call) // Emit code. { m_assembly.setSourceLocation(originLocationOf(_call)); + m_assembly.setDebugAttributes(debugDataOf(_call)->attributes); m_assembly.appendJumpTo( getFunctionLabel(_call.function), static_cast(_call.function.get().returns.size() - _call.function.get().arguments.size()) - (_call.canContinue ? 1 : 0), @@ -134,6 +135,7 @@ void OptimizedEVMCodeTransform::operator()(CFG::BuiltinCall const& _call) // Emit code. { m_assembly.setSourceLocation(originLocationOf(_call)); + m_assembly.setDebugAttributes(debugDataOf(_call)->attributes); static_cast(_call.builtin.get()).generateCode( _call.functionCall, m_assembly, @@ -249,7 +251,9 @@ void OptimizedEVMCodeTransform::createStackLayout(langutil::DebugData::ConstPtr yulAssert(m_assembly.stackHeight() == static_cast(m_stack.size()), ""); // ::createStackLayout asserts that it has successfully achieved the target layout. langutil::SourceLocation sourceLocation = _debugData ? _debugData->originLocation : langutil::SourceLocation{}; + langutil::DebugData::Attributes debugAttributes = _debugData ? _debugData->attributes : langutil::DebugData::Attributes({}); m_assembly.setSourceLocation(sourceLocation); + m_assembly.setDebugAttributes(debugAttributes); ::createStackLayout( m_stack, _targetStack | ranges::to, @@ -317,8 +321,10 @@ void OptimizedEVMCodeTransform::createStackLayout(langutil::DebugData::ConstPtr [&](LiteralSlot const& _literal) { m_assembly.setSourceLocation(originLocationOf(_literal)); + m_assembly.setDebugAttributes(debugDataOf(_literal)->attributes); m_assembly.appendConstant(_literal.value); m_assembly.setSourceLocation(sourceLocation); + m_assembly.setDebugAttributes(debugAttributes); }, [&](FunctionReturnLabelSlot const&) { @@ -329,16 +335,20 @@ void OptimizedEVMCodeTransform::createStackLayout(langutil::DebugData::ConstPtr if (!m_returnLabels.count(&_returnLabel.call.get())) m_returnLabels[&_returnLabel.call.get()] = m_assembly.newLabelId(); m_assembly.setSourceLocation(originLocationOf(_returnLabel.call.get())); + m_assembly.setDebugAttributes(debugDataOf(_returnLabel.call.get())->attributes); m_assembly.appendLabelReference(m_returnLabels.at(&_returnLabel.call.get())); m_assembly.setSourceLocation(sourceLocation); + m_assembly.setDebugAttributes(debugAttributes); }, [&](VariableSlot const& _variable) { if (m_currentFunctionInfo && util::contains(m_currentFunctionInfo->returnVariables, _variable)) { m_assembly.setSourceLocation(originLocationOf(_variable)); + m_assembly.setDebugAttributes(debugDataOf(_variable)->attributes); m_assembly.appendConstant(0); m_assembly.setSourceLocation(sourceLocation); + m_assembly.setDebugAttributes(debugAttributes); return; } yulAssert(false, "Variable not found on stack."); @@ -372,6 +382,7 @@ void OptimizedEVMCodeTransform::operator()(CFG::BasicBlock const& _block) yulAssert(m_generated.insert(&_block).second, ""); m_assembly.setSourceLocation(originLocationOf(_block)); + m_assembly.setDebugAttributes(debugDataOf(_block)->attributes); auto const& blockInfo = m_stackLayout.blockInfos.at(&_block); // Assert that the stack is valid for entering the block. @@ -412,6 +423,7 @@ void OptimizedEVMCodeTransform::operator()(CFG::BasicBlock const& _block) // Exit the block. m_assembly.setSourceLocation(originLocationOf(_block)); + m_assembly.setDebugAttributes(debugDataOf(_block)->attributes); std::visit(util::GenericVisitor{ [&](CFG::BasicBlock::MainExit const&) { @@ -531,6 +543,7 @@ void OptimizedEVMCodeTransform::operator()(CFG::FunctionInfo const& _functionInf m_assembly.setStackHeight(static_cast(m_stack.size())); m_assembly.setSourceLocation(originLocationOf(_functionInfo)); + m_assembly.setDebugAttributes(debugDataOf(_functionInfo)->attributes); m_assembly.appendLabel(getFunctionLabel(_functionInfo.function)); // Create the entry layout of the function body block and visit. diff --git a/test/cmdlineTests/ethdebug_large_debug_attributes/output b/test/cmdlineTests/ethdebug_large_debug_attributes/output index ad74f2ebeede..8c0162b4d8a4 100644 --- a/test/cmdlineTests/ethdebug_large_debug_attributes/output +++ b/test/cmdlineTests/ethdebug_large_debug_attributes/output @@ -5,7 +5,9 @@ Pretty printed source: object "a" { code { { + /// @debug.set {"A":"B","C":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","D":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"} let addr := linkersymbol("contract/test.sol:L") + /// @debug.set {"A":"B","C":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","D":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","E":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","F":"G","H":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"} sstore(0, addr) } } @@ -17,10 +19,10 @@ Binary representation: Text representation: /* "ethdebug_large_debug_attributes/input.yul":54152:54187 */ - linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612") + linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612") // @debug.set {"A":"B","C":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","D":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"} /* "ethdebug_large_debug_attributes/input.yul":108313:108314 */ - 0x00 + 0x00 // @debug.set {"A":"B","C":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","D":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","E":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","F":"G","H":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"} /* "ethdebug_large_debug_attributes/input.yul":108306:108321 */ - sstore + sstore // @debug.set {"A":"B","C":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","D":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","E":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","F":"G","H":"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"} /* "ethdebug_large_debug_attributes/input.yul":22:108327 */ stop diff --git a/test/cmdlineTests/strict_asm_debug_attributes_merge/args b/test/cmdlineTests/strict_asm_debug_attributes_merge/args new file mode 100644 index 000000000000..f45d50838ceb --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_merge/args @@ -0,0 +1 @@ +--strict-assembly --ir-optimized --asm \ No newline at end of file diff --git a/test/cmdlineTests/strict_asm_debug_attributes_merge/input.yul b/test/cmdlineTests/strict_asm_debug_attributes_merge/input.yul new file mode 100644 index 000000000000..2c57d1f62114 --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_merge/input.yul @@ -0,0 +1,29 @@ +object "object" { + code { + { + /// @debug.merge {"scope": 1} + let a + /// @debug.merge {"assignment": 1} + a := z() + /// @debug.merge {"assignment": null} + let b + /// @debug.merge {"assignment": 2} + b := z_1() + /// @debug.merge {"assignment": null} + sstore(a, b) + /// @debug.merge {"scope": null} + } + function z() -> y + { + /// @debug.merge {"scope": 2} + y := calldataload(0) + /// @debug.merge {"scope": null} + } + function z_1() -> y + { + /// @debug.merge {"scope": 3} + y := calldataload(0x20) + /// @debug.merge {"scope": null} + } + } +} diff --git a/test/cmdlineTests/strict_asm_debug_attributes_merge/output b/test/cmdlineTests/strict_asm_debug_attributes_merge/output new file mode 100644 index 000000000000..749da1026f6f --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_merge/output @@ -0,0 +1,66 @@ + +======= strict_asm_debug_attributes_merge/input.yul (EVM) ======= + +Pretty printed source: +object "object" { + code { + { + /// @debug.set {"scope":1} + let a + /// @debug.set {"assignment":1,"scope":1} + a := z() + /// @debug.set {"scope":1} + let b + /// @debug.set {"assignment":2,"scope":1} + b := z_1() + /// @debug.set {"scope":1} + sstore(a, b) + } + function z() -> y + { + /// @debug.set {"scope":2} + y := calldataload(0) + } + function z_1() -> y + { + /// @debug.set {"scope":3} + y := calldataload(0x20) + } + } +} + + +Text representation: + /* "strict_asm_debug_attributes_merge/input.yul":163:166 */ + tag_3 // @debug.set {"assignment":1,"scope":1} + tag_1 // @debug.set {"assignment":1,"scope":1} + jump // in // @debug.set {"assignment":1,"scope":1} +tag_3: // @debug.set {"assignment":1,"scope":1} + /* "strict_asm_debug_attributes_merge/input.yul":299:304 */ + tag_4 // @debug.set {"assignment":2,"scope":1} + tag_2 // @debug.set {"assignment":2,"scope":1} + jump // in // @debug.set {"assignment":2,"scope":1} +tag_4: // @debug.set {"assignment":2,"scope":1} + /* "strict_asm_debug_attributes_merge/input.yul":367:379 */ + swap1 // @debug.set {"scope":1} + sstore // @debug.set {"scope":1} + /* "strict_asm_debug_attributes_merge/input.yul":27:777 */ + stop + /* "strict_asm_debug_attributes_merge/input.yul":443:600 */ +tag_1: + /* "strict_asm_debug_attributes_merge/input.yul":543:544 */ + 0x00 // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_merge/input.yul":530:545 */ + calldataload // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_merge/input.yul":443:600 */ + swap1 + jump // out + /* "strict_asm_debug_attributes_merge/input.yul":609:771 */ +tag_2: + /* "strict_asm_debug_attributes_merge/input.yul":711:715 */ + 0x20 // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_merge/input.yul":698:716 */ + calldataload // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_merge/input.yul":609:771 */ + swap1 + jump // out diff --git a/test/cmdlineTests/strict_asm_debug_attributes_patch/args b/test/cmdlineTests/strict_asm_debug_attributes_patch/args new file mode 100644 index 000000000000..f45d50838ceb --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_patch/args @@ -0,0 +1 @@ +--strict-assembly --ir-optimized --asm \ No newline at end of file diff --git a/test/cmdlineTests/strict_asm_debug_attributes_patch/input.yul b/test/cmdlineTests/strict_asm_debug_attributes_patch/input.yul new file mode 100644 index 000000000000..f96a8d502b34 --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_patch/input.yul @@ -0,0 +1,29 @@ +object "object" { + code { + { + /// @debug.patch {"op": "add", "path": "/scope", "value": 1} + let a + /// @debug.patch {"op": "add", "path": "/assignment", "value": 1} + a := z() + /// @debug.patch {"op": "remove", "path": "/assignment"} + let b + /// @debug.patch {"op": "add", "path": "/assignment", "value": 2} + b := z_1() + /// @debug.patch {"op": "remove", "path": "/assignment"} + sstore(a, b) + /// @debug.patch {"op": "remove", "path": "/scope"} + } + function z() -> y + { + /// @debug.patch {"op": "add", "path": "/scope", "value": 2} + y := calldataload(0) + /// @debug.patch {"op": "remove", "path": "/scope"} + } + function z_1() -> y + { + /// @debug.patch {"op": "add", "path": "/scope", "value": 3} + y := calldataload(0x20) + /// @debug.patch {"op": "remove", "path": "/scope"} + } + } +} diff --git a/test/cmdlineTests/strict_asm_debug_attributes_patch/output b/test/cmdlineTests/strict_asm_debug_attributes_patch/output new file mode 100644 index 000000000000..8dcee6564a4a --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_patch/output @@ -0,0 +1,66 @@ + +======= strict_asm_debug_attributes_patch/input.yul (EVM) ======= + +Pretty printed source: +object "object" { + code { + { + /// @debug.set {"scope":1} + let a + /// @debug.set {"assignment":1,"scope":1} + a := z() + /// @debug.set {"scope":1} + let b + /// @debug.set {"assignment":2,"scope":1} + b := z_1() + /// @debug.set {"scope":1} + sstore(a, b) + } + function z() -> y + { + /// @debug.set {"scope":2} + y := calldataload(0) + } + function z_1() -> y + { + /// @debug.set {"scope":3} + y := calldataload(0x20) + } + } +} + + +Text representation: + /* "strict_asm_debug_attributes_patch/input.yul":227:230 */ + tag_3 // @debug.set {"assignment":1,"scope":1} + tag_1 // @debug.set {"assignment":1,"scope":1} + jump // in // @debug.set {"assignment":1,"scope":1} +tag_3: // @debug.set {"assignment":1,"scope":1} + /* "strict_asm_debug_attributes_patch/input.yul":415:420 */ + tag_4 // @debug.set {"assignment":2,"scope":1} + tag_2 // @debug.set {"assignment":2,"scope":1} + jump // in // @debug.set {"assignment":2,"scope":1} +tag_4: // @debug.set {"assignment":2,"scope":1} + /* "strict_asm_debug_attributes_patch/input.yul":503:515 */ + swap1 // @debug.set {"scope":1} + sstore // @debug.set {"scope":1} + /* "strict_asm_debug_attributes_patch/input.yul":27:1037 */ + stop + /* "strict_asm_debug_attributes_patch/input.yul":599:808 */ +tag_1: + /* "strict_asm_debug_attributes_patch/input.yul":731:732 */ + 0x00 // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_patch/input.yul":718:733 */ + calldataload // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_patch/input.yul":599:808 */ + swap1 + jump // out + /* "strict_asm_debug_attributes_patch/input.yul":817:1031 */ +tag_2: + /* "strict_asm_debug_attributes_patch/input.yul":951:955 */ + 0x20 // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_patch/input.yul":938:956 */ + calldataload // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_patch/input.yul":817:1031 */ + swap1 + jump // out diff --git a/test/cmdlineTests/strict_asm_debug_attributes_set/args b/test/cmdlineTests/strict_asm_debug_attributes_set/args new file mode 100644 index 000000000000..f45d50838ceb --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_set/args @@ -0,0 +1 @@ +--strict-assembly --ir-optimized --asm \ No newline at end of file diff --git a/test/cmdlineTests/strict_asm_debug_attributes_set/input.yul b/test/cmdlineTests/strict_asm_debug_attributes_set/input.yul new file mode 100644 index 000000000000..08733a757ace --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_set/input.yul @@ -0,0 +1,29 @@ +object "object" { + code { + { + /// @debug.set {"scope": 1} + let a + /// @debug.set {"scope": 1, "assignment": 1} + a := z() + /// @debug.set {"scope": 1} + let b + /// @debug.set {"scope": 1, "assignment": 2} + b := z_1() + /// @debug.set {"scope": 1} + sstore(a, b) + /// @debug.set {} + } + function z() -> y + { + /// @debug.set {"scope": 2} + y := calldataload(0) + /// @debug.set {} + } + function z_1() -> y + { + /// @debug.set {"scope": 3} + y := calldataload(0x20) + /// @debug.set {} + } + } +} diff --git a/test/cmdlineTests/strict_asm_debug_attributes_set/output b/test/cmdlineTests/strict_asm_debug_attributes_set/output new file mode 100644 index 000000000000..b318fe4af4ce --- /dev/null +++ b/test/cmdlineTests/strict_asm_debug_attributes_set/output @@ -0,0 +1,66 @@ + +======= strict_asm_debug_attributes_set/input.yul (EVM) ======= + +Pretty printed source: +object "object" { + code { + { + /// @debug.set {"scope":1} + let a + /// @debug.set {"assignment":1,"scope":1} + a := z() + /// @debug.set {"scope":1} + let b + /// @debug.set {"assignment":2,"scope":1} + b := z_1() + /// @debug.set {"scope":1} + sstore(a, b) + } + function z() -> y + { + /// @debug.set {"scope":2} + y := calldataload(0) + } + function z_1() -> y + { + /// @debug.set {"scope":3} + y := calldataload(0x20) + } + } +} + + +Text representation: + /* "strict_asm_debug_attributes_set/input.yul":171:174 */ + tag_3 // @debug.set {"assignment":1,"scope":1} + tag_1 // @debug.set {"assignment":1,"scope":1} + jump // in // @debug.set {"assignment":1,"scope":1} +tag_3: // @debug.set {"assignment":1,"scope":1} + /* "strict_asm_debug_attributes_set/input.yul":307:312 */ + tag_4 // @debug.set {"assignment":2,"scope":1} + tag_2 // @debug.set {"assignment":2,"scope":1} + jump // in // @debug.set {"assignment":2,"scope":1} +tag_4: // @debug.set {"assignment":2,"scope":1} + /* "strict_asm_debug_attributes_set/input.yul":365:377 */ + swap1 // @debug.set {"scope":1} + sstore // @debug.set {"scope":1} + /* "strict_asm_debug_attributes_set/input.yul":27:726 */ + stop + /* "strict_asm_debug_attributes_set/input.yul":426:566 */ +tag_1: + /* "strict_asm_debug_attributes_set/input.yul":524:525 */ + 0x00 // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_set/input.yul":511:526 */ + calldataload // @debug.set {"scope":2} + /* "strict_asm_debug_attributes_set/input.yul":426:566 */ + swap1 + jump // out + /* "strict_asm_debug_attributes_set/input.yul":575:720 */ +tag_2: + /* "strict_asm_debug_attributes_set/input.yul":675:679 */ + 0x20 // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_set/input.yul":662:680 */ + calldataload // @debug.set {"scope":3} + /* "strict_asm_debug_attributes_set/input.yul":575:720 */ + swap1 + jump // out From d548cb1555e15295408c42eb37d35ebdfa0ac44e Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Tue, 12 Mar 2024 15:48:14 +0100 Subject: [PATCH 3/3] [test] Add support to run yul optimizer assembly test. --- libyul/ObjectParser.cpp | 2 +- libyul/ObjectParser.h | 7 +- libyul/optimiser/FunctionGrouper.h | 15 ++- libyul/optimiser/NameDisplacer.h | 10 +- libyul/optimiser/OptimiserStep.h | 2 + libyul/optimiser/Suite.cpp | 5 +- libyul/optimiser/Suite.h | 4 +- test/CMakeLists.txt | 2 + test/InteractiveTests.h | 2 + test/libyul/Common.cpp | 33 +++++- test/libyul/Common.h | 13 ++- test/libyul/KnowledgeBaseTest.cpp | 2 +- test/libyul/YulOptimizerAssemblyTest.cpp | 106 ++++++++++++++++++ test/libyul/YulOptimizerAssemblyTest.h | 54 +++++++++ test/libyul/YulOptimizerTest.cpp | 31 +---- test/libyul/YulOptimizerTest.h | 4 - test/libyul/YulOptimizerTestCommon.cpp | 10 +- test/libyul/YulOptimizerTestCommon.h | 6 +- .../blockFlattener/basic.yul | 70 ++++++++++++ test/tools/CMakeLists.txt | 1 + test/tools/yulopti.cpp | 3 +- tools/yulPhaser/Program.cpp | 3 +- 22 files changed, 334 insertions(+), 51 deletions(-) create mode 100644 test/libyul/YulOptimizerAssemblyTest.cpp create mode 100644 test/libyul/YulOptimizerAssemblyTest.h create mode 100644 test/libyul/yulOptimizerAssemblyTests/blockFlattener/basic.yul diff --git a/libyul/ObjectParser.cpp b/libyul/ObjectParser.cpp index a02b9660b978..fc1e71dd1152 100644 --- a/libyul/ObjectParser.cpp +++ b/libyul/ObjectParser.cpp @@ -171,7 +171,7 @@ std::optional ObjectParser::tryParseSourceNameMapping() const std::shared_ptr ObjectParser::parseBlock(std::optional _sourceNames) { - Parser parser(m_errorReporter, m_dialect, std::move(_sourceNames)); + Parser parser(m_errorReporter, m_dialect, std::move(_sourceNames), m_debugAttributeCache); std::shared_ptr block = parser.parseInline(m_scanner); yulAssert(block || m_errorReporter.hasErrors(), "Invalid block but no error!"); return block; diff --git a/libyul/ObjectParser.h b/libyul/ObjectParser.h index 716a191ea878..7a7cc100dba7 100644 --- a/libyul/ObjectParser.h +++ b/libyul/ObjectParser.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ #include #include +#include namespace solidity::langutil { @@ -46,8 +48,8 @@ namespace solidity::yul class ObjectParser: public langutil::ParserBase { public: - explicit ObjectParser(langutil::ErrorReporter& _errorReporter, Dialect const& _dialect): - ParserBase(_errorReporter), m_dialect(_dialect) {} + explicit ObjectParser(langutil::ErrorReporter& _errorReporter, Dialect const& _dialect, Parser::DebugAttributeCache::Ptr _debugAttributeCache = {}): + ParserBase(_errorReporter), m_dialect(_dialect), m_debugAttributeCache(std::move(_debugAttributeCache)) {} /// Parses a Yul object. /// Falls back to code-only parsing if the source starts with `{`. @@ -67,6 +69,7 @@ class ObjectParser: public langutil::ParserBase void addNamedSubObject(Object& _container, YulString _name, std::shared_ptr _subObject); Dialect const& m_dialect; + Parser::DebugAttributeCache::Ptr m_debugAttributeCache; }; } diff --git a/libyul/optimiser/FunctionGrouper.h b/libyul/optimiser/FunctionGrouper.h index 57ea80cac9f7..be8102b311e2 100644 --- a/libyul/optimiser/FunctionGrouper.h +++ b/libyul/optimiser/FunctionGrouper.h @@ -23,6 +23,9 @@ #pragma once #include +#include + +#include namespace solidity::yul { @@ -41,14 +44,22 @@ class FunctionGrouper { public: static constexpr char const* name{"FunctionGrouper"}; - static void run(OptimiserStepContext&, Block& _ast) { FunctionGrouper{}(_ast); } + static void run(OptimiserStepContext&, Block& _ast, Parser::DebugAttributeCache::Ptr _debugAttributeCache = {}) + { + FunctionGrouper{std::move(_debugAttributeCache)}(_ast); + } void operator()(Block& _block); private: - FunctionGrouper() = default; + explicit FunctionGrouper(Parser::DebugAttributeCache::Ptr _debugAttributeCache) + : m_debugAttributeCache(std::move(_debugAttributeCache)) + { + } bool alreadyGrouped(Block const& _block); + + Parser::DebugAttributeCache::Ptr m_debugAttributeCache; }; } diff --git a/libyul/optimiser/NameDisplacer.h b/libyul/optimiser/NameDisplacer.h index 336dd04e42de..476140f26fd7 100644 --- a/libyul/optimiser/NameDisplacer.h +++ b/libyul/optimiser/NameDisplacer.h @@ -21,11 +21,14 @@ #pragma once +#include #include #include + #include #include +#include namespace solidity::yul { @@ -44,10 +47,12 @@ class NameDisplacer: public ASTModifier public: explicit NameDisplacer( NameDispenser& _dispenser, - std::set const& _namesToFree + std::set const& _namesToFree, + Parser::DebugAttributeCache::Ptr _debugAttributeCache = {} ): m_nameDispenser(_dispenser), - m_namesToFree(_namesToFree) + m_namesToFree(_namesToFree), + m_debugAttributeCache(std::move(_debugAttributeCache)) { for (YulString n: _namesToFree) m_nameDispenser.markUsed(n); @@ -71,6 +76,7 @@ class NameDisplacer: public ASTModifier NameDispenser& m_nameDispenser; std::set const& m_namesToFree; std::map m_translations; + Parser::DebugAttributeCache::Ptr m_debugAttributeCache; }; } diff --git a/libyul/optimiser/OptimiserStep.h b/libyul/optimiser/OptimiserStep.h index e3e5fe4c605d..674a7940c81c 100644 --- a/libyul/optimiser/OptimiserStep.h +++ b/libyul/optimiser/OptimiserStep.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include @@ -39,6 +40,7 @@ struct OptimiserStepContext std::set const& reservedIdentifiers; /// The value nullopt represents creation code std::optional expectedExecutionsPerDeployment; + Parser::DebugAttributeCache::Ptr debugAttributeCache; }; diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 83bc0370092b..e8bea10d9545 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -141,7 +141,8 @@ void OptimiserSuite::run( std::string_view _optimisationSequence, std::string_view _optimisationCleanupSequence, std::optional _expectedExecutionsPerDeployment, - std::set const& _externallyUsedIdentifiers + std::set const& _externallyUsedIdentifiers, + Parser::DebugAttributeCache::Ptr _debugAttributeCache ) { EVMDialect const* evmDialect = dynamic_cast(&_dialect); @@ -161,7 +162,7 @@ void OptimiserSuite::run( Block& ast = *_object.code; NameDispenser dispenser{_dialect, ast, reservedIdentifiers}; - OptimiserStepContext context{_dialect, dispenser, reservedIdentifiers, _expectedExecutionsPerDeployment}; + OptimiserStepContext context{_dialect, dispenser, reservedIdentifiers, _expectedExecutionsPerDeployment, _debugAttributeCache}; OptimiserSuite suite(context, Debug::None); diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 6e3886da3b2d..9d2e7c6436ee 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -21,6 +21,7 @@ #pragma once +#include #include #include #include @@ -70,7 +71,8 @@ class OptimiserSuite std::string_view _optimisationSequence, std::string_view _optimisationCleanupSequence, std::optional _expectedExecutionsPerDeployment, - std::set const& _externallyUsedIdentifiers = {} + std::set const& _externallyUsedIdentifiers = {}, + Parser::DebugAttributeCache::Ptr _debugAttributeCache = {} ); /// Ensures that specified sequence of step abbreviations is well-formed and can be executed. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a264ef0c1160..62da68b288dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -159,6 +159,8 @@ set(libyul_sources libyul/SyntaxTest.cpp libyul/YulInterpreterTest.cpp libyul/YulInterpreterTest.h + libyul/YulOptimizerAssemblyTest.cpp + libyul/YulOptimizerAssemblyTest.h libyul/YulOptimizerTest.cpp libyul/YulOptimizerTest.h libyul/YulOptimizerTestCommon.cpp diff --git a/test/InteractiveTests.h b/test/InteractiveTests.h index 42e20d7e3919..9e44a5ba3bf5 100644 --- a/test/InteractiveTests.h +++ b/test/InteractiveTests.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ Testsuite const g_interactiveTestsuites[] = { /* Title Path Subpath SMT NeedsVM Creator function */ {"Yul Optimizer", "libyul", "yulOptimizerTests", false, false, &yul::test::YulOptimizerTest::create}, + {"Yul Optimizer with Assembly", "libyul", "yulOptimizerAssemblyTests", false, false, &yul::test::YulOptimizerAssemblyTest::create}, {"Yul Interpreter", "libyul", "yulInterpreterTests", false, false, &yul::test::YulInterpreterTest::create}, {"Yul Object Compiler", "libyul", "objectCompiler", false, false, &yul::test::ObjectCompilerTest::create}, {"Yul Control Flow Graph", "libyul", "yulControlFlowGraph", false, false, &yul::test::ControlFlowGraphTest::create}, diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index 10d7d12adddd..2bcf388ec563 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -33,9 +33,13 @@ #include #include #include +#include + +#include #include +#include #include using namespace solidity; @@ -69,13 +73,14 @@ std::pair, std::shared_ptr> yul::te std::pair, std::shared_ptr> yul::test::parse( std::string const& _source, Dialect const& _dialect, - ErrorList& _errors + ErrorList& _errors, + Parser::DebugAttributeCache::Ptr _debugAttributeCache ) { ErrorReporter errorReporter(_errors); CharStream stream(_source, ""); std::shared_ptr scanner = std::make_shared(stream); - std::shared_ptr parserResult = yul::ObjectParser(errorReporter, _dialect).parse(scanner, false); + std::shared_ptr parserResult = yul::ObjectParser(errorReporter, _dialect, std::move(_debugAttributeCache)).parse(scanner, false); if (!parserResult) return {}; if (!parserResult->code || errorReporter.hasErrors()) @@ -88,6 +93,30 @@ std::pair, std::shared_ptr> yul::t return {std::move(parserResult), std::move(analysisInfo)}; } +std::pair, std::shared_ptr> yul::test::parse( + std::ostream& _stream, + std::string const& _linePrefix, + bool const _formatted, + std::string const& _source, + Dialect const& _dialect, + Parser::DebugAttributeCache::Ptr _debugAttributeCache +) +{ + ErrorList errors; + std::shared_ptr object; + std::shared_ptr analysisInfo; + std::tie(object, analysisInfo) = yul::test::parse(_source, _dialect, errors, _debugAttributeCache); + if (!object || !analysisInfo || Error::containsErrors(errors)) + { + util::AnsiColorized(_stream, _formatted, {util::formatting::BOLD, util::formatting::RED}) << _linePrefix << "Error parsing source." << std::endl; + CharStream charStream(_source, ""); + SourceReferenceFormatter{_stream, SingletonCharStreamProvider(charStream), true, false} + .printErrorInformation(errors); + return {}; + } + return {std::move(object), std::move(analysisInfo)}; +} + yul::Block yul::test::disambiguate(std::string const& _source, bool _yul) { auto result = parse(_source, _yul); diff --git a/test/libyul/Common.h b/test/libyul/Common.h index f6c63feb9bb2..45b3bdc0fd73 100644 --- a/test/libyul/Common.h +++ b/test/libyul/Common.h @@ -27,6 +27,8 @@ #include #include +#include + namespace solidity::langutil { class Error; @@ -48,7 +50,16 @@ std::pair, std::shared_ptr> parse(std::string const& _source, bool _yul = true); std::pair, std::shared_ptr> -parse(std::string const& _source, Dialect const& _dialect, langutil::ErrorList& _errors); +parse(std::string const& _source, Dialect const& _dialect, langutil::ErrorList& _errors, Parser::DebugAttributeCache::Ptr _debugAttributeCache = {}); + +std::pair, std::shared_ptr> parse( + std::ostream& _stream, + std::string const& _linePrefix, + bool const _formatted, + std::string const& _source, + Dialect const& _dialect, + Parser::DebugAttributeCache::Ptr _debugAttributeCache = {} +); Block disambiguate(std::string const& _source, bool _yul = true); std::string format(std::string const& _source, bool _yul = true); diff --git a/test/libyul/KnowledgeBaseTest.cpp b/test/libyul/KnowledgeBaseTest.cpp index b1dd0e6d19c5..7af0407097d5 100644 --- a/test/libyul/KnowledgeBaseTest.cpp +++ b/test/libyul/KnowledgeBaseTest.cpp @@ -50,7 +50,7 @@ class KnowledgeBaseTest NameDispenser dispenser(m_dialect, *m_object->code); std::set reserved; - OptimiserStepContext context{m_dialect, dispenser, reserved, 0}; + OptimiserStepContext context{m_dialect, dispenser, reserved, 0, {}}; CommonSubexpressionEliminator::run(context, *m_object->code); m_ssaValues(*m_object->code); diff --git a/test/libyul/YulOptimizerAssemblyTest.cpp b/test/libyul/YulOptimizerAssemblyTest.cpp new file mode 100644 index 000000000000..2e600c3d4dd3 --- /dev/null +++ b/test/libyul/YulOptimizerAssemblyTest.cpp @@ -0,0 +1,106 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace solidity; +using namespace solidity::util; +using namespace solidity::langutil; +using namespace solidity::yul; +using namespace solidity::yul::test; +using namespace solidity::frontend; +using namespace solidity::frontend::test; + +YulOptimizerAssemblyTest::YulOptimizerAssemblyTest(std::string const& _filename): + EVMVersionRestrictedTestCase(_filename) +{ + boost::filesystem::path path(_filename); + + if (path.empty() || std::next(path.begin()) == path.end() || std::next(std::next(path.begin())) == path.end()) + BOOST_THROW_EXCEPTION(std::runtime_error("Filename path has to contain a directory: \"" + _filename + "\".")); + m_optimizerStep = std::prev(std::prev(path.end()))->string(); + + m_source = m_reader.source(); + m_expectation = m_reader.simpleExpectations(); +} + +TestCase::TestResult YulOptimizerAssemblyTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted) +{ + std::shared_ptr object; + std::shared_ptr analysisInfo; + Parser::DebugAttributeCache::Ptr debugAttributeCache = std::make_shared(); + + Dialect const& dialect = test::dialect("evm", solidity::test::CommonOptions::get().evmVersion()); + std::tie(object, analysisInfo) = test::parse(_stream, _linePrefix, _formatted, m_source, dialect, debugAttributeCache); + if (!object) + return TestResult::FatalError; + + object->analysisInfo = analysisInfo; + YulOptimizerTestCommon tester(object, dialect); + tester.setStep(m_optimizerStep); + + if (!tester.runStep()) + { + AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << std::endl; + return TestResult::FatalError; + } + + auto const printed = (object->subObjects.empty() ? AsmPrinter{ dialect }(*object->code) : object->toString(&dialect)); + + m_obtainedResult = "step: " + m_optimizerStep + "\n\n" + printed + "\n"; + + *object->analysisInfo = AsmAnalyzer::analyzeStrictAssertCorrect(dialect, *object); + + evmasm::Assembly assembly{solidity::test::CommonOptions::get().evmVersion(), false, {}}; + EthAssemblyAdapter adapter(assembly); + EVMObjectCompiler::compile( + *object, + adapter, + EVMDialect::strictAssemblyForEVMObjects(solidity::test::CommonOptions::get().evmVersion()), + false, // optimize - don't run any other optimization + solidity::test::CommonOptions::get().eofVersion() + ); + + m_obtainedResult += "\nAssembly:\n" + toString(assembly); + + return checkResult(_stream, _linePrefix, _formatted); +} diff --git a/test/libyul/YulOptimizerAssemblyTest.h b/test/libyul/YulOptimizerAssemblyTest.h new file mode 100644 index 000000000000..eeae052458fd --- /dev/null +++ b/test/libyul/YulOptimizerAssemblyTest.h @@ -0,0 +1,54 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 + +#pragma once + +#include + +namespace solidity::langutil +{ +class Error; +using ErrorList = std::vector>; +} + +namespace solidity::yul +{ +struct AsmAnalysisInfo; +struct Object; +struct Dialect; +} + +namespace solidity::yul::test +{ + +class YulOptimizerAssemblyTest: public solidity::frontend::test::EVMVersionRestrictedTestCase +{ +public: + static std::unique_ptr create(Config const& _config) + { + return std::make_unique(_config.filename); + } + + explicit YulOptimizerAssemblyTest(std::string const& _filename); + + TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; +private: + std::string m_optimizerStep; +}; + +} diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 82e2549809e2..daa1393d0a19 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -26,9 +26,8 @@ #include #include -#include -#include #include +#include #include #include @@ -62,11 +61,11 @@ YulOptimizerTest::YulOptimizerTest(std::string const& _filename): TestCase::TestResult YulOptimizerTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted) { - std::tie(m_object, m_analysisInfo) = parse(_stream, _linePrefix, _formatted, m_source); + soltestAssert(m_dialect, "Dialect not set."); + std::tie(m_object, m_analysisInfo) = parse(_stream, _linePrefix, _formatted, m_source, *m_dialect); if (!m_object) return TestResult::FatalError; - soltestAssert(m_dialect, "Dialect not set."); m_object->analysisInfo = m_analysisInfo; YulOptimizerTestCommon tester(m_object, *m_dialect); @@ -81,7 +80,7 @@ TestCase::TestResult YulOptimizerTest::run(std::ostream& _stream, std::string co auto const printed = (m_object->subObjects.empty() ? AsmPrinter{ *m_dialect }(*m_object->code) : m_object->toString(m_dialect)); // Re-parse new code for compilability - if (!std::get<0>(parse(_stream, _linePrefix, _formatted, printed))) + if (!std::get<0>(parse(_stream, _linePrefix, _formatted, printed, *m_dialect))) { util::AnsiColorized(_stream, _formatted, {util::formatting::BOLD, util::formatting::CYAN}) << _linePrefix << "Result after the optimiser:" << std::endl; @@ -94,25 +93,3 @@ TestCase::TestResult YulOptimizerTest::run(std::ostream& _stream, std::string co return checkResult(_stream, _linePrefix, _formatted); } -std::pair, std::shared_ptr> YulOptimizerTest::parse( - std::ostream& _stream, - std::string const& _linePrefix, - bool const _formatted, - std::string const& _source -) -{ - ErrorList errors; - soltestAssert(m_dialect, ""); - std::shared_ptr object; - std::shared_ptr analysisInfo; - std::tie(object, analysisInfo) = yul::test::parse(_source, *m_dialect, errors); - if (!object || !analysisInfo || Error::containsErrors(errors)) - { - AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << std::endl; - CharStream charStream(_source, ""); - SourceReferenceFormatter{_stream, SingletonCharStreamProvider(charStream), true, false} - .printErrorInformation(errors); - return {}; - } - return {std::move(object), std::move(analysisInfo)}; -} diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 832b5dfb8f7c..161114384a84 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -48,10 +48,6 @@ class YulOptimizerTest: public solidity::frontend::test::EVMVersionRestrictedTes TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; private: - std::pair, std::shared_ptr> parse( - std::ostream& _stream, std::string const& _linePrefix, bool const _formatted, std::string const& _source - ); - std::string m_optimizerStep; Dialect const* m_dialect = nullptr; diff --git a/test/libyul/YulOptimizerTestCommon.cpp b/test/libyul/YulOptimizerTestCommon.cpp index 091a9a0b6cff..a3d5f887682b 100644 --- a/test/libyul/YulOptimizerTestCommon.cpp +++ b/test/libyul/YulOptimizerTestCommon.cpp @@ -75,13 +75,16 @@ using namespace solidity::frontend; YulOptimizerTestCommon::YulOptimizerTestCommon( std::shared_ptr _obj, - Dialect const& _dialect + Dialect const& _dialect, + Parser::DebugAttributeCache::Ptr _debugAttributeCache ) { m_object = _obj; m_ast = m_object->code; m_analysisInfo = m_object->analysisInfo; m_dialect = &_dialect; + if (_debugAttributeCache != nullptr) + m_context->debugAttributeCache = std::move(_debugAttributeCache); m_namedSteps = { {"disambiguator", [&]() { disambiguate(); }}, @@ -442,7 +445,7 @@ std::shared_ptr YulOptimizerTestCommon::run() void YulOptimizerTestCommon::disambiguate() { - *m_object->code = std::get(Disambiguator(*m_dialect, *m_analysisInfo)(*m_object->code)); + *m_object->code = std::get(Disambiguator(*m_dialect, *m_analysisInfo, {})(*m_object->code)); m_analysisInfo.reset(); updateContext(); } @@ -454,6 +457,7 @@ void YulOptimizerTestCommon::updateContext() *m_dialect, *m_nameDispenser, m_reservedIdentifiers, - frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment + frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment, + m_debugAttributeCache }); } diff --git a/test/libyul/YulOptimizerTestCommon.h b/test/libyul/YulOptimizerTestCommon.h index 3dce998c56cc..a78291cdd7f7 100644 --- a/test/libyul/YulOptimizerTestCommon.h +++ b/test/libyul/YulOptimizerTestCommon.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include @@ -40,7 +41,8 @@ class YulOptimizerTestCommon public: explicit YulOptimizerTestCommon( std::shared_ptr _obj, - Dialect const& _dialect + Dialect const& _dialect, + Parser::DebugAttributeCache::Ptr _debugAttributeCache = {} ); /// Sets optimiser step to be run to @param /// _optimiserStep. @@ -71,6 +73,8 @@ class YulOptimizerTestCommon std::shared_ptr m_ast; std::shared_ptr m_analysisInfo; std::map> m_namedSteps; + + Parser::DebugAttributeCache::Ptr m_debugAttributeCache; }; } diff --git a/test/libyul/yulOptimizerAssemblyTests/blockFlattener/basic.yul b/test/libyul/yulOptimizerAssemblyTests/blockFlattener/basic.yul new file mode 100644 index 000000000000..ff388bc0f07e --- /dev/null +++ b/test/libyul/yulOptimizerAssemblyTests/blockFlattener/basic.yul @@ -0,0 +1,70 @@ +/// @debug.set {"block": 0} +{ + /// @debug.set {"block": 1} + { + let _1 := mload(0) + let f_a := mload(1) + let f_r + /// @debug.set {"block": 2} + { + f_a := mload(f_a) + f_r := add(f_a, calldatasize()) + } + /// @debug.set {"block": 3} + let z := mload(/** @debug.set {"block": 4} **/2/** @debug.set {"block": 5} **/) + } +} +// ---- +// step: blockFlattener +// +// /// @debug.set {"block":0} +// { +// /// @debug.set {"block":1} +// { +// let _1 := mload(0) +// let f_a := mload(1) +// let f_r +// /// @debug.set {"block":2} +// f_a := mload(f_a) +// f_r := add(f_a, calldatasize()) +// /// @debug.set {"block":3} +// let z := mload(/** @debug.set {"block":4} */ 2) +// } +// } +// +// Assembly: +// /* "":92:93 */ +// 0x00 // @debug.set {"block":1} +// /* "":86:94 */ +// mload // @debug.set {"block":1} +// /* "":120:121 */ +// 0x01 // @debug.set {"block":1} +// /* "":114:122 */ +// mload // @debug.set {"block":1} +// /* "":131:138 */ +// 0x00 // @debug.set {"block":1} +// /* "":210:213 */ +// dup2 // @debug.set {"block":2} +// /* "":204:214 */ +// mload // @debug.set {"block":2} +// /* "":197:214 */ +// swap2 // @debug.set {"block":2} +// pop // @debug.set {"block":2} +// /* "":243:257 */ +// calldatasize // @debug.set {"block":2} +// /* "":238:241 */ +// dup3 // @debug.set {"block":2} +// /* "":234:258 */ +// add // @debug.set {"block":2} +// /* "":227:258 */ +// swap1 // @debug.set {"block":2} +// pop // @debug.set {"block":2} +// /* "":359:360 */ +// 0x02 // @debug.set {"block":4} +// /* "":322:392 */ +// mload // @debug.set {"block":3} +// /* "":66:398 */ +// pop // @debug.set {"block":1} +// pop // @debug.set {"block":1} +// pop // @debug.set {"block":1} +// pop // @debug.set {"block":1} diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt index 532a08d9fc55..0512b474c76c 100644 --- a/test/tools/CMakeLists.txt +++ b/test/tools/CMakeLists.txt @@ -46,6 +46,7 @@ add_executable(isoltest ../libyul/StackShufflingTest.cpp ../libyul/StackLayoutGeneratorTest.cpp ../libyul/YulOptimizerTest.cpp + ../libyul/YulOptimizerAssemblyTest.cpp ../libyul/YulOptimizerTestCommon.cpp ../libyul/YulInterpreterTest.cpp ) diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index d16b1da1969b..a8432c718131 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -251,7 +251,8 @@ class YulOpti m_dialect, m_nameDispenser, m_reservedIdentifiers, - solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment + solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment, + {} }; }; diff --git a/tools/yulPhaser/Program.cpp b/tools/yulPhaser/Program.cpp index 00abcc8e5c31..2f4632fe3073 100644 --- a/tools/yulPhaser/Program.cpp +++ b/tools/yulPhaser/Program.cpp @@ -195,7 +195,8 @@ std::unique_ptr Program::applyOptimisationSteps( _dialect, _nameDispenser, externallyUsedIdentifiers, - frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment + frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment, + {} }; for (std::string const& step: _optimisationSteps)