-
Notifications
You must be signed in to change notification settings - Fork 160
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
AST formatter/pretty-printer #1003
Conversation
fdb5ea7
to
93cc387
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.
Looks good! Thank you! I left a few small comments inline.
assembly/src/ast/mod.rs
Outdated
/// # Panics | ||
/// | ||
/// Import info must be added before the program can be displayed. |
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.
nit: Let's add a brief description (above the # Panics
line) to say that this writs fully formatted MASM with correct indentation etc.
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.
Let's update the comment to:
Writes this [ProgramAst] as formatted MASM code into the formatter.
The formatted code puts each instruction on a separate line and preserves correct indentation
for instruction blocks.
# Panics
Panics if import info is not associated with this program.
Which command would this be relevant for? Or are you thinking about adding a new command - e.g., |
My plan was to add it as an option to an existing command, e.g., We could add it as a new command instead, if you think that's better. I'm happy to leave that to a future PR. |
Review comments addressed. |
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.
Looks good! Thank you! I left a few more comments inline. Once these are addressed, we can merge.
assembly/src/ast/mod.rs
Outdated
/// # Panics | ||
/// | ||
/// Import info must be added before the program can be displayed. |
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.
Let's update the comment to:
Writes this [ProgramAst] as formatted MASM code into the formatter.
The formatted code puts each instruction on a separate line and preserves correct indentation
for instruction blocks.
# Panics
Panics if import info is not associated with this program.
Yes, let's hold off on this for now. One of the reasons is that we'd erase all internal comments from the input file - and I'm not sure if that's a good idea. |
9735e5f
to
a3ebaae
Compare
Review comments addressed, and PR rebased. |
a3ebaae
to
e2ac922
Compare
Describe your changes
A default formatter is added to
ProgramAst
andModuleAst
. The formatter acts as a pretty-printer for the AST, including indentation and procedure names rather than procedure indices/ids.In order to perform indentation and to output legal assembly, a set of
Formattable
structs have been added. These keep track of the formatting context.Call instructions are handled separately from other instructions, because the procedure indices and ids must be transformed into procedure names.
No tests have been added at this stage, because the formatter will be tested when connected to the compiler. It might also be worthwhile to add a
-pp
or-format
option to the command-line assembler - comments regarding this feature would be appreciated.No documentation has been added, since this PR is not user-facing.
Checklist before requesting a review
next
according to naming convention.