Skip to content

Commit

Permalink
Add asmfmt formatter (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohkale authored Apr 22, 2023
1 parent 49890c3 commit bc6b72c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ The format is based on [Keep a Changelog].
([#174]).
* [`gawk`](https://www.gnu.org/software/gawk/) for
[awk](https://en.wikipedia.org/wiki/AWK) ([#187]).
* [`asmfmt`](https://github.com/klauspost/asmfmt) for assembly ([#168]).

[#168]: https://github.com/radian-software/apheleia/pull/168
[#174]: https://github.com/radian-software/apheleia/pull/174
[#182]: https://github.com/radian-software/apheleia/pull/182
[#187]: https://github.com/radian-software/apheleia/pull/187


## 3.2 (released 2023-02-25)
### Features
* You can use `apheleia-inhibit` as a file-local variable to disable
Expand Down
5 changes: 4 additions & 1 deletion apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
:link '(emacs-commentary-link :tag "Commentary" "apheleia"))

(defcustom apheleia-formatters
'((bean-format . ("bean-format"))
'((asmfmt . ("asmfmt"))
(bean-format . ("bean-format"))
(black . ("black"
(when (apheleia-formatters-extension-p "pyi") "--pyi")
(apheleia-formatters-fill-column "--line-length")
Expand Down Expand Up @@ -189,6 +190,7 @@ rather than using this system."
(json-mode . prettier-json)
(json-ts-mode . prettier-json)
;; rest are alphabetical
(asm-mode . asmfmt)
(awk-mode . gawk)
(bash-ts-mode . shfmt)
(beancount-mode . bean-format)
Expand Down Expand Up @@ -224,6 +226,7 @@ rather than using this system."
(LaTeX-mode . latexindent)
(lua-mode . stylua)
(lisp-mode . lisp-indent)
(nasm-mode . asmfmt)
(nix-mode . nixfmt)
(purescript-mode . purs-tidy)
(python-mode . black)
Expand Down
6 changes: 6 additions & 0 deletions test/formatters/installers/asmfmt.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version=1.3.2

dest=$(mktemp -d)
curl -L "https://github.com/klauspost/asmfmt/releases/download/v$version/asmfmt-Linux_x86_64_$version.tar.gz" | tar -xvzC "$dest"
mv "$dest/asmfmt" /usr/local/bin/asmfmt
rm -rf "$dest"
45 changes: 45 additions & 0 deletions test/formatters/samplecode/asmfmt/in.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Taken from https://files.klauspost.com/diff.html

#include "zasm_GOOS_GOARCH.h"
#include "funcdata.h"
#include "textflag.h"

TEXT runtime·rt0_go(SB),NOSPLIT,$0
// copy arguments forward on an even stack
MOVQ DI, AX // argc
MOVQ SI, BX // argv
SUBQ $(4*8+7), SP // 2args 2auto
ANDQ $~15, SP
MOVQ AX, 16(SP)
MOVQ BX, 24(SP)
// create istack out of the given (operating system) stack.
// _cgo_init may update stackguard.
MOVQ $runtime·g0(SB), DI
LEAQ (-64*1024+104)(SP), BX
MOVQ BX, g_stackguard0(DI)
MOVQ BX, g_stackguard1(DI)
MOVQ BX, (g_stack+stack_lo)(DI)
MOVQ SP, (g_stack+stack_hi)(DI)

// find out information about the processor we're on
MOVQ $0, AX
CPUID
CMPQ AX, $0
JE nocpuinfo
MOVQ $1, AX
CPUID
MOVL CX, runtime·cpuid_ecx(SB)
MOVL DX, runtime·cpuid_edx(SB)
nocpuinfo:
// if there is an _cgo_init, call it.
MOVQ _cgo_init(SB), AX
TESTQ AX, AX
JZ needtls
// g0 already in DI
MOVQ DI, CX // Win64 uses CX for first parameter
MOVQ $setg_gcc<>(SB), SI
CALL AX


46 changes: 46 additions & 0 deletions test/formatters/samplecode/asmfmt/out.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Taken from https: // files.klauspost.com/diff.html

#include "zasm_GOOS_GOARCH.h"
#include "funcdata.h"
#include "textflag.h"

TEXT runtime·rt0_go(SB), NOSPLIT, $0
// copy arguments forward on an even stack
MOVQ DI, AX // argc
MOVQ SI, BX // argv
SUBQ $(4*8+7), SP // 2args 2auto
ANDQ $~15, SP
MOVQ AX, 16(SP)
MOVQ BX, 24(SP)

// create istack out of the given (operating system) stack.
// _cgo_init may update stackguard.
MOVQ $runtime·g0(SB), DI
LEAQ (-64*1024+104)(SP), BX
MOVQ BX, g_stackguard0(DI)
MOVQ BX, g_stackguard1(DI)
MOVQ BX, (g_stack+stack_lo)(DI)
MOVQ SP, (g_stack+stack_hi)(DI)

// find out information about the processor we're on
MOVQ $0, AX
CPUID
CMPQ AX, $0
JE nocpuinfo
MOVQ $1, AX
CPUID
MOVL CX, runtime·cpuid_ecx(SB)
MOVL DX, runtime·cpuid_edx(SB)

nocpuinfo:

// if there is an _cgo_init, call it.
MOVQ _cgo_init(SB), AX
TESTQ AX, AX
JZ needtls

// g0 already in DI
MOVQ DI, CX // Win64 uses CX for first parameter
MOVQ $setg_gcc<>(SB), SI
CALL AX

0 comments on commit bc6b72c

Please sign in to comment.