Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --asm-json output in assembler mode #14612

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

r0qs
Copy link
Member

@r0qs r0qs commented Oct 13, 2023

Extracted from #13673 based on this comment #13673 (comment)

@r0qs r0qs self-assigned this Oct 13, 2023
libevmasm/Assembly.cpp Outdated Show resolved Hide resolved
@r0qs r0qs added the feature label Oct 13, 2023
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from e766721 to bb5a4eb Compare October 16, 2023 13:29
@ekpyron ekpyron added this to the 0.8.22 milestone Oct 16, 2023
@nikola-matic
Copy link
Collaborator

nikola-matic commented Oct 16, 2023

Only took a cursory look, but I think you're missing tests in test/solc/CommandLineParser.cpp and test/solc/CommandLineInterface.cpp.

edit: Actually, perhaps not CommandLineParser since the option is already there.

@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from bb5a4eb to 60c808d Compare October 17, 2023 10:30
@r0qs
Copy link
Member Author

r0qs commented Oct 17, 2023

Only took a cursory look, but I think you're missing tests in test/solc/CommandLineParser.cpp and test/solc/CommandLineInterface.cpp.

edit: Actually, perhaps not CommandLineParser since the option is already there.

Good point. The option is there in the CommandLineParser tests, but not for the assembler mode. I will add it ;)

About the CommandLineInterface tests, I guess it is not needed, is it? There is already command-line tests to check the output. Or do you mean to add a unit test for the collectYulSourceIndices?

@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch 3 times, most recently from c1d82f8 to e1a7045 Compare October 18, 2023 12:53
Copy link
Collaborator

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some refinements that can be made to the code, but it is looking good.

libevmasm/Assembly.cpp Outdated Show resolved Hide resolved
solc/CommandLineInterface.cpp Outdated Show resolved Hide resolved
Changelog.md Outdated Show resolved Hide resolved
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch 2 times, most recently from 4ab1b97 to 0eaf85f Compare October 26, 2023 21:24
@r0qs r0qs removed this from the 0.8.22 milestone Oct 27, 2023
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from 0eaf85f to 25977ef Compare November 9, 2023 13:12
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from 25977ef to 3e18fdc Compare November 19, 2023 10:50
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from 3e18fdc to 477eb60 Compare November 29, 2023 19:16
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from 477eb60 to 0955cd0 Compare December 11, 2023 12:57
@nikola-matic nikola-matic force-pushed the add-asm-json-output-assembler-mode branch from 0955cd0 to 81083a7 Compare December 12, 2023 18:17
@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch from 5a2a274 to 180aaf4 Compare December 13, 2023 12:39
@nikola-matic
Copy link
Collaborator

@r0qs fix the changelog, and I'll approve.

solc/CommandLineInterface.cpp Outdated Show resolved Hide resolved
libevmasm/Assembly.cpp Outdated Show resolved Hide resolved
Comment on lines 1305 to 1315
std::map<std::string, unsigned> sourceIndices = collectYulSourceIndices(*stack.parserResult());
// If sourceIndices are empty, there were no source locations annotated in the yul source.
// In this case, we just add the filename of the yul file itself.
if (sourceIndices.empty())
sourceIndices[src.first] = 0;

sout() << util::jsonPrint(
removeNullMembers(assembly->assemblyJSON(sourceIndices)),
m_options.formatting.json
) << std::endl;
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this logic (without actual printing and removal of nulls of course) in YulStack, similar to how CompilerStack currently has sourceIndices() and assemblyJSON() methods. This will also make it easier to later reuse it in StandardJSON.

It's not a lot of logic, but at least the decision to stick the Yul source name in there is something that you may not even realize you should do when you need to write this again, so it should be encapsulated in a single place.

Copy link
Member Author

@r0qs r0qs Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I moved the logic to YulStack. But I was wondering if placing collectYulSourceIndices (now named sourceIndices) in yul::Object might be more appropriate than in YulStack. Also, maybe this piece of code:

if (sourceIndices.empty())
    sourceIndices[src.first] = 0;

Could be moved to collectYulSourceIndices as well, I haven't made this adjustment yet, as I am uncertain whether this behavior aligns with the expectations of sourceIndices in CompilerStack (i.e. if there is no source locations annotated in the yul source we should have the filename of the yul file pointing to index 0).
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. It would make sense as something like Object::collectSourceIndices() since it does not really depend on anything in the stack.

But then one might expect it to keep the strings shared via shared_ptr. Probably still fine not to, because we can always change it if needed, but the function right now really makes copies like crazy, while the sharing was meant to prevent that so it's a bit against the design of Object :) In the current form might be better to just leave it in the stack.

@r0qs r0qs force-pushed the add-asm-json-output-assembler-mode branch 2 times, most recently from cf927e7 to 59ed68a Compare December 18, 2023 20:24
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Jan 3, 2024
@nikola-matic nikola-matic removed the stale The issue/PR was marked as stale because it has been open for too long. label Jan 3, 2024
@ethereum ethereum deleted a comment from github-actions bot Jan 3, 2024
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Jun 6, 2024
@cameel cameel removed the stale The issue/PR was marked as stale because it has been open for too long. label Jun 7, 2024
@ethereum ethereum deleted a comment from github-actions bot Jun 7, 2024
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Jun 21, 2024
@cameel cameel removed the stale The issue/PR was marked as stale because it has been open for too long. label Jun 23, 2024
@ethereum ethereum deleted a comment from github-actions bot Jun 25, 2024
@aarlt aarlt force-pushed the add-asm-json-output-assembler-mode branch from de114b7 to 6ba226c Compare June 25, 2024 16:43
@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Jul 10, 2024
@ethereum ethereum deleted a comment from github-actions bot Jul 11, 2024
@aarlt aarlt removed the stale The issue/PR was marked as stale because it has been open for too long. label Jul 11, 2024
@aarlt aarlt force-pushed the add-asm-json-output-assembler-mode branch from 6ba226c to 0cc249d Compare July 11, 2024 05:35
libyul/YulStack.h Outdated Show resolved Hide resolved
libevmasm/Assembly.cpp Outdated Show resolved Hide resolved
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost ready to merge. Please rebase on top of develop, squash the commits a bit and fix the typo in the function name I found. Then we can merge.

@aarlt aarlt force-pushed the add-asm-json-output-assembler-mode branch 3 times, most recently from 9d27078 to 905ac49 Compare July 30, 2024 19:00
cameel
cameel previously approved these changes Jul 31, 2024
@cameel cameel force-pushed the add-asm-json-output-assembler-mode branch from 905ac49 to 15e1bbc Compare July 31, 2024 11:10
@@ -163,6 +166,8 @@ class YulStack: public langutil::CharStreamProvider
std::shared_ptr<yul::Object> m_parserResult;
langutil::ErrorList m_errors;
langutil::ErrorReporter m_errorReporter;

std::unique_ptr<std::string> m_sourceMappings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wait. Why did this come back? I remember removing it in one of my PRs because it was unused. Looks like rebasing error.

Co-authored-by: r0qs <[email protected]>
Co-authored-by: Kamil Śliwak <[email protected]>
@cameel cameel force-pushed the add-asm-json-output-assembler-mode branch from 15e1bbc to 9a1d740 Compare July 31, 2024 11:13
@cameel cameel enabled auto-merge July 31, 2024 11:16
@cameel cameel disabled auto-merge July 31, 2024 11:16
@cameel cameel changed the title Add --asm-json option in assembler mode Add --asm-json output in assembler mode Jul 31, 2024
@cameel cameel enabled auto-merge July 31, 2024 11:16
@cameel cameel merged commit 4c7e490 into develop Jul 31, 2024
72 checks passed
@cameel cameel deleted the add-asm-json-output-assembler-mode branch July 31, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

6 participants