klauspost / asmfmt

Go Assembler Formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues with comments with URLs

hughdavenport opened this issue · comments

This may be a bit trickier one to fix. I was intending on making a PR for it this morning but may leave it for another day sorry!

General issue is that having the following (where [COMMENT] is whatever the assembler uses to start a comment that isn't //, for example in fasm (and some other assmblers) this is ;).

[COMMENT] https://example.com

will add whitespace around the // as it thinks that is a comment

[COMMENT] https: // example.com

Looking at the docs of a few assemblers, seems comments are different everwhere...

I'm using fasm where the comment character is a semicolon (https://flatassembler.net/docs.php?article=manual#1.2.1).

Looking at the GAS manual, line comment chars are target dependent (https://sourceware.org/binutils/docs-2.38/as.html#Comments), with some targets using ; as a line comment, and some using it as a line separator...

NASM looks like it uses ; as a line comment char.

Looking through the code of asmfmt, it seems that ; is taken as a line separator, so for my use case I don't think it is appropriate to change that. I think a better way forward is somehow working out what the line comment char is for the file being formatted and using that. I think that I should discuss this with you on the best way forward before making a PR tbh.

What do you think?

For others that come looking, a workaround that I'm using is (works in v1.3.2).

db 0 ; Comment with URL should be quoted as well to not change formatting, e.g. "https://example.com"

@hughdavenport The only target is the Go assembler. I have no intentions of this being compatible with others.

Is this an issue with Go assembly? I don't recall ; being a comment indicator?

Oh no, I hadn't realised that this was just for GoAsm (and hadn't actually heard of that before!). Would you be open to accepting PR's that provide compatibility with other assemblers (such as NASM, GAS, or fasm)?