From bc6b72c05da5fa30919645592baa47501200d587 Mon Sep 17 00:00:00 2001 From: Mohsin Kaleem Date: Sat, 22 Apr 2023 10:26:49 +0100 Subject: [PATCH] Add asmfmt formatter (#168) --- CHANGELOG.md | 3 ++ apheleia.el | 5 ++- test/formatters/installers/asmfmt.bash | 6 +++ test/formatters/samplecode/asmfmt/in.asm | 45 ++++++++++++++++++++++ test/formatters/samplecode/asmfmt/out.asm | 46 +++++++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 test/formatters/installers/asmfmt.bash create mode 100644 test/formatters/samplecode/asmfmt/in.asm create mode 100644 test/formatters/samplecode/asmfmt/out.asm diff --git a/CHANGELOG.md b/CHANGELOG.md index d50c10ce..4e8d922c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apheleia.el b/apheleia.el index 94b92851..5684990a 100644 --- a/apheleia.el +++ b/apheleia.el @@ -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") @@ -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) @@ -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) diff --git a/test/formatters/installers/asmfmt.bash b/test/formatters/installers/asmfmt.bash new file mode 100644 index 00000000..b4ca19a3 --- /dev/null +++ b/test/formatters/installers/asmfmt.bash @@ -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" diff --git a/test/formatters/samplecode/asmfmt/in.asm b/test/formatters/samplecode/asmfmt/in.asm new file mode 100644 index 00000000..61064ea5 --- /dev/null +++ b/test/formatters/samplecode/asmfmt/in.asm @@ -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 + + diff --git a/test/formatters/samplecode/asmfmt/out.asm b/test/formatters/samplecode/asmfmt/out.asm new file mode 100644 index 00000000..9425312e --- /dev/null +++ b/test/formatters/samplecode/asmfmt/out.asm @@ -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 +