support inline and non-spaced comments in assembly

Go contains such inline comments, like:

	crypto/aes/gcm_ppc64x.s:129: VPMSUMD IN, HL, XL // H.lo·H.lo

We didn't notice since these comments were somewhat rare.
While here, "//" does not need to be followed by a space.

The code turns out to be pretty easy with strings.Cut.

Fixes #672.
pull/677/head
Daniel Martí 1 year ago
parent f7bde1d40e
commit 95ef0357da

@ -698,14 +698,15 @@ func transformAsm(args []string) ([]string, error) {
} }
// Leave "//" comments unchanged; they might be directives. // Leave "//" comments unchanged; they might be directives.
if strings.HasPrefix(strings.TrimSpace(line), "// ") { line, comment, hasComment := strings.Cut(line, "//")
buf.WriteString(line)
buf.WriteByte('\n')
continue
}
// Anything else is regular assembly; replace the names. // Anything else is regular assembly; replace the names.
replaceAsmNames(&buf, []byte(line)) replaceAsmNames(&buf, []byte(line))
if hasComment {
buf.WriteString("//")
buf.WriteString(comment)
}
buf.WriteByte('\n') buf.WriteByte('\n')
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {

@ -68,8 +68,9 @@ func main() {
#include "extra/garble_define2_amd64.h" #include "extra/garble_define2_amd64.h"
// A comment may include many·specialasm·runes and it's okay. // A comment may include many·specialasm·runes and it's okay.
// Or the same with leading whitespace: //No space: many·specialasm·runes.
// A comment may include many·specialasm·runes and it's okay. // Indented: many·specialasm·runes.
DATA bar+0(SB)/8, $0 // Inline: many·specialasm·runes.
// Reference an imported package by its package path. // Reference an imported package by its package path.
TEXT ·addJmpPkgPath(SB),$0-16 TEXT ·addJmpPkgPath(SB),$0-16

Loading…
Cancel
Save