asmfmt

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 6 Imported by: 0

README

asmfmt

Go Assembler Formatter

This will format your assembler code in a similar way that gofmt formats your Go code.

Read Introduction: asmfmt: Go Assembler Formatter

Build Status Windows Build Go Reference

See Example 1, Example 2, Example 3, or compare files in the testdata folder.

Status: STABLE. The format will only change if bugs are found. Please report any feedback in the issue section.

install

To install the standalone formatter, go get -u github.com/klauspost/asmfmt/cmd/asmfmt

There are also replacements for gofmt, goimports and goreturns, which will process .s files alongside your go files when formatting a package.

You can choose which to install:

go get -u github.com/klauspost/asmfmt/cmd/gofmt/...
go get -u github.com/klauspost/asmfmt/cmd/goimports/...
go get -u github.com/klauspost/asmfmt/cmd/goreturns/...

Note that these require Go 1.5 due to changes in import paths.

To test if the modified version is used, use goimports -help, and the output should look like this:

usage: goimports [flags] [path ...]
    [flags]
(this version includes asmfmt)

Using gofmt -w mypackage will Gofmt your Go files and format all assembler files as well.

updates

  • Jan 6, 2021: Fix C comments before line comments like VPCMPEQB Y8/*(DI)*/, Y0, Y1 // comment...
  • Aug 8, 2016: Don't indent comments before non-indented instruction.
  • Jun 10, 2016: Fixed crash with end-of-line comments that contained an end-of-block /* part.
  • Apr 14, 2016: Fix end of multiline comments in macro definitions.
  • Apr 14, 2016: Updated tools to Go 1.5+
  • Dec 21, 2015: Space before semi-colons in macro definitions is now trimmed.
  • Dec 21, 2015: Fix line comments in macro definitions (only valid with Go 1.5).
  • Dec 17, 2015: Comments are better aligned to the following section.
  • Dec 17, 2015: Clean semi-colons in multiple instruction per line.

emacs

To automatically format assembler, in .emacs add:

(defun asm-mode-setup ()
  (set (make-local-variable 'gofmt-command) "asmfmt")
  (add-hook 'before-save-hook 'gofmt nil t)
)

(add-hook 'asm-mode-hook 'asm-mode-setup)

usage

asmfmt [flags] [path ...]

The flags are similar to gofmt, except it will only process .s files:

	-d
		Do not print reformatted sources to standard output.
		If a file's formatting is different than asmfmt's, print diffs
		to standard output.
	-e
		Print all (including spurious) errors.
	-l
		Do not print reformatted sources to standard output.
		If a file's formatting is different from asmfmt's, print its name
		to standard output.
	-w
		Do not print reformatted sources to standard output.
		If a file's formatting is different from asmfmt's, overwrite it
		with asmfmt's version.

You should only run asmfmt on files that are assembler files. Assembler files cannot be positively identified, so it will mangle non-assembler files.

formatting

  • Automatic indentation.
  • It uses tabs for indentation and blanks for alignment.
  • 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.
  • Removes ; at end of line.
  • Forced newline before comments, except when preceded by label or another comment.
  • Forced newline before labels, except when preceded by comment.
  • Labels are on a separate lines, except for comments.
  • 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 and GLOBL, FUNCDATA, PCDATA and labels are level 0 indentation.
  • Aligns \ in multiline macros.
  • Whitespace before separating ; is removed. Space is inserted after, if followed by another instruction.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(in io.Reader) ([]byte, error)

Format the input and return the formatted data. If any error is encountered, no data will be returned.

Types

This section is empty.

Directories

Path Synopsis
cmd
asmfmt
Asmfmt formats Go Assembler files.
Asmfmt formats Go Assembler files.
gofmt
Gofmt formats Go programs.
Gofmt formats Go programs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL