Skip to content

Commit

Permalink
ObjectDebugData: Expose a helper for formatting the @use-src comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel authored and clonker committed Aug 19, 2024
1 parent 8f237de commit 6654e87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 20 additions & 11 deletions libyul/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ std::string Object::toString(
yulAssert(hasCode(), "No code");
yulAssert(debugData, "No debug data");

std::string useSrcComment;

if (debugData->sourceNames)
useSrcComment =
"/// @use-src " +
joinHumanReadable(ranges::views::transform(*debugData->sourceNames, [](auto&& _pair) {
return std::to_string(_pair.first) + ":" + util::escapeAndQuoteString(*_pair.second);
})) +
"\n";

std::string inner = "code " + AsmPrinter(
_printingMode,
_dialect,
Expand All @@ -74,7 +64,11 @@ std::string Object::toString(
for (auto const& obj: subObjects)
inner += "\n" + obj->toString(_dialect, _printingMode, _debugInfoSelection, _soliditySourceProvider);

return useSrcComment + "object \"" + name + "\" {\n" + indent(inner) + "\n}";
return
debugData->formatUseSrcComment() +
"object \"" + name + "\" {\n" +
indent(inner) + "\n" +
"}";
}

Json Data::toJson() const
Expand All @@ -85,6 +79,21 @@ Json Data::toJson() const
return ret;
}

std::string ObjectDebugData::formatUseSrcComment() const
{
if (!sourceNames)
return "";

auto formatIdNamePair = [](auto&& _pair) {
return std::to_string(_pair.first) + ":" + util::escapeAndQuoteString(*_pair.second);
};

std::string serializedSourceNames = joinHumanReadable(
ranges::views::transform(*sourceNames, formatIdNamePair)
);
return "/// @use-src " + serializedSourceNames + "\n";
}

Json Object::toJson() const
{
yulAssert(hasCode(), "No code");
Expand Down
2 changes: 2 additions & 0 deletions libyul/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct Data: public ObjectNode
struct ObjectDebugData
{
std::optional<SourceNameMap> sourceNames = {};

std::string formatUseSrcComment() const;
};


Expand Down

0 comments on commit 6654e87

Please sign in to comment.