-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
e766721
to
bb5a4eb
Compare
Only took a cursory look, but I think you're missing tests in edit: Actually, perhaps not CommandLineParser since the option is already there. |
bb5a4eb
to
60c808d
Compare
Good point. The option is there in the About the |
c1d82f8
to
e1a7045
Compare
There was a problem hiding this 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.
4ab1b97
to
0eaf85f
Compare
0eaf85f
to
25977ef
Compare
25977ef
to
3e18fdc
Compare
3e18fdc
to
477eb60
Compare
477eb60
to
0955cd0
Compare
0955cd0
to
81083a7
Compare
5a2a274
to
180aaf4
Compare
@r0qs fix the changelog, and I'll approve. |
solc/CommandLineInterface.cpp
Outdated
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
).
.
There was a problem hiding this comment.
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.
test/cmdlineTests/asm_json_export_yul_arbitrary_source_index/output
Outdated
Show resolved
Hide resolved
cf927e7
to
59ed68a
Compare
de114b7
to
6ba226c
Compare
6ba226c
to
0cc249d
Compare
There was a problem hiding this 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.
9d27078
to
905ac49
Compare
905ac49
to
15e1bbc
Compare
libyul/YulStack.h
Outdated
@@ -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; |
There was a problem hiding this comment.
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]>
15e1bbc
to
9a1d740
Compare
Extracted from #13673 based on this comment #13673 (comment)