Hi!
I was getting annoyed by all the different formatting styles of assembler code. My thought was, that we have “solved” that very nicely with Go, by having a standard formatter, so I set out to do the same for assembly files.
Here is the result: https://github.com/klauspost/asmfmt
It does the following reformatting:
- Automatic indentation.
- It uses tabs for indentation and blanks for alignment (as gofmt).
- It will remove trailing whitespace.
- It will align the first parameter.
- It will align all comments in a block.
- It will eliminate multiple blank lines.
- Forced newline before comments, except when preceded by label or another comment.
- Forced newline before labels, except when preceded by comment.
- Retains block breaks (newline between blocks).
- It will convert single line block comments to line comments.
- Line comments have a space after
//
, except if comment starts with+
. - There is always a space between parameters.
- Macros in the same file are tracked, and not included in parameter indentation.
-
TEXT
,DATA
andGLOBL
and labels are level 0 indentation. - Aligns
\
in multiline macros in blocks.
There is a standalone command, called asmfmt
, with similar syntax as gofmt, which operates on “.s” assembler files. There are replacements for gofmt
, goreturns
and goimports
, which also processes “.s” files when processing a package.
I am looking for feedback before “locking” the format. When testing, you should of course back up your files.
Does it do any stupid formatting? Does it break anything? Does it miss something?
Thanks!